Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f9957304 authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Some wake-ups can be considered unlock-intents" into tm-qpr-dev

parents bf7ec45b 7c08fd4a
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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.
         *
+1 −0
Original line number Diff line number Diff line
@@ -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,
+2 −0
Original line number Diff line number Diff line
@@ -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);
+70 −38
Original line number Diff line number Diff line
@@ -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<Int>()
    private var faceAcquireInfoToTriggerBiometricFailOn = mutableSetOf<Int>()
    private var onUnlockIntentWhenBiometricEnrolled = mutableSetOf<Int>(BIOMETRIC_TYPE_NONE)
    private var onUnlockIntentWhenBiometricEnrolled = mutableSetOf<Int>()
    private var wakeupsConsideredUnlockIntents = mutableSetOf<Int>()

    private val settingsObserver = object : ContentObserver(handler) {
        private val wakeUri = secureSettings.getUriFor(ACTIVE_UNLOCK_ON_WAKE)
@@ -89,6 +95,8 @@ 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(
@@ -98,7 +106,8 @@ class ActiveUnlockConfig @Inject constructor(
                        bioFailUri,
                        faceErrorsUri,
                        faceAcquireInfoUri,
                            unlockIntentWhenBiometricEnrolledUri
                        unlockIntentWhenBiometricEnrolledUri,
                        wakeupsConsideredUnlockIntentsUri,
                    )
            )

@@ -153,7 +162,7 @@ class ActiveUnlockConfig @Inject constructor(
                        secureSettings.getStringForUser(ACTIVE_UNLOCK_ON_FACE_ACQUIRE_INFO,
                                getCurrentUser()),
                        faceAcquireInfoToTriggerBiometricFailOn,
                        setOf<Int>())
                        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,12 +199,14 @@ class ActiveUnlockConfig @Inject constructor(
            out.clear()
            stringSetting?.let {
                for (code: String in stringSetting.split("|")) {
                    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 {
+1 −1
Original line number Diff line number Diff line
@@ -237,7 +237,7 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
            }
            if (mUpdateMonitor.isFaceEnrolled()) {
                mUpdateMonitor.requestActiveUnlock(
                        ActiveUnlockConfig.ACTIVE_UNLOCK_REQUEST_ORIGIN.UNLOCK_INTENT,
                        ActiveUnlockConfig.ActiveUnlockRequestOrigin.UNLOCK_INTENT,
                        "swipeUpOnBouncer");
            }
        }
Loading