Merge "Add wipe on login failure to Privacy Settings page"
This commit is contained in:
committed by
Android (Google) Code Review
commit
3cac802860
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
@@ -53,7 +55,7 @@ public final class AdminActionPreferenceControllerBaseTest extends
|
||||
private class AdminActionPreferenceControllerBaseTestable extends
|
||||
AdminActionPreferenceControllerBase {
|
||||
AdminActionPreferenceControllerBaseTestable() {
|
||||
super(mContext);
|
||||
super(AdminActionPreferenceControllerBaseTest.this.mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -54,7 +54,7 @@ public abstract class AdminActionPreferenceControllerTestBase {
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
}
|
||||
|
||||
protected abstract void setDate(Date date);
|
||||
public abstract void setDate(Date date);
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
|
@@ -80,7 +80,7 @@ public abstract class AdminGrantedPermissionsPreferenceControllerTestBase {
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
preference.setVisible(true);
|
||||
preference.setVisible(false);
|
||||
|
||||
setNumberOfPackagesWithAdminGrantedPermissions(20);
|
||||
when(mContext.getResources().getQuantityString(mStringResourceId, 20, 20))
|
||||
|
@@ -55,8 +55,8 @@ import static org.mockito.Mockito.when;
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
|
||||
private final ComponentName DEVICE_OWNER = new ComponentName("dummy", "component");
|
||||
private final String DEVICE_OWNER_ORGANIZATION = new String("ACME");
|
||||
private final ComponentName OWNER = new ComponentName("dummy", "component");
|
||||
private final String OWNER_ORGANIZATION = new String("ACME");
|
||||
private final Date TIMESTAMP = new Date(2011, 11, 11);
|
||||
private final int MY_USER_ID = UserHandle.myUserId();
|
||||
private final int MANAGED_PROFILE_USER_ID = MY_USER_ID + 1;
|
||||
@@ -91,13 +91,13 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
|
||||
assertThat(mProvider.hasDeviceOwner()).isFalse();
|
||||
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(DEVICE_OWNER);
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(OWNER);
|
||||
assertThat(mProvider.hasDeviceOwner()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsInCompMode() {
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(DEVICE_OWNER);
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(OWNER);
|
||||
assertThat(mProvider.isInCompMode()).isFalse();
|
||||
|
||||
mProfiles.add(new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE));
|
||||
@@ -116,18 +116,17 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more_separator));
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more),
|
||||
new EnterprisePrivacyFeatureProviderImpl.EnterprisePrivacySpan(context), 0);
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(DEVICE_OWNER);
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(OWNER);
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
|
||||
assertThat(mProvider.getDeviceOwnerDisclosure(context)).isEqualTo(disclosure);
|
||||
|
||||
disclosure = new SpannableStringBuilder();
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_with_name,
|
||||
DEVICE_OWNER_ORGANIZATION));
|
||||
OWNER_ORGANIZATION));
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more_separator));
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more),
|
||||
new EnterprisePrivacyFeatureProviderImpl.EnterprisePrivacySpan(context), 0);
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName())
|
||||
.thenReturn(DEVICE_OWNER_ORGANIZATION);
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(OWNER_ORGANIZATION);
|
||||
assertThat(mProvider.getDeviceOwnerDisclosure(context)).isEqualTo(disclosure);
|
||||
}
|
||||
|
||||
@@ -193,4 +192,29 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
ProxyInfo.buildDirectProxy("localhost", 123));
|
||||
assertThat(mProvider.isGlobalHttpProxySet()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMaximumFailedPasswordsForWipeInPrimaryUser() {
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
|
||||
when(mDevicePolicyManager.getDeviceOwnerUserId()).thenReturn(UserHandle.USER_NULL);
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInPrimaryUser()).isEqualTo(0);
|
||||
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(OWNER);
|
||||
when(mDevicePolicyManager.getDeviceOwnerUserId()).thenReturn(UserHandle.USER_SYSTEM);
|
||||
when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, UserHandle.USER_SYSTEM))
|
||||
.thenReturn(10);
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInPrimaryUser()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMaximumFailedPasswordsForWipeInManagedProfile() {
|
||||
when(mDevicePolicyManager.getProfileOwnerAsUser(MANAGED_PROFILE_USER_ID)).thenReturn(OWNER);
|
||||
when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, MANAGED_PROFILE_USER_ID))
|
||||
.thenReturn(10);
|
||||
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInManagedProfile()).isEqualTo(0);
|
||||
|
||||
mProfiles.add(new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE));
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInManagedProfile()).isEqualTo(10);
|
||||
}
|
||||
}
|
||||
|
@@ -73,7 +73,7 @@ public final class EnterprisePrivacySettingsTest {
|
||||
final List<PreferenceController> controllers = mSettings.getPreferenceControllers(
|
||||
ShadowApplication.getInstance().getApplicationContext());
|
||||
assertThat(controllers).isNotNull();
|
||||
assertThat(controllers.size()).isEqualTo(12);
|
||||
assertThat(controllers.size()).isEqualTo(14);
|
||||
assertThat(controllers.get(0)).isInstanceOf(InstalledPackagesPreferenceController.class);
|
||||
assertThat(controllers.get(1)).isInstanceOf(NetworkLogsPreferenceController.class);
|
||||
assertThat(controllers.get(2)).isInstanceOf(BugReportsPreferenceController.class);
|
||||
@@ -93,5 +93,7 @@ public final class EnterprisePrivacySettingsTest {
|
||||
assertThat(controllers.get(10)).isInstanceOf(
|
||||
AlwaysOnVpnManagedProfilePreferenceController.class);
|
||||
assertThat(controllers.get(11)).isInstanceOf(GlobalHttpProxyPreferenceController.class);
|
||||
assertThat(controllers.get(12)).isInstanceOf(FailedPasswordWipePrimaryUserPreferenceController.class);
|
||||
assertThat(controllers.get(13)).isInstanceOf(FailedPasswordWipeManagedProfilePreferenceController.class);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link FailedPasswordWipeManagedProfilePreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class FailedPasswordWipeManagedProfilePreferenceControllerTest extends
|
||||
FailedPasswordWipePreferenceControllerTestBase {
|
||||
|
||||
private int mMaximumFailedPasswordsBeforeWipe = 0;
|
||||
|
||||
public FailedPasswordWipeManagedProfilePreferenceControllerTest() {
|
||||
super("failed_password_wipe_managed_profile",
|
||||
R.plurals.enterprise_privacy_failed_password_wipe_work);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
mController = new FailedPasswordWipeManagedProfilePreferenceController(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaximumFailedPasswordsBeforeWipe(int maximum) {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider
|
||||
.getMaximumFailedPasswordsBeforeWipeInManagedProfile()).thenReturn(maximum);
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.enterprise;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
/**
|
||||
* Tests for {@link FailedPasswordWipePreferenceControllerBase}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class FailedPasswordWipePreferenceControllerBaseTest extends
|
||||
FailedPasswordWipePreferenceControllerTestBase {
|
||||
|
||||
private int mMaximumFailedPasswordsBeforeWipe = 0;
|
||||
|
||||
public FailedPasswordWipePreferenceControllerBaseTest() {
|
||||
super(null, 123 /* stringResourceId */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
mController = new FailedPasswordWipePreferenceControllerBaseTestable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaximumFailedPasswordsBeforeWipe(int maximum) {
|
||||
mMaximumFailedPasswordsBeforeWipe = maximum;
|
||||
}
|
||||
|
||||
private class FailedPasswordWipePreferenceControllerBaseTestable extends
|
||||
FailedPasswordWipePreferenceControllerBase {
|
||||
FailedPasswordWipePreferenceControllerBaseTestable() {
|
||||
super(FailedPasswordWipePreferenceControllerBaseTest.this.mContext, mStringResourceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaximumFailedPasswordsBeforeWipe() {
|
||||
return mMaximumFailedPasswordsBeforeWipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Common base for testing subclasses of {@link FailedPasswordWipePreferenceControllerBase}.
|
||||
*/
|
||||
public abstract class FailedPasswordWipePreferenceControllerTestBase {
|
||||
|
||||
protected final String mKey;
|
||||
protected final int mStringResourceId;
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
protected Context mContext;
|
||||
protected FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
protected FailedPasswordWipePreferenceControllerBase mController;
|
||||
|
||||
public FailedPasswordWipePreferenceControllerTestBase(String key, int stringResourceId) {
|
||||
mKey = key;
|
||||
mStringResourceId = stringResourceId;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
}
|
||||
|
||||
public abstract void setMaximumFailedPasswordsBeforeWipe(int maximum);
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
preference.setVisible(false);
|
||||
|
||||
setMaximumFailedPasswordsBeforeWipe(10);
|
||||
when(mContext.getResources().getQuantityString(mStringResourceId, 10, 10))
|
||||
.thenReturn("10 attempts");
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.getTitle()).isEqualTo("10 attempts");
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
|
||||
setMaximumFailedPasswordsBeforeWipe(0);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick() {
|
||||
assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceKey() {
|
||||
assertThat(mController.getPreferenceKey()).isEqualTo(mKey);
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link FailedPasswordWipePrimaryUserPreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class FailedPasswordWipePrimaryUserPreferenceControllerTest extends
|
||||
FailedPasswordWipePreferenceControllerTestBase {
|
||||
|
||||
private int mMaximumFailedPasswordsBeforeWipe = 0;
|
||||
|
||||
public FailedPasswordWipePrimaryUserPreferenceControllerTest() {
|
||||
super("failed_password_wipe_primary_user",
|
||||
R.plurals.enterprise_privacy_failed_password_wipe_device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
mController = new FailedPasswordWipePrimaryUserPreferenceController(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaximumFailedPasswordsBeforeWipe(int maximum) {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider
|
||||
.getMaximumFailedPasswordsBeforeWipeInPrimaryUser()).thenReturn(maximum);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user