From 7edebeef7e29f3f8738f8b989201c98b0dc9347e Mon Sep 17 00:00:00 2001 From: Mill Chen Date: Fri, 9 Apr 2021 23:14:27 +0800 Subject: [PATCH 1/2] Combined biometric settings implementation There will be multiple biometrics authentications existing at the same time, so we added a new page for multiple biometrics to control biometrics settings. Bug: 183449119 Test: manual test Change-Id: I359082caf771e07dfd5b24973cb8a3cf372c1b30 --- AndroidManifest.xml | 16 ++++ res/values/strings.xml | 20 +++++ res/xml/security_dashboard_settings.xml | 11 +++ .../security_settings_combined_biometric.xml | 69 +++++++++++++++ ...ty_settings_combined_biometric_profile.xml | 56 ++++++++++++ res/xml/security_settings_face.xml | 10 ++- src/com/android/settings/Settings.java | 2 + src/com/android/settings/Utils.java | 7 ++ ...FaceProfileStatusPreferenceController.java | 42 +++++++++ ...ometricFaceStatusPreferenceController.java | 37 ++++++++ ...rintProfileStatusPreferenceController.java | 42 +++++++++ ...FingerprintStatusPreferenceController.java | 38 ++++++++ ...metricSettingsAppPreferenceController.java | 86 +++++++++++++++++++ ...cSettingsKeyguardPreferenceController.java | 67 +++++++++++++++ .../CombinedBiometricProfileSettings.java | 60 +++++++++++++ ...tricProfileStatusPreferenceController.java | 60 +++++++++++++ .../CombinedBiometricSettings.java | 63 ++++++++++++++ ...edBiometricStatusPreferenceController.java | 71 +++++++++++++++ .../FaceSettingsAppPreferenceController.java | 5 ++ ...eSettingsKeyguardPreferenceController.java | 3 +- ...sLockscreenBypassPreferenceController.java | 6 ++ .../face/FaceStatusPreferenceController.java | 2 +- ...aceUnlockCategoryPreferenceController.java | 36 ++++++++ ...FingerprintStatusPreferenceController.java | 3 +- .../core/gateway/SettingsGateway.java | 4 + .../settings/security/SecuritySettings.java | 5 ++ 26 files changed, 817 insertions(+), 4 deletions(-) create mode 100644 res/xml/security_settings_combined_biometric.xml create mode 100644 res/xml/security_settings_combined_biometric_profile.xml create mode 100644 src/com/android/settings/biometrics/combination/BiometricFaceProfileStatusPreferenceController.java create mode 100644 src/com/android/settings/biometrics/combination/BiometricFaceStatusPreferenceController.java create mode 100644 src/com/android/settings/biometrics/combination/BiometricFingerprintProfileStatusPreferenceController.java create mode 100644 src/com/android/settings/biometrics/combination/BiometricFingerprintStatusPreferenceController.java create mode 100644 src/com/android/settings/biometrics/combination/BiometricSettingsAppPreferenceController.java create mode 100644 src/com/android/settings/biometrics/combination/BiometricSettingsKeyguardPreferenceController.java create mode 100644 src/com/android/settings/biometrics/combination/CombinedBiometricProfileSettings.java create mode 100644 src/com/android/settings/biometrics/combination/CombinedBiometricProfileStatusPreferenceController.java create mode 100644 src/com/android/settings/biometrics/combination/CombinedBiometricSettings.java create mode 100644 src/com/android/settings/biometrics/combination/CombinedBiometricStatusPreferenceController.java create mode 100644 src/com/android/settings/biometrics/face/FaceUnlockCategoryPreferenceController.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c352694f9f5..9b11fe81c98 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -494,6 +494,22 @@ android:value="com.android.settings.biometrics.fingerprint.FingerprintSettings$FingerprintSettingsFragment" /> + + + + + + + + Use your fingerprint to unlock your phone or for authentication, like when you sign in to apps or approve a purchase\n\nLearn more + + + Face & fingerprint unlock + + Face and fingerprint + + When you set up face unlock and fingerprint, your phone will ask for your fingerprint when you wear a mask or are in a dark area. + + Ways to unlock + + Use face and fingerprint to + + Unlocking your phone + + Authentication in apps + Skip screen lock? @@ -7990,6 +8006,7 @@ backup, back up gesture face, unlock, auth, sign in + face, unlock, auth, sign in, fingerprint, biometric imei, meid, min, prl version, imei sv network, mobile network state, service state, signal strength, mobile network type, roaming, iccid, eid serial number, hardware version @@ -8015,6 +8032,9 @@ fingerprint, add fingerprint + + face, fingerprint, add fingerprint + dim screen, touchscreen, battery, smart brightness, dynamic brightness, Auto brightness diff --git a/res/xml/security_dashboard_settings.xml b/res/xml/security_dashboard_settings.xml index fd9f3186996..be1f34cebe3 100644 --- a/res/xml/security_dashboard_settings.xml +++ b/res/xml/security_dashboard_settings.xml @@ -55,6 +55,12 @@ android:title="@string/security_settings_face_preference_title" android:summary="@string/summary_placeholder" settings:keywords="@string/keywords_face_settings" /> + + @@ -91,6 +97,11 @@ android:title="@string/security_settings_face_preference_title" android:summary="@string/summary_placeholder" /> + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/xml/security_settings_combined_biometric_profile.xml b/res/xml/security_settings_combined_biometric_profile.xml new file mode 100644 index 00000000000..57111528603 --- /dev/null +++ b/res/xml/security_settings_combined_biometric_profile.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/xml/security_settings_face.xml b/res/xml/security_settings_face.xml index 1fc1ca82de5..131f222685c 100644 --- a/res/xml/security_settings_face.xml +++ b/res/xml/security_settings_face.xml @@ -31,7 +31,8 @@ + android:title="@string/security_settings_face_settings_use_face_category" + settings:controller="com.android.settings.biometrics.face.FaceUnlockCategoryPreferenceController"> + + securityPreferenceControllers = new ArrayList<>(); securityPreferenceControllers.add(new FaceStatusPreferenceController(context)); securityPreferenceControllers.add(new FingerprintStatusPreferenceController(context)); + securityPreferenceControllers.add(new CombinedBiometricStatusPreferenceController(context)); securityPreferenceControllers.add(new ChangeScreenLockPreferenceController(context, host)); controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY) .setChildren(securityPreferenceControllers)); @@ -128,6 +131,8 @@ public class SecuritySettings extends DashboardFragment { context, lifecycle)); profileSecurityControllers.add(new FaceProfileStatusPreferenceController(context)); profileSecurityControllers.add(new FingerprintProfileStatusPreferenceController(context)); + profileSecurityControllers + .add(new CombinedBiometricProfileStatusPreferenceController(context)); controllers.add(new PreferenceCategoryController(context, WORK_PROFILE_SECURITY_CATEGORY) .setChildren(profileSecurityControllers)); controllers.addAll(profileSecurityControllers); From 8843157b011f43c2d188d56f48fd76eb569a5109 Mon Sep 17 00:00:00 2001 From: Mill Chen Date: Thu, 22 Apr 2021 11:21:44 +0800 Subject: [PATCH 2/2] Update confirming credential flow for biometric settings The combined biometrics settings has been integrating face and fingerprint authentication together, so the confirming credential flow has to be invoked before entering biometrics settings page. Bug: 183449119 Test: manual Change-Id: I3c0d059241cb10a254868c2e388c4d3b20305b10 --- .../BiometricStatusPreferenceController.java | 3 + .../combination/BiometricsSettingsBase.java | 197 ++++++++++++++++++ .../CombinedBiometricProfileSettings.java | 21 +- .../CombinedBiometricSettings.java | 21 +- 4 files changed, 226 insertions(+), 16 deletions(-) create mode 100644 src/com/android/settings/biometrics/combination/BiometricsSettingsBase.java diff --git a/src/com/android/settings/biometrics/BiometricStatusPreferenceController.java b/src/com/android/settings/biometrics/BiometricStatusPreferenceController.java index 2a3bfb25947..70f0baf3de5 100644 --- a/src/com/android/settings/biometrics/BiometricStatusPreferenceController.java +++ b/src/com/android/settings/biometrics/BiometricStatusPreferenceController.java @@ -122,6 +122,9 @@ public abstract class BiometricStatusPreferenceController extends BasePreference final String clazz = hasEnrolledBiometrics() ? getSettingsClassName() : getEnrollClassName(); intent.setClassName(SETTINGS_PACKAGE_NAME, clazz); + if (!preference.getExtras().isEmpty()) { + intent.putExtras(preference.getExtras()); + } intent.putExtra(Intent.EXTRA_USER_ID, userId); intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, true); context.startActivity(intent); diff --git a/src/com/android/settings/biometrics/combination/BiometricsSettingsBase.java b/src/com/android/settings/biometrics/combination/BiometricsSettingsBase.java new file mode 100644 index 00000000000..4260c7c9130 --- /dev/null +++ b/src/com/android/settings/biometrics/combination/BiometricsSettingsBase.java @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2021 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.combination; + +import static android.app.Activity.RESULT_OK; + +import static com.android.settings.password.ChooseLockPattern.RESULT_FINISHED; + +import android.app.admin.DevicePolicyManager; +import android.content.Context; +import android.content.Intent; +import android.hardware.face.FaceManager; +import android.hardware.fingerprint.FingerprintManager; +import android.os.Bundle; +import android.os.UserHandle; +import android.util.Log; + +import androidx.annotation.Nullable; +import androidx.preference.Preference; + +import com.android.settings.R; +import com.android.settings.Utils; +import com.android.settings.biometrics.BiometricEnrollBase; +import com.android.settings.biometrics.BiometricUtils; +import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.password.ChooseLockGeneric; +import com.android.settings.password.ChooseLockSettingsHelper; + +/** + * Base fragment with the confirming credential functionality for combined biometrics settings. + */ +public abstract class BiometricsSettingsBase extends DashboardFragment { + + private static final int CONFIRM_REQUEST = 2001; + private static final int CHOOSE_LOCK_REQUEST = 2002; + + private static final String SAVE_STATE_CONFIRM_CREDETIAL = "confirm_credential"; + + protected int mUserId; + protected long mFaceChallenge; + protected long mFingerprintChallenge; + protected int mFaceSensorId; + protected int mFingerprintSensorId; + protected long mGkPwHandle; + private boolean mConfirmCredential; + @Nullable private FaceManager mFaceManager; + @Nullable private FingerprintManager mFingerprintManager; + + @Override + public void onAttach(Context context) { + super.onAttach(context); + mUserId = getActivity().getIntent().getIntExtra(Intent.EXTRA_USER_ID, + UserHandle.myUserId()); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mFaceManager = Utils.getFaceManagerOrNull(getActivity()); + mFingerprintManager = Utils.getFingerprintManagerOrNull(getActivity()); + + if (BiometricUtils.containsGatekeeperPasswordHandle(getIntent())) { + mGkPwHandle = BiometricUtils.getGatekeeperPasswordHandle(getIntent()); + } + + if (savedInstanceState != null) { + mConfirmCredential = savedInstanceState.getBoolean(SAVE_STATE_CONFIRM_CREDETIAL); + if (savedInstanceState.containsKey( + ChooseLockSettingsHelper.EXTRA_KEY_REQUEST_GK_PW_HANDLE)) { + mGkPwHandle = savedInstanceState.getLong( + ChooseLockSettingsHelper.EXTRA_KEY_REQUEST_GK_PW_HANDLE); + } + } + + if (mGkPwHandle == 0L && !mConfirmCredential) { + mConfirmCredential = true; + launchChooseOrConfirmLock(); + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (getActivity().isFinishing()) { + mFaceManager.revokeChallenge(mFaceSensorId, mUserId, mFaceChallenge); + mFingerprintManager.revokeChallenge(mUserId, mFingerprintChallenge); + BiometricUtils.removeGatekeeperPasswordHandle(getActivity(), mGkPwHandle); + } + } + + @Override + public boolean onPreferenceTreeClick(Preference preference) { + final String key = preference.getKey(); + if (getFacePreferenceKey().equals(key)) { + final byte[] token = BiometricUtils.requestGatekeeperHat(getActivity(), mGkPwHandle, + mUserId, mFaceChallenge); + final Bundle extras = preference.getExtras(); + extras.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token); + extras.putInt(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, mFaceSensorId); + extras.putLong(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, mFaceChallenge); + } else if (getFingerprintPreferenceKey().equals(key)) { + final byte[] token = BiometricUtils.requestGatekeeperHat(getActivity(), mGkPwHandle, + mUserId, mFingerprintChallenge); + final Bundle extras = preference.getExtras(); + extras.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token); + extras.putLong(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, mFingerprintChallenge); + } + return super.onPreferenceTreeClick(preference); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(SAVE_STATE_CONFIRM_CREDETIAL, mConfirmCredential); + if (mGkPwHandle != 0L) { + outState.putLong(ChooseLockSettingsHelper.EXTRA_KEY_REQUEST_GK_PW_HANDLE, mGkPwHandle); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == CONFIRM_REQUEST || requestCode == CHOOSE_LOCK_REQUEST) { + mConfirmCredential = false; + if (resultCode == RESULT_FINISHED || resultCode == RESULT_OK) { + if (data != null && BiometricUtils.containsGatekeeperPasswordHandle(data)) { + mGkPwHandle = BiometricUtils.getGatekeeperPasswordHandle(data); + mFaceManager.generateChallenge((sensorId, challenge) -> { + mFaceSensorId = sensorId; + mFaceChallenge = challenge; + }); + mFingerprintManager.generateChallenge(mUserId, (sensorId, challenge) -> { + mFingerprintSensorId = sensorId; + mFingerprintChallenge = challenge; + }); + } else { + Log.d(getLogTag(), "Data null or GK PW missing."); + finish(); + } + } else { + Log.d(getLogTag(), "Password not confirmed."); + finish(); + } + } + } + + /** + * Get the preference key of face for passing through credential data to face settings. + */ + public abstract String getFacePreferenceKey(); + + /** + * Get the preference key of face for passing through credential data to face settings. + */ + public abstract String getFingerprintPreferenceKey(); + + private void launchChooseOrConfirmLock() { + final ChooseLockSettingsHelper.Builder builder = + new ChooseLockSettingsHelper.Builder(getActivity(), this) + .setRequestCode(CONFIRM_REQUEST) + .setTitle(getString(R.string.security_settings_biometric_preference_title)) + .setRequestGatekeeperPasswordHandle(true) + .setForegroundOnly(true) + .setReturnCredentials(true); + if (mUserId != UserHandle.USER_NULL) { + builder.setUserId(mUserId); + } + final boolean launched = builder.show(); + + if (!launched) { + Intent intent = BiometricUtils.getChooseLockIntent(getActivity(), getIntent()); + intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY, + DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); + intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_DISABLED_PREFS, true); + intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_REQUEST_GK_PW_HANDLE, true); + intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_BIOMETRICS, true); + + if (mUserId != UserHandle.USER_NULL) { + intent.putExtra(Intent.EXTRA_USER_ID, mUserId); + } + startActivityForResult(intent, CHOOSE_LOCK_REQUEST); + } + } +} diff --git a/src/com/android/settings/biometrics/combination/CombinedBiometricProfileSettings.java b/src/com/android/settings/biometrics/combination/CombinedBiometricProfileSettings.java index f4d1c398423..08c934dbc44 100644 --- a/src/com/android/settings/biometrics/combination/CombinedBiometricProfileSettings.java +++ b/src/com/android/settings/biometrics/combination/CombinedBiometricProfileSettings.java @@ -17,26 +17,21 @@ package com.android.settings.biometrics.combination; import android.app.settings.SettingsEnums; import android.content.Context; -import android.content.Intent; -import android.os.UserHandle; import com.android.settings.R; -import com.android.settings.dashboard.DashboardFragment; import com.android.settings.search.BaseSearchIndexProvider; /** * Settings screen for multiple biometrics used in work profile. */ -public class CombinedBiometricProfileSettings extends DashboardFragment { +public class CombinedBiometricProfileSettings extends BiometricsSettingsBase { private static final String TAG = "BiometricProfileSetting"; - - private int mUserId; + private static final String KEY_FACE_SETTINGS = "biometric_face_settings_profile"; + private static final String KEY_FINGERPRINT_SETTINGS = "biometric_fingerprint_settings_profile"; @Override public void onAttach(Context context) { super.onAttach(context); - mUserId = getActivity().getIntent().getIntExtra(Intent.EXTRA_USER_ID, - UserHandle.myUserId()); use(BiometricSettingsAppPreferenceController.class).setUserId(mUserId); } @@ -45,6 +40,16 @@ public class CombinedBiometricProfileSettings extends DashboardFragment { return R.xml.security_settings_combined_biometric_profile; } + @Override + public String getFacePreferenceKey() { + return KEY_FACE_SETTINGS; + } + + @Override + public String getFingerprintPreferenceKey() { + return KEY_FINGERPRINT_SETTINGS; + } + @Override protected String getLogTag() { return TAG; diff --git a/src/com/android/settings/biometrics/combination/CombinedBiometricSettings.java b/src/com/android/settings/biometrics/combination/CombinedBiometricSettings.java index 843d93571a5..9ebb62f4939 100644 --- a/src/com/android/settings/biometrics/combination/CombinedBiometricSettings.java +++ b/src/com/android/settings/biometrics/combination/CombinedBiometricSettings.java @@ -17,11 +17,8 @@ package com.android.settings.biometrics.combination; import android.app.settings.SettingsEnums; import android.content.Context; -import android.content.Intent; -import android.os.UserHandle; import com.android.settings.R; -import com.android.settings.dashboard.DashboardFragment; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.search.SearchIndexable; @@ -29,16 +26,14 @@ import com.android.settingslib.search.SearchIndexable; * Settings screen for multiple biometrics. */ @SearchIndexable -public class CombinedBiometricSettings extends DashboardFragment { +public class CombinedBiometricSettings extends BiometricsSettingsBase { private static final String TAG = "BiometricSettings"; - - private int mUserId; + private static final String KEY_FACE_SETTINGS = "biometric_face_settings"; + private static final String KEY_FINGERPRINT_SETTINGS = "biometric_fingerprint_settings"; @Override public void onAttach(Context context) { super.onAttach(context); - mUserId = getActivity().getIntent().getIntExtra(Intent.EXTRA_USER_ID, - UserHandle.myUserId()); use(BiometricSettingsKeyguardPreferenceController.class).setUserId(mUserId); use(BiometricSettingsAppPreferenceController.class).setUserId(mUserId); } @@ -48,6 +43,16 @@ public class CombinedBiometricSettings extends DashboardFragment { return R.xml.security_settings_combined_biometric; } + @Override + public String getFacePreferenceKey() { + return KEY_FACE_SETTINGS; + } + + @Override + public String getFingerprintPreferenceKey() { + return KEY_FINGERPRINT_SETTINGS; + } + @Override protected String getLogTag() { return TAG;