[Screen off unlock UDFPS] Fingerprint Settings integration 2/2

1. Integrate FingerprintSettings with Toggle
2. Sync the Toggle state with SettingProvider key
   "screen_off_unlock_udfps"

Reference: go/udfps-aof #Settings UI design(Deck)

Bug: 373792870
Bug: 369939804
Bug: 369938501
Flag: android.hardware.biometrics.screen_off_unlock_udfps
Test: atest FingerprintSettingsFragmentTest
    atest DevelopmentSettingsDashboardFragmentTest
    atest FingerprintSettingsUnlockCategoryControllerTest
    atest FingerprintSettingsScreenOffUnlockUdfpsPreferenceControllerTest
Test: adb shell settings put secure
      screen_off_unlock_udfps <1|0>
Change-Id: I03794f53684bfb60b4a854e14507e67f60c55a7d
This commit is contained in:
lbill
2024-10-22 09:17:46 +00:00
parent ce5ecef874
commit 88cf7037b0
8 changed files with 436 additions and 26 deletions

View File

@@ -79,6 +79,7 @@ android_library {
"BiometricsSharedLib", "BiometricsSharedLib",
"SystemUIUnfoldLib", "SystemUIUnfoldLib",
"WifiTrackerLib", "WifiTrackerLib",
"android.hardware.biometrics.flags-aconfig-java",
"android.hardware.dumpstate-V1-java", "android.hardware.dumpstate-V1-java",
"android.hardware.dumpstate-V1.0-java", "android.hardware.dumpstate-V1.0-java",
"android.hardware.dumpstate-V1.1-java", "android.hardware.dumpstate-V1.1-java",

View File

@@ -1234,6 +1234,16 @@
<string name="security_settings_fingerprint_bad_calibration_title">Can\u2019t use fingerprint sensor</string> <string name="security_settings_fingerprint_bad_calibration_title">Can\u2019t use fingerprint sensor</string>
<!-- Text shown during fingerprint enrollment to indicate bad sensor calibration. [CHAR LIMIT=100] --> <!-- Text shown during fingerprint enrollment to indicate bad sensor calibration. [CHAR LIMIT=100] -->
<string name="security_settings_fingerprint_bad_calibration">Visit a repair provider.</string> <string name="security_settings_fingerprint_bad_calibration">Visit a repair provider.</string>
<!-- Key for screen off udfps unlock feature. [CHAR LIMIT=NONE] -->
<string name="security_settings_screen_off_unlock_udfps_key" translatable="false">security_settings_screen_off_unlock_udfps</string>
<!-- Title for Key for screen off udfps unlock feature. [CHAR LIMIT=NONE] -->
<string name="security_settings_screen_off_unlock_udfps_title">Screen-off Fingerprint Unlock</string>
<!-- Description for screen off udfps unlock feature. [CHAR LIMIT=NONE] -->
<string name="security_settings_screen_off_unlock_udfps_description">Use Fingerprint Unlock even when the screen is off</string>
<!-- Description for screen off udfps unlock feature. [CHAR LIMIT=NONE] -->
<string name="security_settings_screen_off_unlock_udfps_keywords">Screen-off, Unlock</string>
<!-- Title for the section that has additional security settings. [CHAR LIMIT=60] --> <!-- Title for the section that has additional security settings. [CHAR LIMIT=60] -->
<string name="security_advanced_settings">More security settings</string> <string name="security_advanced_settings">More security settings</string>
<!-- String for the "More security settings" summary when a work profile is on the device. [CHAR_LIMIT=NONE] --> <!-- String for the "More security settings" summary when a work profile is on the device. [CHAR_LIMIT=NONE] -->

View File

@@ -40,7 +40,16 @@
android:title="@string/security_settings_require_screen_on_to_auth_title" android:title="@string/security_settings_require_screen_on_to_auth_title"
android:summary="@string/security_settings_require_screen_on_to_auth_description" android:summary="@string/security_settings_require_screen_on_to_auth_description"
settings:keywords="@string/security_settings_require_screen_on_to_auth_keywords" settings:keywords="@string/security_settings_require_screen_on_to_auth_keywords"
settings:controller="com.android.settings.biometrics.fingerprint.FingerprintSettingsRequireScreenOnToAuthPreferenceController" /> settings:controller="com.android.settings.biometrics.fingerprint.FingerprintSettingsRequireScreenOnToAuthPreferenceController"
settings:isPreferenceVisible="false"/>
<com.android.settingslib.RestrictedSwitchPreference
android:key="@string/security_settings_screen_off_unlock_udfps_key"
android:title="@string/security_settings_screen_off_unlock_udfps_title"
android:summary="@string/security_settings_screen_off_unlock_udfps_description"
settings:keywords="@string/security_settings_screen_off_unlock_udfps_keywords"
settings:controller="com.android.settings.biometrics.fingerprint.FingerprintSettingsScreenOffUnlockUdfpsPreferenceController"
settings:isPreferenceVisible="false"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory

View File

@@ -20,6 +20,7 @@ package com.android.settings.biometrics.fingerprint;
import static android.app.admin.DevicePolicyResources.Strings.Settings.FINGERPRINT_UNLOCK_DISABLED_EXPLANATION; import static android.app.admin.DevicePolicyResources.Strings.Settings.FINGERPRINT_UNLOCK_DISABLED_EXPLANATION;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_FINGERPRINT_LAST_DELETE_MESSAGE; import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_FINGERPRINT_LAST_DELETE_MESSAGE;
import static android.app.admin.DevicePolicyResources.UNDEFINED; import static android.app.admin.DevicePolicyResources.UNDEFINED;
import static android.hardware.biometrics.Flags.screenOffUnlockUdfps;
import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME; import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
import static com.android.settings.Utils.isPrivateProfile; import static com.android.settings.Utils.isPrivateProfile;
@@ -207,6 +208,17 @@ public class FingerprintSettings extends SubSettings {
context, context,
KEY_REQUIRE_SCREEN_ON_TO_AUTH KEY_REQUIRE_SCREEN_ON_TO_AUTH
)); ));
} else if (screenOffUnlockUdfps()) {
controllers.add(
new FingerprintUnlockCategoryController(
context,
KEY_FINGERPRINT_UNLOCK_CATEGORY
));
controllers.add(
new FingerprintSettingsScreenOffUnlockUdfpsPreferenceController(
context,
KEY_SCREEN_OFF_FINGERPRINT_UNLOCK
));
} }
controllers.add(new FingerprintsEnrolledCategoryPreferenceController(context, controllers.add(new FingerprintsEnrolledCategoryPreferenceController(context,
KEY_FINGERPRINTS_ENROLLED_CATEGORY)); KEY_FINGERPRINTS_ENROLLED_CATEGORY));
@@ -233,6 +245,9 @@ public class FingerprintSettings extends SubSettings {
@VisibleForTesting @VisibleForTesting
static final String KEY_REQUIRE_SCREEN_ON_TO_AUTH = static final String KEY_REQUIRE_SCREEN_ON_TO_AUTH =
"security_settings_require_screen_on_to_auth"; "security_settings_require_screen_on_to_auth";
@VisibleForTesting
static final String KEY_SCREEN_OFF_FINGERPRINT_UNLOCK =
"security_settings_screen_off_unlock_udfps";
private static final String KEY_FINGERPRINTS_ENROLLED_CATEGORY = private static final String KEY_FINGERPRINTS_ENROLLED_CATEGORY =
"security_settings_fingerprints_enrolled"; "security_settings_fingerprints_enrolled";
private static final String KEY_FINGERPRINT_UNLOCK_CATEGORY = private static final String KEY_FINGERPRINT_UNLOCK_CATEGORY =
@@ -263,8 +278,11 @@ public class FingerprintSettings extends SubSettings {
mFingerprintUnlockCategoryPreferenceController; mFingerprintUnlockCategoryPreferenceController;
private FingerprintSettingsRequireScreenOnToAuthPreferenceController private FingerprintSettingsRequireScreenOnToAuthPreferenceController
mRequireScreenOnToAuthPreferenceController; mRequireScreenOnToAuthPreferenceController;
private FingerprintSettingsScreenOffUnlockUdfpsPreferenceController
mScreenOffUnlockUdfpsPreferenceController;
private Preference mAddFingerprintPreference; private Preference mAddFingerprintPreference;
private RestrictedSwitchPreference mRequireScreenOnToAuthPreference; private RestrictedSwitchPreference mRequireScreenOnToAuthPreference;
private RestrictedSwitchPreference mScreenOffUnlockUdfpsPreference;
private PreferenceCategory mFingerprintsEnrolledCategory; private PreferenceCategory mFingerprintsEnrolledCategory;
private PreferenceCategory mFingerprintUnlockCategory; private PreferenceCategory mFingerprintUnlockCategory;
private PreferenceCategory mFingerprintUnlockFooter; private PreferenceCategory mFingerprintUnlockFooter;
@@ -621,7 +639,7 @@ public class FingerprintSettings extends SubSettings {
// This needs to be after setting ids, otherwise // This needs to be after setting ids, otherwise
// |mRequireScreenOnToAuthPreferenceController.isChecked| is always checking the primary // |mRequireScreenOnToAuthPreferenceController.isChecked| is always checking the primary
// user instead of the user with |mUserId|. // user instead of the user with |mUserId|.
if (isSfps()) { if (isSfps() || screenOffUnlockUdfps()) {
scrollToPreference(fpPrefKey); scrollToPreference(fpPrefKey);
addFingerprintUnlockCategory(); addFingerprintUnlockCategory();
} }
@@ -671,7 +689,8 @@ public class FingerprintSettings extends SubSettings {
private void addFingerprintUnlockCategory() { private void addFingerprintUnlockCategory() {
mFingerprintUnlockCategory = findPreference(KEY_FINGERPRINT_UNLOCK_CATEGORY); mFingerprintUnlockCategory = findPreference(KEY_FINGERPRINT_UNLOCK_CATEGORY);
setupFingerprintUnlockCategoryPreferences(); if (isSfps()) {
// For both SFPS "screen on to auth" and "rest to unlock"
final Preference restToUnlockPreference = FeatureFactory.getFeatureFactory() final Preference restToUnlockPreference = FeatureFactory.getFeatureFactory()
.getFingerprintFeatureProvider() .getFingerprintFeatureProvider()
.getSfpsRestToUnlockFeature(getContext()) .getSfpsRestToUnlockFeature(getContext())
@@ -679,25 +698,37 @@ public class FingerprintSettings extends SubSettings {
if (restToUnlockPreference != null) { if (restToUnlockPreference != null) {
// Use custom featured preference if any. // Use custom featured preference if any.
mRequireScreenOnToAuthPreference.setTitle(restToUnlockPreference.getTitle()); mRequireScreenOnToAuthPreference.setTitle(restToUnlockPreference.getTitle());
mRequireScreenOnToAuthPreference.setSummary(restToUnlockPreference.getSummary()); mRequireScreenOnToAuthPreference.setSummary(
restToUnlockPreference.getSummary());
mRequireScreenOnToAuthPreference.setChecked( mRequireScreenOnToAuthPreference.setChecked(
((TwoStatePreference) restToUnlockPreference).isChecked()); ((TwoStatePreference) restToUnlockPreference).isChecked());
mRequireScreenOnToAuthPreference.setOnPreferenceChangeListener( mRequireScreenOnToAuthPreference.setOnPreferenceChangeListener(
restToUnlockPreference.getOnPreferenceChangeListener()); restToUnlockPreference.getOnPreferenceChangeListener());
} }
setupFingerprintUnlockCategoryPreferencesForScreenOnToAuth();
} else if (screenOffUnlockUdfps()) {
setupFingerprintUnlockCategoryPreferencesForScreenOffUnlock();
}
updateFingerprintUnlockCategoryVisibility(); updateFingerprintUnlockCategoryVisibility();
} }
private void updateFingerprintUnlockCategoryVisibility() { private void updateFingerprintUnlockCategoryVisibility() {
final boolean mFingerprintUnlockCategoryAvailable = final boolean fingerprintUnlockCategoryAvailable =
mFingerprintUnlockCategoryPreferenceController.isAvailable(); mFingerprintUnlockCategoryPreferenceController.isAvailable();
if (mFingerprintUnlockCategory.isVisible() != mFingerprintUnlockCategoryAvailable) { if (mFingerprintUnlockCategory.isVisible() != fingerprintUnlockCategoryAvailable) {
mFingerprintUnlockCategory.setVisible( mFingerprintUnlockCategory.setVisible(fingerprintUnlockCategoryAvailable);
mFingerprintUnlockCategoryAvailable); }
if (mRequireScreenOnToAuthPreferenceController != null) {
mRequireScreenOnToAuthPreference.setVisible(
mRequireScreenOnToAuthPreferenceController.isAvailable());
}
if (mScreenOffUnlockUdfpsPreferenceController != null) {
mScreenOffUnlockUdfpsPreference.setVisible(
mScreenOffUnlockUdfpsPreferenceController.isAvailable());
} }
} }
private void setupFingerprintUnlockCategoryPreferences() { private void setupFingerprintUnlockCategoryPreferencesForScreenOnToAuth() {
mRequireScreenOnToAuthPreference = findPreference(KEY_REQUIRE_SCREEN_ON_TO_AUTH); mRequireScreenOnToAuthPreference = findPreference(KEY_REQUIRE_SCREEN_ON_TO_AUTH);
mRequireScreenOnToAuthPreference.setChecked( mRequireScreenOnToAuthPreference.setChecked(
mRequireScreenOnToAuthPreferenceController.isChecked()); mRequireScreenOnToAuthPreferenceController.isChecked());
@@ -709,9 +740,21 @@ public class FingerprintSettings extends SubSettings {
}); });
} }
private void setupFingerprintUnlockCategoryPreferencesForScreenOffUnlock() {
mScreenOffUnlockUdfpsPreference = findPreference(KEY_SCREEN_OFF_FINGERPRINT_UNLOCK);
mScreenOffUnlockUdfpsPreference.setChecked(
mScreenOffUnlockUdfpsPreferenceController.isChecked());
mScreenOffUnlockUdfpsPreference.setOnPreferenceChangeListener(
(preference, newValue) -> {
final boolean isChecked = ((TwoStatePreference) preference).isChecked();
mScreenOffUnlockUdfpsPreferenceController.setChecked(!isChecked);
return true;
});
}
private void updatePreferencesAfterFingerprintRemoved() { private void updatePreferencesAfterFingerprintRemoved() {
updateAddPreference(); updateAddPreference();
if (isSfps()) { if (isSfps() || screenOffUnlockUdfps()) {
updateFingerprintUnlockCategoryVisibility(); updateFingerprintUnlockCategoryVisibility();
} }
updatePreferences(); updatePreferences();
@@ -954,6 +997,18 @@ public class FingerprintSettings extends SubSettings {
controller; controller;
} }
}
} else if (screenOffUnlockUdfps()) {
for (AbstractPreferenceController controller : controllers) {
if (controller.getPreferenceKey() == KEY_FINGERPRINT_UNLOCK_CATEGORY) {
mFingerprintUnlockCategoryPreferenceController =
(FingerprintUnlockCategoryController) controller;
} else if (controller.getPreferenceKey() == KEY_SCREEN_OFF_FINGERPRINT_UNLOCK) {
mScreenOffUnlockUdfpsPreferenceController =
(FingerprintSettingsScreenOffUnlockUdfpsPreferenceController)
controller;
}
} }
} }
return controllers; return controllers;
@@ -1070,7 +1125,8 @@ public class FingerprintSettings extends SubSettings {
} else if (requestCode == BIOMETRIC_AUTH_REQUEST) { } else if (requestCode == BIOMETRIC_AUTH_REQUEST) {
mBiometricsAuthenticationRequested = false; mBiometricsAuthenticationRequested = false;
if (resultCode != RESULT_OK) { if (resultCode != RESULT_OK) {
if (resultCode == ConfirmDeviceCredentialActivity.BIOMETRIC_LOCKOUT_ERROR_RESULT) { if (resultCode
== ConfirmDeviceCredentialActivity.BIOMETRIC_LOCKOUT_ERROR_RESULT) {
IdentityCheckBiometricErrorDialog IdentityCheckBiometricErrorDialog
.showBiometricErrorDialogAndFinishActivityOnDismiss(getActivity(), .showBiometricErrorDialogAndFinishActivityOnDismiss(getActivity(),
Utils.BiometricStatus.LOCKOUT); Utils.BiometricStatus.LOCKOUT);

View File

@@ -0,0 +1,119 @@
/*
* Copyright (C) 2024 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.biometrics.fingerprint;
import static android.hardware.biometrics.Flags.screenOffUnlockUdfps;
import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;
import android.provider.Settings;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.Utils;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
/**
* Preference controller that controls whether show screen off UDFPS unlock toggle for users to
* turn this feature ON or OFF
*/
@SearchIndexable
public class FingerprintSettingsScreenOffUnlockUdfpsPreferenceController
extends FingerprintSettingsPreferenceController {
private static final String TAG =
"FingerprintSettingsScreenOffUnlockUdfpsPreferenceController";
@VisibleForTesting
protected FingerprintManager mFingerprintManager;
public FingerprintSettingsScreenOffUnlockUdfpsPreferenceController(
@NonNull Context context, @NonNull String prefKey) {
super(context, prefKey);
mFingerprintManager = Utils.getFingerprintManagerOrNull(context);
}
@Override
public boolean isChecked() {
if (!FingerprintSettings.isFingerprintHardwareDetected(mContext)) {
return false;
} else if (getRestrictingAdmin() != null) {
return false;
}
final boolean defEnabled = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_screen_off_udfps_enabled);
final int value = Settings.Secure.getIntForUser(
mContext.getContentResolver(),
Settings.Secure.SCREEN_OFF_UNLOCK_UDFPS_ENABLED,
defEnabled ? 1 : 0 /* config_screen_off_udfps_enabled */,
getUserHandle());
return value == 1;
}
@Override
public boolean setChecked(boolean isChecked) {
Settings.Secure.putIntForUser(
mContext.getContentResolver(),
Settings.Secure.SCREEN_OFF_UNLOCK_UDFPS_ENABLED,
isChecked ? 1 : 0,
getUserHandle());
return true;
}
@Override
public void updateState(@NonNull Preference preference) {
super.updateState(preference);
if (!FingerprintSettings.isFingerprintHardwareDetected(mContext)) {
preference.setEnabled(false);
} else if (!mFingerprintManager.hasEnrolledTemplates(getUserId())) {
preference.setEnabled(false);
} else if (getRestrictingAdmin() != null) {
preference.setEnabled(false);
} else {
preference.setEnabled(true);
}
}
@SuppressLint("MissingPermission")
@Override
public int getAvailabilityStatus() {
if (mFingerprintManager != null
&& mFingerprintManager.isHardwareDetected()
&& screenOffUnlockUdfps()
&& !mFingerprintManager.isPowerbuttonFps()) {
return mFingerprintManager.hasEnrolledTemplates(getUserId())
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
} else {
return UNSUPPORTED_ON_DEVICE;
}
}
private int getUserHandle() {
return UserHandle.of(getUserId()).getIdentifier();
}
/**
* This feature is not directly searchable.
*/
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {};
}

View File

@@ -16,6 +16,8 @@
package com.android.settings.biometrics.fingerprint; package com.android.settings.biometrics.fingerprint;
import static android.hardware.biometrics.Flags.screenOffUnlockUdfps;
import android.content.Context; import android.content.Context;
import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintManager;
@@ -42,7 +44,7 @@ public class FingerprintUnlockCategoryController extends BasePreferenceControlle
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
if (mFingerprintManager != null if (mFingerprintManager != null
&& mFingerprintManager.isHardwareDetected() && mFingerprintManager.isHardwareDetected()
&& mFingerprintManager.isPowerbuttonFps()) { && (mFingerprintManager.isPowerbuttonFps() || screenOffUnlockUdfps())) {
return mFingerprintManager.hasEnrolledTemplates(getUserId()) return mFingerprintManager.hasEnrolledTemplates(getUserId())
? AVAILABLE : CONDITIONALLY_UNAVAILABLE; ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
} else { } else {

View File

@@ -0,0 +1,157 @@
/*
* Copyright (C) 2024 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.biometrics.fingerprint;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowUtils.class})
public class FingerprintSettingsScreenOffUnlockUdfpsPreferenceControllerTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Mock
private FingerprintManager mFingerprintManager;
@Mock
private PackageManager mPackageManager;
@Mock
private RestrictedSwitchPreference mPreference;
private Context mContext;
private FingerprintSettingsScreenOffUnlockUdfpsPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(eq(Context.FINGERPRINT_SERVICE))).thenReturn(
mFingerprintManager);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
mController = spy(new FingerprintSettingsScreenOffUnlockUdfpsPreferenceController(mContext,
"test_key"));
ReflectionHelpers.setField(mController, "mFingerprintManager", mFingerprintManager);
}
@After
public void tearDown() {
ShadowUtils.reset();
}
@Test
public void onPreferenceChange_settingIsUpdated() {
boolean state = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.SCREEN_OFF_UNLOCK_UDFPS_ENABLED, 1) != 0;
assertThat(mController.isChecked()).isFalse();
assertThat(mController.onPreferenceChange(mPreference, !state)).isTrue();
boolean newState = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.SCREEN_OFF_UNLOCK_UDFPS_ENABLED, 1) != 0;
assertThat(newState).isEqualTo(!state);
}
@Test
@EnableFlags(android.hardware.biometrics.Flags.FLAG_SCREEN_OFF_UNLOCK_UDFPS)
public void isAvailable_isEnabled_whenUdfpsHardwareDetected_AndHasEnrolledFingerprints() {
assertThat(mController.isAvailable()).isEqualTo(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
configure_hardwareDetected_isUdfps_hasEnrolledTemplates(
true /* isHardwareDetected */,
false /* isPowerbuttonFps false implies udfps */,
true /* hasEnrolledTemplates */);
assertThat(mController.isAvailable()).isEqualTo(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
@EnableFlags(android.hardware.biometrics.Flags.FLAG_SCREEN_OFF_UNLOCK_UDFPS)
public void isUnavailable_isDisabled_whenUdfpsHardwareDetected_AndNoEnrolledFingerprints() {
assertThat(mController.isAvailable()).isEqualTo(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
configure_hardwareDetected_isUdfps_hasEnrolledTemplates(
true /* isHardwareDetected */,
false /* isPowerbuttonFps false implies udfps */,
false /* hasEnrolledTemplates */);
assertThat(mController.isAvailable()).isEqualTo(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
@EnableFlags(android.hardware.biometrics.Flags.FLAG_SCREEN_OFF_UNLOCK_UDFPS)
public void isUnavailable_whenHardwareNotDetected() {
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
configure_hardwareDetected_isUdfps_hasEnrolledTemplates(
false /* isHardwareDetected */,
false /* isPowerbuttonFps false implies udfps */,
true /* hasEnrolledTemplates */);
assertThat(mController.isAvailable()).isEqualTo(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
@EnableFlags(android.hardware.biometrics.Flags.FLAG_SCREEN_OFF_UNLOCK_UDFPS)
public void isUnavailable_onNonUdfpsDevice() {
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
configure_hardwareDetected_isUdfps_hasEnrolledTemplates(
true /* isHardwareDetected */,
true /* isPowerbuttonFps false implies udfps */,
true /* hasEnrolledTemplates */);
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
private void configure_hardwareDetected_isUdfps_hasEnrolledTemplates(
boolean isHardwareDetected, boolean isPowerbuttonFps, boolean hasEnrolledTemplates) {
when(mFingerprintManager.isHardwareDetected()).thenReturn(isHardwareDetected);
when(mFingerprintManager.isPowerbuttonFps()).thenReturn(isPowerbuttonFps);
when(mFingerprintManager.hasEnrolledTemplates(anyInt())).thenReturn(hasEnrolledTemplates);
}
}

View File

@@ -30,12 +30,15 @@ import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintManager;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import com.android.settings.testutils.shadow.ShadowUtils; import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settingslib.RestrictedSwitchPreference; import com.android.settingslib.RestrictedSwitchPreference;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -49,6 +52,8 @@ import org.robolectric.util.ReflectionHelpers;
@Config(shadows = {ShadowUtils.class}) @Config(shadows = {ShadowUtils.class})
public class FingerprintSettingsUnlockCategoryControllerTest { public class FingerprintSettingsUnlockCategoryControllerTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Mock @Mock
private FingerprintManager mFingerprintManager; private FingerprintManager mFingerprintManager;
@Mock @Mock
@@ -59,6 +64,8 @@ public class FingerprintSettingsUnlockCategoryControllerTest {
private Context mContext; private Context mContext;
private FingerprintSettingsRequireScreenOnToAuthPreferenceController mController; private FingerprintSettingsRequireScreenOnToAuthPreferenceController mController;
private FingerprintSettingsScreenOffUnlockUdfpsPreferenceController mScreenOffUnlockController;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
@@ -69,7 +76,12 @@ public class FingerprintSettingsUnlockCategoryControllerTest {
mController = spy(new FingerprintSettingsRequireScreenOnToAuthPreferenceController(mContext, mController = spy(new FingerprintSettingsRequireScreenOnToAuthPreferenceController(mContext,
"test_key")); "test_key"));
mScreenOffUnlockController = spy(
new FingerprintSettingsScreenOffUnlockUdfpsPreferenceController(mContext,
"screen_off_unlock_test_key"));
ReflectionHelpers.setField(mController, "mFingerprintManager", mFingerprintManager); ReflectionHelpers.setField(mController, "mFingerprintManager", mFingerprintManager);
ReflectionHelpers.setField(mScreenOffUnlockController, "mFingerprintManager",
mFingerprintManager);
} }
@After @After
@@ -89,6 +101,20 @@ public class FingerprintSettingsUnlockCategoryControllerTest {
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
} }
@Test
@EnableFlags(android.hardware.biometrics.Flags.FLAG_SCREEN_OFF_UNLOCK_UDFPS)
public void isAvailable_isEnabled_whenUdfpsHardwareDetected_AndHasEnrolledFingerprints() {
assertThat(mScreenOffUnlockController.isAvailable()).isEqualTo(false);
assertThat(mScreenOffUnlockController.getAvailabilityStatus()).isEqualTo(
UNSUPPORTED_ON_DEVICE);
configure_hardwareDetected_isSfps_hasEnrolledTemplates(
true /* isHardwareDetected */,
false /* isPowerbuttonFps false implies udfps */,
true /* hasEnrolledTemplates */);
assertThat(mScreenOffUnlockController.isAvailable()).isEqualTo(true);
assertThat(mScreenOffUnlockController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test @Test
public void isUnavailable_isDisabled_whenSfpsHardwareDetected_AndNoEnrolledFingerprints() { public void isUnavailable_isDisabled_whenSfpsHardwareDetected_AndNoEnrolledFingerprints() {
assertThat(mController.isAvailable()).isEqualTo(false); assertThat(mController.isAvailable()).isEqualTo(false);
@@ -102,7 +128,22 @@ public class FingerprintSettingsUnlockCategoryControllerTest {
} }
@Test @Test
public void isUnavailable_whenHardwareNotDetected() { @EnableFlags(android.hardware.biometrics.Flags.FLAG_SCREEN_OFF_UNLOCK_UDFPS)
public void isUnavailable_isDisabled_whenUdfpsHardwareDetected_AndNoEnrolledFingerprints() {
assertThat(mScreenOffUnlockController.isAvailable()).isEqualTo(false);
assertThat(mScreenOffUnlockController.getAvailabilityStatus()).isEqualTo(
UNSUPPORTED_ON_DEVICE);
configure_hardwareDetected_isSfps_hasEnrolledTemplates(
true /* isHardwareDetected */,
false /* isPowerbuttonFps false implies udfps */,
false /* hasEnrolledTemplates */);
assertThat(mScreenOffUnlockController.isAvailable()).isEqualTo(false);
assertThat(mScreenOffUnlockController.getAvailabilityStatus()).isEqualTo(
CONDITIONALLY_UNAVAILABLE);
}
@Test
public void isUnavailable_whenHardwareNotDetected_onSfpsDevice() {
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
configure_hardwareDetected_isSfps_hasEnrolledTemplates( configure_hardwareDetected_isSfps_hasEnrolledTemplates(
@@ -113,6 +154,21 @@ public class FingerprintSettingsUnlockCategoryControllerTest {
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
} }
@Test
@EnableFlags(android.hardware.biometrics.Flags.FLAG_SCREEN_OFF_UNLOCK_UDFPS)
public void isUnavailable_whenHardwareNotDetected_onUdfpsDevice() {
assertThat(mScreenOffUnlockController.isAvailable()).isFalse();
assertThat(mScreenOffUnlockController.getAvailabilityStatus()).isEqualTo(
UNSUPPORTED_ON_DEVICE);
configure_hardwareDetected_isSfps_hasEnrolledTemplates(
false /* isHardwareDetected */,
false /* isPowerbuttonFps false implies udfps */,
true /* hasEnrolledTemplates */);
assertThat(mScreenOffUnlockController.isAvailable()).isEqualTo(false);
assertThat(mScreenOffUnlockController.getAvailabilityStatus()).isEqualTo(
UNSUPPORTED_ON_DEVICE);
}
@Test @Test
public void isUnavailable_onNonSfpsDevice() { public void isUnavailable_onNonSfpsDevice() {
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();