Add initialization functions to ConfigurableBackupTransport

This commit is contained in:
Steve Soltys 2017-10-09 20:02:41 -04:00
parent 0a978c37e8
commit facb7029b9
5 changed files with 44 additions and 33 deletions

View file

@ -6,7 +6,6 @@ import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.stevesoltys.backup.R;
import com.stevesoltys.backup.session.backup.BackupResult;
import com.stevesoltys.backup.session.backup.BackupSession;
@ -63,12 +62,11 @@ class BackupObserver implements BackupSessionObserver {
public void backupSessionCompleted(BackupSession backupSession, BackupResult backupResult) {
ConfigurableBackupTransport backupTransport = ConfigurableBackupTransportService.getBackupTransport();
if (backupTransport.getRestoreComponent() == null || backupTransport.getBackupComponent() == null) {
if (!backupTransport.isActive()) {
return;
}
backupTransport.setBackupComponent(null);
backupTransport.setRestoreComponent(null);
backupTransport.reset();
context.runOnUiThread(() -> {
if (backupResult == BackupResult.SUCCESS) {

View file

@ -15,12 +15,13 @@ import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.Toast;
import com.stevesoltys.backup.R;
import com.stevesoltys.backup.session.BackupManagerController;
import com.stevesoltys.backup.session.backup.BackupSession;
import com.stevesoltys.backup.transport.ConfigurableBackupTransport;
import com.stevesoltys.backup.transport.ConfigurableBackupTransportService;
import com.stevesoltys.backup.transport.component.BackupComponent;
import com.stevesoltys.backup.transport.component.RestoreComponent;
import com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfiguration;
import com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfigurationBuilder;
import com.stevesoltys.backup.transport.component.provider.backup.ContentProviderBackupComponent;
@ -88,12 +89,13 @@ class CreateBackupActivityController {
private boolean initializeBackupTransport(ContentProviderBackupConfiguration configuration) {
ConfigurableBackupTransport backupTransport = ConfigurableBackupTransportService.getBackupTransport();
if (backupTransport.getBackupComponent() != null || backupTransport.getRestoreComponent() != null) {
if (backupTransport.isActive()) {
return false;
}
backupTransport.setBackupComponent(new ContentProviderBackupComponent(configuration));
backupTransport.setRestoreComponent(new ContentProviderRestoreComponent(configuration));
BackupComponent backupComponent = new ContentProviderBackupComponent(configuration);
RestoreComponent restoreComponent = new ContentProviderRestoreComponent(configuration);
backupTransport.initialize(backupComponent, restoreComponent);
return true;
}

View file

@ -15,16 +15,18 @@ import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.Toast;
import com.stevesoltys.backup.R;
import com.stevesoltys.backup.session.BackupManagerController;
import com.stevesoltys.backup.session.restore.RestoreSession;
import com.stevesoltys.backup.transport.ConfigurableBackupTransport;
import com.stevesoltys.backup.transport.ConfigurableBackupTransportService;
import com.stevesoltys.backup.transport.component.BackupComponent;
import com.stevesoltys.backup.transport.component.RestoreComponent;
import com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfiguration;
import com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfigurationBuilder;
import com.stevesoltys.backup.transport.component.provider.backup.ContentProviderBackupComponent;
import com.stevesoltys.backup.transport.component.provider.restore.ContentProviderRestoreComponent;
import libcore.io.IoUtils;
import java.io.File;
import java.io.FileInputStream;
@ -34,8 +36,6 @@ import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import libcore.io.IoUtils;
import static com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfiguration.FULL_BACKUP_DIRECTORY;
/**
@ -120,12 +120,13 @@ class RestoreBackupActivityController {
private boolean initializeBackupTransport(ContentProviderBackupConfiguration configuration) {
ConfigurableBackupTransport backupTransport = ConfigurableBackupTransportService.getBackupTransport();
if(backupTransport.getBackupComponent() != null || backupTransport.getRestoreComponent() != null) {
if(backupTransport.isActive()) {
return false;
}
backupTransport.setBackupComponent(new ContentProviderBackupComponent(configuration));
backupTransport.setRestoreComponent(new ContentProviderRestoreComponent(configuration));
BackupComponent backupComponent = new ContentProviderBackupComponent(configuration);
RestoreComponent restoreComponent = new ContentProviderRestoreComponent(configuration);
backupTransport.initialize(backupComponent, restoreComponent);
return true;
}

View file

@ -55,12 +55,11 @@ class RestoreObserver implements RestoreSessionObserver {
public void restoreSessionCompleted(RestoreResult restoreResult) {
ConfigurableBackupTransport backupTransport = ConfigurableBackupTransportService.getBackupTransport();
if(backupTransport.getRestoreComponent() == null || backupTransport.getBackupComponent() == null) {
if(!backupTransport.isActive()) {
return;
}
backupTransport.setBackupComponent(null);
backupTransport.setRestoreComponent(null);
backupTransport.reset();
context.runOnUiThread(() -> {
if (restoreResult == RestoreResult.SUCCESS) {

View file

@ -6,6 +6,7 @@ import android.app.backup.RestoreSet;
import android.content.pm.PackageInfo;
import android.os.ParcelFileDescriptor;
import com.android.internal.util.Preconditions;
import com.stevesoltys.backup.transport.component.BackupComponent;
import com.stevesoltys.backup.transport.component.RestoreComponent;
@ -26,6 +27,32 @@ public class ConfigurableBackupTransport extends BackupTransport {
restoreComponent = null;
}
public void initialize(BackupComponent backupComponent, RestoreComponent restoreComponent) {
Preconditions.checkNotNull(backupComponent);
Preconditions.checkNotNull(restoreComponent);
Preconditions.checkState(!isActive());
this.restoreComponent = restoreComponent;
this.backupComponent = backupComponent;
}
public void reset() {
backupComponent = null;
restoreComponent = null;
}
public boolean isActive() {
return backupComponent != null && restoreComponent != null;
}
public BackupComponent getBackupComponent() {
return backupComponent;
}
public RestoreComponent getRestoreComponent() {
return restoreComponent;
}
@Override
public String transportDirName() {
return TRANSPORT_DIRECTORY_NAME;
@ -141,20 +168,4 @@ public class ConfigurableBackupTransport extends BackupTransport {
public void finishRestore() {
restoreComponent.finishRestore();
}
public BackupComponent getBackupComponent() {
return backupComponent;
}
public void setBackupComponent(BackupComponent backupComponent) {
this.backupComponent = backupComponent;
}
public RestoreComponent getRestoreComponent() {
return restoreComponent;
}
public void setRestoreComponent(RestoreComponent restoreComponent) {
this.restoreComponent = restoreComponent;
}
}