Merge "Convert the rest of encryption page into pref controller"
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||||
android:title="@string/encryption_and_credential_settings_title"
|
android:title="@string/encryption_and_credential_settings_title"
|
||||||
android:key="encryption_and_credentials_screen">
|
android:key="encryption_and_credentials_screen">
|
||||||
|
|
||||||
@@ -39,7 +40,9 @@
|
|||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:key="credential_storage_type"
|
android:key="credential_storage_type"
|
||||||
android:title="@string/credential_storage_type" />
|
android:title="@string/credential_storage_type"
|
||||||
|
android:summary="@string/summary_placeholder"
|
||||||
|
settings:userRestriction="no_config_credentials" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="trusted_credentials"
|
android:key="trusted_credentials"
|
||||||
@@ -51,12 +54,14 @@
|
|||||||
android:key="user_credentials"
|
android:key="user_credentials"
|
||||||
android:title="@string/user_credentials"
|
android:title="@string/user_credentials"
|
||||||
android:summary="@string/user_credentials_summary"
|
android:summary="@string/user_credentials_summary"
|
||||||
android:fragment="com.android.settings.UserCredentialsSettings" />
|
android:fragment="com.android.settings.UserCredentialsSettings"
|
||||||
|
settings:userRestriction="no_config_credentials" />
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:key="credentials_install"
|
android:key="credentials_install"
|
||||||
android:title="@string/credentials_install"
|
android:title="@string/credentials_install"
|
||||||
android:summary="@string/credentials_install_summary">
|
android:summary="@string/credentials_install_summary"
|
||||||
|
settings:userRestriction="no_config_credentials">
|
||||||
|
|
||||||
<intent
|
<intent
|
||||||
android:action="android.credentials.INSTALL"
|
android:action="android.credentials.INSTALL"
|
||||||
@@ -68,7 +73,8 @@
|
|||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:key="credentials_reset"
|
android:key="credentials_reset"
|
||||||
android:title="@string/credentials_reset"
|
android:title="@string/credentials_reset"
|
||||||
android:summary="@string/credentials_reset_summary">
|
android:summary="@string/credentials_reset_summary"
|
||||||
|
settings:userRestriction="no_config_credentials">
|
||||||
|
|
||||||
<intent
|
<intent
|
||||||
android:action="com.android.credentials.RESET"
|
android:action="com.android.credentials.RESET"
|
||||||
|
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.security;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.security.KeyStore;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
public class CredentialStoragePreferenceController extends
|
||||||
|
RestrictedEncryptionPreferenceController {
|
||||||
|
|
||||||
|
private static final String KEY_CREDENTIAL_STORAGE_TYPE = "credential_storage_type";
|
||||||
|
private final KeyStore mKeyStore;
|
||||||
|
|
||||||
|
public CredentialStoragePreferenceController(Context context) {
|
||||||
|
super(context, UserManager.DISALLOW_CONFIG_CREDENTIALS);
|
||||||
|
mKeyStore = KeyStore.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_CREDENTIAL_STORAGE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
preference.setSummary(mKeyStore.isHardwareBacked()
|
||||||
|
? R.string.credential_storage_type_hardware
|
||||||
|
: R.string.credential_storage_type_software);
|
||||||
|
}
|
||||||
|
}
|
@@ -17,22 +17,16 @@
|
|||||||
package com.android.settings.security;
|
package com.android.settings.security;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.SearchIndexableResource;
|
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.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.widget.PreferenceCategoryController;
|
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.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -40,24 +34,11 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Encryption and Credential settings.
|
* Encryption and Credential settings.
|
||||||
* TODO: Extends this from {@link DashboardFragment} instead
|
|
||||||
*/
|
*/
|
||||||
public class EncryptionAndCredential extends DashboardFragment {
|
public class EncryptionAndCredential extends DashboardFragment {
|
||||||
|
|
||||||
private static final String TAG = "EncryptionAndCredential";
|
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
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
return MetricsEvent.ENCRYPTION_AND_CREDENTIAL;
|
return MetricsEvent.ENCRYPTION_AND_CREDENTIAL;
|
||||||
@@ -70,7 +51,7 @@ public class EncryptionAndCredential extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||||
return buildPreferenceControllers(context);
|
return buildPreferenceControllers(context, getLifecycle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -78,7 +59,8 @@ public class EncryptionAndCredential extends DashboardFragment {
|
|||||||
return R.xml.encryption_and_credential;
|
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 List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
final EncryptionStatusPreferenceController encryptStatusController =
|
final EncryptionStatusPreferenceController encryptStatusController =
|
||||||
new EncryptionStatusPreferenceController(context);
|
new EncryptionStatusPreferenceController(context);
|
||||||
@@ -86,76 +68,13 @@ public class EncryptionAndCredential extends DashboardFragment {
|
|||||||
controllers.add(new PreferenceCategoryController(context,
|
controllers.add(new PreferenceCategoryController(context,
|
||||||
"encryption_and_credentials_status_category",
|
"encryption_and_credentials_status_category",
|
||||||
Arrays.asList(encryptStatusController)));
|
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;
|
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
|
@Override
|
||||||
protected int getHelpResource() {
|
protected int getHelpResource() {
|
||||||
return R.string.help_url_encryption;
|
return R.string.help_url_encryption;
|
||||||
@@ -179,7 +98,7 @@ public class EncryptionAndCredential extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||||
return buildPreferenceControllers(context);
|
return buildPreferenceControllers(context, null /* lifecycle */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -187,25 +106,5 @@ public class EncryptionAndCredential extends DashboardFragment {
|
|||||||
final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
return um.isAdminUser();
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.security;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
public class InstallCredentialsPreferenceController extends
|
||||||
|
RestrictedEncryptionPreferenceController {
|
||||||
|
|
||||||
|
private static final String KEY_CREDENTIALS_INSTALL = "credentials_install";
|
||||||
|
|
||||||
|
public InstallCredentialsPreferenceController(Context context) {
|
||||||
|
super(context, UserManager.DISALLOW_CONFIG_CREDENTIALS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_CREDENTIALS_INSTALL;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.security;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.security.KeyStore;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settingslib.RestrictedPreference;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
|
|
||||||
|
public class ResetCredentialsPreferenceController extends RestrictedEncryptionPreferenceController
|
||||||
|
implements LifecycleObserver, OnResume {
|
||||||
|
|
||||||
|
private static final String KEY_RESET_CREDENTIALS = "credentials_reset";
|
||||||
|
|
||||||
|
private final KeyStore mKeyStore;
|
||||||
|
|
||||||
|
private RestrictedPreference mPreference;
|
||||||
|
|
||||||
|
public ResetCredentialsPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
|
super(context, UserManager.DISALLOW_CONFIG_CREDENTIALS);
|
||||||
|
mKeyStore = KeyStore.getInstance();
|
||||||
|
if (lifecycle != null) {
|
||||||
|
lifecycle.addObserver(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_RESET_CREDENTIALS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = (RestrictedPreference) screen.findPreference(getPreferenceKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
if (mPreference != null && !mPreference.isDisabledByAdmin()) {
|
||||||
|
mPreference.setEnabled(!mKeyStore.isEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.security;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
|
public abstract class RestrictedEncryptionPreferenceController extends
|
||||||
|
AbstractPreferenceController implements PreferenceControllerMixin {
|
||||||
|
|
||||||
|
protected final UserManager mUserManager;
|
||||||
|
|
||||||
|
private final UserHandle mUserHandle;
|
||||||
|
private final String mUserRestriction;
|
||||||
|
|
||||||
|
public RestrictedEncryptionPreferenceController(Context context, String userRestriction) {
|
||||||
|
super(context);
|
||||||
|
mUserHandle = UserHandle.of(UserHandle.myUserId());
|
||||||
|
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
|
mUserRestriction = userRestriction;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return !mUserManager.hasBaseUserRestriction(mUserRestriction, mUserHandle);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.security;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
public class UserCredentialsPreferenceController extends
|
||||||
|
RestrictedEncryptionPreferenceController {
|
||||||
|
|
||||||
|
private static final String KEY_USER_CREDENTIALS = "user_credentials";
|
||||||
|
|
||||||
|
public UserCredentialsPreferenceController(Context context) {
|
||||||
|
super(context, UserManager.DISALLOW_CONFIG_CREDENTIALS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_USER_CREDENTIALS;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.security;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowKeyStore;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
|
||||||
|
shadows = {
|
||||||
|
ShadowKeyStore.class
|
||||||
|
})
|
||||||
|
public class CredentialStoragePreferenceControllerTest {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private CredentialStoragePreferenceController mController;
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mController = new CredentialStoragePreferenceController(mContext);
|
||||||
|
mPreference = new Preference(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_hardwareBacked_showHardwareSummary() {
|
||||||
|
ShadowKeyStore.setHardwareBacked(true);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary())
|
||||||
|
.isEqualTo(mContext.getText(R.string.credential_storage_type_hardware));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_hardwareBacked_showSoftwareSummary() {
|
||||||
|
ShadowKeyStore.setHardwareBacked(false);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary())
|
||||||
|
.isEqualTo(mContext.getText(R.string.credential_storage_type_software));
|
||||||
|
}
|
||||||
|
}
|
@@ -34,7 +34,7 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
|
||||||
shadows = {
|
shadows = {
|
||||||
ShadowUserManager.class,
|
ShadowUserManager.class,
|
||||||
ShadowLockPatternUtils.class
|
ShadowLockPatternUtils.class
|
||||||
|
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.security;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
|
||||||
|
shadows = {
|
||||||
|
ShadowUserManager.class
|
||||||
|
})
|
||||||
|
public class RestrictedEncryptionPreferenceControllerTest {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private ShadowUserManager mUserManager;
|
||||||
|
private CredentialStoragePreferenceController mCredentialStoragePreferenceController;
|
||||||
|
private InstallCredentialsPreferenceController mInstallCredentialsPreferenceController;
|
||||||
|
private ResetCredentialsPreferenceController mResetCredentialsPreferenceController;
|
||||||
|
private UserCredentialsPreferenceController mUserCredentialsPreferenceController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mCredentialStoragePreferenceController =
|
||||||
|
new CredentialStoragePreferenceController(mContext);
|
||||||
|
mInstallCredentialsPreferenceController =
|
||||||
|
new InstallCredentialsPreferenceController(mContext);
|
||||||
|
mResetCredentialsPreferenceController =
|
||||||
|
new ResetCredentialsPreferenceController(mContext, new Lifecycle());
|
||||||
|
mUserCredentialsPreferenceController =
|
||||||
|
new UserCredentialsPreferenceController(mContext);
|
||||||
|
mUserManager = ShadowUserManager.getShadow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
mUserManager.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_noRestriction_shouldReturnTrue() {
|
||||||
|
assertThat(mCredentialStoragePreferenceController.isAvailable()).isTrue();
|
||||||
|
assertThat(mInstallCredentialsPreferenceController.isAvailable()).isTrue();
|
||||||
|
assertThat(mResetCredentialsPreferenceController.isAvailable()).isTrue();
|
||||||
|
assertThat(mUserCredentialsPreferenceController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_hasRestriction_shouldReturnFalse() {
|
||||||
|
mUserManager.addBaseUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS);
|
||||||
|
|
||||||
|
assertThat(mCredentialStoragePreferenceController.isAvailable()).isFalse();
|
||||||
|
assertThat(mInstallCredentialsPreferenceController.isAvailable()).isFalse();
|
||||||
|
assertThat(mResetCredentialsPreferenceController.isAvailable()).isFalse();
|
||||||
|
assertThat(mUserCredentialsPreferenceController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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.testutils.shadow;
|
||||||
|
|
||||||
|
import android.security.KeyStore;
|
||||||
|
|
||||||
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
import org.robolectric.annotation.Resetter;
|
||||||
|
|
||||||
|
@Implements(KeyStore.class)
|
||||||
|
public class ShadowKeyStore {
|
||||||
|
|
||||||
|
private static boolean sIsHardwareBacked;
|
||||||
|
|
||||||
|
@Resetter
|
||||||
|
public void reset() {
|
||||||
|
sIsHardwareBacked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public boolean isHardwareBacked() {
|
||||||
|
return sIsHardwareBacked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setHardwareBacked(boolean hardwareBacked) {
|
||||||
|
sIsHardwareBacked = hardwareBacked;
|
||||||
|
}
|
||||||
|
}
|
@@ -19,30 +19,36 @@ package com.android.settings.testutils.shadow;
|
|||||||
import android.annotation.UserIdInt;
|
import android.annotation.UserIdInt;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Implementation;
|
import org.robolectric.annotation.Implementation;
|
||||||
import org.robolectric.annotation.Implements;
|
import org.robolectric.annotation.Implements;
|
||||||
|
import org.robolectric.annotation.Resetter;
|
||||||
import org.robolectric.shadow.api.Shadow;
|
import org.robolectric.shadow.api.Shadow;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides the API 24 implementation of UserManager.get(Context).
|
|
||||||
*/
|
|
||||||
@Implements(UserManager.class)
|
@Implements(UserManager.class)
|
||||||
public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager {
|
public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager {
|
||||||
|
|
||||||
private SparseArray<UserInfo> mUserInfos = new SparseArray<>();
|
private SparseArray<UserInfo> mUserInfos = new SparseArray<>();
|
||||||
private boolean mAdminUser;
|
private boolean mAdminUser;
|
||||||
|
private List<String> mRestrictions = new ArrayList<>();
|
||||||
|
|
||||||
public void setIsAdminUser(boolean isAdminUser) {
|
public void setIsAdminUser(boolean isAdminUser) {
|
||||||
mAdminUser = isAdminUser;
|
mAdminUser = isAdminUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Resetter
|
||||||
|
public void reset() {
|
||||||
|
mRestrictions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Implementation
|
@Implementation
|
||||||
public boolean isAdminUser() {
|
public boolean isAdminUser() {
|
||||||
return mAdminUser;
|
return mAdminUser;
|
||||||
@@ -72,6 +78,15 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
|
|||||||
return (UserManager) context.getSystemService(Context.USER_SERVICE);
|
return (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public boolean hasBaseUserRestriction(String restrictionKey, UserHandle userHandle) {
|
||||||
|
return mRestrictions.contains(restrictionKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBaseUserRestriction(String restriction) {
|
||||||
|
mRestrictions.add(restriction);
|
||||||
|
}
|
||||||
|
|
||||||
public static ShadowUserManager getShadow() {
|
public static ShadowUserManager getShadow() {
|
||||||
return (ShadowUserManager) Shadow.extract(
|
return (ShadowUserManager) Shadow.extract(
|
||||||
RuntimeEnvironment.application.getSystemService(UserManager.class));
|
RuntimeEnvironment.application.getSystemService(UserManager.class));
|
||||||
|
Reference in New Issue
Block a user