Convert encryption status to preference controller
- Move Crypt/Encryption setting into security package.
- Reformat crypt_keeper_settings.xml
- Add controller and test for encryption status
Bug: 32953042
Test: robotests
Change-Id: I1f4b2f97133435c70a49522a59886ac4da6759af
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 5a310e98..16baf54 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2384,7 +2384,7 @@
<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"
diff --git a/res/layout/crypt_keeper_settings.xml b/res/layout/crypt_keeper_settings.xml
index b54e0a5..6b33e00 100644
--- a/res/layout/crypt_keeper_settings.xml
+++ b/res/layout/crypt_keeper_settings.xml
@@ -14,33 +14,29 @@
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"
@@ -49,8 +45,7 @@
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"
@@ -59,20 +54,14 @@
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>
diff --git a/res/xml/encryption_and_credential.xml b/res/xml/encryption_and_credential.xml
index 715ea14..4960f25 100644
--- a/res/xml/encryption_and_credential.xml
+++ b/res/xml/encryption_and_credential.xml
@@ -14,45 +14,66 @@
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"/>
+ </PreferenceCategory>
- <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"/>
+ <PreferenceCategory
+ android:key="credentials_management"
+ android:title="@string/credentials_title"
+ android:persistent="false"
+ android:order="100">
- <com.android.settingslib.RestrictedPreference android:key="credentials_install"
- android:title="@string/credentials_install"
- android:summary="@string/credentials_install_summary">
+ <com.android.settingslib.RestrictedPreference
+ android:key="credential_storage_type"
+ android:title="@string/credential_storage_type" />
- <intent android:action="android.credentials.INSTALL"
- android:targetPackage="com.android.certinstaller"
- android:targetClass="com.android.certinstaller.CertInstallerMain"/>
+ <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>
diff --git a/res/xml/security_settings_encrypted.xml b/res/xml/security_settings_encrypted.xml
deleted file mode 100644
index fd7cbce..0000000
--- a/res/xml/security_settings_encrypted.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?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>
diff --git a/res/xml/security_settings_unencrypted.xml b/res/xml/security_settings_unencrypted.xml
deleted file mode 100644
index 4b51376..0000000
--- a/res/xml/security_settings_unencrypted.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?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>
diff --git a/src/com/android/settings/applications/DefaultAppSettings.java b/src/com/android/settings/applications/DefaultAppSettings.java
index 1487da3..34b635b 100644
--- a/src/com/android/settings/applications/DefaultAppSettings.java
+++ b/src/com/android/settings/applications/DefaultAppSettings.java
@@ -30,12 +30,12 @@
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;
@@ -75,7 +75,7 @@
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 */));
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 588e465..8eb75ba 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -18,7 +18,6 @@
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;
@@ -45,7 +44,6 @@
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;
@@ -56,6 +54,7 @@
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;
@@ -106,8 +105,8 @@
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;
@@ -115,6 +114,7 @@
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;
diff --git a/src/com/android/settings/CryptKeeperSettings.java b/src/com/android/settings/security/CryptKeeperSettings.java
similarity index 97%
rename from src/com/android/settings/CryptKeeperSettings.java
rename to src/com/android/settings/security/CryptKeeperSettings.java
index e11bccd..7d5ee9d 100644
--- a/src/com/android/settings/CryptKeeperSettings.java
+++ b/src/com/android/settings/security/CryptKeeperSettings.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings;
+package com.android.settings.security;
import android.app.Activity;
import android.app.AlertDialog;
@@ -36,6 +36,9 @@
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;
diff --git a/src/com/android/settings/security/EncryptionAndCredential.java b/src/com/android/settings/security/EncryptionAndCredential.java
index 0972e3e..b281fb7 100644
--- a/src/com/android/settings/security/EncryptionAndCredential.java
+++ b/src/com/android/settings/security/EncryptionAndCredential.java
@@ -16,7 +16,6 @@
package com.android.settings.security;
-import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
@@ -27,15 +26,16 @@
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;
/**
@@ -55,13 +55,9 @@
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;
@@ -74,13 +70,23 @@
@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;
}
/**
@@ -90,26 +96,7 @@
* 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()
@@ -185,14 +172,14 @@
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
- final List<SearchIndexableResource> index = new ArrayList<>();
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.encryption_and_credential;
+ return Arrays.asList(sir);
+ }
- // 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));
-
- return index;
+ @Override
+ public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
}
@Override
@@ -201,12 +188,6 @@
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);
@@ -223,21 +204,6 @@
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;
}
}
diff --git a/src/com/android/settings/security/EncryptionStatusPreferenceController.java b/src/com/android/settings/security/EncryptionStatusPreferenceController.java
new file mode 100644
index 0000000..7d84421
--- /dev/null
+++ b/src/com/android/settings/security/EncryptionStatusPreferenceController.java
@@ -0,0 +1,61 @@
+/*
+ * 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);
+ }
+ }
+}
diff --git a/src/com/android/settings/widget/WorkOnlyCategoryPreferenceController.java b/src/com/android/settings/widget/PreferenceCategoryController.java
similarity index 82%
rename from src/com/android/settings/widget/WorkOnlyCategoryPreferenceController.java
rename to src/com/android/settings/widget/PreferenceCategoryController.java
index a308b2f..9836476 100644
--- a/src/com/android/settings/widget/WorkOnlyCategoryPreferenceController.java
+++ b/src/com/android/settings/widget/PreferenceCategoryController.java
@@ -23,13 +23,18 @@
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;
diff --git a/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java b/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java
index c87c964..60e7dee 100644
--- a/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java
+++ b/tests/robotests/src/com/android/settings/security/EncryptionAndCredentialTest.java
@@ -16,8 +16,6 @@
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;
@@ -28,7 +26,6 @@
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;
@@ -71,16 +68,6 @@
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);
@@ -96,32 +83,4 @@
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);
- }
}
diff --git a/tests/robotests/src/com/android/settings/security/EncryptionStatusPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/EncryptionStatusPreferenceControllerTest.java
new file mode 100644
index 0000000..a53ee42
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/EncryptionStatusPreferenceControllerTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java
index 3182a93..e7f6be5 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java
@@ -27,6 +27,8 @@
public class ShadowLockPatternUtils {
private int mPasswordQuality = 1;
+ private static boolean sDeviceEncryptionEnabled;
+
@Implementation
public boolean isSecure(int id) {
return true;
@@ -42,6 +44,15 @@
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;
diff --git a/tests/robotests/src/com/android/settings/widget/WorkOnlyCategoryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/widget/PreferenceCategoryControllerTest.java
similarity index 91%
rename from tests/robotests/src/com/android/settings/widget/WorkOnlyCategoryPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/widget/PreferenceCategoryControllerTest.java
index 9c7e8fc..23aa378 100644
--- a/tests/robotests/src/com/android/settings/widget/WorkOnlyCategoryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/PreferenceCategoryControllerTest.java
@@ -37,17 +37,17 @@
@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