Convert the rest of encryption page into pref controller
Bug: 32953042 Test: robotests Change-Id: I6c1b28314a988e6499065ddaee2aeae0ac28c537
This commit is contained in:
@@ -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;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
|
||||
shadows = {
|
||||
ShadowUserManager.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.content.Context;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class provides the API 24 implementation of UserManager.get(Context).
|
||||
*/
|
||||
@Implements(UserManager.class)
|
||||
public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager {
|
||||
|
||||
private SparseArray<UserInfo> mUserInfos = new SparseArray<>();
|
||||
private boolean mAdminUser;
|
||||
private List<String> mRestrictions = new ArrayList<>();
|
||||
|
||||
public void setIsAdminUser(boolean isAdminUser) {
|
||||
mAdminUser = isAdminUser;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public void reset() {
|
||||
mRestrictions.clear();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public boolean isAdminUser() {
|
||||
return mAdminUser;
|
||||
@@ -72,6 +78,15 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
|
||||
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() {
|
||||
return (ShadowUserManager) Shadow.extract(
|
||||
RuntimeEnvironment.application.getSystemService(UserManager.class));
|
||||
|
Reference in New Issue
Block a user