Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -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 |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.systemui.doze; |
| 18 | |
Lucas Dupin | b2d9f48 | 2018-11-16 18:55:13 -0800 | [diff] [blame] | 19 | import static com.android.systemui.plugins.SensorManagerPlugin.Sensor.TYPE_WAKE_DISPLAY; |
Lucas Dupin | de64ee0 | 2018-12-21 14:45:12 -0800 | [diff] [blame] | 20 | import static com.android.systemui.plugins.SensorManagerPlugin.Sensor.TYPE_WAKE_LOCK_SCREEN; |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 21 | |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 22 | import android.annotation.AnyThread; |
| 23 | import android.app.ActivityManager; |
Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 24 | import android.app.AlarmManager; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 25 | import android.content.ContentResolver; |
| 26 | import android.content.Context; |
| 27 | import android.database.ContentObserver; |
| 28 | import android.hardware.Sensor; |
| 29 | import android.hardware.SensorManager; |
| 30 | import android.hardware.TriggerEvent; |
| 31 | import android.hardware.TriggerEventListener; |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 32 | import android.hardware.display.AmbientDisplayConfiguration; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 33 | import android.net.Uri; |
| 34 | import android.os.Handler; |
Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 35 | import android.os.SystemClock; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 36 | import android.os.UserHandle; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 37 | import android.provider.Settings; |
| 38 | import android.text.TextUtils; |
| 39 | import android.util.Log; |
| 40 | |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 41 | import androidx.annotation.VisibleForTesting; |
| 42 | |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 43 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 44 | import com.android.internal.logging.nano.MetricsProto; |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 45 | import com.android.systemui.plugins.SensorManagerPlugin; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 46 | import com.android.systemui.statusbar.phone.DozeParameters; |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 47 | import com.android.systemui.util.sensors.AsyncSensorManager; |
| 48 | import com.android.systemui.util.sensors.ProximitySensor; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 49 | import com.android.systemui.util.wakelock.WakeLock; |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 50 | |
| 51 | import java.io.PrintWriter; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 52 | import java.util.List; |
Adrian Roos | 67cca74 | 2017-04-13 16:52:51 -0700 | [diff] [blame] | 53 | import java.util.function.Consumer; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 54 | |
| 55 | public class DozeSensors { |
| 56 | |
| 57 | private static final boolean DEBUG = DozeService.DEBUG; |
| 58 | |
| 59 | private static final String TAG = "DozeSensors"; |
| 60 | |
| 61 | private final Context mContext; |
Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 62 | private final AlarmManager mAlarmManager; |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 63 | private final AsyncSensorManager mSensorManager; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 64 | private final ContentResolver mResolver; |
| 65 | private final TriggerSensor mPickupSensor; |
| 66 | private final DozeParameters mDozeParameters; |
| 67 | private final AmbientDisplayConfiguration mConfig; |
Adrian Roos | c1b5032 | 2017-02-27 21:07:58 +0100 | [diff] [blame] | 68 | private final WakeLock mWakeLock; |
Adrian Roos | 67cca74 | 2017-04-13 16:52:51 -0700 | [diff] [blame] | 69 | private final Consumer<Boolean> mProxCallback; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 70 | private final Callback mCallback; |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 71 | @VisibleForTesting |
lpeter | aca9763 | 2019-06-11 11:13:54 +0800 | [diff] [blame] | 72 | protected TriggerSensor[] mSensors; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 73 | |
| 74 | private final Handler mHandler = new Handler(); |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 75 | private final ProximitySensor mProximitySensor; |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 76 | private long mDebounceFrom; |
lpeter | aca9763 | 2019-06-11 11:13:54 +0800 | [diff] [blame] | 77 | private boolean mSettingRegistered; |
Lucas Dupin | fac2e8e | 2019-06-27 16:10:19 -0700 | [diff] [blame] | 78 | private boolean mListening; |
| 79 | private boolean mPaused; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 80 | |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 81 | public DozeSensors(Context context, AlarmManager alarmManager, AsyncSensorManager sensorManager, |
Lucas Dupin | 323f9ff | 2018-08-27 16:55:56 -0700 | [diff] [blame] | 82 | DozeParameters dozeParameters, AmbientDisplayConfiguration config, WakeLock wakeLock, |
Dave Mankoff | 86c7344 | 2019-12-17 12:15:16 -0500 | [diff] [blame] | 83 | Callback callback, Consumer<Boolean> proxCallback, DozeLog dozeLog) { |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 84 | mContext = context; |
Adrian Roos | 6023ccb | 2017-06-28 16:22:02 +0200 | [diff] [blame] | 85 | mAlarmManager = alarmManager; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 86 | mSensorManager = sensorManager; |
| 87 | mDozeParameters = dozeParameters; |
| 88 | mConfig = config; |
| 89 | mWakeLock = wakeLock; |
Adrian Roos | 67cca74 | 2017-04-13 16:52:51 -0700 | [diff] [blame] | 90 | mProxCallback = proxCallback; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 91 | mResolver = mContext.getContentResolver(); |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 92 | mCallback = callback; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 93 | |
Lucas Dupin | 70bda67 | 2018-12-27 15:43:40 -0800 | [diff] [blame] | 94 | boolean alwaysOn = mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT); |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 95 | mSensors = new TriggerSensor[] { |
| 96 | new TriggerSensor( |
| 97 | mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION), |
| 98 | null /* setting */, |
| 99 | dozeParameters.getPulseOnSigMotion(), |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 100 | DozeLog.PULSE_REASON_SENSOR_SIGMOTION, false /* touchCoords */, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 101 | false /* touchscreen */, dozeLog), |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 102 | mPickupSensor = new TriggerSensor( |
| 103 | mSensorManager.getDefaultSensor(Sensor.TYPE_PICK_UP_GESTURE), |
Lucas Dupin | 4359b55 | 2018-08-09 15:07:54 -0700 | [diff] [blame] | 104 | Settings.Secure.DOZE_PICK_UP_GESTURE, |
Lucas Dupin | fac2e8e | 2019-06-27 16:10:19 -0700 | [diff] [blame] | 105 | true /* settingDef */, |
Lucas Dupin | 4359b55 | 2018-08-09 15:07:54 -0700 | [diff] [blame] | 106 | config.dozePickupSensorAvailable(), |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 107 | DozeLog.REASON_SENSOR_PICKUP, false /* touchCoords */, |
Lucas Dupin | fac2e8e | 2019-06-27 16:10:19 -0700 | [diff] [blame] | 108 | false /* touchscreen */, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 109 | false /* ignoresSetting */, |
| 110 | dozeLog), |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 111 | new TriggerSensor( |
| 112 | findSensorWithType(config.doubleTapSensorType()), |
Lucas Dupin | 4359b55 | 2018-08-09 15:07:54 -0700 | [diff] [blame] | 113 | Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 114 | true /* configured */, |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 115 | DozeLog.REASON_SENSOR_DOUBLE_TAP, |
Adrian Roos | 98d3198 | 2017-08-02 20:50:16 +0200 | [diff] [blame] | 116 | dozeParameters.doubleTapReportsTouchCoordinates(), |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 117 | true /* touchscreen */, |
| 118 | dozeLog), |
Adrian Roos | d0963a0 | 2017-05-15 14:33:37 -0700 | [diff] [blame] | 119 | new TriggerSensor( |
Lucas Dupin | d43bf70 | 2019-01-15 13:40:42 -0800 | [diff] [blame] | 120 | findSensorWithType(config.tapSensorType()), |
| 121 | Settings.Secure.DOZE_TAP_SCREEN_GESTURE, |
| 122 | true /* configured */, |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 123 | DozeLog.REASON_SENSOR_TAP, |
Lucas Dupin | d43bf70 | 2019-01-15 13:40:42 -0800 | [diff] [blame] | 124 | false /* reports touch coordinates */, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 125 | true /* touchscreen */, |
| 126 | dozeLog), |
Lucas Dupin | d43bf70 | 2019-01-15 13:40:42 -0800 | [diff] [blame] | 127 | new TriggerSensor( |
Adrian Roos | d0963a0 | 2017-05-15 14:33:37 -0700 | [diff] [blame] | 128 | findSensorWithType(config.longPressSensorType()), |
| 129 | Settings.Secure.DOZE_PULSE_ON_LONG_PRESS, |
| 130 | false /* settingDef */, |
| 131 | true /* configured */, |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 132 | DozeLog.PULSE_REASON_SENSOR_LONG_PRESS, |
Adrian Roos | 98d3198 | 2017-08-02 20:50:16 +0200 | [diff] [blame] | 133 | true /* reports touch coordinates */, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 134 | true /* touchscreen */, |
| 135 | dozeLog), |
Lucas Dupin | 1ae6cf9 | 2018-12-14 18:06:38 -0800 | [diff] [blame] | 136 | new PluginSensor( |
Lucas Dupin | b2d9f48 | 2018-11-16 18:55:13 -0800 | [diff] [blame] | 137 | new SensorManagerPlugin.Sensor(TYPE_WAKE_DISPLAY), |
Lucas Dupin | 7c7b8c2 | 2019-06-12 15:23:17 -0700 | [diff] [blame] | 138 | Settings.Secure.DOZE_WAKE_DISPLAY_GESTURE, |
Lucas Dupin | 70bda67 | 2018-12-27 15:43:40 -0800 | [diff] [blame] | 139 | mConfig.wakeScreenGestureAvailable() && alwaysOn, |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 140 | DozeLog.REASON_SENSOR_WAKE_UP, |
Lucas Dupin | b2d9f48 | 2018-11-16 18:55:13 -0800 | [diff] [blame] | 141 | false /* reports touch coordinates */, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 142 | false /* touchscreen */, |
| 143 | dozeLog), |
Lucas Dupin | de64ee0 | 2018-12-21 14:45:12 -0800 | [diff] [blame] | 144 | new PluginSensor( |
| 145 | new SensorManagerPlugin.Sensor(TYPE_WAKE_LOCK_SCREEN), |
Lucas Dupin | 7c7b8c2 | 2019-06-12 15:23:17 -0700 | [diff] [blame] | 146 | Settings.Secure.DOZE_WAKE_LOCK_SCREEN_GESTURE, |
| 147 | mConfig.wakeScreenGestureAvailable(), |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 148 | DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN, |
Lucas Dupin | de64ee0 | 2018-12-21 14:45:12 -0800 | [diff] [blame] | 149 | false /* reports touch coordinates */, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 150 | false /* touchscreen */, |
| 151 | mConfig.getWakeLockScreenDebounce(), |
| 152 | dozeLog), |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 153 | }; |
Adrian Roos | 67cca74 | 2017-04-13 16:52:51 -0700 | [diff] [blame] | 154 | |
Dave Mankoff | d94c969 | 2019-10-18 12:38:21 -0400 | [diff] [blame] | 155 | mProximitySensor = new ProximitySensor(context.getResources(), sensorManager); |
Dave Mankoff | 86c7344 | 2019-12-17 12:15:16 -0500 | [diff] [blame] | 156 | setProxListening(false); // Don't immediately start listening when we register. |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 157 | mProximitySensor.register( |
Dave Mankoff | a8a8256 | 2019-09-25 09:48:12 -0400 | [diff] [blame] | 158 | proximityEvent -> { |
| 159 | if (proximityEvent != null) { |
| 160 | mProxCallback.accept(!proximityEvent.getNear()); |
| 161 | } |
| 162 | }); |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 165 | /** |
| 166 | * Temporarily disable some sensors to avoid turning on the device while the user is |
| 167 | * turning it off. |
| 168 | */ |
| 169 | public void requestTemporaryDisable() { |
| 170 | mDebounceFrom = SystemClock.uptimeMillis(); |
| 171 | } |
| 172 | |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 173 | private Sensor findSensorWithType(String type) { |
Adrian Roos | 2981eb0 | 2017-05-26 18:40:09 -0700 | [diff] [blame] | 174 | return findSensorWithType(mSensorManager, type); |
| 175 | } |
| 176 | |
| 177 | static Sensor findSensorWithType(SensorManager sensorManager, String type) { |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 178 | if (TextUtils.isEmpty(type)) { |
| 179 | return null; |
| 180 | } |
Adrian Roos | 2981eb0 | 2017-05-26 18:40:09 -0700 | [diff] [blame] | 181 | List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL); |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 182 | for (Sensor s : sensorList) { |
| 183 | if (type.equals(s.getStringType())) { |
| 184 | return s; |
| 185 | } |
| 186 | } |
| 187 | return null; |
| 188 | } |
| 189 | |
Lucas Dupin | fac2e8e | 2019-06-27 16:10:19 -0700 | [diff] [blame] | 190 | /** |
| 191 | * If sensors should be registered and sending signals. |
| 192 | */ |
Adrian Roos | d6ec1313 | 2016-10-27 11:50:47 -0700 | [diff] [blame] | 193 | public void setListening(boolean listen) { |
Lucas Dupin | fac2e8e | 2019-06-27 16:10:19 -0700 | [diff] [blame] | 194 | if (mListening == listen) { |
| 195 | return; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 196 | } |
Lucas Dupin | fac2e8e | 2019-06-27 16:10:19 -0700 | [diff] [blame] | 197 | mListening = listen; |
| 198 | updateListening(); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Unregister sensors, when listening, unless they are prox gated. |
| 203 | * @see #setListening(boolean) |
| 204 | */ |
| 205 | public void setPaused(boolean paused) { |
| 206 | if (mPaused == paused) { |
| 207 | return; |
| 208 | } |
| 209 | mPaused = paused; |
| 210 | updateListening(); |
| 211 | } |
| 212 | |
Lucas Dupin | 3174c66 | 2019-07-15 15:49:54 -0700 | [diff] [blame] | 213 | /** |
| 214 | * Registers/unregisters sensors based on internal state. |
| 215 | */ |
| 216 | public void updateListening() { |
Lucas Dupin | fac2e8e | 2019-06-27 16:10:19 -0700 | [diff] [blame] | 217 | boolean anyListening = false; |
| 218 | for (TriggerSensor s : mSensors) { |
Lucas Dupin | f40bd8f | 2019-08-07 15:55:00 -0700 | [diff] [blame] | 219 | s.setListening(mListening); |
| 220 | if (mListening) { |
Lucas Dupin | fac2e8e | 2019-06-27 16:10:19 -0700 | [diff] [blame] | 221 | anyListening = true; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | if (!anyListening) { |
| 226 | mResolver.unregisterContentObserver(mSettingsObserver); |
| 227 | } else if (!mSettingRegistered) { |
| 228 | for (TriggerSensor s : mSensors) { |
| 229 | s.registerSettingsObserver(mSettingsObserver); |
| 230 | } |
| 231 | } |
| 232 | mSettingRegistered = anyListening; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Adrian Roos | 98d3198 | 2017-08-02 20:50:16 +0200 | [diff] [blame] | 235 | /** Set the listening state of only the sensors that require the touchscreen. */ |
| 236 | public void setTouchscreenSensorsListening(boolean listening) { |
| 237 | for (TriggerSensor sensor : mSensors) { |
| 238 | if (sensor.mRequiresTouchscreen) { |
| 239 | sensor.setListening(listening); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 244 | public void onUserSwitched() { |
| 245 | for (TriggerSensor s : mSensors) { |
Lucas Dupin | 3174c66 | 2019-07-15 15:49:54 -0700 | [diff] [blame] | 246 | s.updateListening(); |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
Adrian Roos | 67cca74 | 2017-04-13 16:52:51 -0700 | [diff] [blame] | 250 | public void setProxListening(boolean listen) { |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 251 | if (mProximitySensor.isRegistered() && listen) { |
| 252 | mProximitySensor.alertListeners(); |
| 253 | } else { |
| 254 | if (listen) { |
| 255 | mProximitySensor.resume(); |
| 256 | } else { |
| 257 | mProximitySensor.pause(); |
| 258 | } |
| 259 | } |
Adrian Roos | 67cca74 | 2017-04-13 16:52:51 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 262 | private final ContentObserver mSettingsObserver = new ContentObserver(mHandler) { |
| 263 | @Override |
| 264 | public void onChange(boolean selfChange, Uri uri, int userId) { |
| 265 | if (userId != ActivityManager.getCurrentUser()) { |
| 266 | return; |
| 267 | } |
| 268 | for (TriggerSensor s : mSensors) { |
Lucas Dupin | 3174c66 | 2019-07-15 15:49:54 -0700 | [diff] [blame] | 269 | s.updateListening(); |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | }; |
| 273 | |
| 274 | public void setDisableSensorsInterferingWithProximity(boolean disable) { |
| 275 | mPickupSensor.setDisabled(disable); |
| 276 | } |
| 277 | |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 278 | /** Ignore the setting value of only the sensors that require the touchscreen. */ |
| 279 | public void ignoreTouchScreenSensorsSettingInterferingWithDocking(boolean ignore) { |
| 280 | for (TriggerSensor sensor : mSensors) { |
| 281 | if (sensor.mRequiresTouchscreen) { |
| 282 | sensor.ignoreSetting(ignore); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 287 | /** Dump current state */ |
| 288 | public void dump(PrintWriter pw) { |
| 289 | for (TriggerSensor s : mSensors) { |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 290 | pw.println(" Sensor: " + s.toString()); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 291 | } |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 292 | pw.println(" ProxSensor: " + mProximitySensor.toString()); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Adrian Roos | 70da03a | 2017-07-24 16:42:57 +0200 | [diff] [blame] | 295 | /** |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 296 | * @return true if prox is currently near, false if far or null if unknown. |
Adrian Roos | 70da03a | 2017-07-24 16:42:57 +0200 | [diff] [blame] | 297 | */ |
Dave Mankoff | 63a1282 | 2019-09-16 14:38:06 -0400 | [diff] [blame] | 298 | public Boolean isProximityCurrentlyNear() { |
| 299 | return mProximitySensor.isNear(); |
Adrian Roos | 67cca74 | 2017-04-13 16:52:51 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 302 | @VisibleForTesting |
| 303 | class TriggerSensor extends TriggerEventListener { |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 304 | final Sensor mSensor; |
| 305 | final boolean mConfigured; |
| 306 | final int mPulseReason; |
Lucas Dupin | fac2e8e | 2019-06-27 16:10:19 -0700 | [diff] [blame] | 307 | private final String mSetting; |
| 308 | private final boolean mReportsTouchCoordinates; |
| 309 | private final boolean mSettingDefault; |
| 310 | private final boolean mRequiresTouchscreen; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 311 | |
Lucas Dupin | 323f9ff | 2018-08-27 16:55:56 -0700 | [diff] [blame] | 312 | protected boolean mRequested; |
| 313 | protected boolean mRegistered; |
| 314 | protected boolean mDisabled; |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 315 | protected boolean mIgnoresSetting; |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 316 | protected final DozeLog mDozeLog; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 317 | |
Adrian Roos | 25c7a58 | 2017-06-02 12:50:38 -0700 | [diff] [blame] | 318 | public TriggerSensor(Sensor sensor, String setting, boolean configured, int pulseReason, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 319 | boolean reportsTouchCoordinates, boolean requiresTouchscreen, DozeLog dozeLog) { |
Adrian Roos | d0963a0 | 2017-05-15 14:33:37 -0700 | [diff] [blame] | 320 | this(sensor, setting, true /* settingDef */, configured, pulseReason, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 321 | reportsTouchCoordinates, requiresTouchscreen, dozeLog); |
Adrian Roos | d0963a0 | 2017-05-15 14:33:37 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | public TriggerSensor(Sensor sensor, String setting, boolean settingDef, |
Adrian Roos | 98d3198 | 2017-08-02 20:50:16 +0200 | [diff] [blame] | 325 | boolean configured, int pulseReason, boolean reportsTouchCoordinates, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 326 | boolean requiresTouchscreen, DozeLog dozeLog) { |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 327 | this(sensor, setting, settingDef, configured, pulseReason, reportsTouchCoordinates, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 328 | requiresTouchscreen, false /* ignoresSetting */, dozeLog); |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | private TriggerSensor(Sensor sensor, String setting, boolean settingDef, |
| 332 | boolean configured, int pulseReason, boolean reportsTouchCoordinates, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 333 | boolean requiresTouchscreen, boolean ignoresSetting, DozeLog dozeLog) { |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 334 | mSensor = sensor; |
| 335 | mSetting = setting; |
Adrian Roos | d0963a0 | 2017-05-15 14:33:37 -0700 | [diff] [blame] | 336 | mSettingDefault = settingDef; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 337 | mConfigured = configured; |
| 338 | mPulseReason = pulseReason; |
Adrian Roos | 25c7a58 | 2017-06-02 12:50:38 -0700 | [diff] [blame] | 339 | mReportsTouchCoordinates = reportsTouchCoordinates; |
Adrian Roos | 98d3198 | 2017-08-02 20:50:16 +0200 | [diff] [blame] | 340 | mRequiresTouchscreen = requiresTouchscreen; |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 341 | mIgnoresSetting = ignoresSetting; |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 342 | mDozeLog = dozeLog; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | public void setListening(boolean listen) { |
| 346 | if (mRequested == listen) return; |
| 347 | mRequested = listen; |
Lucas Dupin | 3174c66 | 2019-07-15 15:49:54 -0700 | [diff] [blame] | 348 | updateListening(); |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | public void setDisabled(boolean disabled) { |
| 352 | if (mDisabled == disabled) return; |
| 353 | mDisabled = disabled; |
Lucas Dupin | 3174c66 | 2019-07-15 15:49:54 -0700 | [diff] [blame] | 354 | updateListening(); |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 355 | } |
| 356 | |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 357 | public void ignoreSetting(boolean ignored) { |
| 358 | if (mIgnoresSetting == ignored) return; |
| 359 | mIgnoresSetting = ignored; |
Lucas Dupin | 3174c66 | 2019-07-15 15:49:54 -0700 | [diff] [blame] | 360 | updateListening(); |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 361 | } |
| 362 | |
Lucas Dupin | 3174c66 | 2019-07-15 15:49:54 -0700 | [diff] [blame] | 363 | public void updateListening() { |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 364 | if (!mConfigured || mSensor == null) return; |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 365 | if (mRequested && !mDisabled && (enabledBySetting() || mIgnoresSetting) |
| 366 | && !mRegistered) { |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 367 | mRegistered = mSensorManager.requestTriggerSensor(this, mSensor); |
| 368 | if (DEBUG) Log.d(TAG, "requestTriggerSensor " + mRegistered); |
| 369 | } else if (mRegistered) { |
| 370 | final boolean rt = mSensorManager.cancelTriggerSensor(this, mSensor); |
| 371 | if (DEBUG) Log.d(TAG, "cancelTriggerSensor " + rt); |
| 372 | mRegistered = false; |
| 373 | } |
| 374 | } |
| 375 | |
Lucas Dupin | 323f9ff | 2018-08-27 16:55:56 -0700 | [diff] [blame] | 376 | protected boolean enabledBySetting() { |
Jerry Chang | 5d3eb447 | 2018-12-21 11:49:06 +0800 | [diff] [blame] | 377 | if (!mConfig.enabled(UserHandle.USER_CURRENT)) { |
| 378 | return false; |
| 379 | } else if (TextUtils.isEmpty(mSetting)) { |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 380 | return true; |
| 381 | } |
Adrian Roos | d0963a0 | 2017-05-15 14:33:37 -0700 | [diff] [blame] | 382 | return Settings.Secure.getIntForUser(mResolver, mSetting, mSettingDefault ? 1 : 0, |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 383 | UserHandle.USER_CURRENT) != 0; |
| 384 | } |
| 385 | |
| 386 | @Override |
| 387 | public String toString() { |
| 388 | return new StringBuilder("{mRegistered=").append(mRegistered) |
| 389 | .append(", mRequested=").append(mRequested) |
| 390 | .append(", mDisabled=").append(mDisabled) |
| 391 | .append(", mConfigured=").append(mConfigured) |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 392 | .append(", mIgnoresSetting=").append(mIgnoresSetting) |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 393 | .append(", mSensor=").append(mSensor).append("}").toString(); |
| 394 | } |
| 395 | |
| 396 | @Override |
| 397 | @AnyThread |
| 398 | public void onTrigger(TriggerEvent event) { |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 399 | mDozeLog.traceSensor(mPulseReason); |
Adrian Roos | 79bacbb | 2016-10-26 11:00:12 -0700 | [diff] [blame] | 400 | mHandler.post(mWakeLock.wrap(() -> { |
Adrian Roos | d6ec1313 | 2016-10-27 11:50:47 -0700 | [diff] [blame] | 401 | if (DEBUG) Log.d(TAG, "onTrigger: " + triggerEventToString(event)); |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 402 | if (mSensor != null && mSensor.getType() == Sensor.TYPE_PICK_UP_GESTURE) { |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 403 | int subType = (int) event.values[0]; |
| 404 | MetricsLogger.action( |
Adrian Roos | 79bacbb | 2016-10-26 11:00:12 -0700 | [diff] [blame] | 405 | mContext, MetricsProto.MetricsEvent.ACTION_AMBIENT_GESTURE, |
| 406 | subType); |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | mRegistered = false; |
Adrian Roos | 25c7a58 | 2017-06-02 12:50:38 -0700 | [diff] [blame] | 410 | float screenX = -1; |
| 411 | float screenY = -1; |
| 412 | if (mReportsTouchCoordinates && event.values.length >= 2) { |
| 413 | screenX = event.values[0]; |
| 414 | screenY = event.values[1]; |
| 415 | } |
Lucas Dupin | f40bd8f | 2019-08-07 15:55:00 -0700 | [diff] [blame] | 416 | mCallback.onSensorPulse(mPulseReason, screenX, screenY, event.values); |
Lucas Dupin | 6510438 | 2018-12-04 11:53:42 -0800 | [diff] [blame] | 417 | if (!mRegistered) { |
Lucas Dupin | 3174c66 | 2019-07-15 15:49:54 -0700 | [diff] [blame] | 418 | updateListening(); // reregister, this sensor only fires once |
Lucas Dupin | 6510438 | 2018-12-04 11:53:42 -0800 | [diff] [blame] | 419 | } |
Adrian Roos | 79bacbb | 2016-10-26 11:00:12 -0700 | [diff] [blame] | 420 | })); |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | public void registerSettingsObserver(ContentObserver settingsObserver) { |
| 424 | if (mConfigured && !TextUtils.isEmpty(mSetting)) { |
| 425 | mResolver.registerContentObserver( |
| 426 | Settings.Secure.getUriFor(mSetting), false /* descendants */, |
| 427 | mSettingsObserver, UserHandle.USER_ALL); |
| 428 | } |
| 429 | } |
| 430 | |
Lucas Dupin | 323f9ff | 2018-08-27 16:55:56 -0700 | [diff] [blame] | 431 | protected String triggerEventToString(TriggerEvent event) { |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 432 | if (event == null) return null; |
Lucas Dupin | 1ae6cf9 | 2018-12-14 18:06:38 -0800 | [diff] [blame] | 433 | final StringBuilder sb = new StringBuilder("SensorEvent[") |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 434 | .append(event.timestamp).append(',') |
| 435 | .append(event.sensor.getName()); |
| 436 | if (event.values != null) { |
| 437 | for (int i = 0; i < event.values.length; i++) { |
| 438 | sb.append(',').append(event.values[i]); |
| 439 | } |
| 440 | } |
| 441 | return sb.append(']').toString(); |
| 442 | } |
| 443 | } |
| 444 | |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 445 | /** |
Kevin Chyn | f7c3903 | 2018-10-11 00:44:39 -0700 | [diff] [blame] | 446 | * A Sensor that is injected via plugin. |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 447 | */ |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 448 | @VisibleForTesting |
| 449 | class PluginSensor extends TriggerSensor implements SensorManagerPlugin.SensorEventListener { |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 450 | |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 451 | final SensorManagerPlugin.Sensor mPluginSensor; |
| 452 | private long mDebounce; |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 453 | |
Lucas Dupin | 1ae6cf9 | 2018-12-14 18:06:38 -0800 | [diff] [blame] | 454 | PluginSensor(SensorManagerPlugin.Sensor sensor, String setting, boolean configured, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 455 | int pulseReason, boolean reportsTouchCoordinates, boolean requiresTouchscreen, |
| 456 | DozeLog dozeLog) { |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 457 | this(sensor, setting, configured, pulseReason, reportsTouchCoordinates, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 458 | requiresTouchscreen, 0L /* debounce */, dozeLog); |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | PluginSensor(SensorManagerPlugin.Sensor sensor, String setting, boolean configured, |
| 462 | int pulseReason, boolean reportsTouchCoordinates, boolean requiresTouchscreen, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 463 | long debounce, DozeLog dozeLog) { |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 464 | super(null, setting, configured, pulseReason, reportsTouchCoordinates, |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 465 | requiresTouchscreen, dozeLog); |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 466 | mPluginSensor = sensor; |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 467 | mDebounce = debounce; |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | @Override |
Lucas Dupin | 3174c66 | 2019-07-15 15:49:54 -0700 | [diff] [blame] | 471 | public void updateListening() { |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 472 | if (!mConfigured) return; |
| 473 | AsyncSensorManager asyncSensorManager = (AsyncSensorManager) mSensorManager; |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 474 | if (mRequested && !mDisabled && (enabledBySetting() || mIgnoresSetting) |
| 475 | && !mRegistered) { |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 476 | asyncSensorManager.registerPluginListener(mPluginSensor, this); |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 477 | mRegistered = true; |
Lucas Dupin | 1ae6cf9 | 2018-12-14 18:06:38 -0800 | [diff] [blame] | 478 | if (DEBUG) Log.d(TAG, "registerPluginListener"); |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 479 | } else if (mRegistered) { |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 480 | asyncSensorManager.unregisterPluginListener(mPluginSensor, this); |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 481 | mRegistered = false; |
Lucas Dupin | 1ae6cf9 | 2018-12-14 18:06:38 -0800 | [diff] [blame] | 482 | if (DEBUG) Log.d(TAG, "unregisterPluginListener"); |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
| 486 | @Override |
| 487 | public String toString() { |
| 488 | return new StringBuilder("{mRegistered=").append(mRegistered) |
| 489 | .append(", mRequested=").append(mRequested) |
| 490 | .append(", mDisabled=").append(mDisabled) |
| 491 | .append(", mConfigured=").append(mConfigured) |
lpeter | 8a5f470 | 2019-01-18 16:53:07 +0800 | [diff] [blame] | 492 | .append(", mIgnoresSetting=").append(mIgnoresSetting) |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 493 | .append(", mSensor=").append(mPluginSensor).append("}").toString(); |
| 494 | } |
| 495 | |
Lucas Dupin | 1ae6cf9 | 2018-12-14 18:06:38 -0800 | [diff] [blame] | 496 | private String triggerEventToString(SensorManagerPlugin.SensorEvent event) { |
Lucas Dupin | b2d9f48 | 2018-11-16 18:55:13 -0800 | [diff] [blame] | 497 | if (event == null) return null; |
| 498 | final StringBuilder sb = new StringBuilder("PluginTriggerEvent[") |
| 499 | .append(event.getSensor()).append(',') |
| 500 | .append(event.getVendorType()); |
| 501 | if (event.getValues() != null) { |
| 502 | for (int i = 0; i < event.getValues().length; i++) { |
| 503 | sb.append(',').append(event.getValues()[i]); |
| 504 | } |
| 505 | } |
| 506 | return sb.append(']').toString(); |
Lucas Dupin | 323f9ff | 2018-08-27 16:55:56 -0700 | [diff] [blame] | 507 | } |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 508 | |
| 509 | @Override |
| 510 | public void onSensorChanged(SensorManagerPlugin.SensorEvent event) { |
Beverly | cc4a62f | 2019-09-26 14:55:28 -0400 | [diff] [blame] | 511 | mDozeLog.traceSensor(mPulseReason); |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 512 | mHandler.post(mWakeLock.wrap(() -> { |
| 513 | final long now = SystemClock.uptimeMillis(); |
| 514 | if (now < mDebounceFrom + mDebounce) { |
Lucas Dupin | bca7ec7 | 2019-05-30 10:24:54 -0700 | [diff] [blame] | 515 | Log.d(TAG, "onSensorEvent dropped: " + triggerEventToString(event)); |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 516 | return; |
| 517 | } |
| 518 | if (DEBUG) Log.d(TAG, "onSensorEvent: " + triggerEventToString(event)); |
Lucas Dupin | f40bd8f | 2019-08-07 15:55:00 -0700 | [diff] [blame] | 519 | mCallback.onSensorPulse(mPulseReason, -1, -1, event.getValues()); |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 520 | })); |
| 521 | } |
Lucas Dupin | 323f9ff | 2018-08-27 16:55:56 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 524 | public interface Callback { |
Adrian Roos | d6ec1313 | 2016-10-27 11:50:47 -0700 | [diff] [blame] | 525 | |
| 526 | /** |
| 527 | * Called when a sensor requests a pulse |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 528 | * @param pulseReason Requesting sensor, e.g. {@link DozeLog#REASON_SENSOR_PICKUP} |
Adrian Roos | 25c7a58 | 2017-06-02 12:50:38 -0700 | [diff] [blame] | 529 | * @param screenX the location on the screen where the sensor fired or -1 |
Lucas Dupin | f40bd8f | 2019-08-07 15:55:00 -0700 | [diff] [blame] | 530 | * if the sensor doesn't support reporting screen locations. |
Adrian Roos | 25c7a58 | 2017-06-02 12:50:38 -0700 | [diff] [blame] | 531 | * @param screenY the location on the screen where the sensor fired or -1 |
Lucas Dupin | b2d9f48 | 2018-11-16 18:55:13 -0800 | [diff] [blame] | 532 | * @param rawValues raw values array from the event. |
Adrian Roos | d6ec1313 | 2016-10-27 11:50:47 -0700 | [diff] [blame] | 533 | */ |
Lucas Dupin | f40bd8f | 2019-08-07 15:55:00 -0700 | [diff] [blame] | 534 | void onSensorPulse(int pulseReason, float screenX, float screenY, float[] rawValues); |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 535 | } |
| 536 | } |