blob: 37c7a2e3027fc3fdcfe81d6d17332e0e432105c6 [file] [log] [blame]
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001/*
Dave Mankoffdde5ee62019-05-02 17:36:11 -04002 * Copyright (C) 2019 The Android Open Source Project
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07003 *
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
Dave Mankoffdde5ee62019-05-02 17:36:11 -040014 * limitations under the License.
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070015 */
16
17package com.android.systemui.classifier;
18
Lucas Dupin13b8cec2020-02-28 16:31:57 -080019import android.app.ActivityManager;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070020import android.content.Context;
21import android.database.ContentObserver;
22import android.hardware.Sensor;
23import android.hardware.SensorEvent;
24import android.hardware.SensorEventListener;
25import android.hardware.SensorManager;
Lucas Dupin7e35d142019-05-08 15:13:36 -070026import android.hardware.biometrics.BiometricSourceType;
Adrian Roos7bb38a92016-07-21 11:44:01 -070027import android.net.Uri;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070028import android.os.Handler;
Selim Cinekf8c4add2017-06-08 09:54:58 -070029import android.os.Looper;
Adrian Roosc5584ce2016-02-24 14:17:19 -080030import android.os.PowerManager;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070031import android.os.UserHandle;
32import android.provider.Settings;
Adrian Roos004437e2017-08-16 11:58:02 +020033import android.view.InputDevice;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070034import android.view.MotionEvent;
Adrian Roosca664b92016-04-18 14:40:27 -070035import android.view.accessibility.AccessibilityManager;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070036
Dave Mankoff63c576e2019-05-01 18:00:01 -040037import com.android.internal.logging.MetricsLogger;
Lucas Dupin7e35d142019-05-08 15:13:36 -070038import com.android.keyguard.KeyguardUpdateMonitor;
39import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020040import com.android.systemui.Dependency;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070041import com.android.systemui.analytics.DataCollector;
Dave Mankoffc7cf9fc2019-12-19 15:43:20 -050042import com.android.systemui.dagger.qualifiers.UiBackground;
Dave Mankoff468d4f62019-05-08 14:56:29 -040043import com.android.systemui.plugins.FalsingManager;
Beverly8fdb5332019-02-04 14:29:49 -050044import com.android.systemui.plugins.statusbar.StatusBarStateController;
45import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070046import com.android.systemui.statusbar.StatusBarState;
Dave Mankoff63a12822019-09-16 14:38:06 -040047import com.android.systemui.util.sensors.AsyncSensorManager;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070048
Adrian Roos401caae2016-03-04 13:35:21 -080049import java.io.PrintWriter;
Dave Mankoffc7cf9fc2019-12-19 15:43:20 -050050import java.util.concurrent.Executor;
Adrian Roos401caae2016-03-04 13:35:21 -080051
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070052/**
53 * When the phone is locked, listens to touch, sensor and phone events and sends them to
54 * DataCollector and HumanInteractionClassifier.
55 *
56 * It does not collect touch events when the bouncer shows up.
57 */
Dave Mankoff468d4f62019-05-08 14:56:29 -040058public class FalsingManagerImpl implements FalsingManager {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070059 private static final String ENFORCE_BOUNCER = "falsing_manager_enforce_bouncer";
60
Blazej Magnowski6dc59b42015-09-22 15:14:20 -070061 private static final int[] CLASSIFIER_SENSORS = new int[] {
62 Sensor.TYPE_PROXIMITY,
63 };
64
65 private static final int[] COLLECTOR_SENSORS = new int[] {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070066 Sensor.TYPE_ACCELEROMETER,
67 Sensor.TYPE_GYROSCOPE,
68 Sensor.TYPE_PROXIMITY,
69 Sensor.TYPE_LIGHT,
70 Sensor.TYPE_ROTATION_VECTOR,
71 };
Dave Mankoff1dee0342019-07-11 17:44:54 -040072 public static final String FALSING_REMAIN_LOCKED = "falsing_failure_after_attempts";
73 public static final String FALSING_SUCCESS = "falsing_success_after_attempts";
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070074
Selim Cinekf8c4add2017-06-08 09:54:58 -070075 private final Handler mHandler = new Handler(Looper.getMainLooper());
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070076 private final Context mContext;
77
78 private final SensorManager mSensorManager;
79 private final DataCollector mDataCollector;
80 private final HumanInteractionClassifier mHumanInteractionClassifier;
Adrian Roosca664b92016-04-18 14:40:27 -070081 private final AccessibilityManager mAccessibilityManager;
Dave Mankoffc7cf9fc2019-12-19 15:43:20 -050082 private final Executor mUiBgExecutor;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070083
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070084 private boolean mEnforceBouncer = false;
85 private boolean mBouncerOn = false;
Siarhei Vishniakou81e1ffd2018-05-04 16:08:22 -070086 private boolean mBouncerOffOnDown = false;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070087 private boolean mSessionActive = false;
Adrian Roos004437e2017-08-16 11:58:02 +020088 private boolean mIsTouchScreen = true;
Lucas Dupin7e35d142019-05-08 15:13:36 -070089 private boolean mJustUnlockedWithFace = false;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070090 private int mState = StatusBarState.SHADE;
Adrian Roosc5584ce2016-02-24 14:17:19 -080091 private boolean mScreenOn;
Adrian Roose395b5d2017-06-28 16:52:37 +020092 private boolean mShowingAod;
Adrian Roos8e291a52016-12-09 16:10:19 -080093 private Runnable mPendingWtf;
Dave Mankoff63c576e2019-05-01 18:00:01 -040094 private int mIsFalseTouchCalls;
95 private MetricsLogger mMetricsLogger;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070096
Dave Mankoffdde5ee62019-05-02 17:36:11 -040097 private SensorEventListener mSensorEventListener = new SensorEventListener() {
98 @Override
99 public synchronized void onSensorChanged(SensorEvent event) {
100 mDataCollector.onSensorChanged(event);
101 mHumanInteractionClassifier.onSensorChanged(event);
102 }
103
104 @Override
105 public void onAccuracyChanged(Sensor sensor, int accuracy) {
106 mDataCollector.onAccuracyChanged(sensor, accuracy);
107 }
108 };
109
110 public StateListener mStatusBarStateListener = new StateListener() {
111 @Override
112 public void onStateChanged(int newState) {
113 if (FalsingLog.ENABLED) {
114 FalsingLog.i("setStatusBarState", new StringBuilder()
115 .append("from=").append(StatusBarState.toShortString(mState))
116 .append(" to=").append(StatusBarState.toShortString(newState))
117 .toString());
118 }
119 mState = newState;
120 updateSessionActive();
121 }
122 };
123
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700124 protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) {
125 @Override
126 public void onChange(boolean selfChange) {
127 updateConfiguration();
128 }
129 };
Lucas Dupin7e35d142019-05-08 15:13:36 -0700130 private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback =
131 new KeyguardUpdateMonitorCallback() {
132 @Override
133 public void onBiometricAuthenticated(int userId,
Haining Chenc06c4812020-01-13 20:38:53 -0800134 BiometricSourceType biometricSourceType,
135 boolean isStrongBiometric) {
Lucas Dupin7e35d142019-05-08 15:13:36 -0700136 if (userId == KeyguardUpdateMonitor.getCurrentUser()
137 && biometricSourceType == BiometricSourceType.FACE) {
138 mJustUnlockedWithFace = true;
139 }
140 }
141 };
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700142
Dave Mankoffc7cf9fc2019-12-19 15:43:20 -0500143 FalsingManagerImpl(Context context, @UiBackground Executor uiBgExecutor) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700144 mContext = context;
Adrian Roos7a8ae8a2017-08-02 16:26:50 +0200145 mSensorManager = Dependency.get(AsyncSensorManager.class);
Adrian Roosca664b92016-04-18 14:40:27 -0700146 mAccessibilityManager = context.getSystemService(AccessibilityManager.class);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700147 mDataCollector = DataCollector.getInstance(mContext);
148 mHumanInteractionClassifier = HumanInteractionClassifier.getInstance(mContext);
Dave Mankoffc7cf9fc2019-12-19 15:43:20 -0500149 mUiBgExecutor = uiBgExecutor;
Adrian Roosc5584ce2016-02-24 14:17:19 -0800150 mScreenOn = context.getSystemService(PowerManager.class).isInteractive();
Dave Mankoff63c576e2019-05-01 18:00:01 -0400151 mMetricsLogger = new MetricsLogger();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700152
153 mContext.getContentResolver().registerContentObserver(
154 Settings.Secure.getUriFor(ENFORCE_BOUNCER), false,
155 mSettingsObserver,
156 UserHandle.USER_ALL);
157
158 updateConfiguration();
Dave Mankoffdde5ee62019-05-02 17:36:11 -0400159 Dependency.get(StatusBarStateController.class).addCallback(mStatusBarStateListener);
Dave Mankoffe2294692019-08-14 11:53:13 -0400160 Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mKeyguardUpdateCallback);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700161 }
162
163 private void updateConfiguration() {
164 mEnforceBouncer = 0 != Settings.Secure.getInt(mContext.getContentResolver(),
165 ENFORCE_BOUNCER, 0);
166 }
167
Adrian Roosc5584ce2016-02-24 14:17:19 -0800168 private boolean shouldSessionBeActive() {
Dave Mankoffdde5ee62019-05-02 17:36:11 -0400169 if (FalsingLog.ENABLED && FalsingLog.VERBOSE) {
Adrian Roos401caae2016-03-04 13:35:21 -0800170 FalsingLog.v("shouldBeActive", new StringBuilder()
171 .append("enabled=").append(isEnabled() ? 1 : 0)
172 .append(" mScreenOn=").append(mScreenOn ? 1 : 0)
173 .append(" mState=").append(StatusBarState.toShortString(mState))
Dave Mankoffb32ba472019-07-16 15:07:01 -0400174 .append(" mShowingAod=").append(mShowingAod ? 1 : 0)
Adrian Roos401caae2016-03-04 13:35:21 -0800175 .toString()
176 );
Dave Mankoffdde5ee62019-05-02 17:36:11 -0400177 }
Adrian Roose395b5d2017-06-28 16:52:37 +0200178 return isEnabled() && mScreenOn && (mState == StatusBarState.KEYGUARD) && !mShowingAod;
Adrian Roosc5584ce2016-02-24 14:17:19 -0800179 }
180
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700181 private boolean sessionEntrypoint() {
Adrian Roosc5584ce2016-02-24 14:17:19 -0800182 if (!mSessionActive && shouldSessionBeActive()) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700183 onSessionStart();
184 return true;
185 }
186 return false;
187 }
188
Adrian Roosc5584ce2016-02-24 14:17:19 -0800189 private void sessionExitpoint(boolean force) {
190 if (mSessionActive && (force || !shouldSessionBeActive())) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700191 mSessionActive = false;
Dave Mankoff63c576e2019-05-01 18:00:01 -0400192 if (mIsFalseTouchCalls != 0) {
193 if (FalsingLog.ENABLED) {
194 FalsingLog.i(
195 "isFalseTouchCalls", "Calls before failure: " + mIsFalseTouchCalls);
196 }
197 mMetricsLogger.histogram(FALSING_REMAIN_LOCKED, mIsFalseTouchCalls);
198 mIsFalseTouchCalls = 0;
199 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200200
201 // This can be expensive, and doesn't need to happen on the main thread.
Dave Mankoffc7cf9fc2019-12-19 15:43:20 -0500202 mUiBgExecutor.execute(() -> {
Dave Mankoffdde5ee62019-05-02 17:36:11 -0400203 mSensorManager.unregisterListener(mSensorEventListener);
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200204 });
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700205 }
206 }
207
Adrian Roose395b5d2017-06-28 16:52:37 +0200208 public void updateSessionActive() {
209 if (shouldSessionBeActive()) {
210 sessionEntrypoint();
211 } else {
212 sessionExitpoint(false /* force */);
213 }
214 }
215
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700216 private void onSessionStart() {
Adrian Roos401caae2016-03-04 13:35:21 -0800217 if (FalsingLog.ENABLED) {
Dave Mankoff9febfeb2019-12-18 12:18:00 -0500218 FalsingLog.i("onSessionStart", "classifierEnabled=" + isClassifierEnabled());
Adrian Roos8e291a52016-12-09 16:10:19 -0800219 clearPendingWtf();
Adrian Roos401caae2016-03-04 13:35:21 -0800220 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700221 mBouncerOn = false;
222 mSessionActive = true;
Lucas Dupin7e35d142019-05-08 15:13:36 -0700223 mJustUnlockedWithFace = false;
Dave Mankoff63c576e2019-05-01 18:00:01 -0400224 mIsFalseTouchCalls = 0;
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700225
226 if (mHumanInteractionClassifier.isEnabled()) {
227 registerSensors(CLASSIFIER_SENSORS);
228 }
Adrian Roos7bb38a92016-07-21 11:44:01 -0700229 if (mDataCollector.isEnabledFull()) {
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700230 registerSensors(COLLECTOR_SENSORS);
231 }
Selim Cinek1ed50042018-01-18 17:12:32 -0800232 if (mDataCollector.isEnabled()) {
233 mDataCollector.onFalsingSessionStarted();
234 }
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700235 }
236
237 private void registerSensors(int [] sensors) {
238 for (int sensorType : sensors) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700239 Sensor s = mSensorManager.getDefaultSensor(sensorType);
240 if (s != null) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200241
242 // This can be expensive, and doesn't need to happen on the main thread.
Dave Mankoffc7cf9fc2019-12-19 15:43:20 -0500243 mUiBgExecutor.execute(() -> {
Dave Mankoffdde5ee62019-05-02 17:36:11 -0400244 mSensorManager.registerListener(
245 mSensorEventListener, s, SensorManager.SENSOR_DELAY_GAME);
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200246 });
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700247 }
248 }
249 }
250
Dave Mankoff9febfeb2019-12-18 12:18:00 -0500251 public boolean isClassifierEnabled() {
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700252 return mHumanInteractionClassifier.isEnabled();
253 }
254
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700255 private boolean isEnabled() {
256 return mHumanInteractionClassifier.isEnabled() || mDataCollector.isEnabled();
257 }
258
Dave Mankoffc88d6222018-10-25 15:31:20 -0400259 public boolean isUnlockingDisabled() {
260 return mDataCollector.isUnlockingDisabled();
261 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700262 /**
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700263 * @return true if the classifier determined that this is not a human interacting with the phone
264 */
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700265 public boolean isFalseTouch() {
Adrian Roos401caae2016-03-04 13:35:21 -0800266 if (FalsingLog.ENABLED) {
Adrian Roos6a04cb12016-03-14 20:21:02 -0700267 // We're getting some false wtfs from touches that happen after the device went
268 // to sleep. Only report missing sessions that happen when the device is interactive.
Adrian Roos8e291a52016-12-09 16:10:19 -0800269 if (!mSessionActive && mContext.getSystemService(PowerManager.class).isInteractive()
270 && mPendingWtf == null) {
271 int enabled = isEnabled() ? 1 : 0;
272 int screenOn = mScreenOn ? 1 : 0;
273 String state = StatusBarState.toShortString(mState);
274 Throwable here = new Throwable("here");
275 FalsingLog.wLogcat("isFalseTouch", new StringBuilder()
Adrian Roos401caae2016-03-04 13:35:21 -0800276 .append("Session is not active, yet there's a query for a false touch.")
Adrian Roos8e291a52016-12-09 16:10:19 -0800277 .append(" enabled=").append(enabled)
278 .append(" mScreenOn=").append(screenOn)
279 .append(" mState=").append(state)
280 .append(". Escalating to WTF if screen does not turn on soon.")
Adrian Roos401caae2016-03-04 13:35:21 -0800281 .toString());
Adrian Roos8e291a52016-12-09 16:10:19 -0800282
283 // Unfortunately we're also getting false positives for touches that happen right
284 // after the screen turns on, but before that notification has made it to us.
285 // Unfortunately there's no good way to catch that, except to wait and see if we get
286 // the screen on notification soon.
287 mPendingWtf = () -> FalsingLog.wtf("isFalseTouch", new StringBuilder()
288 .append("Session did not become active after query for a false touch.")
289 .append(" enabled=").append(enabled)
290 .append('/').append(isEnabled() ? 1 : 0)
291 .append(" mScreenOn=").append(screenOn)
292 .append('/').append(mScreenOn ? 1 : 0)
293 .append(" mState=").append(state)
294 .append('/').append(StatusBarState.toShortString(mState))
295 .append(". Look for warnings ~1000ms earlier to see root cause.")
296 .toString(), here);
297 mHandler.postDelayed(mPendingWtf, 1000);
Adrian Roos401caae2016-03-04 13:35:21 -0800298 }
299 }
Lucas Dupin13b8cec2020-02-28 16:31:57 -0800300 if (ActivityManager.isRunningInUserTestHarness()) {
301 // This is a test device running UiAutomator code.
302 return false;
303 }
Adrian Roosca664b92016-04-18 14:40:27 -0700304 if (mAccessibilityManager.isTouchExplorationEnabled()) {
305 // Touch exploration triggers false positives in the classifier and
306 // already sufficiently prevents false unlocks.
307 return false;
308 }
Adrian Roos004437e2017-08-16 11:58:02 +0200309 if (!mIsTouchScreen) {
310 // Unlocking with input devices besides the touchscreen should already be sufficiently
311 // anti-falsed.
312 return false;
313 }
Lucas Dupin7e35d142019-05-08 15:13:36 -0700314 if (mJustUnlockedWithFace) {
315 // Unlocking with face is a strong user presence signal, we can assume the user
316 // is present until the next session starts.
317 return false;
318 }
Dave Mankoff63c576e2019-05-01 18:00:01 -0400319 mIsFalseTouchCalls++;
320 boolean isFalse = mHumanInteractionClassifier.isFalseTouch();
321 if (!isFalse) {
322 if (FalsingLog.ENABLED) {
323 FalsingLog.i("isFalseTouchCalls", "Calls before success: " + mIsFalseTouchCalls);
324 }
325 mMetricsLogger.histogram(FALSING_SUCCESS, mIsFalseTouchCalls);
326 mIsFalseTouchCalls = 0;
327 }
328 return isFalse;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700329 }
330
Adrian Roos8e291a52016-12-09 16:10:19 -0800331 private void clearPendingWtf() {
332 if (mPendingWtf != null) {
333 mHandler.removeCallbacks(mPendingWtf);
334 mPendingWtf = null;
335 }
336 }
337
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700338
339 public boolean shouldEnforceBouncer() {
340 return mEnforceBouncer;
341 }
342
Adrian Roose395b5d2017-06-28 16:52:37 +0200343 public void setShowingAod(boolean showingAod) {
344 mShowingAod = showingAod;
345 updateSessionActive();
346 }
347
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700348 public void onScreenTurningOn() {
Adrian Roos401caae2016-03-04 13:35:21 -0800349 if (FalsingLog.ENABLED) {
350 FalsingLog.i("onScreenTurningOn", new StringBuilder()
351 .append("from=").append(mScreenOn ? 1 : 0)
352 .toString());
Adrian Roos8e291a52016-12-09 16:10:19 -0800353 clearPendingWtf();
Adrian Roos401caae2016-03-04 13:35:21 -0800354 }
Adrian Roosc5584ce2016-02-24 14:17:19 -0800355 mScreenOn = true;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700356 if (sessionEntrypoint()) {
357 mDataCollector.onScreenTurningOn();
358 }
359 }
360
361 public void onScreenOnFromTouch() {
Adrian Roos401caae2016-03-04 13:35:21 -0800362 if (FalsingLog.ENABLED) {
363 FalsingLog.i("onScreenOnFromTouch", new StringBuilder()
364 .append("from=").append(mScreenOn ? 1 : 0)
365 .toString());
366 }
Adrian Roosc5584ce2016-02-24 14:17:19 -0800367 mScreenOn = true;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700368 if (sessionEntrypoint()) {
369 mDataCollector.onScreenOnFromTouch();
370 }
371 }
372
373 public void onScreenOff() {
Adrian Roos401caae2016-03-04 13:35:21 -0800374 if (FalsingLog.ENABLED) {
375 FalsingLog.i("onScreenOff", new StringBuilder()
376 .append("from=").append(mScreenOn ? 1 : 0)
377 .toString());
378 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700379 mDataCollector.onScreenOff();
Adrian Roosc5584ce2016-02-24 14:17:19 -0800380 mScreenOn = false;
381 sessionExitpoint(false /* force */);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700382 }
383
Dave Mankoff1b2144d2020-02-11 14:45:46 -0500384 public void onSuccessfulUnlock() {
Adrian Roos401caae2016-03-04 13:35:21 -0800385 if (FalsingLog.ENABLED) {
386 FalsingLog.i("onSucccessfulUnlock", "");
387 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700388 mDataCollector.onSucccessfulUnlock();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700389 }
390
391 public void onBouncerShown() {
Adrian Roos401caae2016-03-04 13:35:21 -0800392 if (FalsingLog.ENABLED) {
393 FalsingLog.i("onBouncerShown", new StringBuilder()
394 .append("from=").append(mBouncerOn ? 1 : 0)
395 .toString());
396 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700397 if (!mBouncerOn) {
398 mBouncerOn = true;
399 mDataCollector.onBouncerShown();
400 }
401 }
402
403 public void onBouncerHidden() {
Adrian Roos401caae2016-03-04 13:35:21 -0800404 if (FalsingLog.ENABLED) {
405 FalsingLog.i("onBouncerHidden", new StringBuilder()
406 .append("from=").append(mBouncerOn ? 1 : 0)
407 .toString());
408 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700409 if (mBouncerOn) {
410 mBouncerOn = false;
411 mDataCollector.onBouncerHidden();
412 }
413 }
414
415 public void onQsDown() {
Adrian Roos401caae2016-03-04 13:35:21 -0800416 if (FalsingLog.ENABLED) {
417 FalsingLog.i("onQsDown", "");
418 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700419 mHumanInteractionClassifier.setType(Classifier.QUICK_SETTINGS);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700420 mDataCollector.onQsDown();
421 }
422
423 public void setQsExpanded(boolean expanded) {
424 mDataCollector.setQsExpanded(expanded);
425 }
426
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800427 public void onTrackingStarted(boolean secure) {
Adrian Roos401caae2016-03-04 13:35:21 -0800428 if (FalsingLog.ENABLED) {
429 FalsingLog.i("onTrackingStarted", "");
430 }
Dave Mankoffdde5ee62019-05-02 17:36:11 -0400431 mHumanInteractionClassifier.setType(secure
432 ? Classifier.BOUNCER_UNLOCK : Classifier.UNLOCK);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700433 mDataCollector.onTrackingStarted();
434 }
435
436 public void onTrackingStopped() {
437 mDataCollector.onTrackingStopped();
438 }
439
440 public void onNotificationActive() {
441 mDataCollector.onNotificationActive();
442 }
443
Adrian Roos9f0b0022016-11-09 15:56:50 -0800444 public void onNotificationDoubleTap(boolean accepted, float dx, float dy) {
445 if (FalsingLog.ENABLED) {
446 FalsingLog.i("onNotificationDoubleTap", "accepted=" + accepted
447 + " dx=" + dx + " dy=" + dy + " (px)");
448 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700449 mDataCollector.onNotificationDoubleTap();
450 }
451
452 public void setNotificationExpanded() {
453 mDataCollector.setNotificationExpanded();
454 }
455
456 public void onNotificatonStartDraggingDown() {
Adrian Roos401caae2016-03-04 13:35:21 -0800457 if (FalsingLog.ENABLED) {
458 FalsingLog.i("onNotificatonStartDraggingDown", "");
459 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700460 mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DRAG_DOWN);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700461 mDataCollector.onNotificatonStartDraggingDown();
462 }
463
Selim Cinek3d6ae232019-01-04 14:14:33 -0800464 public void onStartExpandingFromPulse() {
465 if (FalsingLog.ENABLED) {
466 FalsingLog.i("onStartExpandingFromPulse", "");
467 }
468 mHumanInteractionClassifier.setType(Classifier.PULSE_EXPAND);
469 mDataCollector.onStartExpandingFromPulse();
470 }
471
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700472 public void onNotificatonStopDraggingDown() {
473 mDataCollector.onNotificatonStopDraggingDown();
474 }
475
Selim Cinek3d6ae232019-01-04 14:14:33 -0800476 public void onExpansionFromPulseStopped() {
477 mDataCollector.onExpansionFromPulseStopped();
478 }
479
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700480 public void onNotificationDismissed() {
481 mDataCollector.onNotificationDismissed();
482 }
483
484 public void onNotificatonStartDismissing() {
Adrian Roos401caae2016-03-04 13:35:21 -0800485 if (FalsingLog.ENABLED) {
486 FalsingLog.i("onNotificatonStartDismissing", "");
487 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700488 mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DISMISS);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700489 mDataCollector.onNotificatonStartDismissing();
490 }
491
492 public void onNotificatonStopDismissing() {
493 mDataCollector.onNotificatonStopDismissing();
494 }
495
496 public void onCameraOn() {
497 mDataCollector.onCameraOn();
498 }
499
500 public void onLeftAffordanceOn() {
501 mDataCollector.onLeftAffordanceOn();
502 }
503
504 public void onAffordanceSwipingStarted(boolean rightCorner) {
Adrian Roos401caae2016-03-04 13:35:21 -0800505 if (FalsingLog.ENABLED) {
506 FalsingLog.i("onAffordanceSwipingStarted", "");
507 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700508 if (rightCorner) {
509 mHumanInteractionClassifier.setType(Classifier.RIGHT_AFFORDANCE);
510 } else {
511 mHumanInteractionClassifier.setType(Classifier.LEFT_AFFORDANCE);
512 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700513 mDataCollector.onAffordanceSwipingStarted(rightCorner);
514 }
515
516 public void onAffordanceSwipingAborted() {
517 mDataCollector.onAffordanceSwipingAborted();
518 }
519
520 public void onUnlockHintStarted() {
521 mDataCollector.onUnlockHintStarted();
522 }
523
524 public void onCameraHintStarted() {
525 mDataCollector.onCameraHintStarted();
526 }
527
528 public void onLeftAffordanceHintStarted() {
529 mDataCollector.onLeftAffordanceHintStarted();
530 }
531
532 public void onTouchEvent(MotionEvent event, int width, int height) {
Adrian Roos004437e2017-08-16 11:58:02 +0200533 if (event.getAction() == MotionEvent.ACTION_DOWN) {
534 mIsTouchScreen = event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN);
Siarhei Vishniakou81e1ffd2018-05-04 16:08:22 -0700535 // If the bouncer was not shown during the down event,
536 // we want the entire gesture going to HumanInteractionClassifier
537 mBouncerOffOnDown = !mBouncerOn;
Adrian Roos004437e2017-08-16 11:58:02 +0200538 }
Siarhei Vishniakou81e1ffd2018-05-04 16:08:22 -0700539 if (mSessionActive) {
540 if (!mBouncerOn) {
541 // In case bouncer is "visible", but onFullyShown has not yet been called,
542 // avoid adding the event to DataCollector
543 mDataCollector.onTouchEvent(event, width, height);
544 }
545 if (mBouncerOffOnDown) {
546 mHumanInteractionClassifier.onTouchEvent(event);
547 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700548 }
549 }
Adrian Roos401caae2016-03-04 13:35:21 -0800550
551 public void dump(PrintWriter pw) {
552 pw.println("FALSING MANAGER");
Dave Mankoff9febfeb2019-12-18 12:18:00 -0500553 pw.print("classifierEnabled="); pw.println(isClassifierEnabled() ? 1 : 0);
Adrian Roos401caae2016-03-04 13:35:21 -0800554 pw.print("mSessionActive="); pw.println(mSessionActive ? 1 : 0);
555 pw.print("mBouncerOn="); pw.println(mSessionActive ? 1 : 0);
556 pw.print("mState="); pw.println(StatusBarState.toShortString(mState));
557 pw.print("mScreenOn="); pw.println(mScreenOn ? 1 : 0);
558 pw.println();
559 }
Adrian Roos7bb38a92016-07-21 11:44:01 -0700560
Dave Mankoffb32ba472019-07-16 15:07:01 -0400561 @Override
562 public void cleanup() {
563 mSensorManager.unregisterListener(mSensorEventListener);
564 mContext.getContentResolver().unregisterContentObserver(mSettingsObserver);
565 Dependency.get(StatusBarStateController.class).removeCallback(mStatusBarStateListener);
Dave Mankoffe2294692019-08-14 11:53:13 -0400566 Dependency.get(KeyguardUpdateMonitor.class).removeCallback(mKeyguardUpdateCallback);
Dave Mankoffb32ba472019-07-16 15:07:01 -0400567 }
568
Adrian Roos7bb38a92016-07-21 11:44:01 -0700569 public Uri reportRejectedTouch() {
570 if (mDataCollector.isEnabled()) {
571 return mDataCollector.reportRejectedTouch();
572 }
573 return null;
574 }
575
576 public boolean isReportingEnabled() {
577 return mDataCollector.isReportingEnabled();
578 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700579}