Switch to builder pattern for ContentProviderBackupConfiguration
This commit is contained in:
parent
2497a94e4c
commit
e27a8b308f
4 changed files with 49 additions and 14 deletions
|
@ -61,8 +61,8 @@ class CreateBackupActivityController {
|
|||
String[] selectedPackageArray = selectedPackages.toArray(new String[selectedPackages.size() + 1]);
|
||||
selectedPackageArray[selectedPackageArray.length - 1] = "@pm@";
|
||||
|
||||
ContentProviderBackupConfiguration backupConfiguration = ContentProviderBackupConfigurationBuilder.
|
||||
buildDefaultConfiguration(parent, contentUri, selectedPackageArray.length);
|
||||
ContentProviderBackupConfiguration backupConfiguration = new ContentProviderBackupConfigurationBuilder()
|
||||
.setContext(parent).setOutputUri(contentUri).setPackages(selectedPackageArray).build();
|
||||
boolean success = initializeBackupTransport(backupConfiguration);
|
||||
|
||||
if (!success) {
|
||||
|
|
|
@ -93,8 +93,8 @@ class RestoreBackupActivityController {
|
|||
try {
|
||||
String[] selectedPackageArray = selectedPackages.toArray(new String[selectedPackages.size()]);
|
||||
|
||||
ContentProviderBackupConfiguration backupConfiguration = ContentProviderBackupConfigurationBuilder.
|
||||
buildDefaultConfiguration(parent, contentUri, selectedPackageArray.length);
|
||||
ContentProviderBackupConfiguration backupConfiguration = new ContentProviderBackupConfigurationBuilder().
|
||||
setContext(parent).setOutputUri(contentUri).setPackages(selectedPackageArray).build();
|
||||
boolean success = initializeBackupTransport(backupConfiguration);
|
||||
|
||||
if(!success) {
|
||||
|
|
|
@ -18,13 +18,13 @@ public class ContentProviderBackupConfiguration {
|
|||
|
||||
private final long backupSizeQuota;
|
||||
|
||||
private final int packageCount;
|
||||
private final String[] packages;
|
||||
|
||||
public ContentProviderBackupConfiguration(Context context, Uri uri, long backupSizeQuota, int packageCount) {
|
||||
ContentProviderBackupConfiguration(Context context, Uri uri, String[] packages, long backupSizeQuota) {
|
||||
this.context = context;
|
||||
this.uri = uri;
|
||||
this.packages = packages;
|
||||
this.backupSizeQuota = backupSizeQuota;
|
||||
this.packageCount = packageCount;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
|
@ -40,7 +40,7 @@ public class ContentProviderBackupConfiguration {
|
|||
}
|
||||
|
||||
public int getPackageCount() {
|
||||
return packageCount;
|
||||
return packages.length;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,11 +8,46 @@ import android.net.Uri;
|
|||
*/
|
||||
public class ContentProviderBackupConfigurationBuilder {
|
||||
|
||||
private static final long DEFAULT_BACKUP_SIZE_QUOTA = Long.MAX_VALUE;
|
||||
private Context context;
|
||||
|
||||
public static ContentProviderBackupConfiguration buildDefaultConfiguration(Context context, Uri outputUri,
|
||||
int packageCount) {
|
||||
return new ContentProviderBackupConfiguration(context, outputUri, DEFAULT_BACKUP_SIZE_QUOTA, packageCount);
|
||||
private Uri outputUri;
|
||||
|
||||
private String[] packages;
|
||||
|
||||
private long backupSizeQuota = Long.MAX_VALUE;
|
||||
|
||||
public ContentProviderBackupConfiguration build() {
|
||||
|
||||
if(context == null) {
|
||||
throw new IllegalArgumentException("Context must be set.");
|
||||
|
||||
} else if (outputUri == null) {
|
||||
throw new IllegalArgumentException("Output URI must be set.");
|
||||
|
||||
} else if(packages == null) {
|
||||
throw new IllegalArgumentException("Package list must be set.");
|
||||
}
|
||||
|
||||
return new ContentProviderBackupConfiguration(context, outputUri, packages, backupSizeQuota);
|
||||
}
|
||||
|
||||
public ContentProviderBackupConfigurationBuilder setContext(Context context) {
|
||||
this.context = context;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentProviderBackupConfigurationBuilder setOutputUri(Uri outputUri) {
|
||||
this.outputUri = outputUri;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentProviderBackupConfigurationBuilder setPackages(String[] packages) {
|
||||
this.packages = packages;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentProviderBackupConfigurationBuilder setBackupSizeQuota(long backupSizeQuota) {
|
||||
this.backupSizeQuota = backupSizeQuota;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue