summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsunnyshao <sunnyshao@android.com>2018-03-29 19:50:20 +0800
committerFan Zhang <zhfan@google.com>2018-04-18 18:02:53 -0700
commit15ec2cf8effb32a475e4eb22d3295d39c41c0811 (patch)
tree3fb359f47118d5a2143c7b7dce0723b6609c4d20 /src
parentf1191f6bf906f998afb17da35267c51b9300e16b (diff)
downloadpackages_apps_Settings-15ec2cf8effb32a475e4eb22d3295d39c41c0811.tar.gz
packages_apps_Settings-15ec2cf8effb32a475e4eb22d3295d39c41c0811.tar.bz2
packages_apps_Settings-15ec2cf8effb32a475e4eb22d3295d39c41c0811.zip
Modified the PrivacySettings and add PreferenceControllers
- Changed the PrivacySettings to DashboardFragment. - Added the new five related PreferenceControllers and related codes - Modified the privacy_settings.xml - Removed the PrivacySettingsTest test by design changed - Moved the PrivacySettings.java from root directory to backup Test: manual Test: make RunSettingsRoboTests Change-Id: Ic88e2e58a11d024d2394f75c3db5b46fe2d86dba
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/PrivacySettings.java248
-rw-r--r--src/com/android/settings/backup/AutoRestorePreferenceController.java89
-rw-r--r--src/com/android/settings/backup/BackupDataPreferenceController.java64
-rw-r--r--src/com/android/settings/backup/BackupInactivePreferenceController.java39
-rw-r--r--src/com/android/settings/backup/ConfigureAccountPreferenceController.java64
-rw-r--r--src/com/android/settings/backup/DataManagementPreferenceController.java58
-rw-r--r--src/com/android/settings/backup/PrivacySettings.java96
-rw-r--r--src/com/android/settings/backup/PrivacySettingsConfigData.java85
-rw-r--r--src/com/android/settings/backup/PrivacySettingsUtils.java122
-rw-r--r--src/com/android/settings/core/gateway/SettingsGateway.java2
10 files changed, 618 insertions, 249 deletions
diff --git a/src/com/android/settings/PrivacySettings.java b/src/com/android/settings/PrivacySettings.java
deleted file mode 100644
index 24774e0657..0000000000
--- a/src/com/android/settings/PrivacySettings.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * 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.backup.IBackupManager;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.os.Bundle;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.provider.SearchIndexableResource;
-import android.provider.Settings;
-import android.support.annotation.VisibleForTesting;
-import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.Preference.OnPreferenceChangeListener;
-import android.support.v7.preference.PreferenceScreen;
-import android.util.Log;
-
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.search.Indexable;
-import com.android.settingslib.RestrictedLockUtils;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Gesture lock pattern settings.
- */
-public class PrivacySettings extends SettingsPreferenceFragment {
-
- // Vendor specific
- private static final String GSETTINGS_PROVIDER = "com.google.settings";
- @VisibleForTesting
- static final String BACKUP_DATA = "backup_data";
- @VisibleForTesting
- static final String AUTO_RESTORE = "auto_restore";
- @VisibleForTesting
- static final String CONFIGURE_ACCOUNT = "configure_account";
- @VisibleForTesting
- static final String DATA_MANAGEMENT = "data_management";
- private static final String BACKUP_INACTIVE = "backup_inactive";
- private static final String TAG = "PrivacySettings";
- private IBackupManager mBackupManager;
- private Preference mBackup;
- private SwitchPreference mAutoRestore;
- private Preference mConfigure;
- private Preference mManageData;
- private boolean mEnabled;
-
- @Override
- public int getMetricsCategory() {
- return MetricsEvent.PRIVACY;
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Don't allow any access if this is not an admin user.
- // TODO: backup/restore currently only works with owner user b/22760572
- mEnabled = UserManager.get(getActivity()).isAdminUser();
- if (!mEnabled) {
- return;
- }
-
- addPreferencesFromResource(R.xml.privacy_settings);
- final PreferenceScreen screen = getPreferenceScreen();
- mBackupManager = IBackupManager.Stub.asInterface(
- ServiceManager.getService(Context.BACKUP_SERVICE));
-
- setPreferenceReferences(screen);
-
- Set<String> keysToRemove = new HashSet<>();
- getNonVisibleKeys(getActivity(), keysToRemove);
- final int screenPreferenceCount = screen.getPreferenceCount();
- for (int i = screenPreferenceCount - 1; i >= 0; --i) {
- Preference preference = screen.getPreference(i);
- if (keysToRemove.contains(preference.getKey())) {
- screen.removePreference(preference);
- }
- }
-
- updateToggles();
- }
-
- @Override
- public void onResume() {
- super.onResume();
-
- // Refresh UI
- if (mEnabled) {
- updateToggles();
- }
- }
-
- @VisibleForTesting
- void setPreferenceReferences(PreferenceScreen screen) {
- mBackup = screen.findPreference(BACKUP_DATA);
-
- mAutoRestore = (SwitchPreference) screen.findPreference(AUTO_RESTORE);
- mAutoRestore.setOnPreferenceChangeListener(preferenceChangeListener);
-
- mConfigure = screen.findPreference(CONFIGURE_ACCOUNT);
- mManageData = screen.findPreference(DATA_MANAGEMENT);
- }
-
- private OnPreferenceChangeListener preferenceChangeListener = new OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (!(preference instanceof SwitchPreference)) {
- return true;
- }
- boolean nextValue = (Boolean) newValue;
- boolean result = false;
- if (preference == mAutoRestore) {
- try {
- mBackupManager.setAutoRestore(nextValue);
- result = true;
- } catch (RemoteException e) {
- mAutoRestore.setChecked(!nextValue);
- }
- }
- return result;
- }
- };
-
-
- /*
- * Creates toggles for each backup/reset preference.
- */
- private void updateToggles() {
- ContentResolver res = getContentResolver();
-
- boolean backupEnabled = false;
- Intent configIntent = null;
- String configSummary = null;
- Intent manageIntent = null;
- String manageLabel = null;
- try {
- backupEnabled = mBackupManager.isBackupEnabled();
- String transport = mBackupManager.getCurrentTransport();
- configIntent = validatedActivityIntent(
- mBackupManager.getConfigurationIntent(transport), "config");
- configSummary = mBackupManager.getDestinationString(transport);
- manageIntent = validatedActivityIntent(
- mBackupManager.getDataManagementIntent(transport), "management");
- manageLabel = mBackupManager.getDataManagementLabel(transport);
-
- mBackup.setSummary(backupEnabled
- ? R.string.accessibility_feature_state_on
- : R.string.accessibility_feature_state_off);
- } catch (RemoteException e) {
- // leave it 'false' and disable the UI; there's no backup manager
- mBackup.setEnabled(false);
- }
-
- mAutoRestore.setChecked(Settings.Secure.getInt(res,
- Settings.Secure.BACKUP_AUTO_RESTORE, 1) == 1);
- mAutoRestore.setEnabled(backupEnabled);
-
- final boolean configureEnabled = (configIntent != null) && backupEnabled;
- mConfigure.setEnabled(configureEnabled);
- mConfigure.setIntent(configIntent);
- setConfigureSummary(configSummary);
-
- final boolean manageEnabled = (manageIntent != null) && backupEnabled;
- if (manageEnabled) {
- mManageData.setIntent(manageIntent);
- if (manageLabel != null) {
- mManageData.setTitle(manageLabel);
- }
- } else {
- // Hide the item if data management intent is not supported by transport.
- getPreferenceScreen().removePreference(mManageData);
- }
- }
-
- private Intent validatedActivityIntent(Intent intent, String logLabel) {
- if (intent != null) {
- PackageManager pm = getPackageManager();
- List<ResolveInfo> resolved = pm.queryIntentActivities(intent, 0);
- if (resolved == null || resolved.isEmpty()) {
- intent = null;
- Log.e(TAG, "Backup " + logLabel + " intent " + intent
- + " fails to resolve; ignoring");
- }
- }
- return intent;
- }
-
- private void setConfigureSummary(String summary) {
- if (summary != null) {
- mConfigure.setSummary(summary);
- } else {
- mConfigure.setSummary(R.string.backup_configure_account_default_summary);
- }
- }
-
- @Override
- public int getHelpResource() {
- return R.string.help_url_backup_reset;
- }
-
- private static void getNonVisibleKeys(Context context, Collection<String> nonVisibleKeys) {
- final IBackupManager backupManager = IBackupManager.Stub.asInterface(
- ServiceManager.getService(Context.BACKUP_SERVICE));
- boolean isServiceActive = false;
- try {
- isServiceActive = backupManager.isBackupServiceActive(UserHandle.myUserId());
- } catch (RemoteException e) {
- Log.w(TAG, "Failed querying backup manager service activity status. " +
- "Assuming it is inactive.");
- }
- boolean vendorSpecific = context.getPackageManager().
- resolveContentProvider(GSETTINGS_PROVIDER, 0) == null;
- if (vendorSpecific || isServiceActive) {
- nonVisibleKeys.add(BACKUP_INACTIVE);
- }
- if (vendorSpecific || !isServiceActive) {
- nonVisibleKeys.add(BACKUP_DATA);
- nonVisibleKeys.add(AUTO_RESTORE);
- nonVisibleKeys.add(CONFIGURE_ACCOUNT);
- }
- }
-}
diff --git a/src/com/android/settings/backup/AutoRestorePreferenceController.java b/src/com/android/settings/backup/AutoRestorePreferenceController.java
new file mode 100644
index 0000000000..7bcf350e3d
--- /dev/null
+++ b/src/com/android/settings/backup/AutoRestorePreferenceController.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2018 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.backup;
+
+import android.app.backup.IBackupManager;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.provider.Settings;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+import android.util.Log;
+
+import com.android.settings.core.TogglePreferenceController;
+
+public class AutoRestorePreferenceController extends TogglePreferenceController {
+ private static final String TAG = "AutoRestorePrefCtrler";
+
+ private PrivacySettingsConfigData mPSCD;
+ private Preference mPreference;
+
+ public AutoRestorePreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ public void setPrivacySettingsConfigData(final PrivacySettingsConfigData pData) {
+ mPSCD = pData;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (!PrivacySettingsUtils.isAdminUser(mContext)) {
+ return DISABLED_FOR_USER;
+ }
+ if (PrivacySettingsUtils.isInvisibleKey(mContext, PrivacySettingsUtils.AUTO_RESTORE)) {
+ return DISABLED_UNSUPPORTED;
+ }
+ return AVAILABLE;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ mPreference = preference;
+ preference.setEnabled(mPSCD.isBackupEnabled());
+ }
+
+ @Override
+ public boolean isChecked() {
+ final ContentResolver res = mContext.getContentResolver();
+
+ return Settings.Secure.getInt(res,
+ Settings.Secure.BACKUP_AUTO_RESTORE, 1) == 1;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ final boolean nextValue = isChecked;
+ boolean result = false;
+
+ final IBackupManager backupManager = IBackupManager.Stub.asInterface(
+ ServiceManager.getService(Context.BACKUP_SERVICE));
+
+ try {
+ backupManager.setAutoRestore(nextValue);
+ result = true;
+ } catch (RemoteException e) {
+ ((SwitchPreference) mPreference).setChecked(!nextValue);
+ Log.e(TAG, "Error can't set setAutoRestore", e);
+ }
+
+ return result;
+ }
+} \ No newline at end of file
diff --git a/src/com/android/settings/backup/BackupDataPreferenceController.java b/src/com/android/settings/backup/BackupDataPreferenceController.java
new file mode 100644
index 0000000000..0a0f581c1f
--- /dev/null
+++ b/src/com/android/settings/backup/BackupDataPreferenceController.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2018 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.backup;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.R;
+
+public class BackupDataPreferenceController extends BasePreferenceController {
+ private PrivacySettingsConfigData mPSCD;
+
+ public BackupDataPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ public void setPrivacySettingsConfigData(final PrivacySettingsConfigData pData) {
+ mPSCD = pData;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (!PrivacySettingsUtils.isAdminUser(mContext)) {
+ return DISABLED_FOR_USER;
+ }
+ if (PrivacySettingsUtils.isInvisibleKey(mContext, PrivacySettingsUtils.BACKUP_DATA)) {
+ return DISABLED_UNSUPPORTED;
+ }
+ return AVAILABLE;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ if (mPSCD.isBackupGray()) {
+ preference.setEnabled(false);
+ }
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ if (!mPSCD.isBackupGray()) {
+ return mPSCD.isBackupEnabled()
+ ? mContext.getText(R.string.accessibility_feature_state_on)
+ : mContext.getText(R.string.accessibility_feature_state_off);
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/src/com/android/settings/backup/BackupInactivePreferenceController.java b/src/com/android/settings/backup/BackupInactivePreferenceController.java
new file mode 100644
index 0000000000..d44801e97e
--- /dev/null
+++ b/src/com/android/settings/backup/BackupInactivePreferenceController.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2018 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.backup;
+
+import android.content.Context;
+
+import com.android.settings.core.BasePreferenceController;
+
+public class BackupInactivePreferenceController extends BasePreferenceController {
+
+ public BackupInactivePreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (!PrivacySettingsUtils.isAdminUser(mContext)) {
+ return DISABLED_FOR_USER;
+ }
+ if (PrivacySettingsUtils.isInvisibleKey(mContext, PrivacySettingsUtils.BACKUP_INACTIVE)) {
+ return DISABLED_UNSUPPORTED;
+ }
+ return AVAILABLE;
+ }
+} \ No newline at end of file
diff --git a/src/com/android/settings/backup/ConfigureAccountPreferenceController.java b/src/com/android/settings/backup/ConfigureAccountPreferenceController.java
new file mode 100644
index 0000000000..f1bcee9150
--- /dev/null
+++ b/src/com/android/settings/backup/ConfigureAccountPreferenceController.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2018 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.backup;
+
+import android.content.Context;
+import android.content.Intent;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.R;
+
+public class ConfigureAccountPreferenceController extends BasePreferenceController {
+ private PrivacySettingsConfigData mPSCD;
+
+ public ConfigureAccountPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ public void setPrivacySettingsConfigData(final PrivacySettingsConfigData pData) {
+ mPSCD = pData;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (!PrivacySettingsUtils.isAdminUser(mContext)) {
+ return DISABLED_FOR_USER;
+ }
+ if (PrivacySettingsUtils.isInvisibleKey(mContext, PrivacySettingsUtils.CONFIGURE_ACCOUNT)) {
+ return DISABLED_UNSUPPORTED;
+ }
+ return AVAILABLE;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ final Intent configIntent = mPSCD.getConfigIntent();
+ final boolean configureEnabled = (configIntent != null) && mPSCD.isBackupEnabled();
+ preference.setEnabled(configureEnabled);
+ preference.setIntent(configIntent);
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ final String configSummary = mPSCD.getConfigSummary();
+ return configSummary != null
+ ? configSummary
+ : mContext.getText(R.string.backup_configure_account_default_summary);
+ }
+} \ No newline at end of file
diff --git a/src/com/android/settings/backup/DataManagementPreferenceController.java b/src/com/android/settings/backup/DataManagementPreferenceController.java
new file mode 100644
index 0000000000..de987abbde
--- /dev/null
+++ b/src/com/android/settings/backup/DataManagementPreferenceController.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2018 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.backup;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.BasePreferenceController;
+
+public class DataManagementPreferenceController extends BasePreferenceController {
+ private PrivacySettingsConfigData mPSCD;
+ private boolean mManageEnabled;
+
+ public DataManagementPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ public void setPrivacySettingsConfigData(final PrivacySettingsConfigData pData) {
+ mPSCD = pData;
+ mManageEnabled = (mPSCD.getManageIntent() != null) && mPSCD.isBackupEnabled();
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (!PrivacySettingsUtils.isAdminUser(mContext)) {
+ return DISABLED_FOR_USER;
+ }
+ if (!mManageEnabled) {
+ return DISABLED_UNSUPPORTED;
+ }
+ return AVAILABLE;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ if (mManageEnabled) {
+ preference.setIntent(mPSCD.getManageIntent());
+ final String manageLabel = mPSCD.getManageLabel();
+ if (manageLabel != null) {
+ preference.setTitle(manageLabel);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/android/settings/backup/PrivacySettings.java b/src/com/android/settings/backup/PrivacySettings.java
new file mode 100644
index 0000000000..9b342e7477
--- /dev/null
+++ b/src/com/android/settings/backup/PrivacySettings.java
@@ -0,0 +1,96 @@
+/*
+ * 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.backup;
+
+import android.content.Context;
+import android.provider.SearchIndexableResource;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.Arrays;
+import java.util.List;
+
+@SearchIndexable
+public class PrivacySettings extends DashboardFragment {
+ private static final String TAG = "PrivacySettings";
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsEvent.PRIVACY;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.privacy_settings;
+ }
+
+ @Override
+ public int getHelpResource() {
+ return R.string.help_url_backup_reset;
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ updatePrivacySettingsConfigData(context);
+ }
+
+ @Override
+ protected void updatePreferenceStates() {
+ updatePrivacySettingsConfigData(getContext());
+ super.updatePreferenceStates();
+ }
+
+ private void updatePrivacySettingsConfigData(final Context context) {
+ final PrivacySettingsConfigData pData = new PrivacySettingsConfigData();
+ if (PrivacySettingsUtils.isAdminUser(context)) {
+ PrivacySettingsUtils.updatePrivacyBuffer(context, pData);
+ }
+
+ use(BackupDataPreferenceController.class).setPrivacySettingsConfigData(pData);
+ use(ConfigureAccountPreferenceController.class).setPrivacySettingsConfigData(pData);
+ use(DataManagementPreferenceController.class).setPrivacySettingsConfigData(pData);
+ use(AutoRestorePreferenceController.class).setPrivacySettingsConfigData(pData);
+ }
+
+ public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+ boolean enabled) {
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.privacy_settings;
+ return Arrays.asList(sir);
+ }
+
+ @Override
+ protected boolean isPageSearchEnabled(Context context) {
+ final BackupSettingsHelper backupHelper = new BackupSettingsHelper(context);
+ return !backupHelper.isBackupProvidedByManufacturer() &&
+ !backupHelper.isIntentProvidedByTransport();
+ }
+ };
+}
diff --git a/src/com/android/settings/backup/PrivacySettingsConfigData.java b/src/com/android/settings/backup/PrivacySettingsConfigData.java
new file mode 100644
index 0000000000..9b72a829a2
--- /dev/null
+++ b/src/com/android/settings/backup/PrivacySettingsConfigData.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2018 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.backup;
+
+import android.content.Intent;
+
+public class PrivacySettingsConfigData {
+ private boolean mBackupEnabled;
+ private boolean mBackupGray;
+ private Intent mConfigIntent;
+ private String mConfigSummary;
+ private Intent mManageIntent;
+ private String mManageLabel;
+
+ public PrivacySettingsConfigData() {
+ mBackupEnabled = false;
+ mBackupGray = false;
+ mConfigIntent = null;
+ mConfigSummary = null;
+ mManageIntent = null;
+ mManageLabel = null;
+ }
+
+ public boolean isBackupEnabled() {
+ return mBackupEnabled;
+ }
+
+ public void setBackupEnabled(final boolean backupEnabled) {
+ mBackupEnabled = backupEnabled;
+ }
+
+ public boolean isBackupGray() {
+ return mBackupGray;
+ }
+
+ public void setBackupGray(final boolean backupGray) {
+ mBackupGray = backupGray;
+ }
+
+ public Intent getConfigIntent() {
+ return mConfigIntent;
+ }
+
+ public void setConfigIntent(final Intent configIntent) {
+ mConfigIntent = configIntent;
+ }
+
+ public String getConfigSummary() {
+ return mConfigSummary;
+ }
+
+ public void setConfigSummary(final String configSummary) {
+ mConfigSummary = configSummary;
+ }
+
+ public Intent getManageIntent() {
+ return mManageIntent;
+ }
+
+ public void setManageIntent(final Intent manageIntent) {
+ mManageIntent = manageIntent;
+ }
+
+ public String getManageLabel() {
+ return mManageLabel;
+ }
+
+ public void setManageLabel(final String manageLabel) {
+ mManageLabel = manageLabel;
+ }
+}
diff --git a/src/com/android/settings/backup/PrivacySettingsUtils.java b/src/com/android/settings/backup/PrivacySettingsUtils.java
new file mode 100644
index 0000000000..f8f21ddeef
--- /dev/null
+++ b/src/com/android/settings/backup/PrivacySettingsUtils.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2018 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.backup;
+
+import android.app.backup.IBackupManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.util.Log;
+
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+public class PrivacySettingsUtils {
+ private static final String TAG = "PrivacySettingsUtils";
+ private static final String GSETTINGS_PROVIDER = "com.google.settings";
+
+ static final String BACKUP_DATA = "backup_data";
+ static final String AUTO_RESTORE = "auto_restore";
+ static final String CONFIGURE_ACCOUNT = "configure_account";
+ static final String BACKUP_INACTIVE = "backup_inactive";
+
+ // Don't allow any access if this is not an admin user.
+ // TODO: backup/restore currently only works with owner user b/22760572
+ static boolean isAdminUser(final Context context) {
+ return UserManager.get(context).isAdminUser();
+ }
+
+ /**
+ * Send a {@param key} to check its preference will display in PrivacySettings or not.
+ */
+ static boolean isInvisibleKey(final Context context, final String key) {
+ final Set<String> keysToRemove = getInvisibleKey(context);
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG,
+ "keysToRemove size=" + keysToRemove.size() + " keysToRemove=" + keysToRemove);
+ }
+ if (keysToRemove.contains(key)) {
+ return true;
+ }
+ return false;
+ }
+
+ private static Set<String> getInvisibleKey(final Context context) {
+ final IBackupManager backupManager = IBackupManager.Stub.asInterface(
+ ServiceManager.getService(Context.BACKUP_SERVICE));
+ boolean isServiceActive = false;
+ try {
+ isServiceActive = backupManager.isBackupServiceActive(UserHandle.myUserId());
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed querying backup manager service activity status. " +
+ "Assuming it is inactive.");
+ }
+ boolean vendorSpecific = context.getPackageManager().
+ resolveContentProvider(GSETTINGS_PROVIDER, 0) == null;
+ final Set<String> inVisibleKeys = new TreeSet<>();
+ if (vendorSpecific || isServiceActive) {
+ inVisibleKeys.add(BACKUP_INACTIVE);
+ }
+ if (vendorSpecific || !isServiceActive) {
+ inVisibleKeys.add(BACKUP_DATA);
+ inVisibleKeys.add(AUTO_RESTORE);
+ inVisibleKeys.add(CONFIGURE_ACCOUNT);
+ }
+ return inVisibleKeys;
+ }
+
+ public static void updatePrivacyBuffer(final Context context, PrivacySettingsConfigData data) {
+ final IBackupManager backupManager = IBackupManager.Stub.asInterface(
+ ServiceManager.getService(Context.BACKUP_SERVICE));
+
+ try {
+ data.setBackupEnabled(backupManager.isBackupEnabled());
+ String transport = backupManager.getCurrentTransport();
+ data.setConfigIntent(validatedActivityIntent(context,
+ backupManager.getConfigurationIntent(transport), "config"));
+ data.setConfigSummary(backupManager.getDestinationString(transport));
+ data.setManageIntent(validatedActivityIntent(context,
+ backupManager.getDataManagementIntent(transport), "management"));
+ data.setManageLabel(backupManager.getDataManagementLabel(transport));
+ data.setBackupGray(false);
+ } catch (RemoteException e) {
+ // leave it 'false' and disable the UI; there's no backup manager
+ // mBackup.setEnabled(false);
+ data.setBackupGray(true);
+ }
+ }
+
+ private static Intent validatedActivityIntent(final Context context, Intent intent,
+ String logLabel) {
+ if (intent != null) {
+ PackageManager pm = context.getPackageManager();
+ List<ResolveInfo> resolved = pm.queryIntentActivities(intent, 0);
+ if (resolved == null || resolved.isEmpty()) {
+ intent = null;
+ Log.e(TAG, "Backup " + logLabel + " intent " + intent
+ + " fails to resolve; ignoring");
+ }
+ }
+ return intent;
+ }
+} \ No newline at end of file
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index aa9d7b5487..be9b722a5a 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -21,7 +21,6 @@ import com.android.settings.DeviceAdminSettings;
import com.android.settings.DisplaySettings;
import com.android.settings.IccLockSettings;
import com.android.settings.MasterClear;
-import com.android.settings.PrivacySettings;
import com.android.settings.Settings;
import com.android.settings.TestingSettings;
import com.android.settings.TetherSettings;
@@ -51,6 +50,7 @@ import com.android.settings.applications.appinfo.WriteSettingsDetails;
import com.android.settings.applications.appops.BackgroundCheckSummary;
import com.android.settings.applications.assist.ManageAssist;
import com.android.settings.applications.manageapplications.ManageApplications;
+import com.android.settings.backup.PrivacySettings;
import com.android.settings.backup.ToggleBackupSettingFragment;
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;