Lucas Dupin | c9c2c8f | 2019-06-26 16:32:56 -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 | |
Lucas Dupin | c9c2c8f | 2019-06-26 16:32:56 -0700 | [diff] [blame] | 19 | import android.hardware.Sensor |
| 20 | import android.hardware.TriggerEvent |
| 21 | import android.hardware.TriggerEventListener |
| 22 | import com.android.keyguard.KeyguardUpdateMonitor |
| 23 | import com.android.keyguard.KeyguardUpdateMonitorCallback |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 24 | import com.android.systemui.Dumpable |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 25 | import com.android.systemui.dump.DumpManager |
Lucas Dupin | c9c2c8f | 2019-06-26 16:32:56 -0700 | [diff] [blame] | 26 | import com.android.systemui.plugins.statusbar.StatusBarStateController |
| 27 | import com.android.systemui.util.Assert |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 28 | import com.android.systemui.util.sensors.AsyncSensorManager |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 29 | import java.io.FileDescriptor |
| 30 | import java.io.PrintWriter |
Lucas Dupin | c9c2c8f | 2019-06-26 16:32:56 -0700 | [diff] [blame] | 31 | |
| 32 | class KeyguardLiftController constructor( |
Lucas Dupin | c9c2c8f | 2019-06-26 16:32:56 -0700 | [diff] [blame] | 33 | private val statusBarStateController: StatusBarStateController, |
Dave Mankoff | 80c612b | 2019-10-23 17:47:24 -0400 | [diff] [blame] | 34 | private val asyncSensorManager: AsyncSensorManager, |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 35 | private val keyguardUpdateMonitor: KeyguardUpdateMonitor, |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 36 | dumpManager: DumpManager |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 37 | ) : StatusBarStateController.StateListener, Dumpable, KeyguardUpdateMonitorCallback() { |
Lucas Dupin | c9c2c8f | 2019-06-26 16:32:56 -0700 | [diff] [blame] | 38 | |
Lucas Dupin | c9c2c8f | 2019-06-26 16:32:56 -0700 | [diff] [blame] | 39 | private val pickupSensor = asyncSensorManager.getDefaultSensor(Sensor.TYPE_PICK_UP_GESTURE) |
| 40 | private var isListening = false |
| 41 | private var bouncerVisible = false |
| 42 | |
| 43 | init { |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 44 | dumpManager.registerDumpable(javaClass.name, this) |
Lucas Dupin | c9c2c8f | 2019-06-26 16:32:56 -0700 | [diff] [blame] | 45 | statusBarStateController.addCallback(this) |
| 46 | keyguardUpdateMonitor.registerCallback(this) |
| 47 | updateListeningState() |
| 48 | } |
| 49 | |
| 50 | private val listener: TriggerEventListener = object : TriggerEventListener() { |
| 51 | override fun onTrigger(event: TriggerEvent?) { |
| 52 | Assert.isMainThread() |
| 53 | // Not listening anymore since trigger events unregister themselves |
| 54 | isListening = false |
| 55 | updateListeningState() |
| 56 | keyguardUpdateMonitor.requestFaceAuth() |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | override fun onDozingChanged(isDozing: Boolean) { |
| 61 | updateListeningState() |
| 62 | } |
| 63 | |
| 64 | override fun onKeyguardBouncerChanged(bouncer: Boolean) { |
| 65 | bouncerVisible = bouncer |
| 66 | updateListeningState() |
| 67 | } |
| 68 | |
| 69 | override fun onKeyguardVisibilityChanged(showing: Boolean) { |
| 70 | updateListeningState() |
| 71 | } |
| 72 | |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 73 | override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<out String>) { |
| 74 | pw.println("KeyguardLiftController:") |
| 75 | pw.println(" pickupSensor: $pickupSensor") |
| 76 | pw.println(" isListening: $isListening") |
| 77 | pw.println(" bouncerVisible: $bouncerVisible") |
| 78 | } |
| 79 | |
Lucas Dupin | c9c2c8f | 2019-06-26 16:32:56 -0700 | [diff] [blame] | 80 | private fun updateListeningState() { |
Lucas Dupin | 3b745dd | 2019-09-23 11:54:56 -0700 | [diff] [blame] | 81 | if (pickupSensor == null) { |
| 82 | return |
| 83 | } |
Lucas Dupin | c9c2c8f | 2019-06-26 16:32:56 -0700 | [diff] [blame] | 84 | val onKeyguard = keyguardUpdateMonitor.isKeyguardVisible && |
| 85 | !statusBarStateController.isDozing |
| 86 | |
| 87 | val shouldListen = onKeyguard || bouncerVisible |
| 88 | if (shouldListen != isListening) { |
| 89 | isListening = shouldListen |
| 90 | |
| 91 | if (shouldListen) { |
| 92 | asyncSensorManager.requestTriggerSensor(listener, pickupSensor) |
| 93 | } else { |
| 94 | asyncSensorManager.cancelTriggerSensor(listener, pickupSensor) |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | } |