Add backup password setting UI

Bug 4901637

Change-Id: I515f1475d3675285a830b4b5ddd1f011f1b56e3a
This commit is contained in:
Christopher Tate
2011-07-25 12:09:10 -07:00
parent 95ce1898c5
commit 4f33878f20
6 changed files with 244 additions and 2 deletions

View File

@@ -43,11 +43,13 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
private static final String BACKUP_DATA = "backup_data";
private static final String AUTO_RESTORE = "auto_restore";
private static final String CONFIGURE_ACCOUNT = "configure_account";
private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password";
private IBackupManager mBackupManager;
private CheckBoxPreference mBackup;
private CheckBoxPreference mAutoRestore;
private Dialog mConfirmDialog;
private PreferenceScreen mConfigure;
private PreferenceScreen mPassword;
private static final int DIALOG_ERASE_BACKUP = 2;
private int mDialogType;
@@ -64,6 +66,7 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
mBackup = (CheckBoxPreference) screen.findPreference(BACKUP_DATA);
mAutoRestore = (CheckBoxPreference) screen.findPreference(AUTO_RESTORE);
mConfigure = (PreferenceScreen) screen.findPreference(CONFIGURE_ACCOUNT);
mPassword = (PreferenceScreen) screen.findPreference(LOCAL_BACKUP_PASSWORD);
// Vendor specific
if (getActivity().getPackageManager().
@@ -158,7 +161,9 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
mConfigure.setEnabled(configureEnabled);
mConfigure.setIntent(configIntent);
setConfigureSummary(configSummary);
}
updatePasswordSummary();
}
private void setConfigureSummary(String summary) {
if (summary != null) {
@@ -178,6 +183,18 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
}
}
private void updatePasswordSummary() {
try {
if (mBackupManager.hasBackupPassword()) {
mPassword.setSummary(R.string.local_backup_password_summary_change);
} else {
mPassword.setSummary(R.string.local_backup_password_summary_none);
}
} catch (RemoteException e) {
// Not much we can do here
}
}
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
//updateProviders();

View File

@@ -0,0 +1,106 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings;
import android.app.Activity;
import android.app.backup.IBackupManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class SetFullBackupPassword extends Activity {
static final String TAG = "SetFullBackupPassword";
IBackupManager mBackupManager;
TextView mCurrentPw, mNewPw, mConfirmNewPw;
Button mCancel, mSet;
OnClickListener mButtonListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (v == mSet) {
final String curPw = mCurrentPw.getText().toString();
final String newPw = mNewPw.getText().toString();
final String confirmPw = mConfirmNewPw.getText().toString();
if (!newPw.equals(confirmPw)) {
// Mismatch between new pw and its confirmation re-entry
Log.i(TAG, "password mismatch");
Toast.makeText(SetFullBackupPassword.this,
"!!! New password and confirmation don't match !!!",
Toast.LENGTH_LONG).show();
return;
}
// TODO: should we distinguish cases of has/hasn't set a pw before?
if (setBackupPassword(curPw, newPw)) {
// success
Log.i(TAG, "password set successfully");
Toast.makeText(SetFullBackupPassword.this,
"!!! New backup password set !!!",
Toast.LENGTH_LONG).show();
finish();
} else {
// failure -- bad existing pw, usually
Log.i(TAG, "failure; password mismatch?");
Toast.makeText(SetFullBackupPassword.this,
"!!! Failure setting backup password !!!",
Toast.LENGTH_LONG).show();
}
} else if (v == mCancel) {
finish();
} else {
Log.w(TAG, "Click on unknown view");
}
}
};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService("backup"));
setContentView(R.layout.set_backup_pw);
mCurrentPw = (TextView) findViewById(R.id.current_backup_pw);
mNewPw = (TextView) findViewById(R.id.new_backup_pw);
mConfirmNewPw = (TextView) findViewById(R.id.confirm_new_backup_pw);
mCancel = (Button) findViewById(R.id.backup_pw_cancel_button);
mSet = (Button) findViewById(R.id.backup_pw_set_button);
mCancel.setOnClickListener(mButtonListener);
mSet.setOnClickListener(mButtonListener);
}
private boolean setBackupPassword(String currentPw, String newPw) {
try {
return mBackupManager.setBackupPassword(currentPw, newPw);
} catch (RemoteException e) {
Log.e(TAG, "Unable to communicate with backup manager");
return false;
}
}
}