Convert the rest of encryption page into pref controller

Bug: 32953042
Test: robotests
Change-Id: I6c1b28314a988e6499065ddaee2aeae0ac28c537
This commit is contained in:
Fan Zhang
2017-11-02 14:09:34 -07:00
parent c58a88368f
commit b2aae6cd57
12 changed files with 465 additions and 118 deletions

View File

@@ -17,22 +17,16 @@
package com.android.settings.security;
import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.security.KeyStore;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
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.settings.widget.PreferenceCategoryController;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.Arrays;
@@ -40,24 +34,11 @@ import java.util.List;
/**
* Encryption and Credential settings.
* TODO: Extends this from {@link DashboardFragment} instead
*/
public class EncryptionAndCredential extends DashboardFragment {
private static final String TAG = "EncryptionAndCredential";
// Misc Settings
private static final String KEY_CREDENTIAL_STORAGE_TYPE = "credential_storage_type";
private static final String KEY_USER_CREDENTIALS = "user_credentials";
private static final String KEY_RESET_CREDENTIALS = "credentials_reset";
private static final String KEY_CREDENTIALS_INSTALL = "credentials_install";
private static final String KEY_CREDENTIALS_MANAGER = "credentials_management";
private static final int MY_USER_ID = UserHandle.myUserId();
private KeyStore mKeyStore;
private RestrictedPreference mResetCredentials;
@Override
public int getMetricsCategory() {
return MetricsEvent.ENCRYPTION_AND_CREDENTIAL;
@@ -70,7 +51,7 @@ public class EncryptionAndCredential extends DashboardFragment {
@Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
return buildPreferenceControllers(context);
return buildPreferenceControllers(context, getLifecycle());
}
@Override
@@ -78,7 +59,8 @@ public class EncryptionAndCredential extends DashboardFragment {
return R.xml.encryption_and_credential;
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
final EncryptionStatusPreferenceController encryptStatusController =
new EncryptionStatusPreferenceController(context);
@@ -86,76 +68,13 @@ public class EncryptionAndCredential extends DashboardFragment {
controllers.add(new PreferenceCategoryController(context,
"encryption_and_credentials_status_category",
Arrays.asList(encryptStatusController)));
controllers.add(new CredentialStoragePreferenceController(context));
controllers.add(new UserCredentialsPreferenceController(context));
controllers.add(new ResetCredentialsPreferenceController(context, lifecycle));
controllers.add(new InstallCredentialsPreferenceController(context));
return controllers;
}
/**
* Important!
*
* Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
* logic or adding/removing preferences here.
*/
private PreferenceScreen createPreferenceHierarchy() {
final PreferenceScreen root = getPreferenceScreen();
// Credential storage
mKeyStore = KeyStore.getInstance(); // needs to be initialized for onResume()
if (!RestrictedLockUtils.hasBaseUserRestriction(getActivity(),
UserManager.DISALLOW_CONFIG_CREDENTIALS, MY_USER_ID)) {
RestrictedPreference userCredentials = (RestrictedPreference) root.findPreference(
KEY_USER_CREDENTIALS);
userCredentials.checkRestrictionAndSetDisabled(
UserManager.DISALLOW_CONFIG_CREDENTIALS);
RestrictedPreference credentialStorageType = (RestrictedPreference) root.findPreference(
KEY_CREDENTIAL_STORAGE_TYPE);
credentialStorageType.checkRestrictionAndSetDisabled(
UserManager.DISALLOW_CONFIG_CREDENTIALS);
RestrictedPreference installCredentials = (RestrictedPreference) root.findPreference(
KEY_CREDENTIALS_INSTALL);
installCredentials.checkRestrictionAndSetDisabled(
UserManager.DISALLOW_CONFIG_CREDENTIALS);
mResetCredentials = (RestrictedPreference) root.findPreference(KEY_RESET_CREDENTIALS);
mResetCredentials.checkRestrictionAndSetDisabled(
UserManager.DISALLOW_CONFIG_CREDENTIALS);
final int storageSummaryRes =
mKeyStore.isHardwareBacked() ? R.string.credential_storage_type_hardware
: R.string.credential_storage_type_software;
credentialStorageType.setSummary(storageSummaryRes);
} else {
PreferenceGroup credentialsManager = (PreferenceGroup)
root.findPreference(KEY_CREDENTIALS_MANAGER);
credentialsManager.removePreference(root.findPreference(KEY_RESET_CREDENTIALS));
credentialsManager.removePreference(root.findPreference(KEY_CREDENTIALS_INSTALL));
credentialsManager.removePreference(root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE));
credentialsManager.removePreference(root.findPreference(KEY_USER_CREDENTIALS));
}
return root;
}
@Override
public void onResume() {
super.onResume();
// Make sure we reload the preference hierarchy since some of these settings
// depend on others...
createPreferenceHierarchy();
if (mResetCredentials != null && !mResetCredentials.isDisabledByAdmin()) {
mResetCredentials.setEnabled(!mKeyStore.isEmpty());
}
}
/**
* see confirmPatternThenDisableAndClear
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
createPreferenceHierarchy();
}
@Override
protected int getHelpResource() {
return R.string.help_url_encryption;
@@ -179,7 +98,7 @@ public class EncryptionAndCredential extends DashboardFragment {
@Override
public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
return buildPreferenceControllers(context);
return buildPreferenceControllers(context, null /* lifecycle */);
}
@Override
@@ -187,25 +106,5 @@ public class EncryptionAndCredential extends DashboardFragment {
final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
return um.isAdminUser();
}
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
if (!isPageSearchEnabled(context)) {
return keys;
}
final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
if (um.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) {
keys.add(KEY_CREDENTIALS_MANAGER);
keys.add(KEY_RESET_CREDENTIALS);
keys.add(KEY_CREDENTIALS_INSTALL);
keys.add(KEY_CREDENTIAL_STORAGE_TYPE);
keys.add(KEY_USER_CREDENTIALS);
}
return keys;
}
}
}