Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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.doze; |
| 18 | |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Adrian Roos | fe54aa0 | 2016-11-07 14:14:25 -0800 | [diff] [blame] | 20 | import android.app.AlarmManager; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 21 | import android.app.IWallpaperManager; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Adrian Roos | 2981eb0 | 2017-05-26 18:40:09 -0700 | [diff] [blame] | 23 | import android.hardware.Sensor; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 24 | import android.hardware.SensorManager; |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 25 | import android.hardware.display.AmbientDisplayConfiguration; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 26 | import android.os.Handler; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 27 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 28 | import com.android.keyguard.KeyguardUpdateMonitor; |
Adrian Roos | 2981eb0 | 2017-05-26 18:40:09 -0700 | [diff] [blame] | 29 | import com.android.systemui.R; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 30 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Dave Mankoff | 10d4b8de | 2020-05-26 15:05:07 -0400 | [diff] [blame] | 31 | import com.android.systemui.dagger.qualifiers.Main; |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 32 | import com.android.systemui.dock.DockManager; |
Lucas Dupin | 737b851 | 2019-08-09 10:35:34 -0700 | [diff] [blame] | 33 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 34 | import com.android.systemui.plugins.FalsingManager; |
Lucas Dupin | c1d2041 | 2019-07-17 09:49:52 -0700 | [diff] [blame] | 35 | import com.android.systemui.statusbar.phone.BiometricUnlockController; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 36 | import com.android.systemui.statusbar.phone.DozeParameters; |
Lucas Dupin | bd7366d | 2019-09-25 13:39:21 -0700 | [diff] [blame] | 37 | import com.android.systemui.statusbar.policy.BatteryController; |
Dave Mankoff | dddcae9 | 2020-05-13 12:46:18 -0400 | [diff] [blame] | 38 | import com.android.systemui.util.concurrency.DelayableExecutor; |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 39 | import com.android.systemui.util.sensors.AsyncSensorManager; |
Dave Mankoff | bf52f4b | 2019-09-20 14:34:28 -0400 | [diff] [blame] | 40 | import com.android.systemui.util.sensors.ProximitySensor; |
Adrian Roos | 0fb55ae | 2017-04-14 14:49:11 -0700 | [diff] [blame] | 41 | import com.android.systemui.util.wakelock.DelayedWakeLock; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 42 | import com.android.systemui.util.wakelock.WakeLock; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 43 | |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 44 | import javax.inject.Inject; |
| 45 | |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 46 | public class DozeFactory { |
| 47 | |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 48 | private final FalsingManager mFalsingManager; |
| 49 | private final DozeLog mDozeLog; |
| 50 | private final DozeParameters mDozeParameters; |
| 51 | private final BatteryController mBatteryController; |
| 52 | private final AsyncSensorManager mAsyncSensorManager; |
| 53 | private final AlarmManager mAlarmManager; |
| 54 | private final WakefulnessLifecycle mWakefulnessLifecycle; |
| 55 | private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
| 56 | private final DockManager mDockManager; |
| 57 | private final IWallpaperManager mWallpaperManager; |
Dave Mankoff | d94c969 | 2019-10-18 12:38:21 -0400 | [diff] [blame] | 58 | private final ProximitySensor mProximitySensor; |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 59 | private final DelayedWakeLock.Builder mDelayedWakeLockBuilder; |
| 60 | private final Handler mHandler; |
Dave Mankoff | dddcae9 | 2020-05-13 12:46:18 -0400 | [diff] [blame] | 61 | private final DelayableExecutor mDelayableExecutor; |
Dave Mankoff | bbc2f8f | 2019-10-21 12:21:29 -0400 | [diff] [blame] | 62 | private final BiometricUnlockController mBiometricUnlockController; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 63 | private final BroadcastDispatcher mBroadcastDispatcher; |
Heemin Seog | 4764fba | 2020-05-12 13:33:18 -0700 | [diff] [blame] | 64 | private final DozeHost mDozeHost; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 65 | |
| 66 | @Inject |
| 67 | public DozeFactory(FalsingManager falsingManager, DozeLog dozeLog, |
| 68 | DozeParameters dozeParameters, BatteryController batteryController, |
| 69 | AsyncSensorManager asyncSensorManager, AlarmManager alarmManager, |
| 70 | WakefulnessLifecycle wakefulnessLifecycle, KeyguardUpdateMonitor keyguardUpdateMonitor, |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 71 | DockManager dockManager, @Nullable IWallpaperManager wallpaperManager, |
| 72 | ProximitySensor proximitySensor, |
Dave Mankoff | 10d4b8de | 2020-05-26 15:05:07 -0400 | [diff] [blame] | 73 | DelayedWakeLock.Builder delayedWakeLockBuilder, @Main Handler handler, |
Dave Mankoff | e957af6d | 2020-06-03 10:28:20 -0400 | [diff] [blame] | 74 | @Main DelayableExecutor delayableExecutor, |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 75 | BiometricUnlockController biometricUnlockController, |
Heemin Seog | 4764fba | 2020-05-12 13:33:18 -0700 | [diff] [blame] | 76 | BroadcastDispatcher broadcastDispatcher, DozeHost dozeHost) { |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 77 | mFalsingManager = falsingManager; |
| 78 | mDozeLog = dozeLog; |
| 79 | mDozeParameters = dozeParameters; |
| 80 | mBatteryController = batteryController; |
| 81 | mAsyncSensorManager = asyncSensorManager; |
| 82 | mAlarmManager = alarmManager; |
| 83 | mWakefulnessLifecycle = wakefulnessLifecycle; |
| 84 | mKeyguardUpdateMonitor = keyguardUpdateMonitor; |
| 85 | mDockManager = dockManager; |
| 86 | mWallpaperManager = wallpaperManager; |
Dave Mankoff | d94c969 | 2019-10-18 12:38:21 -0400 | [diff] [blame] | 87 | mProximitySensor = proximitySensor; |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 88 | mDelayedWakeLockBuilder = delayedWakeLockBuilder; |
| 89 | mHandler = handler; |
Dave Mankoff | dddcae9 | 2020-05-13 12:46:18 -0400 | [diff] [blame] | 90 | mDelayableExecutor = delayableExecutor; |
Dave Mankoff | bbc2f8f | 2019-10-21 12:21:29 -0400 | [diff] [blame] | 91 | mBiometricUnlockController = biometricUnlockController; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 92 | mBroadcastDispatcher = broadcastDispatcher; |
Heemin Seog | 4764fba | 2020-05-12 13:33:18 -0700 | [diff] [blame] | 93 | mDozeHost = dozeHost; |
Adrian Roos | f9d13f6 | 2016-11-08 15:42:20 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 96 | /** Creates a DozeMachine with its parts for {@code dozeService}. */ |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 97 | DozeMachine assembleMachine(DozeService dozeService) { |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 98 | AmbientDisplayConfiguration config = new AmbientDisplayConfiguration(dozeService); |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 99 | WakeLock wakeLock = mDelayedWakeLockBuilder.setHandler(mHandler).setTag("Doze").build(); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 100 | |
Adrian Roos | 3e23eb5 | 2017-07-07 15:58:57 +0200 | [diff] [blame] | 101 | DozeMachine.Service wrappedService = dozeService; |
Heemin Seog | 4764fba | 2020-05-12 13:33:18 -0700 | [diff] [blame] | 102 | wrappedService = new DozeBrightnessHostForwarder(wrappedService, mDozeHost); |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 103 | wrappedService = DozeScreenStatePreventingAdapter.wrapIfNeeded( |
| 104 | wrappedService, mDozeParameters); |
| 105 | wrappedService = DozeSuspendScreenStatePreventingAdapter.wrapIfNeeded( |
| 106 | wrappedService, mDozeParameters); |
Adrian Roos | 3e23eb5 | 2017-07-07 15:58:57 +0200 | [diff] [blame] | 107 | |
Lucas Dupin | 737b851 | 2019-08-09 10:35:34 -0700 | [diff] [blame] | 108 | DozeMachine machine = new DozeMachine(wrappedService, config, wakeLock, |
Yogisha Dixit | 65f26b7 | 2020-02-07 17:30:49 +0000 | [diff] [blame] | 109 | mWakefulnessLifecycle, mBatteryController, mDozeLog, mDockManager, |
Heemin Seog | 4764fba | 2020-05-12 13:33:18 -0700 | [diff] [blame] | 110 | mDozeHost); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 111 | machine.setParts(new DozeMachine.Part[]{ |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 112 | new DozePauser(mHandler, machine, mAlarmManager, mDozeParameters.getPolicy()), |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 113 | new DozeFalsingManagerAdapter(mFalsingManager), |
Heemin Seog | 4764fba | 2020-05-12 13:33:18 -0700 | [diff] [blame] | 114 | createDozeTriggers(dozeService, mAsyncSensorManager, mDozeHost, |
Dave Mankoff | dddcae9 | 2020-05-13 12:46:18 -0400 | [diff] [blame] | 115 | mAlarmManager, config, mDozeParameters, mDelayableExecutor, wakeLock, |
| 116 | machine, mDockManager, mDozeLog), |
Heemin Seog | 4764fba | 2020-05-12 13:33:18 -0700 | [diff] [blame] | 117 | createDozeUi(dozeService, mDozeHost, wakeLock, machine, mHandler, |
Dave Mankoff | 6be8b38 | 2019-11-05 21:30:07 -0500 | [diff] [blame] | 118 | mAlarmManager, mDozeParameters, mDozeLog), |
Heemin Seog | 4764fba | 2020-05-12 13:33:18 -0700 | [diff] [blame] | 119 | new DozeScreenState(wrappedService, mHandler, mDozeHost, mDozeParameters, |
Dave Mankoff | 6be8b38 | 2019-11-05 21:30:07 -0500 | [diff] [blame] | 120 | wakeLock), |
| 121 | createDozeScreenBrightness(dozeService, wrappedService, mAsyncSensorManager, |
Heemin Seog | 4764fba | 2020-05-12 13:33:18 -0700 | [diff] [blame] | 122 | mDozeHost, mDozeParameters, mHandler), |
Dave Mankoff | 6be8b38 | 2019-11-05 21:30:07 -0500 | [diff] [blame] | 123 | new DozeWallpaperState(mWallpaperManager, mBiometricUnlockController, |
| 124 | mDozeParameters), |
Jerry Chang | ae4dc4b | 2019-10-16 18:45:03 +0800 | [diff] [blame] | 125 | new DozeDockHandler(config, machine, mDockManager), |
Aran Ink | 4c0d560 | 2019-06-21 14:27:32 -0400 | [diff] [blame] | 126 | new DozeAuthRemover(dozeService) |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 127 | }); |
| 128 | |
| 129 | return machine; |
| 130 | } |
| 131 | |
Adrian Roos | c7fd696 | 2017-09-06 16:46:46 +0200 | [diff] [blame] | 132 | private DozeMachine.Part createDozeScreenBrightness(Context context, |
Adrian Roos | c8e29e7 | 2017-08-03 18:25:42 +0200 | [diff] [blame] | 133 | DozeMachine.Service service, SensorManager sensorManager, DozeHost host, |
Adrian Roos | 2f5a385 | 2018-04-23 17:48:08 +0200 | [diff] [blame] | 134 | DozeParameters params, Handler handler) { |
Adrian Roos | 2981eb0 | 2017-05-26 18:40:09 -0700 | [diff] [blame] | 135 | Sensor sensor = DozeSensors.findSensorWithType(sensorManager, |
| 136 | context.getString(R.string.doze_brightness_sensor_type)); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 137 | return new DozeScreenBrightness(context, service, sensorManager, sensor, |
| 138 | mBroadcastDispatcher, host, handler, params.getPolicy()); |
Adrian Roos | 2981eb0 | 2017-05-26 18:40:09 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 141 | private DozeTriggers createDozeTriggers(Context context, AsyncSensorManager sensorManager, |
Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 142 | DozeHost host, AlarmManager alarmManager, AmbientDisplayConfiguration config, |
Dave Mankoff | dddcae9 | 2020-05-13 12:46:18 -0400 | [diff] [blame] | 143 | DozeParameters params, DelayableExecutor delayableExecutor, WakeLock wakeLock, |
| 144 | DozeMachine machine, DockManager dockManager, DozeLog dozeLog) { |
Adrian Roos | 664c9d7 | 2017-04-28 15:52:24 -0700 | [diff] [blame] | 145 | boolean allowPulseTriggers = true; |
Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 146 | return new DozeTriggers(context, machine, host, alarmManager, config, params, |
Dave Mankoff | dddcae9 | 2020-05-13 12:46:18 -0400 | [diff] [blame] | 147 | sensorManager, delayableExecutor, wakeLock, allowPulseTriggers, dockManager, |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 148 | mProximitySensor, dozeLog, mBroadcastDispatcher); |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 149 | |
Adrian Roos | f9d13f6 | 2016-11-08 15:42:20 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | private DozeMachine.Part createDozeUi(Context context, DozeHost host, WakeLock wakeLock, |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 153 | DozeMachine machine, Handler handler, AlarmManager alarmManager, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 154 | DozeParameters params, DozeLog dozeLog) { |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 155 | return new DozeUi(context, alarmManager, machine, wakeLock, host, handler, params, |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 156 | mKeyguardUpdateMonitor, dozeLog); |
Adrian Roos | f9d13f6 | 2016-11-08 15:42:20 -0800 | [diff] [blame] | 157 | } |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 158 | } |