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
193 lines
6.8 KiB
Java
193 lines
6.8 KiB
Java
/*
|
|
* Copyright (C) 2009 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.AlertDialog;
|
|
import android.app.Dialog;
|
|
import android.app.backup.IBackupManager;
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.RemoteException;
|
|
import android.os.ServiceManager;
|
|
import android.preference.CheckBoxPreference;
|
|
import android.preference.Preference;
|
|
import android.preference.PreferenceScreen;
|
|
import android.provider.Settings;
|
|
|
|
/**
|
|
* Gesture lock pattern settings.
|
|
*/
|
|
public class PrivacySettings extends SettingsPreferenceFragment implements
|
|
DialogInterface.OnClickListener {
|
|
|
|
// Vendor specific
|
|
private static final String GSETTINGS_PROVIDER = "com.google.settings";
|
|
private static final String BACKUP_CATEGORY = "backup_category";
|
|
private static final String BACKUP_DATA = "backup_data";
|
|
private static final String AUTO_RESTORE = "auto_restore";
|
|
private static final String CONFIGURE_TRANSPORT = "configure_transport";
|
|
private IBackupManager mBackupManager;
|
|
private CheckBoxPreference mBackup;
|
|
private CheckBoxPreference mAutoRestore;
|
|
private Dialog mConfirmDialog;
|
|
private PreferenceScreen mConfigure;
|
|
|
|
private static final int DIALOG_ERASE_BACKUP = 2;
|
|
private int mDialogType;
|
|
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
addPreferencesFromResource(R.xml.privacy_settings);
|
|
final PreferenceScreen screen = getPreferenceScreen();
|
|
|
|
mBackupManager = IBackupManager.Stub.asInterface(
|
|
ServiceManager.getService(Context.BACKUP_SERVICE));
|
|
|
|
mBackup = (CheckBoxPreference) screen.findPreference(BACKUP_DATA);
|
|
mAutoRestore = (CheckBoxPreference) screen.findPreference(AUTO_RESTORE);
|
|
mConfigure = (PreferenceScreen) screen.findPreference(CONFIGURE_TRANSPORT);
|
|
|
|
// Vendor specific
|
|
if (getActivity().getPackageManager().
|
|
resolveContentProvider(GSETTINGS_PROVIDER, 0) == null) {
|
|
screen.removePreference(findPreference(BACKUP_CATEGORY));
|
|
}
|
|
updateToggles();
|
|
}
|
|
|
|
@Override
|
|
public void onStop() {
|
|
if (mConfirmDialog != null && mConfirmDialog.isShowing()) {
|
|
mConfirmDialog.dismiss();
|
|
}
|
|
mConfirmDialog = null;
|
|
mDialogType = 0;
|
|
super.onStop();
|
|
}
|
|
|
|
@Override
|
|
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
|
|
Preference preference) {
|
|
if (preference == mBackup) {
|
|
if (!mBackup.isChecked()) {
|
|
showEraseBackupDialog();
|
|
} else {
|
|
setBackupEnabled(true);
|
|
}
|
|
} else if (preference == mAutoRestore) {
|
|
IBackupManager bm = IBackupManager.Stub.asInterface(
|
|
ServiceManager.getService(Context.BACKUP_SERVICE));
|
|
if (bm != null) {
|
|
// TODO: disable via the backup manager interface
|
|
boolean curState = mAutoRestore.isChecked();
|
|
try {
|
|
bm.setAutoRestore(curState);
|
|
} catch (RemoteException e) {
|
|
mAutoRestore.setChecked(!curState);
|
|
}
|
|
}
|
|
}
|
|
|
|
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
|
}
|
|
|
|
private void showEraseBackupDialog() {
|
|
mBackup.setChecked(true);
|
|
|
|
mDialogType = DIALOG_ERASE_BACKUP;
|
|
CharSequence msg = getResources().getText(R.string.backup_erase_dialog_message);
|
|
// TODO: DialogFragment?
|
|
mConfirmDialog = new AlertDialog.Builder(getActivity()).setMessage(msg)
|
|
.setTitle(R.string.backup_erase_dialog_title)
|
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
.setPositiveButton(android.R.string.ok, this)
|
|
.setNegativeButton(android.R.string.cancel, this)
|
|
.show();
|
|
}
|
|
|
|
/*
|
|
* Creates toggles for each available location provider
|
|
*/
|
|
private void updateToggles() {
|
|
ContentResolver res = getContentResolver();
|
|
|
|
boolean backupEnabled = false;
|
|
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);
|
|
|
|
mAutoRestore.setChecked(Settings.Secure.getInt(res,
|
|
Settings.Secure.BACKUP_AUTO_RESTORE, 1) == 1);
|
|
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) {
|
|
if (which == DialogInterface.BUTTON_POSITIVE) {
|
|
//updateProviders();
|
|
if (mDialogType == DIALOG_ERASE_BACKUP) {
|
|
setBackupEnabled(false);
|
|
}
|
|
} else {
|
|
if (mDialogType == DIALOG_ERASE_BACKUP) {
|
|
mBackup.setChecked(true);
|
|
mAutoRestore.setEnabled(true);
|
|
}
|
|
}
|
|
mDialogType = 0;
|
|
}
|
|
|
|
/**
|
|
* Informs the BackupManager of a change in backup state - if backup is disabled,
|
|
* the data on the server will be erased.
|
|
* @param enable whether to enable backup
|
|
*/
|
|
private void setBackupEnabled(boolean enable) {
|
|
if (mBackupManager != null) {
|
|
try {
|
|
mBackupManager.setBackupEnabled(enable);
|
|
} catch (RemoteException e) {
|
|
mBackup.setChecked(!enable);
|
|
mAutoRestore.setEnabled(!enable);
|
|
return;
|
|
}
|
|
}
|
|
mBackup.setChecked(enable);
|
|
mAutoRestore.setEnabled(enable);
|
|
}
|
|
}
|