summaryrefslogtreecommitdiff
path: root/packages/BackupRestoreConfirmation/src
diff options
context:
space:
mode:
authorAnnie Meng <anniemeng@google.com>2018-01-25 12:46:07 +0000
committerAnnie Meng <anniemeng@google.com>2018-01-29 12:43:20 +0000
commitd38749b6ff3f2cf35f656e16ee09eeafd8afb7c0 (patch)
treeb17ac405deae0a636ba3b279ad1f3726ac304cb4 /packages/BackupRestoreConfirmation/src
parentc41d14828faf780c786f967f1dd781d3fb883e6a (diff)
Update adb backup/restore confirmation activity on new intent
Now, if adb backup/restore is currently active and the activity is passed a new intent, the activity instance would be updated with the new intent. Same for if the activity is relaunched. Before, the activity would ignore intent changes and use old tokens and views, leading to backing up/restoring wrong files. Bug: 65723308 Test: adb backup -f old.ab -all; ctrl-c; adb backup -f new.ab -all; gts-tradefed run commandAndExit gts-dev -m GtsBackupHostTestCases Change-Id: Ifa11efecf82a682a578dab7e5795328ab7d0c054
Diffstat (limited to 'packages/BackupRestoreConfirmation/src')
-rw-r--r--packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java87
1 files changed, 65 insertions, 22 deletions
diff --git a/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java
index 9fa7a6646c9c..d6b6bf8d1e56 100644
--- a/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java
+++ b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java
@@ -52,7 +52,9 @@ public class BackupRestoreConfirmation extends Activity {
static final String TAG = "BackupRestoreConfirmation";
static final boolean DEBUG = true;
- static final String DID_ACKNOWLEDGE = "did_acknowledge";
+ static final String KEY_DID_ACKNOWLEDGE = "did_acknowledge";
+ static final String KEY_TOKEN = "token";
+ static final String KEY_ACTION = "action";
static final int MSG_START_BACKUP = 1;
static final int MSG_BACKUP_PACKAGE = 2;
@@ -69,6 +71,7 @@ public class BackupRestoreConfirmation extends Activity {
int mToken;
boolean mIsEncrypted;
boolean mDidAcknowledge;
+ String mAction;
TextView mStatusView;
TextView mCurPassword;
@@ -134,26 +137,9 @@ public class BackupRestoreConfirmation extends Activity {
super.onCreate(icicle);
final Intent intent = getIntent();
- final String action = intent.getAction();
- final int layoutId;
- final int titleId;
- if (action.equals(FullBackup.FULL_BACKUP_INTENT_ACTION)) {
- layoutId = R.layout.confirm_backup;
- titleId = R.string.backup_confirm_title;
- } else if (action.equals(FullBackup.FULL_RESTORE_INTENT_ACTION)) {
- layoutId = R.layout.confirm_restore;
- titleId = R.string.restore_confirm_title;
- } else {
- Slog.w(TAG, "Backup/restore confirmation activity launched with invalid action!");
- finish();
- return;
- }
-
- mToken = intent.getIntExtra(FullBackup.CONF_TOKEN_INTENT_EXTRA, -1);
- if (mToken < 0) {
- Slog.e(TAG, "Backup/restore confirmation requested but no token passed!");
- finish();
+ boolean tokenValid = setTokenOrFinish(intent, icicle);
+ if (!tokenValid) { // already called finish()
return;
}
@@ -169,6 +155,61 @@ public class BackupRestoreConfirmation extends Activity {
mObserver.setHandler(mHandler);
}
+ setViews(intent, icicle);
+ }
+
+ @Override
+ public void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ setIntent(intent);
+
+ boolean tokenValid = setTokenOrFinish(intent, null);
+ if (!tokenValid) { // already called finish()
+ return;
+ }
+
+ setViews(intent, null);
+ }
+
+ private boolean setTokenOrFinish(Intent intent, Bundle icicle) {
+ mToken = intent.getIntExtra(FullBackup.CONF_TOKEN_INTENT_EXTRA, -1);
+
+ // for relaunch, we try to use the last token before exit
+ if (icicle != null) {
+ mToken = icicle.getInt(KEY_TOKEN, mToken);
+ }
+
+ if (mToken < 0) {
+ Slog.e(TAG, "Backup/restore confirmation requested but no token passed!");
+ finish();
+ return false;
+ }
+
+ return true;
+ }
+
+ private void setViews(Intent intent, Bundle icicle) {
+ mAction = intent.getAction();
+
+ // for relaunch, we try to use the last action before exit
+ if (icicle != null) {
+ mAction = icicle.getString(KEY_ACTION, mAction);
+ }
+
+ final int layoutId;
+ final int titleId;
+ if (mAction.equals(FullBackup.FULL_BACKUP_INTENT_ACTION)) {
+ layoutId = R.layout.confirm_backup;
+ titleId = R.string.backup_confirm_title;
+ } else if (mAction.equals(FullBackup.FULL_RESTORE_INTENT_ACTION)) {
+ layoutId = R.layout.confirm_restore;
+ titleId = R.string.restore_confirm_title;
+ } else {
+ Slog.w(TAG, "Backup/restore confirmation activity launched with invalid action!");
+ finish();
+ return;
+ }
+
setTitle(titleId);
setContentView(layoutId);
@@ -202,7 +243,7 @@ public class BackupRestoreConfirmation extends Activity {
// if we're a relaunch we may need to adjust button enable state
if (icicle != null) {
- mDidAcknowledge = icicle.getBoolean(DID_ACKNOWLEDGE, false);
+ mDidAcknowledge = icicle.getBoolean(KEY_DID_ACKNOWLEDGE, false);
mAllowButton.setEnabled(!mDidAcknowledge);
mDenyButton.setEnabled(!mDidAcknowledge);
}
@@ -249,7 +290,9 @@ public class BackupRestoreConfirmation extends Activity {
@Override
protected void onSaveInstanceState(Bundle outState) {
- outState.putBoolean(DID_ACKNOWLEDGE, mDidAcknowledge);
+ outState.putBoolean(KEY_DID_ACKNOWLEDGE, mDidAcknowledge);
+ outState.putInt(KEY_TOKEN, mToken);
+ outState.putString(KEY_ACTION, mAction);
}
void sendAcknowledgement(int token, boolean allow, IFullBackupRestoreObserver observer) {