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
This commit is contained in:
@@ -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.os.UserManager;
|
||||
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 @@ public class EncryptionAndCredentialTest {
|
||||
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 @@ public class EncryptionAndCredentialTest {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ import org.robolectric.annotation.Implements;
|
||||
public class ShadowLockPatternUtils {
|
||||
|
||||
private int mPasswordQuality = 1;
|
||||
private static boolean sDeviceEncryptionEnabled;
|
||||
|
||||
@Implementation
|
||||
public boolean isSecure(int id) {
|
||||
return true;
|
||||
@@ -42,6 +44,15 @@ public class ShadowLockPatternUtils {
|
||||
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;
|
||||
|
||||
@@ -37,17 +37,17 @@ import java.util.List;
|
||||
|
||||
@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
|
||||
Reference in New Issue
Block a user