From 7fcd9aa09102fbf75515dc6b34448a6639f98ef3 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 12 Jun 2019 09:19:38 -0300 Subject: [PATCH] Resolve review comments about backup compontent refactoring --- README.md | 7 ++++++- .../backup/activity/MainActivityController.java | 11 ++++++++--- .../restore/RestoreBackupActivityController.java | 2 +- .../backup/service/backup/BackupJobService.java | 3 ++- .../backup/transport/ConfigurableBackupTransport.java | 6 ------ .../provider/ContentProviderBackupComponent.java | 6 +++--- .../provider/ContentProviderBackupConstants.java | 11 +++++++++-- .../provider/ContentProviderRestoreComponent.java | 4 ++-- 8 files changed, 31 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index fca0dc89..4129ce8b 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,15 @@ AOSP. ## What makes this different? This application is compiled with the operating system and does not require a rooted device for use. It uses the same -internal APIs as `adb backup` and only requires one permission: `android.permission.BACKUP`. +internal APIs as `adb backup` and only requires the permission `android.permission.BACKUP` for this. ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/stevesoltys/backup. +## Permissions + +* `android.permission.BACKUP` to be allowed to back up apps +* `android.permission.RECEIVE_BOOT_COMPLETED` to schedule automatic backups after boot + ## License This application is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). diff --git a/app/src/main/java/com/stevesoltys/backup/activity/MainActivityController.java b/app/src/main/java/com/stevesoltys/backup/activity/MainActivityController.java index d9e13fff..5f8cea31 100644 --- a/app/src/main/java/com/stevesoltys/backup/activity/MainActivityController.java +++ b/app/src/main/java/com/stevesoltys/backup/activity/MainActivityController.java @@ -5,7 +5,6 @@ import android.app.job.JobInfo; import android.app.job.JobScheduler; import android.content.ActivityNotFoundException; import android.content.ComponentName; -import android.content.ContentResolver; import android.content.Intent; import android.net.Uri; import android.widget.Toast; @@ -89,6 +88,8 @@ public class MainActivityController { Toast.makeText(parent, "Please make at least one manual backup first.", Toast.LENGTH_SHORT).show(); return false; } + + // schedule backups final ComponentName serviceName = new ComponentName(parent, BackupJobService.class); JobInfo job = new JobInfo.Builder(JOB_ID_BACKGROUND_BACKUP, serviceName) .setRequiredNetworkType(NETWORK_TYPE_UNMETERED) @@ -100,8 +101,13 @@ public class MainActivityController { .build(); JobScheduler scheduler = requireNonNull(parent.getSystemService(JobScheduler.class)); scheduler.schedule(job); + + // remember that backups were scheduled setBackupsScheduled(parent); + + // show Toast informing the user Toast.makeText(parent, "Backups will run automatically now", Toast.LENGTH_SHORT).show(); + return true; } @@ -116,12 +122,11 @@ public class MainActivityController { } Uri folderUri = result.getData(); - ContentResolver contentResolver = parent.getContentResolver(); // persist permission to access backup folder across reboots int takeFlags = result.getFlags() & (FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION); - contentResolver.takePersistableUriPermission(folderUri, takeFlags); + parent.getContentResolver().takePersistableUriPermission(folderUri, takeFlags); // store backup folder location in settings setBackupFolderUri(parent, folderUri); diff --git a/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivityController.java b/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivityController.java index ed3ed757..916a57dd 100644 --- a/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivityController.java +++ b/app/src/main/java/com/stevesoltys/backup/activity/restore/RestoreBackupActivityController.java @@ -29,7 +29,7 @@ import java.util.zip.ZipInputStream; import libcore.io.IoUtils; -import static com.stevesoltys.backup.transport.ConfigurableBackupTransport.DEFAULT_FULL_BACKUP_DIRECTORY; +import static com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConstants.DEFAULT_FULL_BACKUP_DIRECTORY; /** * @author Steve Soltys diff --git a/app/src/main/java/com/stevesoltys/backup/service/backup/BackupJobService.java b/app/src/main/java/com/stevesoltys/backup/service/backup/BackupJobService.java index 67260600..0c62be8f 100644 --- a/app/src/main/java/com/stevesoltys/backup/service/backup/BackupJobService.java +++ b/app/src/main/java/com/stevesoltys/backup/service/backup/BackupJobService.java @@ -30,6 +30,7 @@ public class BackupJobService extends JobService { ); private final IBackupManager backupManager; + private final PackageService packageService = new PackageService(); public BackupJobService() { backupManager = IBackupManager.Stub.asInterface(getService("backup")); @@ -40,7 +41,7 @@ public class BackupJobService extends JobService { Log.i(TAG, "Triggering full backup"); startService(new Intent(this, ConfigurableBackupTransportService.class)); try { - LinkedList packages = new LinkedList<>(new PackageService().getEligiblePackages()); + LinkedList packages = new LinkedList<>(packageService.getEligiblePackages()); packages.removeAll(IGNORED_PACKAGES); // TODO use an observer to know when backups fail String[] packageArray = packages.toArray(new String[packages.size()]); diff --git a/app/src/main/java/com/stevesoltys/backup/transport/ConfigurableBackupTransport.java b/app/src/main/java/com/stevesoltys/backup/transport/ConfigurableBackupTransport.java index 505b0670..69c92f31 100644 --- a/app/src/main/java/com/stevesoltys/backup/transport/ConfigurableBackupTransport.java +++ b/app/src/main/java/com/stevesoltys/backup/transport/ConfigurableBackupTransport.java @@ -21,12 +21,6 @@ public class ConfigurableBackupTransport extends BackupTransport { private static final String TRANSPORT_DIRECTORY_NAME = "com.stevesoltys.backup.transport.ConfigurableBackupTransport"; - public static final String DEFAULT_FULL_BACKUP_DIRECTORY = "full/"; - - public static final String DEFAULT_INCREMENTAL_BACKUP_DIRECTORY = "incr/"; - - public static final long DEFAULT_BACKUP_QUOTA = Long.MAX_VALUE; - private final BackupComponent backupComponent; private final RestoreComponent restoreComponent; diff --git a/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderBackupComponent.java b/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderBackupComponent.java index e964ec61..2f6a677c 100644 --- a/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderBackupComponent.java +++ b/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderBackupComponent.java @@ -39,9 +39,9 @@ import static android.provider.DocumentsContract.buildDocumentUriUsingTree; import static android.provider.DocumentsContract.createDocument; import static android.provider.DocumentsContract.getTreeDocumentId; import static com.stevesoltys.backup.activity.MainActivityController.DOCUMENT_MIME_TYPE; -import static com.stevesoltys.backup.transport.ConfigurableBackupTransport.DEFAULT_BACKUP_QUOTA; -import static com.stevesoltys.backup.transport.ConfigurableBackupTransport.DEFAULT_FULL_BACKUP_DIRECTORY; -import static com.stevesoltys.backup.transport.ConfigurableBackupTransport.DEFAULT_INCREMENTAL_BACKUP_DIRECTORY; +import static com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConstants.DEFAULT_BACKUP_QUOTA; +import static com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConstants.DEFAULT_FULL_BACKUP_DIRECTORY; +import static com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConstants.DEFAULT_INCREMENTAL_BACKUP_DIRECTORY; import static java.util.Objects.requireNonNull; /** diff --git a/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderBackupConstants.java b/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderBackupConstants.java index b87e30a8..4020f9d9 100644 --- a/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderBackupConstants.java +++ b/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderBackupConstants.java @@ -3,7 +3,14 @@ package com.stevesoltys.backup.transport.component.provider; /** * @author Steve Soltys */ -class ContentProviderBackupConstants { +public interface ContentProviderBackupConstants { + + String SALT_FILE_PATH = "salt"; + + String DEFAULT_FULL_BACKUP_DIRECTORY = "full/"; + + String DEFAULT_INCREMENTAL_BACKUP_DIRECTORY = "incr/"; + + long DEFAULT_BACKUP_QUOTA = Long.MAX_VALUE; - static final String SALT_FILE_PATH = "salt"; } diff --git a/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderRestoreComponent.java b/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderRestoreComponent.java index 05f1abcd..f983bed9 100644 --- a/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderRestoreComponent.java +++ b/app/src/main/java/com/stevesoltys/backup/transport/component/provider/ContentProviderRestoreComponent.java @@ -41,8 +41,8 @@ import static android.app.backup.BackupTransport.TRANSPORT_OK; import static android.app.backup.BackupTransport.TRANSPORT_PACKAGE_REJECTED; import static android.app.backup.RestoreDescription.TYPE_FULL_STREAM; import static android.app.backup.RestoreDescription.TYPE_KEY_VALUE; -import static com.stevesoltys.backup.transport.ConfigurableBackupTransport.DEFAULT_FULL_BACKUP_DIRECTORY; -import static com.stevesoltys.backup.transport.ConfigurableBackupTransport.DEFAULT_INCREMENTAL_BACKUP_DIRECTORY; +import static com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConstants.DEFAULT_FULL_BACKUP_DIRECTORY; +import static com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConstants.DEFAULT_INCREMENTAL_BACKUP_DIRECTORY; import static java.util.Objects.requireNonNull; /**