<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.CryptKeeperSettings" />
+ android:value="com.android.settings.security.CryptKeeperSettings" />
</activity>
<activity android:name="Settings$DataPlanUsageSummaryActivity"
limitations under the License.
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical"
->
-
+ android:paddingStart="@dimen/preference_no_icon_padding_start"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dip"
- android:layout_marginStart="16dp"
- android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
- android:layout_weight="1"
- >
+ android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:orientation="vertical"
- >
+ android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dip"
android:layout_marginBottom="16dip"
android:textAppearance="?android:attr/textAppearanceMedium"
- android:text="@string/crypt_keeper_desc"
- />
+ android:text="@string/crypt_keeper_desc" />
<TextView
android:id="@+id/warning_low_charge"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:text="@string/crypt_keeper_low_charge_text"
- android:visibility="gone"
- />
+ android:visibility="gone" />
<TextView
android:id="@+id/warning_unplugged"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:text="@string/crypt_keeper_unplugged_text"
- android:visibility="gone"
- />
+ android:visibility="gone" />
</LinearLayout>
-
</ScrollView>
<Button
android:id="@+id/initiate_encrypt"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="16dip"
- android:layout_marginBottom="16dip"
+ style="@style/ActionPrimaryButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/crypt_keeper_button_text"
- android:gravity="center"
- />
-
+ android:layout_gravity="end"
+ android:text="@string/crypt_keeper_button_text" />
</LinearLayout>
limitations under the License.
-->
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- android:title="@string/encryption_and_credential_settings_title"
- android:key="encryption_and_credentials_screen">
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/encryption_and_credential_settings_title"
+ android:key="encryption_and_credentials_screen">
- <PreferenceCategory android:key="credentials_management"
- android:title="@string/credentials_title"
- android:persistent="false"
- android:order="100">
+ <PreferenceCategory
+ android:key="encryption_and_credentials_status_category"
+ android:title="@string/crypt_keeper_settings_title">
- <com.android.settingslib.RestrictedPreference android:key="credential_storage_type"
- android:title="@string/credential_storage_type" />
+ <Preference
+ android:key="encryption_and_credentials_encryption_status"
+ android:title="@string/crypt_keeper_encrypt_title"
+ android:fragment="com.android.settings.security.CryptKeeperSettings"
+ android:summary="@string/summary_placeholder" />
- <Preference android:key="trusted_credentials"
- android:title="@string/trusted_credentials"
- android:summary="@string/trusted_credentials_summary"
- android:fragment="com.android.settings.TrustedCredentialsSettings"/>
-
- <com.android.settingslib.RestrictedPreference android:key="user_credentials"
- android:title="@string/user_credentials"
- android:summary="@string/user_credentials_summary"
- android:fragment="com.android.settings.UserCredentialsSettings"/>
-
- <com.android.settingslib.RestrictedPreference android:key="credentials_install"
- android:title="@string/credentials_install"
- android:summary="@string/credentials_install_summary">
+ </PreferenceCategory>
- <intent android:action="android.credentials.INSTALL"
- android:targetPackage="com.android.certinstaller"
- android:targetClass="com.android.certinstaller.CertInstallerMain"/>
+ <PreferenceCategory
+ android:key="credentials_management"
+ android:title="@string/credentials_title"
+ android:persistent="false"
+ android:order="100">
+
+ <com.android.settingslib.RestrictedPreference
+ android:key="credential_storage_type"
+ android:title="@string/credential_storage_type" />
+
+ <Preference
+ android:key="trusted_credentials"
+ android:title="@string/trusted_credentials"
+ android:summary="@string/trusted_credentials_summary"
+ android:fragment="com.android.settings.TrustedCredentialsSettings" />
+
+ <com.android.settingslib.RestrictedPreference
+ android:key="user_credentials"
+ android:title="@string/user_credentials"
+ android:summary="@string/user_credentials_summary"
+ android:fragment="com.android.settings.UserCredentialsSettings" />
+
+ <com.android.settingslib.RestrictedPreference
+ android:key="credentials_install"
+ android:title="@string/credentials_install"
+ android:summary="@string/credentials_install_summary">
+
+ <intent
+ android:action="android.credentials.INSTALL"
+ android:targetPackage="com.android.certinstaller"
+ android:targetClass="com.android.certinstaller.CertInstallerMain" />
</com.android.settingslib.RestrictedPreference>
- <com.android.settingslib.RestrictedPreference android:key="credentials_reset"
- android:title="@string/credentials_reset"
- android:summary="@string/credentials_reset_summary">
+ <com.android.settingslib.RestrictedPreference
+ android:key="credentials_reset"
+ android:title="@string/credentials_reset"
+ android:summary="@string/credentials_reset_summary">
- <intent android:action="com.android.credentials.RESET"
- android:targetPackage="com.android.settings"
- android:targetClass="com.android.settings.CredentialStorage"/>
+ <intent
+ android:action="com.android.credentials.RESET"
+ android:targetPackage="com.android.settings"
+ android:targetClass="com.android.settings.CredentialStorage" />
</com.android.settingslib.RestrictedPreference>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 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.
--->
-
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- android:key="security_settings_encrypted_screen"
- android:title="@string/security_settings_title">
-
- <PreferenceCategory
- android:key="security_category_for_encrypted_device"
- android:title="@string/crypt_keeper_settings_title">
-
- <Preference
- android:key="crypt_keeper_encrypt_title"
- android:title="@string/crypt_keeper_encrypt_title"
- android:summary="@string/crypt_keeper_encrypted_summary"/>
-
- </PreferenceCategory>
-
-
-</PreferenceScreen>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2010 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.
--->
-
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- android:key="security_settings_unencrypted_screen"
- android:title="@string/crypt_keeper_settings_title">
-
- <PreferenceCategory
- android:key="security_category_for_unencrypted_device"
- android:title="@string/crypt_keeper_settings_title">
-
- <Preference
- android:key="encryption"
- android:title="@string/crypt_keeper_encrypt_title"
- android:fragment="com.android.settings.CryptKeeperSettings" />
-
- </PreferenceCategory>
-
-</PreferenceScreen>
import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
import com.android.settings.applications.defaultapps.DefaultWorkBrowserPreferenceController;
-import com.android.settings.widget.WorkOnlyCategoryPreferenceController;
import com.android.settings.applications.defaultapps.DefaultWorkPhonePreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
+import com.android.settings.widget.PreferenceCategoryController;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
workControllers.add(new DefaultWorkPhonePreferenceController(context));
workControllers.add(new DefaultWorkBrowserPreferenceController(context));
controllers.addAll(workControllers);
- controllers.add(new WorkOnlyCategoryPreferenceController(
+ controllers.add(new PreferenceCategoryController(
context, KEY_DEFAULT_WORK_CATEGORY, workControllers));
controllers.add(new DefaultAssistPreferenceController(context, KEY_ASSIST_VOICE_INPUT,
false /* showSetting */));
import com.android.settings.ApnEditor;
import com.android.settings.ApnSettings;
-import com.android.settings.CryptKeeperSettings;
import com.android.settings.DateTimeSettings;
import com.android.settings.DeviceAdminSettings;
import com.android.settings.DeviceInfoSettings;
import com.android.settings.applications.DrawOverlayDetails;
import com.android.settings.applications.ExternalSourcesDetails;
import com.android.settings.applications.InstalledAppDetails;
-import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.applications.ManageDomainUrls;
import com.android.settings.applications.NotificationApps;
import com.android.settings.applications.PictureInPictureDetails;
import com.android.settings.applications.VrListenerSettings;
import com.android.settings.applications.WriteSettingsDetails;
import com.android.settings.applications.assist.ManageAssist;
+import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
import com.android.settings.bluetooth.BluetoothSettings;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.notification.NotificationStation;
import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.ZenAccessSettings;
-import com.android.settings.notification.ZenModeBehaviorSettings;
import com.android.settings.notification.ZenModeAutomationSettings;
+import com.android.settings.notification.ZenModeBehaviorSettings;
import com.android.settings.notification.ZenModeEventRuleSettings;
import com.android.settings.notification.ZenModeScheduleRuleSettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.password.ChooseLockPattern;
import com.android.settings.print.PrintJobSettingsFragment;
import com.android.settings.print.PrintSettingsFragment;
+import com.android.settings.security.CryptKeeperSettings;
import com.android.settings.security.LockscreenDashboardFragment;
import com.android.settings.sim.SimSettings;
import com.android.settings.support.SupportDashboardActivity;
* limitations under the License.
*/
-package com.android.settings;
+package com.android.settings.security;
import android.app.Activity;
import android.app.AlertDialog;
import android.widget.Button;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.CryptKeeperConfirm;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.password.ConfirmLockPattern;
package com.android.settings.security;
-import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
import android.support.v7.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.internal.widget.LockPatternUtils;
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 java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
private static final int MY_USER_ID = UserHandle.myUserId();
- private UserManager mUm;
-
private KeyStore mKeyStore;
private RestrictedPreference mResetCredentials;
- private boolean mIsAdmin;
-
@Override
public int getMetricsCategory() {
return MetricsEvent.ENCRYPTION_AND_CREDENTIAL;
@Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
- mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
- return null;
+ return buildPreferenceControllers(context);
}
@Override
protected int getPreferenceScreenResId() {
- return 0;
+ return R.xml.encryption_and_credential;
+ }
+
+ private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
+ final EncryptionStatusPreferenceController encryptStatusController =
+ new EncryptionStatusPreferenceController(context);
+ controllers.add(encryptStatusController);
+ controllers.add(new PreferenceCategoryController(context,
+ "encryption_and_credentials_status_category",
+ Arrays.asList(encryptStatusController)));
+ return controllers;
}
/**
* logic or adding/removing preferences here.
*/
private PreferenceScreen createPreferenceHierarchy() {
- PreferenceScreen root = getPreferenceScreen();
- if (root != null) {
- root.removeAll();
- }
- addPreferencesFromResource(R.xml.encryption_and_credential);
- root = getPreferenceScreen();
-
- // Add options for device encryption
- mIsAdmin = mUm.isAdminUser();
-
- if (mIsAdmin) {
- if (LockPatternUtils.isDeviceEncryptionEnabled()) {
- // The device is currently encrypted.
- addPreferencesFromResource(R.xml.security_settings_encrypted);
- } else {
- // This device supports encryption but isn't encrypted.
- addPreferencesFromResource(R.xml.security_settings_unencrypted);
- }
- }
-
+ final PreferenceScreen root = getPreferenceScreen();
// Credential storage
mKeyStore = KeyStore.getInstance(); // needs to be initialized for onResume()
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- final List<SearchIndexableResource> index = new ArrayList<>();
-
- // Add everything. We will suppress some of them in getNonIndexableKeys()
- index.add(getSearchResource(context, R.xml.encryption_and_credential));
- index.add(getSearchResource(context, R.xml.security_settings_encrypted));
- index.add(getSearchResource(context, R.xml.security_settings_unencrypted));
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.encryption_and_credential;
+ return Arrays.asList(sir);
+ }
- return index;
+ @Override
+ public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
}
@Override
return um.isAdminUser();
}
- private SearchIndexableResource getSearchResource(Context context, int xmlResId) {
- final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = xmlResId;
- return sir;
- }
-
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
keys.add(KEY_USER_CREDENTIALS);
}
- final DevicePolicyManager dpm = (DevicePolicyManager)
- context.getSystemService(Context.DEVICE_POLICY_SERVICE);
- switch (dpm.getStorageEncryptionStatus()) {
- case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
- // The device is currently encrypted. Disable security_settings_unencrypted
- keys.addAll(getNonIndexableKeysFromXml(
- context, R.xml.security_settings_unencrypted));
- break;
- default:
- // This device supports encryption but isn't encrypted.
- keys.addAll(getNonIndexableKeysFromXml(
- context, R.xml.security_settings_encrypted));
- break;
- }
-
return keys;
}
}
--- /dev/null
+/*
+ * 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.support.v7.preference.Preference;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class EncryptionStatusPreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin {
+
+ private static final String PREF_KEY = "encryption_and_credentials_encryption_status";
+
+ private final UserManager mUserManager;
+
+ public EncryptionStatusPreferenceController(Context context) {
+ super(context);
+ mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return mUserManager.isAdminUser();
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final boolean encryptionEnabled = LockPatternUtils.isDeviceEncryptionEnabled();
+ if (encryptionEnabled) {
+ preference.setFragment(null);
+ preference.setSummary(R.string.crypt_keeper_encrypted_summary);
+ } else {
+ preference.setFragment(CryptKeeperSettings.class.getName());
+ preference.setSummary(R.string.summary_placeholder);
+ }
+ }
+}
import java.util.List;
-public class WorkOnlyCategoryPreferenceController extends AbstractPreferenceController
+/**
+ * A controller for generic Preference categories. If all controllers for its children reports
+ * not-available, this controller will also report not-available, and subsequently will be hidden by
+ * UI.
+ */
+public class PreferenceCategoryController extends AbstractPreferenceController
implements PreferenceControllerMixin {
private final String mKey;
private final List<AbstractPreferenceController> mChildren;
- public WorkOnlyCategoryPreferenceController(Context context,
+ public PreferenceCategoryController(Context context,
String key, List<AbstractPreferenceController> childrenControllers) {
super(context);
mKey = key;
package com.android.settings.security;
-import static android.app.admin.DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE;
-import static android.app.admin.DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE;
import static com.android.settings.security.EncryptionAndCredential.SEARCH_INDEX_DATA_PROVIDER;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
assertThat(fragment.getMetricsCategory()).isEqualTo(MetricsEvent.ENCRYPTION_AND_CREDENTIAL);
}
- // Search provider tests
- @Test
- public void getXmlResourcesToIndex_shouldReturnAllXmls() {
- final List<SearchIndexableResource> index =
- SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
- mContext, true /* enabled */);
-
- assertThat(index).hasSize(3);
- }
-
@Test
public void getNonIndexableKeys_pageIsDisabled_shouldReturnAllKeysAsNonIndexable() {
when(mUserManager.isAdminUser()).thenReturn(false);
assertThat(keys).containsExactlyElementsIn(expectedKeys);
}
-
- @Test
- public void getNonIndexableKeys_deviceEncrypted_shouldReturnUnencryptedKeys() {
- when(mUserManager.isAdminUser()).thenReturn(true);
- when(mDevicePolicyManager.getStorageEncryptionStatus()).thenReturn(
- ENCRYPTION_STATUS_ACTIVE);
-
- final List<String> expectedKeys = new ArrayList<>();
- expectedKeys.addAll(((BaseSearchIndexProvider) SEARCH_INDEX_DATA_PROVIDER)
- .getNonIndexableKeysFromXml(mContext, R.xml.security_settings_unencrypted));
- final List<String> keys = SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
-
- assertThat(keys).containsExactlyElementsIn(expectedKeys);
- }
-
- @Test
- public void getNonIndexableKeys_deviceNotEncrypted_shouldReturnEncryptedKeys() {
- when(mUserManager.isAdminUser()).thenReturn(true);
- when(mDevicePolicyManager.getStorageEncryptionStatus())
- .thenReturn(ENCRYPTION_STATUS_INACTIVE);
-
- final List<String> expectedKeys = new ArrayList<>();
- expectedKeys.addAll(((BaseSearchIndexProvider) SEARCH_INDEX_DATA_PROVIDER)
- .getNonIndexableKeysFromXml(mContext, R.xml.security_settings_encrypted));
- final List<String> keys = SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
-
- assertThat(keys).containsExactlyElementsIn(expectedKeys);
- }
}
--- /dev/null
+/*
+ * 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.ShadowLockPatternUtils;
+import com.android.settings.testutils.shadow.ShadowUserManager;
+
+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,
+ shadows = {
+ ShadowUserManager.class,
+ ShadowLockPatternUtils.class
+ })
+public class EncryptionStatusPreferenceControllerTest {
+
+ private Context mContext;
+ private EncryptionStatusPreferenceController mController;
+ private Preference mPreference;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mController = new EncryptionStatusPreferenceController(mContext);
+ mPreference = new Preference(mContext);
+ }
+
+ @Test
+ public void isAvailable_admin_true() {
+ ShadowUserManager.getShadow().setIsAdminUser(true);
+
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_notAdmin_false() {
+ ShadowUserManager.getShadow().setIsAdminUser(false);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void updateSummary_encrypted_shouldSayEncrypted() {
+ ShadowLockPatternUtils.setDeviceEncryptionEnabled(true);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getFragment()).isNull();
+ assertThat(mPreference.getSummary())
+ .isEqualTo(mContext.getText(R.string.crypt_keeper_encrypted_summary));
+ }
+
+ @Test
+ public void updateSummary_unencrypted_shouldHasEncryptionFragment() {
+ ShadowLockPatternUtils.setDeviceEncryptionEnabled(false);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getSummary())
+ .isEqualTo(mContext.getText(R.string.summary_placeholder));
+ assertThat(mPreference.getFragment()).isEqualTo(CryptKeeperSettings.class.getName());
+ }
+}
public class ShadowLockPatternUtils {
private int mPasswordQuality = 1;
+ private static boolean sDeviceEncryptionEnabled;
+
@Implementation
public boolean isSecure(int id) {
return true;
return mPasswordQuality;
}
+ @Implementation
+ public static boolean isDeviceEncryptionEnabled() {
+ return sDeviceEncryptionEnabled;
+ }
+
+ public static void setDeviceEncryptionEnabled(boolean deviceEncryptionEnabled) {
+ sDeviceEncryptionEnabled = deviceEncryptionEnabled;
+ }
+
// Non-Android accessor.
public int getPasswordQuality() {
return mPasswordQuality;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class WorkOnlyCategoryPreferenceControllerTest {
+public class PreferenceCategoryControllerTest {
private Context mContext;
- private WorkOnlyCategoryPreferenceController mController;
+ private PreferenceCategoryController mController;
private List<AbstractPreferenceController> mChildren;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mChildren = new ArrayList<>();
- mController = new WorkOnlyCategoryPreferenceController(mContext, "pref_key", mChildren);
+ mController = new PreferenceCategoryController(mContext, "pref_key", mChildren);
}
@Test