diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index b4a33fffeb482..de0f8ef99f59d 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -9920,6 +9920,17 @@ public final class Settings { public static final String ACTIVE_UNLOCK_ON_UNLOCK_INTENT_WHEN_BIOMETRIC_ENROLLED = "active_unlock_on_unlock_intent_when_biometric_enrolled"; + /** + * If active unlock triggers on unlock intents, then also request active unlock on + * these wake-up reasons. See PowerManager.WakeReason for value mappings. + * WakeReasons should be separated by a pipe. For example: "0|3" or "0". If this + * setting should be disabled, then this should be set to an empty string. A null value + * will use the system default value (WAKE_REASON_UNFOLD_DEVICE). + * @hide + */ + public static final String ACTIVE_UNLOCK_WAKEUPS_CONSIDERED_UNLOCK_INTENTS = + "active_unlock_wakeups_considered_unlock_intents"; + /** * Whether the assist gesture should be enabled. * diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java index 211030a90c476..c537d96b41937 100644 --- a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java +++ b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java @@ -130,6 +130,7 @@ public class SecureSettings { Settings.Secure.ACTIVE_UNLOCK_ON_FACE_ERRORS, Settings.Secure.ACTIVE_UNLOCK_ON_FACE_ACQUIRE_INFO, Settings.Secure.ACTIVE_UNLOCK_ON_UNLOCK_INTENT_WHEN_BIOMETRIC_ENROLLED, + Settings.Secure.ACTIVE_UNLOCK_WAKEUPS_CONSIDERED_UNLOCK_INTENTS, Settings.Secure.VR_DISPLAY_MODE, Settings.Secure.NOTIFICATION_BADGING, Settings.Secure.NOTIFICATION_DISMISS_RTL, diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java index 0539f09e20d31..8a67a0d816779 100644 --- a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java +++ b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java @@ -189,6 +189,8 @@ public class SecureSettingsValidators { VALIDATORS.put(Secure.ACTIVE_UNLOCK_ON_FACE_ACQUIRE_INFO, ANY_STRING_VALIDATOR); VALIDATORS.put(Secure.ACTIVE_UNLOCK_ON_UNLOCK_INTENT_WHEN_BIOMETRIC_ENROLLED, ANY_STRING_VALIDATOR); + VALIDATORS.put(Secure.ACTIVE_UNLOCK_WAKEUPS_CONSIDERED_UNLOCK_INTENTS, + ANY_STRING_VALIDATOR); VALIDATORS.put(Secure.ASSIST_GESTURE_ENABLED, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.ASSIST_GESTURE_WAKE_ENABLED, BOOLEAN_VALIDATOR); diff --git a/packages/SystemUI/src/com/android/keyguard/ActiveUnlockConfig.kt b/packages/SystemUI/src/com/android/keyguard/ActiveUnlockConfig.kt index 38fa354534188..54ae84f97b172 100644 --- a/packages/SystemUI/src/com/android/keyguard/ActiveUnlockConfig.kt +++ b/packages/SystemUI/src/com/android/keyguard/ActiveUnlockConfig.kt @@ -16,18 +16,20 @@ package com.android.keyguard -import android.annotation.IntDef import android.content.ContentResolver import android.database.ContentObserver import android.hardware.biometrics.BiometricFaceConstants.FACE_ERROR_TIMEOUT import android.net.Uri import android.os.Handler +import android.os.PowerManager +import android.os.PowerManager.WAKE_REASON_UNFOLD_DEVICE import android.os.UserHandle import android.provider.Settings.Secure.ACTIVE_UNLOCK_ON_BIOMETRIC_FAIL import android.provider.Settings.Secure.ACTIVE_UNLOCK_ON_FACE_ACQUIRE_INFO import android.provider.Settings.Secure.ACTIVE_UNLOCK_ON_FACE_ERRORS import android.provider.Settings.Secure.ACTIVE_UNLOCK_ON_UNLOCK_INTENT import android.provider.Settings.Secure.ACTIVE_UNLOCK_ON_UNLOCK_INTENT_WHEN_BIOMETRIC_ENROLLED +import android.provider.Settings.Secure.ACTIVE_UNLOCK_WAKEUPS_CONSIDERED_UNLOCK_INTENTS import android.provider.Settings.Secure.ACTIVE_UNLOCK_ON_WAKE import android.util.Log import com.android.keyguard.KeyguardUpdateMonitor.getCurrentUser @@ -52,23 +54,26 @@ class ActiveUnlockConfig @Inject constructor( companion object { const val TAG = "ActiveUnlockConfig" - - const val BIOMETRIC_TYPE_NONE = 0 - const val BIOMETRIC_TYPE_ANY_FACE = 1 - const val BIOMETRIC_TYPE_ANY_FINGERPRINT = 2 - const val BIOMETRIC_TYPE_UNDER_DISPLAY_FINGERPRINT = 3 } - @Retention(AnnotationRetention.SOURCE) - @IntDef(BIOMETRIC_TYPE_NONE, BIOMETRIC_TYPE_ANY_FACE, BIOMETRIC_TYPE_ANY_FINGERPRINT, - BIOMETRIC_TYPE_UNDER_DISPLAY_FINGERPRINT) - annotation class BiometricType - /** * Indicates the origin for an active unlock request. */ - enum class ACTIVE_UNLOCK_REQUEST_ORIGIN { - WAKE, UNLOCK_INTENT, BIOMETRIC_FAIL, ASSISTANT + enum class ActiveUnlockRequestOrigin { + WAKE, + UNLOCK_INTENT, + BIOMETRIC_FAIL, + ASSISTANT, + } + + /** + * Biometric type options. + */ + enum class BiometricType(val intValue: Int) { + NONE(0), + ANY_FACE(1), + ANY_FINGERPRINT(2), + UNDER_DISPLAY_FINGERPRINT(3), } var keyguardUpdateMonitor: KeyguardUpdateMonitor? = null @@ -76,9 +81,10 @@ class ActiveUnlockConfig @Inject constructor( private var requestActiveUnlockOnUnlockIntent = false private var requestActiveUnlockOnBioFail = false - private var faceErrorsToTriggerBiometricFailOn = mutableSetOf(FACE_ERROR_TIMEOUT) + private var faceErrorsToTriggerBiometricFailOn = mutableSetOf() private var faceAcquireInfoToTriggerBiometricFailOn = mutableSetOf() - private var onUnlockIntentWhenBiometricEnrolled = mutableSetOf(BIOMETRIC_TYPE_NONE) + private var onUnlockIntentWhenBiometricEnrolled = mutableSetOf() + private var wakeupsConsideredUnlockIntents = mutableSetOf() private val settingsObserver = object : ContentObserver(handler) { private val wakeUri = secureSettings.getUriFor(ACTIVE_UNLOCK_ON_WAKE) @@ -89,16 +95,19 @@ class ActiveUnlockConfig @Inject constructor( secureSettings.getUriFor(ACTIVE_UNLOCK_ON_FACE_ACQUIRE_INFO) private val unlockIntentWhenBiometricEnrolledUri = secureSettings.getUriFor(ACTIVE_UNLOCK_ON_UNLOCK_INTENT_WHEN_BIOMETRIC_ENROLLED) + private val wakeupsConsideredUnlockIntentsUri = + secureSettings.getUriFor(ACTIVE_UNLOCK_WAKEUPS_CONSIDERED_UNLOCK_INTENTS) fun register() { registerUri( listOf( - wakeUri, - unlockIntentUri, - bioFailUri, - faceErrorsUri, - faceAcquireInfoUri, - unlockIntentWhenBiometricEnrolledUri + wakeUri, + unlockIntentUri, + bioFailUri, + faceErrorsUri, + faceAcquireInfoUri, + unlockIntentWhenBiometricEnrolledUri, + wakeupsConsideredUnlockIntentsUri, ) ) @@ -153,7 +162,7 @@ class ActiveUnlockConfig @Inject constructor( secureSettings.getStringForUser(ACTIVE_UNLOCK_ON_FACE_ACQUIRE_INFO, getCurrentUser()), faceAcquireInfoToTriggerBiometricFailOn, - setOf()) + emptySet()) } if (selfChange || uris.contains(unlockIntentWhenBiometricEnrolledUri)) { @@ -162,7 +171,16 @@ class ActiveUnlockConfig @Inject constructor( ACTIVE_UNLOCK_ON_UNLOCK_INTENT_WHEN_BIOMETRIC_ENROLLED, getCurrentUser()), onUnlockIntentWhenBiometricEnrolled, - setOf(BIOMETRIC_TYPE_NONE)) + setOf(BiometricType.NONE.intValue)) + } + + if (selfChange || uris.contains(wakeupsConsideredUnlockIntentsUri)) { + processStringArray( + secureSettings.getStringForUser( + ACTIVE_UNLOCK_WAKEUPS_CONSIDERED_UNLOCK_INTENTS, + getCurrentUser()), + wakeupsConsideredUnlockIntents, + setOf(WAKE_REASON_UNFOLD_DEVICE)) } } @@ -181,10 +199,12 @@ class ActiveUnlockConfig @Inject constructor( out.clear() stringSetting?.let { for (code: String in stringSetting.split("|")) { - try { - out.add(code.toInt()) - } catch (e: NumberFormatException) { - Log.e(TAG, "Passed an invalid setting=$code") + if (code.isNotEmpty()) { + try { + out.add(code.toInt()) + } catch (e: NumberFormatException) { + Log.e(TAG, "Passed an invalid setting=$code") + } } } } ?: out.addAll(default) @@ -220,23 +240,31 @@ class ActiveUnlockConfig @Inject constructor( return faceAcquireInfoToTriggerBiometricFailOn.contains(acquiredInfo) } + /** + * Whether the PowerManager wake reason is considered an unlock intent and should use origin + * [ActiveUnlockRequestOrigin.UNLOCK_INTENT] instead of [ActiveUnlockRequestOrigin.WAKE]. + */ + fun isWakeupConsideredUnlockIntent(pmWakeReason: Int): Boolean { + return wakeupsConsideredUnlockIntents.contains(pmWakeReason) + } + /** * Whether to trigger active unlock based on where the request is coming from and * the current settings. */ - fun shouldAllowActiveUnlockFromOrigin(requestOrigin: ACTIVE_UNLOCK_REQUEST_ORIGIN): Boolean { + fun shouldAllowActiveUnlockFromOrigin(requestOrigin: ActiveUnlockRequestOrigin): Boolean { return when (requestOrigin) { - ACTIVE_UNLOCK_REQUEST_ORIGIN.WAKE -> requestActiveUnlockOnWakeup + ActiveUnlockRequestOrigin.WAKE -> requestActiveUnlockOnWakeup - ACTIVE_UNLOCK_REQUEST_ORIGIN.UNLOCK_INTENT -> + ActiveUnlockRequestOrigin.UNLOCK_INTENT -> requestActiveUnlockOnUnlockIntent || requestActiveUnlockOnWakeup || (shouldRequestActiveUnlockOnUnlockIntentFromBiometricEnrollment()) - ACTIVE_UNLOCK_REQUEST_ORIGIN.BIOMETRIC_FAIL -> + ActiveUnlockRequestOrigin.BIOMETRIC_FAIL -> requestActiveUnlockOnBioFail || requestActiveUnlockOnUnlockIntent || requestActiveUnlockOnWakeup - ACTIVE_UNLOCK_REQUEST_ORIGIN.ASSISTANT -> isActiveUnlockEnabled() + ActiveUnlockRequestOrigin.ASSISTANT -> isActiveUnlockEnabled() } } @@ -252,18 +280,18 @@ class ActiveUnlockConfig @Inject constructor( val udfpsEnrolled = it.isUdfpsEnrolled if (!anyFaceEnrolled && !anyFingerprintEnrolled) { - return onUnlockIntentWhenBiometricEnrolled.contains(BIOMETRIC_TYPE_NONE) + return onUnlockIntentWhenBiometricEnrolled.contains(BiometricType.NONE.intValue) } if (!anyFaceEnrolled && anyFingerprintEnrolled) { return onUnlockIntentWhenBiometricEnrolled.contains( - BIOMETRIC_TYPE_ANY_FINGERPRINT) || + BiometricType.ANY_FINGERPRINT.intValue) || (udfpsEnrolled && onUnlockIntentWhenBiometricEnrolled.contains( - BIOMETRIC_TYPE_UNDER_DISPLAY_FINGERPRINT)) + BiometricType.UNDER_DISPLAY_FINGERPRINT.intValue)) } if (!anyFingerprintEnrolled && anyFaceEnrolled) { - return onUnlockIntentWhenBiometricEnrolled.contains(BIOMETRIC_TYPE_ANY_FACE) + return onUnlockIntentWhenBiometricEnrolled.contains(BiometricType.ANY_FACE.intValue) } } @@ -275,11 +303,15 @@ class ActiveUnlockConfig @Inject constructor( pw.println(" requestActiveUnlockOnWakeup=$requestActiveUnlockOnWakeup") pw.println(" requestActiveUnlockOnUnlockIntent=$requestActiveUnlockOnUnlockIntent") pw.println(" requestActiveUnlockOnBioFail=$requestActiveUnlockOnBioFail") - pw.println(" requestActiveUnlockOnUnlockIntentWhenBiometricEnrolled=" + - "$onUnlockIntentWhenBiometricEnrolled") + pw.println(" requestActiveUnlockOnUnlockIntentWhenBiometricEnrolled=${ + onUnlockIntentWhenBiometricEnrolled.map { BiometricType.values()[it] } + }") pw.println(" requestActiveUnlockOnFaceError=$faceErrorsToTriggerBiometricFailOn") pw.println(" requestActiveUnlockOnFaceAcquireInfo=" + "$faceAcquireInfoToTriggerBiometricFailOn") + pw.println(" activeUnlockWakeupsConsideredUnlockIntents=${ + wakeupsConsideredUnlockIntents.map { PowerManager.wakeReasonToString(it) } + }") pw.println("Current state:") keyguardUpdateMonitor?.let { diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java index 57bfe5421049a..9fcacce311d1b 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java @@ -237,7 +237,7 @@ public class KeyguardSecurityContainerController extends ViewController