blob: 2c61da34376316d8c29f3b08dfad6a1a25473a2a [file] [log] [blame]
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001/*
2 * Copyright (C) 2015 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
17package com.android.systemui.classifier;
18
19import android.content.Context;
20import android.database.ContentObserver;
21import android.hardware.Sensor;
22import android.hardware.SensorEvent;
23import android.hardware.SensorEventListener;
24import android.hardware.SensorManager;
Adrian Roos7bb38a92016-07-21 11:44:01 -070025import android.net.Uri;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070026import android.os.Handler;
Selim Cinekf8c4add2017-06-08 09:54:58 -070027import android.os.Looper;
Adrian Roosc5584ce2016-02-24 14:17:19 -080028import android.os.PowerManager;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070029import android.os.UserHandle;
30import android.provider.Settings;
Adrian Roos004437e2017-08-16 11:58:02 +020031import android.view.InputDevice;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070032import android.view.MotionEvent;
Adrian Roosca664b92016-04-18 14:40:27 -070033import android.view.accessibility.AccessibilityManager;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070034
Jorim Jaggie549a8d2017-05-15 02:40:05 +020035import com.android.systemui.Dependency;
36import com.android.systemui.UiOffloadThread;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070037import com.android.systemui.analytics.DataCollector;
38import com.android.systemui.statusbar.StatusBarState;
Jason Monk1fd3fc32018-08-14 17:20:09 -040039import com.android.systemui.statusbar.StatusBarStateController;
40import com.android.systemui.statusbar.StatusBarStateController.StateListener;
Adrian Roos7a8ae8a2017-08-02 16:26:50 +020041import com.android.systemui.util.AsyncSensorManager;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070042
Adrian Roos401caae2016-03-04 13:35:21 -080043import java.io.PrintWriter;
44
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070045/**
46 * When the phone is locked, listens to touch, sensor and phone events and sends them to
47 * DataCollector and HumanInteractionClassifier.
48 *
49 * It does not collect touch events when the bouncer shows up.
50 */
51public class FalsingManager implements SensorEventListener {
52 private static final String ENFORCE_BOUNCER = "falsing_manager_enforce_bouncer";
53
Blazej Magnowski6dc59b42015-09-22 15:14:20 -070054 private static final int[] CLASSIFIER_SENSORS = new int[] {
55 Sensor.TYPE_PROXIMITY,
56 };
57
58 private static final int[] COLLECTOR_SENSORS = new int[] {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070059 Sensor.TYPE_ACCELEROMETER,
60 Sensor.TYPE_GYROSCOPE,
61 Sensor.TYPE_PROXIMITY,
62 Sensor.TYPE_LIGHT,
63 Sensor.TYPE_ROTATION_VECTOR,
64 };
65
Selim Cinekf8c4add2017-06-08 09:54:58 -070066 private final Handler mHandler = new Handler(Looper.getMainLooper());
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070067 private final Context mContext;
68
69 private final SensorManager mSensorManager;
70 private final DataCollector mDataCollector;
71 private final HumanInteractionClassifier mHumanInteractionClassifier;
Adrian Roosca664b92016-04-18 14:40:27 -070072 private final AccessibilityManager mAccessibilityManager;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020073 private final UiOffloadThread mUiOffloadThread;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070074
75 private static FalsingManager sInstance = null;
76
77 private boolean mEnforceBouncer = false;
78 private boolean mBouncerOn = false;
Siarhei Vishniakou81e1ffd2018-05-04 16:08:22 -070079 private boolean mBouncerOffOnDown = false;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070080 private boolean mSessionActive = false;
Adrian Roos004437e2017-08-16 11:58:02 +020081 private boolean mIsTouchScreen = true;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070082 private int mState = StatusBarState.SHADE;
Adrian Roosc5584ce2016-02-24 14:17:19 -080083 private boolean mScreenOn;
Adrian Roose395b5d2017-06-28 16:52:37 +020084 private boolean mShowingAod;
Adrian Roos8e291a52016-12-09 16:10:19 -080085 private Runnable mPendingWtf;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070086
Jason Monk1fd3fc32018-08-14 17:20:09 -040087 private final StateListener mStateListener = this::setStatusBarState;
88
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070089 protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) {
90 @Override
91 public void onChange(boolean selfChange) {
92 updateConfiguration();
93 }
94 };
95
96 private FalsingManager(Context context) {
97 mContext = context;
Adrian Roos7a8ae8a2017-08-02 16:26:50 +020098 mSensorManager = Dependency.get(AsyncSensorManager.class);
Adrian Roosca664b92016-04-18 14:40:27 -070099 mAccessibilityManager = context.getSystemService(AccessibilityManager.class);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700100 mDataCollector = DataCollector.getInstance(mContext);
101 mHumanInteractionClassifier = HumanInteractionClassifier.getInstance(mContext);
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200102 mUiOffloadThread = Dependency.get(UiOffloadThread.class);
Adrian Roosc5584ce2016-02-24 14:17:19 -0800103 mScreenOn = context.getSystemService(PowerManager.class).isInteractive();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700104
105 mContext.getContentResolver().registerContentObserver(
106 Settings.Secure.getUriFor(ENFORCE_BOUNCER), false,
107 mSettingsObserver,
108 UserHandle.USER_ALL);
109
110 updateConfiguration();
Jason Monk1fd3fc32018-08-14 17:20:09 -0400111 Dependency.get(StatusBarStateController.class).addListener(mStateListener);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700112 }
113
114 public static FalsingManager getInstance(Context context) {
115 if (sInstance == null) {
116 sInstance = new FalsingManager(context);
117 }
118 return sInstance;
119 }
120
121 private void updateConfiguration() {
122 mEnforceBouncer = 0 != Settings.Secure.getInt(mContext.getContentResolver(),
123 ENFORCE_BOUNCER, 0);
124 }
125
Adrian Roosc5584ce2016-02-24 14:17:19 -0800126 private boolean shouldSessionBeActive() {
Adrian Roos401caae2016-03-04 13:35:21 -0800127 if (FalsingLog.ENABLED && FalsingLog.VERBOSE)
128 FalsingLog.v("shouldBeActive", new StringBuilder()
129 .append("enabled=").append(isEnabled() ? 1 : 0)
130 .append(" mScreenOn=").append(mScreenOn ? 1 : 0)
131 .append(" mState=").append(StatusBarState.toShortString(mState))
132 .toString()
133 );
Adrian Roose395b5d2017-06-28 16:52:37 +0200134 return isEnabled() && mScreenOn && (mState == StatusBarState.KEYGUARD) && !mShowingAod;
Adrian Roosc5584ce2016-02-24 14:17:19 -0800135 }
136
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700137 private boolean sessionEntrypoint() {
Adrian Roosc5584ce2016-02-24 14:17:19 -0800138 if (!mSessionActive && shouldSessionBeActive()) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700139 onSessionStart();
140 return true;
141 }
142 return false;
143 }
144
Adrian Roosc5584ce2016-02-24 14:17:19 -0800145 private void sessionExitpoint(boolean force) {
146 if (mSessionActive && (force || !shouldSessionBeActive())) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700147 mSessionActive = false;
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200148
149 // This can be expensive, and doesn't need to happen on the main thread.
150 mUiOffloadThread.submit(() -> {
151 mSensorManager.unregisterListener(this);
152 });
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700153 }
154 }
155
Adrian Roose395b5d2017-06-28 16:52:37 +0200156 public void updateSessionActive() {
157 if (shouldSessionBeActive()) {
158 sessionEntrypoint();
159 } else {
160 sessionExitpoint(false /* force */);
161 }
162 }
163
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700164 private void onSessionStart() {
Adrian Roos401caae2016-03-04 13:35:21 -0800165 if (FalsingLog.ENABLED) {
166 FalsingLog.i("onSessionStart", "classifierEnabled=" + isClassiferEnabled());
Adrian Roos8e291a52016-12-09 16:10:19 -0800167 clearPendingWtf();
Adrian Roos401caae2016-03-04 13:35:21 -0800168 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700169 mBouncerOn = false;
170 mSessionActive = true;
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700171
172 if (mHumanInteractionClassifier.isEnabled()) {
173 registerSensors(CLASSIFIER_SENSORS);
174 }
Adrian Roos7bb38a92016-07-21 11:44:01 -0700175 if (mDataCollector.isEnabledFull()) {
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700176 registerSensors(COLLECTOR_SENSORS);
177 }
Selim Cinek1ed50042018-01-18 17:12:32 -0800178 if (mDataCollector.isEnabled()) {
179 mDataCollector.onFalsingSessionStarted();
180 }
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700181 }
182
183 private void registerSensors(int [] sensors) {
184 for (int sensorType : sensors) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700185 Sensor s = mSensorManager.getDefaultSensor(sensorType);
186 if (s != null) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200187
188 // This can be expensive, and doesn't need to happen on the main thread.
189 mUiOffloadThread.submit(() -> {
190 mSensorManager.registerListener(this, s, SensorManager.SENSOR_DELAY_GAME);
191 });
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700192 }
193 }
194 }
195
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700196 public boolean isClassiferEnabled() {
197 return mHumanInteractionClassifier.isEnabled();
198 }
199
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700200 private boolean isEnabled() {
201 return mHumanInteractionClassifier.isEnabled() || mDataCollector.isEnabled();
202 }
203
Dave Mankoffc88d6222018-10-25 15:31:20 -0400204 public boolean isUnlockingDisabled() {
205 return mDataCollector.isUnlockingDisabled();
206 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700207 /**
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700208 * @return true if the classifier determined that this is not a human interacting with the phone
209 */
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700210 public boolean isFalseTouch() {
Adrian Roos401caae2016-03-04 13:35:21 -0800211 if (FalsingLog.ENABLED) {
Adrian Roos6a04cb12016-03-14 20:21:02 -0700212 // We're getting some false wtfs from touches that happen after the device went
213 // to sleep. Only report missing sessions that happen when the device is interactive.
Adrian Roos8e291a52016-12-09 16:10:19 -0800214 if (!mSessionActive && mContext.getSystemService(PowerManager.class).isInteractive()
215 && mPendingWtf == null) {
216 int enabled = isEnabled() ? 1 : 0;
217 int screenOn = mScreenOn ? 1 : 0;
218 String state = StatusBarState.toShortString(mState);
219 Throwable here = new Throwable("here");
220 FalsingLog.wLogcat("isFalseTouch", new StringBuilder()
Adrian Roos401caae2016-03-04 13:35:21 -0800221 .append("Session is not active, yet there's a query for a false touch.")
Adrian Roos8e291a52016-12-09 16:10:19 -0800222 .append(" enabled=").append(enabled)
223 .append(" mScreenOn=").append(screenOn)
224 .append(" mState=").append(state)
225 .append(". Escalating to WTF if screen does not turn on soon.")
Adrian Roos401caae2016-03-04 13:35:21 -0800226 .toString());
Adrian Roos8e291a52016-12-09 16:10:19 -0800227
228 // Unfortunately we're also getting false positives for touches that happen right
229 // after the screen turns on, but before that notification has made it to us.
230 // Unfortunately there's no good way to catch that, except to wait and see if we get
231 // the screen on notification soon.
232 mPendingWtf = () -> FalsingLog.wtf("isFalseTouch", new StringBuilder()
233 .append("Session did not become active after query for a false touch.")
234 .append(" enabled=").append(enabled)
235 .append('/').append(isEnabled() ? 1 : 0)
236 .append(" mScreenOn=").append(screenOn)
237 .append('/').append(mScreenOn ? 1 : 0)
238 .append(" mState=").append(state)
239 .append('/').append(StatusBarState.toShortString(mState))
240 .append(". Look for warnings ~1000ms earlier to see root cause.")
241 .toString(), here);
242 mHandler.postDelayed(mPendingWtf, 1000);
Adrian Roos401caae2016-03-04 13:35:21 -0800243 }
244 }
Adrian Roosca664b92016-04-18 14:40:27 -0700245 if (mAccessibilityManager.isTouchExplorationEnabled()) {
246 // Touch exploration triggers false positives in the classifier and
247 // already sufficiently prevents false unlocks.
248 return false;
249 }
Adrian Roos004437e2017-08-16 11:58:02 +0200250 if (!mIsTouchScreen) {
251 // Unlocking with input devices besides the touchscreen should already be sufficiently
252 // anti-falsed.
253 return false;
254 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700255 return mHumanInteractionClassifier.isFalseTouch();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700256 }
257
Adrian Roos8e291a52016-12-09 16:10:19 -0800258 private void clearPendingWtf() {
259 if (mPendingWtf != null) {
260 mHandler.removeCallbacks(mPendingWtf);
261 mPendingWtf = null;
262 }
263 }
264
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700265 @Override
266 public synchronized void onSensorChanged(SensorEvent event) {
267 mDataCollector.onSensorChanged(event);
268 mHumanInteractionClassifier.onSensorChanged(event);
269 }
270
271 @Override
272 public void onAccuracyChanged(Sensor sensor, int accuracy) {
273 mDataCollector.onAccuracyChanged(sensor, accuracy);
274 }
275
276 public boolean shouldEnforceBouncer() {
277 return mEnforceBouncer;
278 }
279
Adrian Roose395b5d2017-06-28 16:52:37 +0200280 public void setShowingAod(boolean showingAod) {
281 mShowingAod = showingAod;
282 updateSessionActive();
283 }
284
Jason Monk1fd3fc32018-08-14 17:20:09 -0400285 private void setStatusBarState(int state) {
Adrian Roos401caae2016-03-04 13:35:21 -0800286 if (FalsingLog.ENABLED) {
287 FalsingLog.i("setStatusBarState", new StringBuilder()
288 .append("from=").append(StatusBarState.toShortString(mState))
289 .append(" to=").append(StatusBarState.toShortString(state))
290 .toString());
291 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700292 mState = state;
Adrian Roose395b5d2017-06-28 16:52:37 +0200293 updateSessionActive();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700294 }
295
296 public void onScreenTurningOn() {
Adrian Roos401caae2016-03-04 13:35:21 -0800297 if (FalsingLog.ENABLED) {
298 FalsingLog.i("onScreenTurningOn", new StringBuilder()
299 .append("from=").append(mScreenOn ? 1 : 0)
300 .toString());
Adrian Roos8e291a52016-12-09 16:10:19 -0800301 clearPendingWtf();
Adrian Roos401caae2016-03-04 13:35:21 -0800302 }
Adrian Roosc5584ce2016-02-24 14:17:19 -0800303 mScreenOn = true;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700304 if (sessionEntrypoint()) {
305 mDataCollector.onScreenTurningOn();
306 }
307 }
308
309 public void onScreenOnFromTouch() {
Adrian Roos401caae2016-03-04 13:35:21 -0800310 if (FalsingLog.ENABLED) {
311 FalsingLog.i("onScreenOnFromTouch", new StringBuilder()
312 .append("from=").append(mScreenOn ? 1 : 0)
313 .toString());
314 }
Adrian Roosc5584ce2016-02-24 14:17:19 -0800315 mScreenOn = true;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700316 if (sessionEntrypoint()) {
317 mDataCollector.onScreenOnFromTouch();
318 }
319 }
320
321 public void onScreenOff() {
Adrian Roos401caae2016-03-04 13:35:21 -0800322 if (FalsingLog.ENABLED) {
323 FalsingLog.i("onScreenOff", new StringBuilder()
324 .append("from=").append(mScreenOn ? 1 : 0)
325 .toString());
326 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700327 mDataCollector.onScreenOff();
Adrian Roosc5584ce2016-02-24 14:17:19 -0800328 mScreenOn = false;
329 sessionExitpoint(false /* force */);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700330 }
331
332 public void onSucccessfulUnlock() {
Adrian Roos401caae2016-03-04 13:35:21 -0800333 if (FalsingLog.ENABLED) {
334 FalsingLog.i("onSucccessfulUnlock", "");
335 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700336 mDataCollector.onSucccessfulUnlock();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700337 }
338
339 public void onBouncerShown() {
Adrian Roos401caae2016-03-04 13:35:21 -0800340 if (FalsingLog.ENABLED) {
341 FalsingLog.i("onBouncerShown", new StringBuilder()
342 .append("from=").append(mBouncerOn ? 1 : 0)
343 .toString());
344 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700345 if (!mBouncerOn) {
346 mBouncerOn = true;
347 mDataCollector.onBouncerShown();
348 }
349 }
350
351 public void onBouncerHidden() {
Adrian Roos401caae2016-03-04 13:35:21 -0800352 if (FalsingLog.ENABLED) {
353 FalsingLog.i("onBouncerHidden", new StringBuilder()
354 .append("from=").append(mBouncerOn ? 1 : 0)
355 .toString());
356 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700357 if (mBouncerOn) {
358 mBouncerOn = false;
359 mDataCollector.onBouncerHidden();
360 }
361 }
362
363 public void onQsDown() {
Adrian Roos401caae2016-03-04 13:35:21 -0800364 if (FalsingLog.ENABLED) {
365 FalsingLog.i("onQsDown", "");
366 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700367 mHumanInteractionClassifier.setType(Classifier.QUICK_SETTINGS);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700368 mDataCollector.onQsDown();
369 }
370
371 public void setQsExpanded(boolean expanded) {
372 mDataCollector.setQsExpanded(expanded);
373 }
374
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800375 public void onTrackingStarted(boolean secure) {
Adrian Roos401caae2016-03-04 13:35:21 -0800376 if (FalsingLog.ENABLED) {
377 FalsingLog.i("onTrackingStarted", "");
378 }
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800379 mHumanInteractionClassifier.setType(secure ?
380 Classifier.BOUNCER_UNLOCK : Classifier.UNLOCK);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700381 mDataCollector.onTrackingStarted();
382 }
383
384 public void onTrackingStopped() {
385 mDataCollector.onTrackingStopped();
386 }
387
388 public void onNotificationActive() {
389 mDataCollector.onNotificationActive();
390 }
391
Adrian Roos9f0b0022016-11-09 15:56:50 -0800392 public void onNotificationDoubleTap(boolean accepted, float dx, float dy) {
393 if (FalsingLog.ENABLED) {
394 FalsingLog.i("onNotificationDoubleTap", "accepted=" + accepted
395 + " dx=" + dx + " dy=" + dy + " (px)");
396 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700397 mDataCollector.onNotificationDoubleTap();
398 }
399
400 public void setNotificationExpanded() {
401 mDataCollector.setNotificationExpanded();
402 }
403
404 public void onNotificatonStartDraggingDown() {
Adrian Roos401caae2016-03-04 13:35:21 -0800405 if (FalsingLog.ENABLED) {
406 FalsingLog.i("onNotificatonStartDraggingDown", "");
407 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700408 mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DRAG_DOWN);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700409 mDataCollector.onNotificatonStartDraggingDown();
410 }
411
412 public void onNotificatonStopDraggingDown() {
413 mDataCollector.onNotificatonStopDraggingDown();
414 }
415
416 public void onNotificationDismissed() {
417 mDataCollector.onNotificationDismissed();
418 }
419
420 public void onNotificatonStartDismissing() {
Adrian Roos401caae2016-03-04 13:35:21 -0800421 if (FalsingLog.ENABLED) {
422 FalsingLog.i("onNotificatonStartDismissing", "");
423 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700424 mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DISMISS);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700425 mDataCollector.onNotificatonStartDismissing();
426 }
427
428 public void onNotificatonStopDismissing() {
429 mDataCollector.onNotificatonStopDismissing();
430 }
431
432 public void onCameraOn() {
433 mDataCollector.onCameraOn();
434 }
435
436 public void onLeftAffordanceOn() {
437 mDataCollector.onLeftAffordanceOn();
438 }
439
440 public void onAffordanceSwipingStarted(boolean rightCorner) {
Adrian Roos401caae2016-03-04 13:35:21 -0800441 if (FalsingLog.ENABLED) {
442 FalsingLog.i("onAffordanceSwipingStarted", "");
443 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700444 if (rightCorner) {
445 mHumanInteractionClassifier.setType(Classifier.RIGHT_AFFORDANCE);
446 } else {
447 mHumanInteractionClassifier.setType(Classifier.LEFT_AFFORDANCE);
448 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700449 mDataCollector.onAffordanceSwipingStarted(rightCorner);
450 }
451
452 public void onAffordanceSwipingAborted() {
453 mDataCollector.onAffordanceSwipingAborted();
454 }
455
456 public void onUnlockHintStarted() {
457 mDataCollector.onUnlockHintStarted();
458 }
459
460 public void onCameraHintStarted() {
461 mDataCollector.onCameraHintStarted();
462 }
463
464 public void onLeftAffordanceHintStarted() {
465 mDataCollector.onLeftAffordanceHintStarted();
466 }
467
468 public void onTouchEvent(MotionEvent event, int width, int height) {
Adrian Roos004437e2017-08-16 11:58:02 +0200469 if (event.getAction() == MotionEvent.ACTION_DOWN) {
470 mIsTouchScreen = event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN);
Siarhei Vishniakou81e1ffd2018-05-04 16:08:22 -0700471 // If the bouncer was not shown during the down event,
472 // we want the entire gesture going to HumanInteractionClassifier
473 mBouncerOffOnDown = !mBouncerOn;
Adrian Roos004437e2017-08-16 11:58:02 +0200474 }
Siarhei Vishniakou81e1ffd2018-05-04 16:08:22 -0700475 if (mSessionActive) {
476 if (!mBouncerOn) {
477 // In case bouncer is "visible", but onFullyShown has not yet been called,
478 // avoid adding the event to DataCollector
479 mDataCollector.onTouchEvent(event, width, height);
480 }
481 if (mBouncerOffOnDown) {
482 mHumanInteractionClassifier.onTouchEvent(event);
483 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700484 }
485 }
Adrian Roos401caae2016-03-04 13:35:21 -0800486
487 public void dump(PrintWriter pw) {
488 pw.println("FALSING MANAGER");
489 pw.print("classifierEnabled="); pw.println(isClassiferEnabled() ? 1 : 0);
490 pw.print("mSessionActive="); pw.println(mSessionActive ? 1 : 0);
491 pw.print("mBouncerOn="); pw.println(mSessionActive ? 1 : 0);
492 pw.print("mState="); pw.println(StatusBarState.toShortString(mState));
493 pw.print("mScreenOn="); pw.println(mScreenOn ? 1 : 0);
494 pw.println();
495 }
Adrian Roos7bb38a92016-07-21 11:44:01 -0700496
497 public Uri reportRejectedTouch() {
498 if (mDataCollector.isEnabled()) {
499 return mDataCollector.reportRejectedTouch();
500 }
501 return null;
502 }
503
504 public boolean isReportingEnabled() {
505 return mDataCollector.isReportingEnabled();
506 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700507}