diff --git a/src/com/android/settings/password/ChooseLockPassword.java b/src/com/android/settings/password/ChooseLockPassword.java index 55e01b0a0c0..00ba2921a18 100644 --- a/src/com/android/settings/password/ChooseLockPassword.java +++ b/src/com/android/settings/password/ChooseLockPassword.java @@ -831,7 +831,7 @@ public class ChooseLockPassword extends SettingsActivity { mIsAlphaMode ? R.string.lockpassword_password_too_short : R.string.lockpassword_pin_too_short); - if (mLockPatternUtils.isAutoPinConfirmFeatureAvailable() + if (LockPatternUtils.isAutoPinConfirmFeatureAvailable() && !mIsAlphaMode && error.requirement < MIN_AUTO_PIN_REQUIREMENT_LENGTH) { Map arguments = new HashMap<>(); @@ -929,7 +929,7 @@ public class ChooseLockPassword extends SettingsActivity { } private void setAutoPinConfirmOption(boolean enabled, int length) { - if (!mLockPatternUtils.isAutoPinConfirmFeatureAvailable() + if (!LockPatternUtils.isAutoPinConfirmFeatureAvailable() || mAutoPinConfirmOption == null) { return; } diff --git a/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceController.java b/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceController.java index 75af1faf2c9..ff4a8b7924c 100644 --- a/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceController.java +++ b/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceController.java @@ -57,7 +57,7 @@ public class AutoPinConfirmPreferenceController extends AbstractPreferenceContro @Override public boolean isAvailable() { - return mLockPatternUtils.isAutoPinConfirmFeatureAvailable() && isPinLock() + return LockPatternUtils.isAutoPinConfirmFeatureAvailable() && isPinLock() && isPinLengthEligibleForAutoConfirmation(); } diff --git a/tests/robotests/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceControllerTest.java index 370b214eb5e..55e1f1a23c7 100644 --- a/tests/robotests/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/security/screenlock/AutoPinConfirmPreferenceControllerTest.java @@ -16,17 +16,23 @@ package com.android.settings.security.screenlock; +import static android.provider.DeviceConfig.NAMESPACE_AUTO_PIN_CONFIRMATION; + +import static com.android.internal.widget.LockPatternUtils.FLAG_ENABLE_AUTO_PIN_CONFIRMATION; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; +import android.provider.DeviceConfig; import androidx.preference.SwitchPreference; import androidx.test.core.app.ApplicationProvider; import com.android.internal.widget.LockPatternUtils; +import com.android.settings.testutils.shadow.ShadowDeviceConfig; import org.junit.Before; import org.junit.Test; @@ -34,8 +40,10 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; @RunWith(RobolectricTestRunner.class) +@Config(shadows = {ShadowDeviceConfig.class}) public class AutoPinConfirmPreferenceControllerTest { private static final Integer TEST_USER_ID = 1; @Mock @@ -54,16 +62,18 @@ public class AutoPinConfirmPreferenceControllerTest { @Test public void isAvailable_featureEnabledAndLockSetToNone_shouldReturnFalse() { + DeviceConfig.setProperty(NAMESPACE_AUTO_PIN_CONFIRMATION, FLAG_ENABLE_AUTO_PIN_CONFIRMATION, + "true", /* makeDefault */ false); when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true); - when(mLockPatternUtils.isAutoPinConfirmFeatureAvailable()).thenReturn(true); assertThat(mController.isAvailable()).isFalse(); } @Test public void isAvailable_featureEnabledAndLockSetToPassword_shouldReturnFalse() { + DeviceConfig.setProperty(NAMESPACE_AUTO_PIN_CONFIRMATION, FLAG_ENABLE_AUTO_PIN_CONFIRMATION, + "true", /* makeDefault */ false); when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true); - when(mLockPatternUtils.isAutoPinConfirmFeatureAvailable()).thenReturn(true); when(mLockPatternUtils.getCredentialTypeForUser(TEST_USER_ID)) .thenReturn(LockPatternUtils.CREDENTIAL_TYPE_PASSWORD); @@ -72,7 +82,8 @@ public class AutoPinConfirmPreferenceControllerTest { @Test public void isAvailable_featureEnabledAndLockSetToPIN_lengthLessThanSix_shouldReturnFalse() { - when(mLockPatternUtils.isAutoPinConfirmFeatureAvailable()).thenReturn(true); + DeviceConfig.setProperty(NAMESPACE_AUTO_PIN_CONFIRMATION, FLAG_ENABLE_AUTO_PIN_CONFIRMATION, + "true", /* makeDefault */ false); when(mLockPatternUtils.getCredentialTypeForUser(TEST_USER_ID)) .thenReturn(LockPatternUtils.CREDENTIAL_TYPE_PIN); when(mLockPatternUtils.getPinLength(TEST_USER_ID)).thenReturn(5L); @@ -82,8 +93,9 @@ public class AutoPinConfirmPreferenceControllerTest { @Test public void isAvailable_featureEnabledAndLockSetToPIN_lengthMoreThanEqSix_shouldReturnTrue() { + DeviceConfig.setProperty(NAMESPACE_AUTO_PIN_CONFIRMATION, FLAG_ENABLE_AUTO_PIN_CONFIRMATION, + "true", /* makeDefault */ false); when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true); - when(mLockPatternUtils.isAutoPinConfirmFeatureAvailable()).thenReturn(true); when(mLockPatternUtils.getCredentialTypeForUser(TEST_USER_ID)) .thenReturn(LockPatternUtils.CREDENTIAL_TYPE_PIN); when(mLockPatternUtils.getPinLength(TEST_USER_ID)).thenReturn(6L); @@ -93,7 +105,8 @@ public class AutoPinConfirmPreferenceControllerTest { @Test public void isAvailable_featureDisabledAndLockSetToPIN_shouldReturnFalse() { - when(mLockPatternUtils.isAutoPinConfirmFeatureAvailable()).thenReturn(false); + DeviceConfig.setProperty(NAMESPACE_AUTO_PIN_CONFIRMATION, FLAG_ENABLE_AUTO_PIN_CONFIRMATION, + "false", /* makeDefault */ false); when(mLockPatternUtils.isSecure(TEST_USER_ID)).thenReturn(true); when(mLockPatternUtils.getCredentialTypeForUser(TEST_USER_ID)) .thenReturn(LockPatternUtils.CREDENTIAL_TYPE_PIN); @@ -103,7 +116,8 @@ public class AutoPinConfirmPreferenceControllerTest { @Test public void updateState_ChangingSettingState_shouldSetPreferenceToAppropriateCheckedState() { - when(mLockPatternUtils.isAutoPinConfirmFeatureAvailable()).thenReturn(true); + DeviceConfig.setProperty(NAMESPACE_AUTO_PIN_CONFIRMATION, FLAG_ENABLE_AUTO_PIN_CONFIRMATION, + "true", /* makeDefault */ false); // When auto_pin_confirm setting is disabled, switchPreference is unchecked when(mLockPatternUtils.isAutoPinConfirmEnabled(TEST_USER_ID)).thenReturn(false); mController.updateState(mPreference); @@ -117,7 +131,8 @@ public class AutoPinConfirmPreferenceControllerTest { @Test public void onPreferenceChange_shouldUpdatePinAutoConfirmSetting() { - when(mLockPatternUtils.isAutoPinConfirmFeatureAvailable()).thenReturn(true); + DeviceConfig.setProperty(NAMESPACE_AUTO_PIN_CONFIRMATION, FLAG_ENABLE_AUTO_PIN_CONFIRMATION, + "true", /* makeDefault */ false); mController.onPreferenceChange(mPreference, /* newValue= */ true); verify(mLockPatternUtils).setAutoPinConfirm(true, TEST_USER_ID); }