Snap for 9875146 from 5a2ba07f63 to udc-release

Change-Id: Ia14ae105ef6ef9f112fa262f61723edaddc1c930
This commit is contained in:
Android Build Coastguard Worker
2023-04-04 03:09:55 +00:00
9 changed files with 494 additions and 33 deletions

View File

@@ -83,6 +83,12 @@
<string name="security_settings_face_enroll_introduction_message" product="tablet">Use your face to unlock your tablet, authorize purchases, or sign in to apps.</string> <string name="security_settings_face_enroll_introduction_message" product="tablet">Use your face to unlock your tablet, authorize purchases, or sign in to apps.</string>
<!-- Introduction detail message shown in face enrollment dialog [CHAR LIMIT=NONE]--> <!-- Introduction detail message shown in face enrollment dialog [CHAR LIMIT=NONE]-->
<string name="security_settings_face_enroll_introduction_message" product="device">Use your face to unlock your device, authorize purchases, or sign in to apps.</string> <string name="security_settings_face_enroll_introduction_message" product="device">Use your face to unlock your device, authorize purchases, or sign in to apps.</string>
<!-- Subtitle shown on the face enrollment introduction screen with in-app authentication. [CHAR LIMIT=NONE] -->
<string name="security_settings_face_enroll_introduction_message_class3" product="default">Use your face to unlock your phone or for authentication in apps, like when you sign in to apps or approve a purchase.</string>
<!-- Subtitle shown on the face enrollment introduction screen with in-app authentication. [CHAR LIMIT=NONE] -->
<string name="security_settings_face_enroll_introduction_message_class3" product="tablet">Use your face to unlock your tablet or for authentication in apps, like when you sign in to apps or approve a purchase.</string>
<!-- Subtitle shown on the face enrollment introduction screen with in-app authentication. [CHAR LIMIT=NONE] -->
<string name="security_settings_face_enroll_introduction_message_class3" product="device">Use your face to unlock your device or for authentication in apps, like when you sign in to apps or approve a purchase.</string>
<!-- Introduction detail message shown in face enrollment dialog when asking for parental consent [CHAR LIMIT=NONE]--> <!-- Introduction detail message shown in face enrollment dialog when asking for parental consent [CHAR LIMIT=NONE]-->
<string name="security_settings_face_enroll_introduction_consent_message_0" product="default">Allow your child to use their face to unlock their phone</string> <string name="security_settings_face_enroll_introduction_consent_message_0" product="default">Allow your child to use their face to unlock their phone</string>
<!-- Introduction detail message shown in face enrollment dialog when asking for parental consent [CHAR LIMIT=NONE]--> <!-- Introduction detail message shown in face enrollment dialog when asking for parental consent [CHAR LIMIT=NONE]-->

View File

@@ -871,6 +871,12 @@
<string name="biometric_settings_use_face_or_fingerprint_preference_summary">Using face or fingerprint</string> <string name="biometric_settings_use_face_or_fingerprint_preference_summary">Using face or fingerprint</string>
<!-- Button text shown during enrollment to proceed after a child user has handed the device to a parent or guardian. [CHAR LIMIT=22] --> <!-- Button text shown during enrollment to proceed after a child user has handed the device to a parent or guardian. [CHAR LIMIT=22] -->
<string name="biometric_settings_hand_back_to_guardian_ok">OK</string> <string name="biometric_settings_hand_back_to_guardian_ok">OK</string>
<!-- Dialog title for dialog which shows when trying to add fingerprint in split mode. [CHAR LIMIT=45] -->
<string name="biometric_settings_add_fingerprint_in_split_mode_title">Can\u2019t set up fingerprint</string>
<!-- Dialog message for dialog which shows when trying to add fingerprint in split mode. [CHAR LIMIT=45] -->
<string name="biometric_settings_add_fingerprint_in_split_mode_message">Exit split screen to set up Fingerprint Unlock</string>
<!-- Button text shown in adding fingerprint dialog that allows the user to go back to the settings page [CHAR LIMIT=22] -->
<string name="biometric_settings_add_fingerprint_in_split_mode_ok">OK</string>
<!-- Title of dialog shown when the user tries to skip setting up a screen lock, warning them of potential consequences of not doing so [CHAR LIMIT=30]--> <!-- Title of dialog shown when the user tries to skip setting up a screen lock, warning them of potential consequences of not doing so [CHAR LIMIT=30]-->
<string name="lock_screen_intro_skip_title">Skip screen lock?</string> <string name="lock_screen_intro_skip_title">Skip screen lock?</string>

View File

@@ -489,15 +489,18 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
finish(); finish();
} }
@Override protected void updateDescriptionText() {
protected void initViews() {
super.initViews();
if (mBiometricUnlockDisabledByAdmin && !mParentalConsentRequired) { if (mBiometricUnlockDisabledByAdmin && !mParentalConsentRequired) {
setDescriptionText(getDescriptionDisabledByAdmin()); setDescriptionText(getDescriptionDisabledByAdmin());
} }
} }
@Override
protected void initViews() {
super.initViews();
updateDescriptionText();
}
@NonNull @NonNull
protected PorterDuffColorFilter getIconColorFilter() { protected PorterDuffColorFilter getIconColorFilter() {
if (mIconColorFilter == null) { if (mIconColorFilter == null) {

View File

@@ -41,6 +41,7 @@ import com.android.settings.R;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricEnrollBase; import com.android.settings.biometrics.BiometricEnrollBase;
import com.android.settings.biometrics.BiometricUtils; import com.android.settings.biometrics.BiometricUtils;
import com.android.settings.biometrics.fingerprint.FingerprintSettings.FingerprintSettingsFragment;
import com.android.settings.core.SettingsBaseActivity; import com.android.settings.core.SettingsBaseActivity;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.password.ChooseLockGeneric; import com.android.settings.password.ChooseLockGeneric;
@@ -166,6 +167,14 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
return true; return true;
} else if (getFingerprintPreferenceKey().equals(key)) { } else if (getFingerprintPreferenceKey().equals(key)) {
mDoNotFinishActivity = true; mDoNotFinishActivity = true;
if (shouldSkipForUdfpsInMultiWindowMode()) {
new FingerprintSettingsFragment.FingerprintSplitScreenDialog().show(
getActivity().getSupportFragmentManager(),
FingerprintSettingsFragment.FingerprintSplitScreenDialog.class.getName());
return true;
}
mFingerprintManager.generateChallenge(mUserId, (sensorId, userId, challenge) -> { mFingerprintManager.generateChallenge(mUserId, (sensorId, userId, challenge) -> {
try { try {
final byte[] token = requestGatekeeperHat(context, mGkPwHandle, mUserId, final byte[] token = requestGatekeeperHat(context, mGkPwHandle, mUserId,
@@ -377,4 +386,27 @@ public abstract class BiometricsSettingsBase extends DashboardFragment {
return 0; return 0;
} }
} }
/**
* Returns whether the click should be skipped.
* True if the following conditions are all met:
* 1. It's split mode.
* 2. It's udfps.
* 3. There is no enrolled fingerprint. (If there is enrolled fingerprint, FingerprintSettings
* will handle the adding fingerprint.
*/
private boolean shouldSkipForUdfpsInMultiWindowMode() {
if (!getActivity().isInMultiWindowMode() || mFingerprintManager.hasEnrolledFingerprints(
mUserId)) {
return false;
}
for (FingerprintSensorPropertiesInternal prop :
mFingerprintManager.getSensorPropertiesInternal()) {
if (prop.isAnyUdfpsType()) {
return true;
}
}
return false;
}
} }

View File

@@ -26,7 +26,10 @@ import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.hardware.SensorPrivacyManager; import android.hardware.SensorPrivacyManager;
import android.hardware.biometrics.BiometricAuthenticator; import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.SensorProperties;
import android.hardware.face.FaceManager; import android.hardware.face.FaceManager;
import android.hardware.face.FaceSensorPropertiesInternal;
import android.hardware.face.IFaceAuthenticatorsRegisteredCallback;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserHandle; import android.os.UserHandle;
import android.text.Html; import android.text.Html;
@@ -60,6 +63,8 @@ import com.google.android.setupcompat.template.FooterButton;
import com.google.android.setupcompat.util.WizardManagerHelper; import com.google.android.setupcompat.util.WizardManagerHelper;
import com.google.android.setupdesign.span.LinkSpan; import com.google.android.setupdesign.span.LinkSpan;
import java.util.List;
/** /**
* Provides introductory info about face unlock and prompts the user to agree before starting face * Provides introductory info about face unlock and prompts the user to agree before starting face
* enrollment. * enrollment.
@@ -71,6 +76,7 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
@Nullable private FooterButton mPrimaryFooterButton; @Nullable private FooterButton mPrimaryFooterButton;
@Nullable private FooterButton mSecondaryFooterButton; @Nullable private FooterButton mSecondaryFooterButton;
@Nullable private SensorPrivacyManager mSensorPrivacyManager; @Nullable private SensorPrivacyManager mSensorPrivacyManager;
private boolean mIsFaceStrong;
@Override @Override
protected void onCancelButtonClick(View view) { protected void onCancelButtonClick(View view) {
@@ -154,14 +160,6 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
inControlMessage.setMovementMethod(LinkMovementMethod.getInstance()); inControlMessage.setMovementMethod(LinkMovementMethod.getInstance());
lessSecure.setText(getLessSecureMessage()); lessSecure.setText(getLessSecureMessage());
// Set up and show the "less secure" info section if necessary.
if (getResources().getBoolean(R.bool.config_face_intro_show_less_secure)) {
final LinearLayout infoRowLessSecure = findViewById(R.id.info_row_less_secure);
final ImageView iconLessSecure = findViewById(R.id.icon_less_secure);
infoRowLessSecure.setVisibility(View.VISIBLE);
iconLessSecure.getBackground().setColorFilter(getIconColorFilter());
}
// Set up and show the "require eyes" info section if necessary. // Set up and show the "require eyes" info section if necessary.
if (getResources().getBoolean(R.bool.config_face_intro_show_require_eyes)) { if (getResources().getBoolean(R.bool.config_face_intro_show_require_eyes)) {
final LinearLayout infoRowRequireEyes = findViewById(R.id.info_row_require_eyes); final LinearLayout infoRowRequireEyes = findViewById(R.id.info_row_require_eyes);
@@ -172,6 +170,28 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
infoMessageRequireEyes.setText(getInfoMessageRequireEyes()); infoMessageRequireEyes.setText(getInfoMessageRequireEyes());
} }
mFaceManager.addAuthenticatorsRegisteredCallback(
new IFaceAuthenticatorsRegisteredCallback.Stub() {
@Override
public void onAllAuthenticatorsRegistered(
@NonNull List<FaceSensorPropertiesInternal> sensors) {
if (sensors.isEmpty()) {
Log.e(TAG, "No sensors");
return;
}
boolean isFaceStrong = sensors.get(0).sensorStrength
== SensorProperties.STRENGTH_STRONG;
if (mIsFaceStrong == isFaceStrong) {
return;
}
mIsFaceStrong = isFaceStrong;
onFaceStrengthChanged();
}
});
onFaceStrengthChanged();
// This path is an entry point for SetNewPasswordController, e.g. // This path is an entry point for SetNewPasswordController, e.g.
// adb shell am start -a android.app.action.SET_NEW_PASSWORD // adb shell am start -a android.app.action.SET_NEW_PASSWORD
if (mToken == null && BiometricUtils.containsGatekeeperPasswordHandle(getIntent())) { if (mToken == null && BiometricUtils.containsGatekeeperPasswordHandle(getIntent())) {
@@ -554,6 +574,15 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
return R.string.security_settings_face_enroll_introduction_more; return R.string.security_settings_face_enroll_introduction_more;
} }
@Override
protected void updateDescriptionText() {
if (mIsFaceStrong) {
setDescriptionText(getString(
R.string.security_settings_face_enroll_introduction_message_class3));
}
super.updateDescriptionText();
}
@NonNull @NonNull
protected static Intent setSkipPendingEnroll(@Nullable Intent data) { protected static Intent setSkipPendingEnroll(@Nullable Intent data) {
if (data == null) { if (data == null) {
@@ -562,4 +591,16 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
data.putExtra(MultiBiometricEnrollHelper.EXTRA_SKIP_PENDING_ENROLL, true); data.putExtra(MultiBiometricEnrollHelper.EXTRA_SKIP_PENDING_ENROLL, true);
return data; return data;
} }
private void onFaceStrengthChanged() {
// Set up and show the "less secure" info section if necessary.
if (!mIsFaceStrong && getResources().getBoolean(
R.bool.config_face_intro_show_less_secure)) {
final LinearLayout infoRowLessSecure = findViewById(R.id.info_row_less_secure);
final ImageView iconLessSecure = findViewById(R.id.icon_less_secure);
infoRowLessSecure.setVisibility(View.VISIBLE);
iconLessSecure.getBackground().setColorFilter(getIconColorFilter());
}
updateDescriptionText();
}
} }

View File

@@ -159,7 +159,8 @@ public class FingerprintSettings extends SubSettings {
private static final String TAG = "FingerprintSettings"; private static final String TAG = "FingerprintSettings";
private static final String KEY_FINGERPRINT_ITEM_PREFIX = "key_fingerprint_item"; private static final String KEY_FINGERPRINT_ITEM_PREFIX = "key_fingerprint_item";
private static final String KEY_FINGERPRINT_ADD = "key_fingerprint_add"; @VisibleForTesting
static final String KEY_FINGERPRINT_ADD = "key_fingerprint_add";
private static final String KEY_FINGERPRINT_ENABLE_KEYGUARD_TOGGLE = private static final String KEY_FINGERPRINT_ENABLE_KEYGUARD_TOGGLE =
"fingerprint_enable_keyguard_toggle"; "fingerprint_enable_keyguard_toggle";
private static final String KEY_LAUNCHED_CONFIRM = "launched_confirm"; private static final String KEY_LAUNCHED_CONFIRM = "launched_confirm";
@@ -178,8 +179,8 @@ public class FingerprintSettings extends SubSettings {
private static final int CONFIRM_REQUEST = 101; private static final int CONFIRM_REQUEST = 101;
private static final int CHOOSE_LOCK_GENERIC_REQUEST = 102; private static final int CHOOSE_LOCK_GENERIC_REQUEST = 102;
@VisibleForTesting
private static final int ADD_FINGERPRINT_REQUEST = 10; static final int ADD_FINGERPRINT_REQUEST = 10;
private static final int AUTO_ADD_FIRST_FINGERPRINT_REQUEST = 11; private static final int AUTO_ADD_FIRST_FINGERPRINT_REQUEST = 11;
protected static final boolean DEBUG = false; protected static final boolean DEBUG = false;
@@ -694,6 +695,15 @@ public class FingerprintSettings extends SubSettings {
public boolean onPreferenceTreeClick(Preference pref) { public boolean onPreferenceTreeClick(Preference pref) {
final String key = pref.getKey(); final String key = pref.getKey();
if (KEY_FINGERPRINT_ADD.equals(key)) { if (KEY_FINGERPRINT_ADD.equals(key)) {
// If it's udfps in split mode, show the error dialog and don't need to show adding
// fingerprint intent.
if (shouldSkipForUdfpsInMultiWindowMode()) {
new FingerprintSplitScreenDialog().show(
getActivity().getSupportFragmentManager(),
FingerprintSplitScreenDialog.class.getName());
return true;
}
mIsEnrolling = true; mIsEnrolling = true;
Intent intent = new Intent(); Intent intent = new Intent();
if (FeatureFlagUtils.isEnabled(getContext(), if (FeatureFlagUtils.isEnabled(getContext(),
@@ -997,6 +1007,14 @@ public class FingerprintSettings extends SubSettings {
updatePreferences(); updatePreferences();
} }
/**
* Returns whether the click should be skipped.
* True if it's udfps and it's in split mode.
*/
private boolean shouldSkipForUdfpsInMultiWindowMode() {
return getActivity().isInMultiWindowMode() && isUdfps();
}
private final Runnable mFingerprintLockoutReset = new Runnable() { private final Runnable mFingerprintLockoutReset = new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -1246,6 +1264,29 @@ public class FingerprintSettings extends SubSettings {
return alertDialog; return alertDialog;
} }
} }
/**
* This alert dialog shows when fingerprint is being added in multi window mode.
*/
public static class FingerprintSplitScreenDialog extends InstrumentedDialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(
R.string.biometric_settings_add_fingerprint_in_split_mode_title)
.setMessage(
R.string.biometric_settings_add_fingerprint_in_split_mode_message)
.setPositiveButton(
R.string.biometric_settings_add_fingerprint_in_split_mode_ok,
(DialogInterface.OnClickListener) (dialog, which) -> dialog.dismiss());
return builder.create();
}
@Override
public int getMetricsCategory() {
return SettingsEnums.DIALOG_ADD_FINGERPRINT_ERROR_IN_SPLIT_MODE;
}
}
} }
public static class FingerprintPreference extends TwoTargetPreference { public static class FingerprintPreference extends TwoTargetPreference {

View File

@@ -16,7 +16,11 @@
package com.android.settings.biometrics.combination; package com.android.settings.biometrics.combination;
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_POWER_BUTTON;
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
import static com.android.settings.biometrics.combination.BiometricsSettingsBase.CONFIRM_REQUEST; import static com.android.settings.biometrics.combination.BiometricsSettingsBase.CONFIRM_REQUEST;
import static com.android.settings.biometrics.fingerprint.FingerprintSettings.FingerprintSettingsFragment;
import static com.android.settings.password.ChooseLockPattern.RESULT_FINISHED; import static com.android.settings.password.ChooseLockPattern.RESULT_FINISHED;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -24,17 +28,24 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.hardware.biometrics.ComponentInfoInternal;
import android.hardware.biometrics.SensorProperties;
import android.hardware.face.FaceManager; import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintSensorProperties;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -43,6 +54,8 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.XmlRes; import androidx.annotation.XmlRes;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -56,6 +69,7 @@ import com.android.settings.testutils.shadow.ShadowSettingsPreferenceFragment;
import com.android.settings.testutils.shadow.ShadowUtils; import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -80,6 +94,7 @@ public class CombinedBiometricProfileSettingsTest {
private TestCombinedBiometricProfileSettings mFragment; private TestCombinedBiometricProfileSettings mFragment;
private Context mContext; private Context mContext;
private FragmentActivity mActivity;
@Rule @Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule(); public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@@ -91,6 +106,8 @@ public class CombinedBiometricProfileSettingsTest {
private BiometricSettingsAppPreferenceController mBiometricSettingsAppPreferenceController; private BiometricSettingsAppPreferenceController mBiometricSettingsAppPreferenceController;
@Mock @Mock
private FaceManager mFaceManager; private FaceManager mFaceManager;
@Mock
private FragmentTransaction mFragmentTransaction;
@Before @Before
public void setUp() { public void setUp() {
@@ -98,11 +115,11 @@ public class CombinedBiometricProfileSettingsTest {
ShadowUtils.setFaceManager(mFaceManager); ShadowUtils.setFaceManager(mFaceManager);
FakeFeatureFactory.setupForTest(); FakeFeatureFactory.setupForTest();
FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class, mActivity = spy(Robolectric.buildActivity(FragmentActivity.class,
new Intent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, 1L)).get(); new Intent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, 1L)).get());
mContext = spy(ApplicationProvider.getApplicationContext()); mContext = spy(ApplicationProvider.getApplicationContext());
mFragment = spy(new TestCombinedBiometricProfileSettings(mContext)); mFragment = spy(new TestCombinedBiometricProfileSettings(mContext));
doReturn(activity).when(mFragment).getActivity(); doReturn(mActivity).when(mFragment).getActivity();
ReflectionHelpers.setField(mFragment, "mDashboardFeatureProvider", ReflectionHelpers.setField(mFragment, "mDashboardFeatureProvider",
FakeFeatureFactory.setupForTest().dashboardFeatureProvider); FakeFeatureFactory.setupForTest().dashboardFeatureProvider);
@@ -121,6 +138,11 @@ public class CombinedBiometricProfileSettingsTest {
}).when(mFragment).findPreference(any()); }).when(mFragment).findPreference(any());
} }
@After
public void tearDown() {
ShadowUtils.reset();
}
@Test @Test
public void testClickFingerprintUnlockWithValidGkPwHandle() { public void testClickFingerprintUnlockWithValidGkPwHandle() {
doAnswer(invocation -> { doAnswer(invocation -> {
@@ -299,6 +321,84 @@ public class CombinedBiometricProfileSettingsTest {
assertThat(capturedPreferences.get(0).getKey()).isEqualTo(mFragment.getFacePreferenceKey()); assertThat(capturedPreferences.get(0).getKey()).isEqualTo(mFragment.getFacePreferenceKey());
} }
@Test
public void testClickFingerprintUnlockInMultiWindow_onUdfpsDevice_withoutEnrolledFp_showsDialog() {
clickFingerprintUnlockInSplitScreenMode(TYPE_UDFPS_OPTICAL, /*hasEnrolledFingerprint*/
false);
verify(mBiometricSettingsAppPreferenceController, times(0)).handlePreferenceTreeClick(
any());
verify(mFragmentTransaction).add(any(),
eq(FingerprintSettingsFragment.FingerprintSplitScreenDialog.class.getName()));
}
@Test
public void testClickFingerprintUnlockInMultiWindow_onUdfpsDevice_withEnrolledFp_noDialog() {
clickFingerprintUnlockInSplitScreenMode(TYPE_UDFPS_OPTICAL, /*hasEnrolledFingerprint*/true);
verify(mBiometricSettingsAppPreferenceController).handlePreferenceTreeClick(
mPreferenceCaptor.capture());
List<Preference> capturedPreferences = mPreferenceCaptor.getAllValues();
assertThat(capturedPreferences.size()).isEqualTo(1);
assertThat(capturedPreferences.get(0).getKey()).isEqualTo(
mFragment.getFingerprintPreferenceKey());
verify(mFragmentTransaction, never()).add(any(),
eq(FingerprintSettingsFragment.FingerprintSplitScreenDialog.class.getName()));
}
@Test
public void testClickFingerprintUnlockInMultiWindow_onSfpsDevice_withoutEnrolledFp_noDialog() {
clickFingerprintUnlockInSplitScreenMode(TYPE_POWER_BUTTON, /*hasEnrolledFingerprint*/false);
verify(mBiometricSettingsAppPreferenceController).handlePreferenceTreeClick(
mPreferenceCaptor.capture());
List<Preference> capturedPreferences = mPreferenceCaptor.getAllValues();
assertThat(capturedPreferences.size()).isEqualTo(1);
assertThat(capturedPreferences.get(0).getKey()).isEqualTo(
mFragment.getFingerprintPreferenceKey());
verify(mFragmentTransaction, never()).add(any(),
eq(FingerprintSettingsFragment.FingerprintSplitScreenDialog.class.getName()));
}
private void clickFingerprintUnlockInSplitScreenMode(
@FingerprintSensorProperties.SensorType int sensorType,
boolean hasEnrolledFingerprint) {
final ArrayList<FingerprintSensorPropertiesInternal> props = new ArrayList<>();
props.add(new FingerprintSensorPropertiesInternal(
0 /* sensorId */,
SensorProperties.STRENGTH_STRONG,
1 /* maxEnrollmentsPerUser */,
new ArrayList<ComponentInfoInternal>(),
sensorType,
true /* resetLockoutRequiresHardwareAuthToken */));
doReturn(props).when(mFingerprintManager).getSensorPropertiesInternal();
doAnswer(invocation -> {
final FingerprintManager.GenerateChallengeCallback callback =
invocation.getArgument(1);
callback.onChallengeGenerated(0, 0, 1L);
return null;
}).when(mFingerprintManager).generateChallenge(anyInt(), any());
doReturn(new byte[]{1}).when(mFragment).requestGatekeeperHat(any(), anyLong(), anyInt(),
anyLong());
FragmentManager fragmentManager = mock(FragmentManager.class);
doReturn(fragmentManager).when(mActivity).getSupportFragmentManager();
doReturn(mFragmentTransaction).when(fragmentManager).beginTransaction();
doReturn(true).when(mActivity).isInMultiWindowMode();
doReturn(hasEnrolledFingerprint).when(mFingerprintManager).hasEnrolledFingerprints(
anyInt());
// Start fragment
mFragment.onAttach(mContext);
mFragment.onCreate(null);
mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
mFragment.onResume();
// User clicks on "Fingerprint Unlock"
final Preference preference = new Preference(mContext);
preference.setKey(mFragment.getFingerprintPreferenceKey());
mFragment.onPreferenceTreeClick(preference);
}
/** /**
* a test fragment that initializes PreferenceScreen for testing. * a test fragment that initializes PreferenceScreen for testing.
*/ */

View File

@@ -32,7 +32,9 @@ import static com.google.common.truth.Truth.assertWithMessage;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.app.Activity; import android.app.Activity;
@@ -41,6 +43,9 @@ import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.hardware.face.Face; import android.hardware.face.Face;
import android.hardware.face.FaceManager; import android.hardware.face.FaceManager;
import android.hardware.face.FaceSensorProperties;
import android.hardware.face.FaceSensorPropertiesInternal;
import android.hardware.face.IFaceAuthenticatorsRegisteredCallback;
import android.os.UserHandle; import android.os.UserHandle;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
@@ -72,6 +77,8 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@@ -99,6 +106,8 @@ public class FaceEnrollIntroductionTest {
private FaceManager mFaceManager; private FaceManager mFaceManager;
@Mock @Mock
private LockPatternUtils mLockPatternUtils; private LockPatternUtils mLockPatternUtils;
@Captor
private ArgumentCaptor<IFaceAuthenticatorsRegisteredCallback> mCaptor;
private Context mContext; private Context mContext;
private ActivityController<? extends Activity> mController; private ActivityController<? extends Activity> mController;
@@ -127,7 +136,6 @@ public class FaceEnrollIntroductionTest {
return mConfirmingCredentials; return mConfirmingCredentials;
} }
public FaceManager mOverrideFaceManager = null;
@NonNull @NonNull
public GateKeeperAction mGateKeeperAction = GateKeeperAction.CALL_SUPER; public GateKeeperAction mGateKeeperAction = GateKeeperAction.CALL_SUPER;
@@ -145,12 +153,6 @@ public class FaceEnrollIntroductionTest {
} }
} }
@Nullable
@Override
protected FaceManager getFaceManager() {
return mOverrideFaceManager;
}
@Override @Override
protected boolean launchPostureGuidance() { protected boolean launchPostureGuidance() {
return super.launchPostureGuidance(); return super.launchPostureGuidance();
@@ -186,7 +188,7 @@ public class FaceEnrollIntroductionTest {
mController = Robolectric.buildActivity( mController = Robolectric.buildActivity(
TestFaceEnrollIntroduction.class, testIntent); TestFaceEnrollIntroduction.class, testIntent);
mActivity = (TestFaceEnrollIntroduction) spy(mController.get()); mActivity = (TestFaceEnrollIntroduction) spy(mController.get());
mActivity.mOverrideFaceManager = mFaceManager; doReturn(mFaceManager).when(mActivity).getFaceManager();
when(mActivity.getPostureGuidanceIntent()).thenReturn(null); when(mActivity.getPostureGuidanceIntent()).thenReturn(null);
when(mContext.getApplicationContext()).thenReturn(mContext); when(mContext.getApplicationContext()).thenReturn(mContext);
when(mContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager); when(mContext.getSystemService(Context.FACE_SERVICE)).thenReturn(mFaceManager);
@@ -229,7 +231,6 @@ public class FaceEnrollIntroductionTest {
}).when(mFaceManager).generateChallenge(anyInt(), any()); }).when(mFaceManager).generateChallenge(anyInt(), any());
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent); mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get(); mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
} }
private GlifLayout getGlifLayout(Activity activity) { private GlifLayout getGlifLayout(Activity activity) {
@@ -310,12 +311,51 @@ public class FaceEnrollIntroductionTest {
} }
@Test @Test
public void testFaceEnrollIntroduction_hasDescription() { public void testFaceEnrollIntroduction_hasDescription_weakFace() throws Exception {
setupActivity(); setupActivity();
verify(mFaceManager).addAuthenticatorsRegisteredCallback(mCaptor.capture());
CharSequence desc = getGlifLayout(mActivity).getDescriptionText(); CharSequence desc = getGlifLayout(mActivity).getDescriptionText();
assertThat(desc.toString()).isEqualTo( assertThat(desc.toString()).isEqualTo(
mContext.getString(R.string.security_settings_face_enroll_introduction_message)); mContext.getString(R.string.security_settings_face_enroll_introduction_message));
List<FaceSensorPropertiesInternal> props = List.of(new FaceSensorPropertiesInternal(
0 /* id */,
FaceSensorProperties.STRENGTH_WEAK,
1 /* maxTemplatesAllowed */,
new ArrayList<>() /* componentInfo */,
FaceSensorProperties.TYPE_UNKNOWN,
true /* supportsFaceDetection */,
true /* supportsSelfIllumination */,
false /* resetLockoutRequiresChallenge */));
mCaptor.getValue().onAllAuthenticatorsRegistered(props);
desc = getGlifLayout(mActivity).getDescriptionText();
assertThat(desc.toString()).isEqualTo(
mContext.getString(R.string.security_settings_face_enroll_introduction_message));
}
@Test
public void testFaceEnrollIntroduction_hasDescriptionNoLessSecure_strongFace()
throws Exception {
setupActivity();
verify(mFaceManager).addAuthenticatorsRegisteredCallback(mCaptor.capture());
List<FaceSensorPropertiesInternal> props = List.of(new FaceSensorPropertiesInternal(
0 /* id */,
FaceSensorProperties.STRENGTH_STRONG,
1 /* maxTemplatesAllowed */,
new ArrayList<>() /* componentInfo */,
FaceSensorProperties.TYPE_UNKNOWN,
true /* supportsFaceDetection */,
true /* supportsSelfIllumination */,
false /* resetLockoutRequiresChallenge */));
mCaptor.getValue().onAllAuthenticatorsRegistered(props);
CharSequence desc = getGlifLayout(mActivity).getDescriptionText();
assertThat(desc.toString()).isEqualTo(
mContext.getString(
R.string.security_settings_face_enroll_introduction_message_class3));
} }
@Test @Test
@@ -412,7 +452,6 @@ public class FaceEnrollIntroductionTest {
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent); mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get(); mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create(); mController.create();
@@ -432,7 +471,6 @@ public class FaceEnrollIntroductionTest {
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent); mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get(); mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create(); mController.create();
@@ -450,7 +488,6 @@ public class FaceEnrollIntroductionTest {
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent); mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get(); mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create(); mController.create();
@@ -470,7 +507,6 @@ public class FaceEnrollIntroductionTest {
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent); mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get(); mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create(); mController.create();
mController.start(); mController.start();
@@ -489,7 +525,6 @@ public class FaceEnrollIntroductionTest {
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent); mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get(); mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create(); mController.create();
mController.start(); mController.start();

View File

@@ -0,0 +1,197 @@
/*
* Copyright (C) 2023 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.fingerprint.FingerprintSensorProperties.TYPE_POWER_BUTTON;
import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
import static com.android.settings.biometrics.fingerprint.FingerprintSettings.FingerprintSettingsFragment;
import static com.android.settings.biometrics.fingerprint.FingerprintSettings.FingerprintSettingsFragment.ADD_FINGERPRINT_REQUEST;
import static com.android.settings.biometrics.fingerprint.FingerprintSettings.FingerprintSettingsFragment.KEY_FINGERPRINT_ADD;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.Intent;
import android.hardware.biometrics.ComponentInfoInternal;
import android.hardware.biometrics.SensorProperties;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintSensorProperties;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.Preference;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.testutils.shadow.ShadowSettingsPreferenceFragment;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.testutils.shadow.ShadowUtils;
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.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowSettingsPreferenceFragment.class, ShadowUtils.class, ShadowFragment.class,
ShadowUserManager.class})
public class FingerprintSettingsFragmentTest {
private FingerprintSettingsFragment mFragment;
private Context mContext;
private FragmentActivity mActivity;
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Mock
private FingerprintManager mFingerprintManager;
@Mock
private FragmentTransaction mFragmentTransaction;
@Before
public void setUp() {
doReturn(true).when(mFingerprintManager).isHardwareDetected();
ShadowUtils.setFingerprintManager(mFingerprintManager);
FakeFeatureFactory.setupForTest();
Intent intent = new Intent();
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, 1L);
mActivity = spy(Robolectric.buildActivity(FragmentActivity.class, intent).get());
mContext = spy(ApplicationProvider.getApplicationContext());
mFragment = spy(new FingerprintSettingsFragment());
doReturn(mActivity).when(mFragment).getActivity();
doReturn(mContext).when(mFragment).getContext();
FragmentManager fragmentManager = mock(FragmentManager.class);
doReturn(mFragmentTransaction).when(fragmentManager).beginTransaction();
doReturn(mFragmentTransaction).when(mFragmentTransaction).add(any(), anyString());
doReturn(fragmentManager).when(mFragment).getFragmentManager();
doReturn(fragmentManager).when(mActivity).getSupportFragmentManager();
doNothing().when(mFragment).startActivityForResult(any(Intent.class), anyInt());
}
@After
public void tearDown() {
ShadowUtils.reset();
}
@Test
public void testAddFingerprint_onUdfpsDevice_inFullScreen_noDialog() {
setSensorType(TYPE_UDFPS_OPTICAL);
// Start fragment
mFragment.onAttach(mContext);
mFragment.onCreate(null);
mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
mFragment.onResume();
// Click "Add Fingerprint"
final Preference preference = new Preference(mContext);
preference.setKey(KEY_FINGERPRINT_ADD);
mFragment.onPreferenceTreeClick(preference);
verify(mFragment).startActivityForResult(any(), eq(ADD_FINGERPRINT_REQUEST));
verify(mFragmentTransaction, never()).add(any(),
eq(FingerprintSettingsFragment.FingerprintSplitScreenDialog.class.getName()));
}
@Test
public void testAddFingerprint_onUdfpsDevice_inMultiWindow_showsDialog() {
setSensorType(TYPE_UDFPS_OPTICAL);
// Start fragment
mFragment.onAttach(mContext);
mFragment.onCreate(null);
mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
mFragment.onResume();
doReturn(true).when(mActivity).isInMultiWindowMode();
// Click "Add Fingerprint"
final Preference preference = new Preference(mContext);
preference.setKey(KEY_FINGERPRINT_ADD);
mFragment.onPreferenceTreeClick(preference);
verify(mFragment, times(0)).startActivityForResult(any(), eq(ADD_FINGERPRINT_REQUEST));
verify(mFragmentTransaction).add(any(),
eq(FingerprintSettingsFragment.FingerprintSplitScreenDialog.class.getName()));
}
@Test
public void testAddFingerprint_onSfpsDevice_inMultiWindow_noDialog() {
setSensorType(TYPE_POWER_BUTTON);
// Start fragment
mFragment.onAttach(mContext);
mFragment.onCreate(null);
mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
mFragment.onResume();
doReturn(true).when(mActivity).isInMultiWindowMode();
// Click "Add Fingerprint"
final Preference preference = new Preference(mContext);
preference.setKey(KEY_FINGERPRINT_ADD);
mFragment.onPreferenceTreeClick(preference);
verify(mFragment).startActivityForResult(any(), eq(ADD_FINGERPRINT_REQUEST));
verify(mFragmentTransaction, never()).add(any(),
eq(FingerprintSettingsFragment.FingerprintSplitScreenDialog.class.getName()));
}
private void setSensorType(@FingerprintSensorProperties.SensorType int sensorType) {
final ArrayList<FingerprintSensorPropertiesInternal> props = new ArrayList<>();
props.add(new FingerprintSensorPropertiesInternal(
0 /* sensorId */,
SensorProperties.STRENGTH_STRONG,
1 /* maxEnrollmentsPerUser */,
new ArrayList<ComponentInfoInternal>(),
sensorType,
true /* resetLockoutRequiresHardwareAuthToken */));
doReturn(props).when(mFingerprintManager).getSensorPropertiesInternal();
}
}