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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
96
src/com/android/settings/backup/PrivacySettings.java
Normal file
96
src/com/android/settings/backup/PrivacySettings.java
Normal file
@@ -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();
|
||||
}
|
||||
};
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
122
src/com/android/settings/backup/PrivacySettingsUtils.java
Normal file
122
src/com/android/settings/backup/PrivacySettingsUtils.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user