Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone |
| 18 | |
| 19 | import android.content.Context |
Mady Mellor | dce1bf3 | 2019-06-25 14:31:19 -0700 | [diff] [blame] | 20 | import android.content.pm.PackageManager |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 21 | import android.hardware.biometrics.BiometricSourceType |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 22 | import android.provider.Settings |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 23 | import com.android.systemui.DumpController |
| 24 | import com.android.systemui.Dumpable |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 25 | import com.android.systemui.plugins.statusbar.StatusBarStateController |
Selim Cinek | a6a3ebc | 2019-06-19 18:33:17 -0700 | [diff] [blame] | 26 | import com.android.systemui.statusbar.NotificationLockscreenUserManager |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 27 | import com.android.systemui.statusbar.StatusBarState |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 28 | import com.android.systemui.statusbar.policy.KeyguardStateController |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 29 | import com.android.systemui.tuner.TunerService |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 30 | import java.io.FileDescriptor |
Lucas Dupin | 5a5e0bd | 2019-07-11 14:19:11 +0900 | [diff] [blame] | 31 | import java.io.PrintWriter |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 32 | import javax.inject.Inject |
| 33 | import javax.inject.Singleton |
| 34 | |
| 35 | @Singleton |
Lucas Dupin | 960b7e7f | 2020-01-24 15:47:28 -0800 | [diff] [blame] | 36 | open class KeyguardBypassController : Dumpable { |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 37 | |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 38 | private val mKeyguardStateController: KeyguardStateController |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 39 | private val statusBarStateController: StatusBarStateController |
Lucas Dupin | 0f6d5d8 | 2019-07-30 15:47:04 -0700 | [diff] [blame] | 40 | private var hasFaceFeature: Boolean |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 41 | |
Selim Cinek | b8cc6ef | 2019-06-14 16:37:53 -0700 | [diff] [blame] | 42 | /** |
| 43 | * The pending unlock type which is set if the bypass was blocked when it happened. |
| 44 | */ |
| 45 | private var pendingUnlockType: BiometricSourceType? = null |
Lucas Dupin | 206fe56 | 2019-05-31 14:36:42 -0700 | [diff] [blame] | 46 | |
Selim Cinek | f89a5dc | 2019-06-18 15:10:25 -0700 | [diff] [blame] | 47 | lateinit var unlockController: BiometricUnlockController |
| 48 | var isPulseExpanding = false |
| 49 | |
| 50 | /** |
| 51 | * If face unlock dismisses the lock screen or keeps user on keyguard for the current user. |
| 52 | */ |
| 53 | var bypassEnabled: Boolean = false |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 54 | get() = field && mKeyguardStateController.isFaceAuthEnabled |
Selim Cinek | f89a5dc | 2019-06-18 15:10:25 -0700 | [diff] [blame] | 55 | private set |
| 56 | |
| 57 | var bouncerShowing: Boolean = false |
Selim Cinek | ec17775 | 2019-06-19 18:13:51 -0700 | [diff] [blame] | 58 | var launchingAffordance: Boolean = false |
Selim Cinek | ae2702d | 2019-06-19 18:04:05 -0700 | [diff] [blame] | 59 | var qSExpanded = false |
| 60 | set(value) { |
| 61 | val changed = field != value |
| 62 | field = value |
| 63 | if (changed && !value) { |
| 64 | maybePerformPendingUnlock() |
| 65 | } |
| 66 | } |
Selim Cinek | f89a5dc | 2019-06-18 15:10:25 -0700 | [diff] [blame] | 67 | |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 68 | @Inject |
Lucas Dupin | 5a5e0bd | 2019-07-11 14:19:11 +0900 | [diff] [blame] | 69 | constructor( |
| 70 | context: Context, |
| 71 | tunerService: TunerService, |
| 72 | statusBarStateController: StatusBarStateController, |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 73 | lockscreenUserManager: NotificationLockscreenUserManager, |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 74 | keyguardStateController: KeyguardStateController, |
| 75 | dumpController: DumpController |
Lucas Dupin | 5a5e0bd | 2019-07-11 14:19:11 +0900 | [diff] [blame] | 76 | ) { |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 77 | this.mKeyguardStateController = keyguardStateController |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 78 | this.statusBarStateController = statusBarStateController |
Lucas Dupin | 5a5e0bd | 2019-07-11 14:19:11 +0900 | [diff] [blame] | 79 | |
Lucas Dupin | 0f6d5d8 | 2019-07-30 15:47:04 -0700 | [diff] [blame] | 80 | hasFaceFeature = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE) |
| 81 | if (!hasFaceFeature) { |
Lucas Dupin | 1b883b4 | 2019-05-28 17:43:59 -0700 | [diff] [blame] | 82 | return |
| 83 | } |
| 84 | |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 85 | dumpController.registerDumpable("KeyguardBypassController", this) |
Lucas Dupin | 5a5e0bd | 2019-07-11 14:19:11 +0900 | [diff] [blame] | 86 | statusBarStateController.addCallback(object : StatusBarStateController.StateListener { |
| 87 | override fun onStateChanged(newState: Int) { |
| 88 | if (newState != StatusBarState.KEYGUARD) { |
| 89 | pendingUnlockType = null |
| 90 | } |
| 91 | } |
| 92 | }) |
| 93 | |
Lucas Dupin | 1b883b4 | 2019-05-28 17:43:59 -0700 | [diff] [blame] | 94 | val dismissByDefault = if (context.resources.getBoolean( |
Lucas Dupin | 5a5e0bd | 2019-07-11 14:19:11 +0900 | [diff] [blame] | 95 | com.android.internal.R.bool.config_faceAuthDismissesKeyguard)) 1 else 0 |
| 96 | tunerService.addTunable(object : TunerService.Tunable { |
| 97 | override fun onTuningChanged(key: String?, newValue: String?) { |
| 98 | bypassEnabled = tunerService.getValue(key, dismissByDefault) != 0 |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 99 | } |
| 100 | }, Settings.Secure.FACE_UNLOCK_DISMISSES_KEYGUARD) |
Steve Elliott | b47f1c7 | 2019-12-19 12:39:26 -0500 | [diff] [blame] | 101 | lockscreenUserManager.addUserChangedListener( |
| 102 | object : NotificationLockscreenUserManager.UserChangedListener { |
| 103 | override fun onUserChanged(userId: Int) { |
| 104 | pendingUnlockType = null |
| 105 | } |
| 106 | }) |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 107 | } |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Notify that the biometric unlock has happened. |
| 111 | * |
| 112 | * @return false if we can not wake and unlock right now |
| 113 | */ |
| 114 | fun onBiometricAuthenticated(biometricSourceType: BiometricSourceType): Boolean { |
Selim Cinek | b8cc6ef | 2019-06-14 16:37:53 -0700 | [diff] [blame] | 115 | if (bypassEnabled) { |
Lucas Dupin | 4befb74 | 2019-07-01 11:31:31 -0700 | [diff] [blame] | 116 | val can = canBypass() |
| 117 | if (!can && (isPulseExpanding || qSExpanded)) { |
Selim Cinek | b8cc6ef | 2019-06-14 16:37:53 -0700 | [diff] [blame] | 118 | pendingUnlockType = biometricSourceType |
Selim Cinek | b8cc6ef | 2019-06-14 16:37:53 -0700 | [diff] [blame] | 119 | } |
Lucas Dupin | 4befb74 | 2019-07-01 11:31:31 -0700 | [diff] [blame] | 120 | return can |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 121 | } |
| 122 | return true |
| 123 | } |
Selim Cinek | b8cc6ef | 2019-06-14 16:37:53 -0700 | [diff] [blame] | 124 | |
| 125 | fun maybePerformPendingUnlock() { |
| 126 | if (pendingUnlockType != null) { |
| 127 | if (onBiometricAuthenticated(pendingUnlockType!!)) { |
| 128 | unlockController.startWakeAndUnlock(pendingUnlockType) |
| 129 | pendingUnlockType = null |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
Lucas Dupin | 4befb74 | 2019-07-01 11:31:31 -0700 | [diff] [blame] | 134 | /** |
| 135 | * If keyguard can be dismissed because of bypass. |
| 136 | */ |
| 137 | fun canBypass(): Boolean { |
| 138 | if (bypassEnabled) { |
| 139 | return when { |
| 140 | bouncerShowing -> true |
| 141 | statusBarStateController.state != StatusBarState.KEYGUARD -> false |
| 142 | launchingAffordance -> false |
| 143 | isPulseExpanding || qSExpanded -> false |
| 144 | else -> true |
| 145 | } |
| 146 | } |
| 147 | return false |
| 148 | } |
| 149 | |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 150 | /** |
| 151 | * If shorter animations should be played when unlocking. |
| 152 | */ |
| 153 | fun canPlaySubtleWindowAnimations(): Boolean { |
| 154 | if (bypassEnabled) { |
| 155 | return when { |
| 156 | statusBarStateController.state != StatusBarState.KEYGUARD -> false |
| 157 | qSExpanded -> false |
| 158 | else -> true |
| 159 | } |
| 160 | } |
| 161 | return false |
| 162 | } |
| 163 | |
Selim Cinek | b8cc6ef | 2019-06-14 16:37:53 -0700 | [diff] [blame] | 164 | fun onStartedGoingToSleep() { |
| 165 | pendingUnlockType = null |
| 166 | } |
Lucas Dupin | 5a5e0bd | 2019-07-11 14:19:11 +0900 | [diff] [blame] | 167 | |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 168 | override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<out String>) { |
Lucas Dupin | 5a5e0bd | 2019-07-11 14:19:11 +0900 | [diff] [blame] | 169 | pw.println("KeyguardBypassController:") |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 170 | pw.println(" pendingUnlockType: $pendingUnlockType") |
| 171 | pw.println(" bypassEnabled: $bypassEnabled") |
| 172 | pw.println(" canBypass: ${canBypass()}") |
| 173 | pw.println(" bouncerShowing: $bouncerShowing") |
| 174 | pw.println(" isPulseExpanding: $isPulseExpanding") |
| 175 | pw.println(" launchingAffordance: $launchingAffordance") |
| 176 | pw.println(" qSExpanded: $qSExpanded") |
| 177 | pw.println(" hasFaceFeature: $hasFaceFeature") |
Lucas Dupin | 5a5e0bd | 2019-07-11 14:19:11 +0900 | [diff] [blame] | 178 | } |
Selim Cinek | 84b2acc | 2019-07-07 00:40:38 -0700 | [diff] [blame] | 179 | |
| 180 | companion object { |
| 181 | const val BYPASS_PANEL_FADE_DURATION = 67 |
| 182 | } |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 183 | } |