Resolve review comments about backup compontent refactoring
This commit is contained in:
parent
92ce6c1a5c
commit
7fcd9aa091
8 changed files with 31 additions and 19 deletions
|
@ -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).
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<String> packages = new LinkedList<>(new PackageService().getEligiblePackages());
|
||||
LinkedList<String> 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()]);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue