public class DriveServiceHelper
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
APP_FOLDER
App folder on Drive
|
private java.lang.String |
ERR_INTERNAL
Error accessing Drive API
|
private java.lang.String |
ERR_PERMISSION
No permissions for Drive
|
private android.content.Context |
mAppCtxt
Global Application Context
|
private java.lang.String |
MIME_TYPE
Mime type of backups
|
private static DriveServiceHelper |
sInstance
Static instance
|
private java.lang.String |
TAG
Class Indentifier
|
private int |
WAIT_TIME_SECS
Timeout for task completion
|
Modifier | Constructor and Description |
---|---|
private |
DriveServiceHelper(android.content.Context context) |
Modifier and Type | Method and Description |
---|---|
private void |
checkAppFolderPermission()
Check permissions for our appFolder
|
(package private) Backup |
createBackup(java.lang.String filename,
byte[] data)
Create a new backup
|
private com.google.android.gms.tasks.Task<com.google.api.services.drive.model.File> |
createFile(com.google.api.services.drive.Drive service,
java.lang.String fileName,
java.util.Map<java.lang.String,java.lang.String> appProperties)
Create a zip file in the user's App directory.
|
(package private) void |
deleteBackup(java.lang.String fileId)
Delete a backup
|
private com.google.android.gms.tasks.Task<java.lang.Void> |
deleteFile(com.google.api.services.drive.Drive service,
java.lang.String fileId)
Delete a file on Drive
|
(package private) BackupContents |
getBackupContents(java.lang.String fileId)
Get the contents of a backup
|
java.util.List<Backup> |
getBackups()
Retrieve all the backups in our appFolder
|
private com.google.android.gms.tasks.Task<BackupContents> |
getContents(com.google.api.services.drive.Drive service,
java.lang.String fileId)
Get the contents of a backup
|
private com.google.api.services.drive.Drive |
getDriveService()
get the DriveService
|
static DriveServiceHelper |
INST(android.content.Context context)
Lazily create our instance
|
private com.google.android.gms.tasks.Task<com.google.api.services.drive.model.FileList> |
listFiles(com.google.api.services.drive.Drive service)
Get the files in the user's App Data folder
|
boolean |
noAppFolderPermission()
No permission for our appFolder
|
private com.google.android.gms.tasks.Task<com.google.api.services.drive.model.File> |
saveContents(com.google.api.services.drive.Drive service,
java.lang.String fileId,
java.lang.String filename,
byte[] contents)
Seve a file and its contents
|
(package private) void |
updateBackup(java.lang.String fileId,
java.lang.String filename,
byte[] data)
Update a backup
|
private static DriveServiceHelper sInstance
private final android.content.Context mAppCtxt
private final int WAIT_TIME_SECS
private final java.lang.String MIME_TYPE
private final java.lang.String ERR_PERMISSION
private final java.lang.String ERR_INTERNAL
private final java.lang.String TAG
private final java.lang.String APP_FOLDER
private DriveServiceHelper(@NonNull android.content.Context context)
public static DriveServiceHelper INST(@NonNull android.content.Context context)
context
- any old contextpublic boolean noAppFolderPermission()
@NonNull public java.util.List<Backup> getBackups() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException, DriveException
java.util.concurrent.ExecutionException
java.lang.InterruptedException
java.util.concurrent.TimeoutException
DriveException
@NonNull Backup createBackup(java.lang.String filename, byte[] data) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException, DriveException
filename
- name of filedata
- contents of filejava.util.concurrent.ExecutionException
java.lang.InterruptedException
java.util.concurrent.TimeoutException
DriveException
void updateBackup(@NonNull java.lang.String fileId, java.lang.String filename, @NonNull byte[] data) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException, DriveException
fileId
- file to updatefilename
- file to updatedata
- update datajava.util.concurrent.ExecutionException
java.lang.InterruptedException
java.util.concurrent.TimeoutException
DriveException
void deleteBackup(java.lang.String fileId) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException, DriveException
fileId
- name of filejava.util.concurrent.ExecutionException
java.lang.InterruptedException
java.util.concurrent.TimeoutException
DriveException
@NonNull BackupContents getBackupContents(java.lang.String fileId) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.util.concurrent.TimeoutException, DriveException
fileId
- file to retrievejava.util.concurrent.ExecutionException
java.lang.InterruptedException
java.util.concurrent.TimeoutException
DriveException
private com.google.android.gms.tasks.Task<com.google.api.services.drive.model.File> createFile(com.google.api.services.drive.Drive service, java.lang.String fileName, java.util.Map<java.lang.String,java.lang.String> appProperties)
private com.google.android.gms.tasks.Task<com.google.api.services.drive.model.FileList> listFiles(com.google.api.services.drive.Drive service)
private com.google.android.gms.tasks.Task<BackupContents> getContents(com.google.api.services.drive.Drive service, java.lang.String fileId)
private com.google.android.gms.tasks.Task<com.google.api.services.drive.model.File> saveContents(com.google.api.services.drive.Drive service, java.lang.String fileId, java.lang.String filename, byte[] contents)
private com.google.android.gms.tasks.Task<java.lang.Void> deleteFile(com.google.api.services.drive.Drive service, java.lang.String fileId)
private void checkAppFolderPermission() throws DriveException
DriveException
@NonNull private com.google.api.services.drive.Drive getDriveService() throws DriveException
DriveException