BackupRestoreConfirmationpublic class BackupRestoreConfirmation extends android.app.Activity Confirm with the user that a requested full backup/restore operation is legitimate.
Any attempt to perform a full backup/restore will launch this UI and wait for a
designated timeout interval (nominally 30 seconds) for the user to confirm. If the
user fails to respond within the timeout period, or explicitly refuses the operation
within the UI presented here, no data will be transferred off the device.
Note that the fully scoped name of this class is baked into the backup manager service. |
Fields Summary |
---|
static final String | TAG | static final boolean | DEBUG | static final String | DID_ACKNOWLEDGE | static final int | MSG_START_BACKUP | static final int | MSG_BACKUP_PACKAGE | static final int | MSG_END_BACKUP | static final int | MSG_START_RESTORE | static final int | MSG_RESTORE_PACKAGE | static final int | MSG_END_RESTORE | static final int | MSG_TIMEOUT | android.os.Handler | mHandler | android.app.backup.IBackupManager | mBackupManager | android.os.storage.IMountService | mMountService | FullObserver | mObserver | int | mToken | boolean | mIsEncrypted | boolean | mDidAcknowledge | android.widget.TextView | mStatusView | android.widget.TextView | mCurPassword | android.widget.TextView | mEncPassword | android.widget.Button | mAllowButton | android.widget.Button | mDenyButton |
Methods Summary |
---|
boolean | deviceIsEncrypted()
try {
return mMountService.getEncryptionState()
!= IMountService.ENCRYPTION_STATE_NONE
&& mMountService.getPasswordType()
!= StorageManager.CRYPT_TYPE_DEFAULT;
} catch (Exception e) {
// If we can't talk to the mount service we have a serious problem; fail
// "secure" i.e. assuming that the device is encrypted.
Slog.e(TAG, "Unable to communicate with mount service: " + e.getMessage());
return true;
}
| boolean | haveBackupPassword()
try {
return mBackupManager.hasBackupPassword();
} catch (RemoteException e) {
return true; // in the failure case, assume we need one
}
| private void | monitorEncryptionPassword()
mAllowButton.setEnabled(false);
mEncPassword.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) { }
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void afterTextChanged(Editable s) {
mAllowButton.setEnabled(mEncPassword.getText().length() > 0);
}
});
| public void | onCreate(android.os.Bundle icicle)
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();
return;
}
mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE));
mMountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
mHandler = new ObserverHandler(getApplicationContext());
final Object oldObserver = getLastNonConfigurationInstance();
if (oldObserver == null) {
mObserver = new FullObserver(mHandler);
} else {
mObserver = (FullObserver) oldObserver;
mObserver.setHandler(mHandler);
}
setTitle(titleId);
setContentView(layoutId);
// Same resource IDs for each layout variant (backup / restore)
mStatusView = (TextView) findViewById(R.id.package_name);
mAllowButton = (Button) findViewById(R.id.button_allow);
mDenyButton = (Button) findViewById(R.id.button_deny);
mCurPassword = (TextView) findViewById(R.id.password);
mEncPassword = (TextView) findViewById(R.id.enc_password);
TextView curPwDesc = (TextView) findViewById(R.id.password_desc);
mAllowButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendAcknowledgement(mToken, true, mObserver);
mAllowButton.setEnabled(false);
mDenyButton.setEnabled(false);
}
});
mDenyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendAcknowledgement(mToken, false, mObserver);
mAllowButton.setEnabled(false);
mDenyButton.setEnabled(false);
finish();
}
});
// if we're a relaunch we may need to adjust button enable state
if (icicle != null) {
mDidAcknowledge = icicle.getBoolean(DID_ACKNOWLEDGE, false);
mAllowButton.setEnabled(!mDidAcknowledge);
mDenyButton.setEnabled(!mDidAcknowledge);
}
// We vary the password prompt depending on whether one is predefined, and whether
// the device is encrypted.
mIsEncrypted = deviceIsEncrypted();
if (!haveBackupPassword()) {
curPwDesc.setVisibility(View.GONE);
mCurPassword.setVisibility(View.GONE);
if (layoutId == R.layout.confirm_backup) {
TextView encPwDesc = (TextView) findViewById(R.id.enc_password_desc);
if (mIsEncrypted) {
encPwDesc.setText(R.string.backup_enc_password_required);
monitorEncryptionPassword();
} else {
encPwDesc.setText(R.string.backup_enc_password_optional);
}
}
}
| public java.lang.Object | onRetainNonConfigurationInstance()
return mObserver;
| protected void | onSaveInstanceState(android.os.Bundle outState)
outState.putBoolean(DID_ACKNOWLEDGE, mDidAcknowledge);
| void | sendAcknowledgement(int token, boolean allow, android.app.backup.IFullBackupRestoreObserver observer)
if (!mDidAcknowledge) {
mDidAcknowledge = true;
try {
CharSequence encPassword = mEncPassword.getText();
mBackupManager.acknowledgeFullBackupOrRestore(mToken,
allow,
String.valueOf(mCurPassword.getText()),
String.valueOf(encPassword),
mObserver);
} catch (RemoteException e) {
// TODO: bail gracefully if we can't contact the backup manager
}
}
|
|