Add backup configuration action to Privacy settings

Settings now queries the backup manager for a configuration Intent and
text descriptive of the state of the currently-active transport.  These
are used by a new Intent PreferenceScreen within the backup section of
the Privacy settings UI.

When touched, the Configure item launches the Intent supplied by the
transport; when no such Intent is available, the item is disabled.  The
summary text describing the current backup state is also supplied by
the transport.

Bug: 2753632
Change-Id: I3d8fb3d4b08a2b6fa8d3ad8f9e02a66430948423
This commit is contained in:
Christopher Tate
2010-12-08 18:46:38 -08:00
parent 1c7e49ba67
commit df6a7e55cc
3 changed files with 42 additions and 6 deletions

View File

@@ -2906,6 +2906,10 @@ found in the list of installed applications.</string>
<string name="backup_data_title">Back up my data</string> <string name="backup_data_title">Back up my data</string>
<!-- Summary text of the "back up data" setting --> <!-- Summary text of the "back up data" setting -->
<string name="backup_data_summary">Back up application data, Wi-Fi passwords, and other settings to Google servers</string> <string name="backup_data_summary">Back up application data, Wi-Fi passwords, and other settings to Google servers</string>
<!-- Configure backup options menu title [CHAR LIMIT=25]-->
<string name="backup_configure_transport_title">Configure backup</string>
<!-- Default summary text of the "Configure backup" setting [CHAR LIMIT=80]-->
<string name="backup_configure_transport_default_summary">No backup destination is available.</string>
<!-- Auto-restore menu title --> <!-- Auto-restore menu title -->
<string name="auto_restore_title">Automatic restore</string> <string name="auto_restore_title">Automatic restore</string>
<!-- Summary text of the "automatic restore" setting --> <!-- Summary text of the "automatic restore" setting -->

View File

@@ -25,6 +25,14 @@
android:title="@string/backup_data_title" android:title="@string/backup_data_title"
android:summary="@string/backup_data_summary" android:summary="@string/backup_data_summary"
android:persistent="false" /> android:persistent="false" />
<PreferenceScreen
android:key="configure_transport"
android:dependency="backup_data"
android:layout="?android:attr/preferenceLayoutChild"
android:title="@string/backup_configure_transport_title"
android:summary="@string/backup_configure_transport_default_summary">
<intent android:action="dummy" />
</PreferenceScreen>
<CheckBoxPreference <CheckBoxPreference
android:key="auto_restore" android:key="auto_restore"
android:title="@string/auto_restore_title" android:title="@string/auto_restore_title"

View File

@@ -22,6 +22,7 @@ import android.app.backup.IBackupManager;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
@@ -41,9 +42,12 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
private static final String BACKUP_CATEGORY = "backup_category"; private static final String BACKUP_CATEGORY = "backup_category";
private static final String BACKUP_DATA = "backup_data"; private static final String BACKUP_DATA = "backup_data";
private static final String AUTO_RESTORE = "auto_restore"; private static final String AUTO_RESTORE = "auto_restore";
private static final String CONFIGURE_TRANSPORT = "configure_transport";
private IBackupManager mBackupManager;
private CheckBoxPreference mBackup; private CheckBoxPreference mBackup;
private CheckBoxPreference mAutoRestore; private CheckBoxPreference mAutoRestore;
private Dialog mConfirmDialog; private Dialog mConfirmDialog;
private PreferenceScreen mConfigure;
private static final int DIALOG_ERASE_BACKUP = 2; private static final int DIALOG_ERASE_BACKUP = 2;
private int mDialogType; private int mDialogType;
@@ -54,8 +58,12 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
addPreferencesFromResource(R.xml.privacy_settings); addPreferencesFromResource(R.xml.privacy_settings);
final PreferenceScreen screen = getPreferenceScreen(); final PreferenceScreen screen = getPreferenceScreen();
mBackupManager = IBackupManager.Stub.asInterface(
ServiceManager.getService(Context.BACKUP_SERVICE));
mBackup = (CheckBoxPreference) screen.findPreference(BACKUP_DATA); mBackup = (CheckBoxPreference) screen.findPreference(BACKUP_DATA);
mAutoRestore = (CheckBoxPreference) screen.findPreference(AUTO_RESTORE); mAutoRestore = (CheckBoxPreference) screen.findPreference(AUTO_RESTORE);
mConfigure = (PreferenceScreen) screen.findPreference(CONFIGURE_TRANSPORT);
// Vendor specific // Vendor specific
if (getActivity().getPackageManager(). if (getActivity().getPackageManager().
@@ -121,13 +129,31 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
private void updateToggles() { private void updateToggles() {
ContentResolver res = getContentResolver(); ContentResolver res = getContentResolver();
final boolean backupEnabled = Settings.Secure.getInt(res, boolean backupEnabled = false;
Settings.Secure.BACKUP_ENABLED, 0) == 1; Intent configIntent = null;
String configSummary = null;
try {
backupEnabled = mBackupManager.isBackupEnabled();
String transport = mBackupManager.getCurrentTransport();
configIntent = mBackupManager.getConfigurationIntent(transport);
configSummary = mBackupManager.getDestinationString(transport);
} catch (RemoteException e) {
// leave it 'false' and disable the UI; there's no backup manager
mBackup.setEnabled(false);
}
mBackup.setChecked(backupEnabled); mBackup.setChecked(backupEnabled);
mAutoRestore.setChecked(Settings.Secure.getInt(res, mAutoRestore.setChecked(Settings.Secure.getInt(res,
Settings.Secure.BACKUP_AUTO_RESTORE, 1) == 1); Settings.Secure.BACKUP_AUTO_RESTORE, 1) == 1);
mAutoRestore.setEnabled(backupEnabled); mAutoRestore.setEnabled(backupEnabled);
mConfigure.setEnabled(configIntent != null);
mConfigure.setIntent(configIntent);
if (configSummary != null) {
mConfigure.setSummary(configSummary);
} else {
mConfigure.setSummary(R.string.backup_configure_transport_default_summary);
}
} }
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@@ -151,11 +177,9 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
* @param enable whether to enable backup * @param enable whether to enable backup
*/ */
private void setBackupEnabled(boolean enable) { private void setBackupEnabled(boolean enable) {
IBackupManager bm = IBackupManager.Stub.asInterface( if (mBackupManager != null) {
ServiceManager.getService(Context.BACKUP_SERVICE));
if (bm != null) {
try { try {
bm.setBackupEnabled(enable); mBackupManager.setBackupEnabled(enable);
} catch (RemoteException e) { } catch (RemoteException e) {
mBackup.setChecked(!enable); mBackup.setChecked(!enable);
mAutoRestore.setEnabled(!enable); mAutoRestore.setEnabled(!enable);