blob: a63fdbd63e02f3a514b6722ef9a23bdc45a927a4 [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;
Beverly8fdb5332019-02-04 14:29:49 -050038import com.android.systemui.plugins.statusbar.StatusBarStateController;
39import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070040import com.android.systemui.statusbar.StatusBarState;
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 */
Lucas Dupin7fc9dc12019-01-03 09:19:43 -080051public class FalsingManager implements SensorEventListener, StateListener {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070052 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
87 protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) {
88 @Override
89 public void onChange(boolean selfChange) {
90 updateConfiguration();
91 }
92 };
93
94 private FalsingManager(Context context) {
95 mContext = context;
Adrian Roos7a8ae8a2017-08-02 16:26:50 +020096 mSensorManager = Dependency.get(AsyncSensorManager.class);
Adrian Roosca664b92016-04-18 14:40:27 -070097 mAccessibilityManager = context.getSystemService(AccessibilityManager.class);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070098 mDataCollector = DataCollector.getInstance(mContext);
99 mHumanInteractionClassifier = HumanInteractionClassifier.getInstance(mContext);
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200100 mUiOffloadThread = Dependency.get(UiOffloadThread.class);
Adrian Roosc5584ce2016-02-24 14:17:19 -0800101 mScreenOn = context.getSystemService(PowerManager.class).isInteractive();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700102
103 mContext.getContentResolver().registerContentObserver(
104 Settings.Secure.getUriFor(ENFORCE_BOUNCER), false,
105 mSettingsObserver,
106 UserHandle.USER_ALL);
107
108 updateConfiguration();
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800109 Dependency.get(StatusBarStateController.class).addCallback(this);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700110 }
111
112 public static FalsingManager getInstance(Context context) {
113 if (sInstance == null) {
114 sInstance = new FalsingManager(context);
115 }
116 return sInstance;
117 }
118
119 private void updateConfiguration() {
120 mEnforceBouncer = 0 != Settings.Secure.getInt(mContext.getContentResolver(),
121 ENFORCE_BOUNCER, 0);
122 }
123
Adrian Roosc5584ce2016-02-24 14:17:19 -0800124 private boolean shouldSessionBeActive() {
Adrian Roos401caae2016-03-04 13:35:21 -0800125 if (FalsingLog.ENABLED && FalsingLog.VERBOSE)
126 FalsingLog.v("shouldBeActive", new StringBuilder()
127 .append("enabled=").append(isEnabled() ? 1 : 0)
128 .append(" mScreenOn=").append(mScreenOn ? 1 : 0)
129 .append(" mState=").append(StatusBarState.toShortString(mState))
130 .toString()
131 );
Adrian Roose395b5d2017-06-28 16:52:37 +0200132 return isEnabled() && mScreenOn && (mState == StatusBarState.KEYGUARD) && !mShowingAod;
Adrian Roosc5584ce2016-02-24 14:17:19 -0800133 }
134
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700135 private boolean sessionEntrypoint() {
Adrian Roosc5584ce2016-02-24 14:17:19 -0800136 if (!mSessionActive && shouldSessionBeActive()) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700137 onSessionStart();
138 return true;
139 }
140 return false;
141 }
142
Adrian Roosc5584ce2016-02-24 14:17:19 -0800143 private void sessionExitpoint(boolean force) {
144 if (mSessionActive && (force || !shouldSessionBeActive())) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700145 mSessionActive = false;
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200146
147 // This can be expensive, and doesn't need to happen on the main thread.
148 mUiOffloadThread.submit(() -> {
149 mSensorManager.unregisterListener(this);
150 });
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700151 }
152 }
153
Adrian Roose395b5d2017-06-28 16:52:37 +0200154 public void updateSessionActive() {
155 if (shouldSessionBeActive()) {
156 sessionEntrypoint();
157 } else {
158 sessionExitpoint(false /* force */);
159 }
160 }
161
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700162 private void onSessionStart() {
Adrian Roos401caae2016-03-04 13:35:21 -0800163 if (FalsingLog.ENABLED) {
164 FalsingLog.i("onSessionStart", "classifierEnabled=" + isClassiferEnabled());
Adrian Roos8e291a52016-12-09 16:10:19 -0800165 clearPendingWtf();
Adrian Roos401caae2016-03-04 13:35:21 -0800166 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700167 mBouncerOn = false;
168 mSessionActive = true;
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700169
170 if (mHumanInteractionClassifier.isEnabled()) {
171 registerSensors(CLASSIFIER_SENSORS);
172 }
Adrian Roos7bb38a92016-07-21 11:44:01 -0700173 if (mDataCollector.isEnabledFull()) {
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700174 registerSensors(COLLECTOR_SENSORS);
175 }
Selim Cinek1ed50042018-01-18 17:12:32 -0800176 if (mDataCollector.isEnabled()) {
177 mDataCollector.onFalsingSessionStarted();
178 }
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700179 }
180
181 private void registerSensors(int [] sensors) {
182 for (int sensorType : sensors) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700183 Sensor s = mSensorManager.getDefaultSensor(sensorType);
184 if (s != null) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200185
186 // This can be expensive, and doesn't need to happen on the main thread.
187 mUiOffloadThread.submit(() -> {
188 mSensorManager.registerListener(this, s, SensorManager.SENSOR_DELAY_GAME);
189 });
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700190 }
191 }
192 }
193
Blazej Magnowski6dc59b42015-09-22 15:14:20 -0700194 public boolean isClassiferEnabled() {
195 return mHumanInteractionClassifier.isEnabled();
196 }
197
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700198 private boolean isEnabled() {
199 return mHumanInteractionClassifier.isEnabled() || mDataCollector.isEnabled();
200 }
201
Dave Mankoffc88d6222018-10-25 15:31:20 -0400202 public boolean isUnlockingDisabled() {
203 return mDataCollector.isUnlockingDisabled();
204 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700205 /**
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700206 * @return true if the classifier determined that this is not a human interacting with the phone
207 */
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700208 public boolean isFalseTouch() {
Adrian Roos401caae2016-03-04 13:35:21 -0800209 if (FalsingLog.ENABLED) {
Adrian Roos6a04cb12016-03-14 20:21:02 -0700210 // We're getting some false wtfs from touches that happen after the device went
211 // to sleep. Only report missing sessions that happen when the device is interactive.
Adrian Roos8e291a52016-12-09 16:10:19 -0800212 if (!mSessionActive && mContext.getSystemService(PowerManager.class).isInteractive()
213 && mPendingWtf == null) {
214 int enabled = isEnabled() ? 1 : 0;
215 int screenOn = mScreenOn ? 1 : 0;
216 String state = StatusBarState.toShortString(mState);
217 Throwable here = new Throwable("here");
218 FalsingLog.wLogcat("isFalseTouch", new StringBuilder()
Adrian Roos401caae2016-03-04 13:35:21 -0800219 .append("Session is not active, yet there's a query for a false touch.")
Adrian Roos8e291a52016-12-09 16:10:19 -0800220 .append(" enabled=").append(enabled)
221 .append(" mScreenOn=").append(screenOn)
222 .append(" mState=").append(state)
223 .append(". Escalating to WTF if screen does not turn on soon.")
Adrian Roos401caae2016-03-04 13:35:21 -0800224 .toString());
Adrian Roos8e291a52016-12-09 16:10:19 -0800225
226 // Unfortunately we're also getting false positives for touches that happen right
227 // after the screen turns on, but before that notification has made it to us.
228 // Unfortunately there's no good way to catch that, except to wait and see if we get
229 // the screen on notification soon.
230 mPendingWtf = () -> FalsingLog.wtf("isFalseTouch", new StringBuilder()
231 .append("Session did not become active after query for a false touch.")
232 .append(" enabled=").append(enabled)
233 .append('/').append(isEnabled() ? 1 : 0)
234 .append(" mScreenOn=").append(screenOn)
235 .append('/').append(mScreenOn ? 1 : 0)
236 .append(" mState=").append(state)
237 .append('/').append(StatusBarState.toShortString(mState))
238 .append(". Look for warnings ~1000ms earlier to see root cause.")
239 .toString(), here);
240 mHandler.postDelayed(mPendingWtf, 1000);
Adrian Roos401caae2016-03-04 13:35:21 -0800241 }
242 }
Adrian Roosca664b92016-04-18 14:40:27 -0700243 if (mAccessibilityManager.isTouchExplorationEnabled()) {
244 // Touch exploration triggers false positives in the classifier and
245 // already sufficiently prevents false unlocks.
246 return false;
247 }
Adrian Roos004437e2017-08-16 11:58:02 +0200248 if (!mIsTouchScreen) {
249 // Unlocking with input devices besides the touchscreen should already be sufficiently
250 // anti-falsed.
251 return false;
252 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700253 return mHumanInteractionClassifier.isFalseTouch();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700254 }
255
Adrian Roos8e291a52016-12-09 16:10:19 -0800256 private void clearPendingWtf() {
257 if (mPendingWtf != null) {
258 mHandler.removeCallbacks(mPendingWtf);
259 mPendingWtf = null;
260 }
261 }
262
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700263 @Override
264 public synchronized void onSensorChanged(SensorEvent event) {
265 mDataCollector.onSensorChanged(event);
266 mHumanInteractionClassifier.onSensorChanged(event);
267 }
268
269 @Override
270 public void onAccuracyChanged(Sensor sensor, int accuracy) {
271 mDataCollector.onAccuracyChanged(sensor, accuracy);
272 }
273
274 public boolean shouldEnforceBouncer() {
275 return mEnforceBouncer;
276 }
277
Adrian Roose395b5d2017-06-28 16:52:37 +0200278 public void setShowingAod(boolean showingAod) {
279 mShowingAod = showingAod;
280 updateSessionActive();
281 }
282
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800283 @Override
284 public void onStateChanged(int newState) {
Adrian Roos401caae2016-03-04 13:35:21 -0800285 if (FalsingLog.ENABLED) {
286 FalsingLog.i("setStatusBarState", new StringBuilder()
287 .append("from=").append(StatusBarState.toShortString(mState))
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800288 .append(" to=").append(StatusBarState.toShortString(newState))
Adrian Roos401caae2016-03-04 13:35:21 -0800289 .toString());
290 }
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800291 mState = newState;
Adrian Roose395b5d2017-06-28 16:52:37 +0200292 updateSessionActive();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700293 }
294
295 public void onScreenTurningOn() {
Adrian Roos401caae2016-03-04 13:35:21 -0800296 if (FalsingLog.ENABLED) {
297 FalsingLog.i("onScreenTurningOn", new StringBuilder()
298 .append("from=").append(mScreenOn ? 1 : 0)
299 .toString());
Adrian Roos8e291a52016-12-09 16:10:19 -0800300 clearPendingWtf();
Adrian Roos401caae2016-03-04 13:35:21 -0800301 }
Adrian Roosc5584ce2016-02-24 14:17:19 -0800302 mScreenOn = true;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700303 if (sessionEntrypoint()) {
304 mDataCollector.onScreenTurningOn();
305 }
306 }
307
308 public void onScreenOnFromTouch() {
Adrian Roos401caae2016-03-04 13:35:21 -0800309 if (FalsingLog.ENABLED) {
310 FalsingLog.i("onScreenOnFromTouch", new StringBuilder()
311 .append("from=").append(mScreenOn ? 1 : 0)
312 .toString());
313 }
Adrian Roosc5584ce2016-02-24 14:17:19 -0800314 mScreenOn = true;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700315 if (sessionEntrypoint()) {
316 mDataCollector.onScreenOnFromTouch();
317 }
318 }
319
320 public void onScreenOff() {
Adrian Roos401caae2016-03-04 13:35:21 -0800321 if (FalsingLog.ENABLED) {
322 FalsingLog.i("onScreenOff", new StringBuilder()
323 .append("from=").append(mScreenOn ? 1 : 0)
324 .toString());
325 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700326 mDataCollector.onScreenOff();
Adrian Roosc5584ce2016-02-24 14:17:19 -0800327 mScreenOn = false;
328 sessionExitpoint(false /* force */);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700329 }
330
331 public void onSucccessfulUnlock() {
Adrian Roos401caae2016-03-04 13:35:21 -0800332 if (FalsingLog.ENABLED) {
333 FalsingLog.i("onSucccessfulUnlock", "");
334 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700335 mDataCollector.onSucccessfulUnlock();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700336 }
337
338 public void onBouncerShown() {
Adrian Roos401caae2016-03-04 13:35:21 -0800339 if (FalsingLog.ENABLED) {
340 FalsingLog.i("onBouncerShown", new StringBuilder()
341 .append("from=").append(mBouncerOn ? 1 : 0)
342 .toString());
343 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700344 if (!mBouncerOn) {
345 mBouncerOn = true;
346 mDataCollector.onBouncerShown();
347 }
348 }
349
350 public void onBouncerHidden() {
Adrian Roos401caae2016-03-04 13:35:21 -0800351 if (FalsingLog.ENABLED) {
352 FalsingLog.i("onBouncerHidden", new StringBuilder()
353 .append("from=").append(mBouncerOn ? 1 : 0)
354 .toString());
355 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700356 if (mBouncerOn) {
357 mBouncerOn = false;
358 mDataCollector.onBouncerHidden();
359 }
360 }
361
362 public void onQsDown() {
Adrian Roos401caae2016-03-04 13:35:21 -0800363 if (FalsingLog.ENABLED) {
364 FalsingLog.i("onQsDown", "");
365 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700366 mHumanInteractionClassifier.setType(Classifier.QUICK_SETTINGS);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700367 mDataCollector.onQsDown();
368 }
369
370 public void setQsExpanded(boolean expanded) {
371 mDataCollector.setQsExpanded(expanded);
372 }
373
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800374 public void onTrackingStarted(boolean secure) {
Adrian Roos401caae2016-03-04 13:35:21 -0800375 if (FalsingLog.ENABLED) {
376 FalsingLog.i("onTrackingStarted", "");
377 }
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800378 mHumanInteractionClassifier.setType(secure ?
379 Classifier.BOUNCER_UNLOCK : Classifier.UNLOCK);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700380 mDataCollector.onTrackingStarted();
381 }
382
383 public void onTrackingStopped() {
384 mDataCollector.onTrackingStopped();
385 }
386
387 public void onNotificationActive() {
388 mDataCollector.onNotificationActive();
389 }
390
Adrian Roos9f0b0022016-11-09 15:56:50 -0800391 public void onNotificationDoubleTap(boolean accepted, float dx, float dy) {
392 if (FalsingLog.ENABLED) {
393 FalsingLog.i("onNotificationDoubleTap", "accepted=" + accepted
394 + " dx=" + dx + " dy=" + dy + " (px)");
395 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700396 mDataCollector.onNotificationDoubleTap();
397 }
398
399 public void setNotificationExpanded() {
400 mDataCollector.setNotificationExpanded();
401 }
402
403 public void onNotificatonStartDraggingDown() {
Adrian Roos401caae2016-03-04 13:35:21 -0800404 if (FalsingLog.ENABLED) {
405 FalsingLog.i("onNotificatonStartDraggingDown", "");
406 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700407 mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DRAG_DOWN);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700408 mDataCollector.onNotificatonStartDraggingDown();
409 }
410
Selim Cinek3d6ae232019-01-04 14:14:33 -0800411 public void onStartExpandingFromPulse() {
412 if (FalsingLog.ENABLED) {
413 FalsingLog.i("onStartExpandingFromPulse", "");
414 }
415 mHumanInteractionClassifier.setType(Classifier.PULSE_EXPAND);
416 mDataCollector.onStartExpandingFromPulse();
417 }
418
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700419 public void onNotificatonStopDraggingDown() {
420 mDataCollector.onNotificatonStopDraggingDown();
421 }
422
Selim Cinek3d6ae232019-01-04 14:14:33 -0800423 public void onExpansionFromPulseStopped() {
424 mDataCollector.onExpansionFromPulseStopped();
425 }
426
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700427 public void onNotificationDismissed() {
428 mDataCollector.onNotificationDismissed();
429 }
430
431 public void onNotificatonStartDismissing() {
Adrian Roos401caae2016-03-04 13:35:21 -0800432 if (FalsingLog.ENABLED) {
433 FalsingLog.i("onNotificatonStartDismissing", "");
434 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700435 mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DISMISS);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700436 mDataCollector.onNotificatonStartDismissing();
437 }
438
439 public void onNotificatonStopDismissing() {
440 mDataCollector.onNotificatonStopDismissing();
441 }
442
443 public void onCameraOn() {
444 mDataCollector.onCameraOn();
445 }
446
447 public void onLeftAffordanceOn() {
448 mDataCollector.onLeftAffordanceOn();
449 }
450
451 public void onAffordanceSwipingStarted(boolean rightCorner) {
Adrian Roos401caae2016-03-04 13:35:21 -0800452 if (FalsingLog.ENABLED) {
453 FalsingLog.i("onAffordanceSwipingStarted", "");
454 }
Blazej Magnowski9f01c5b2015-09-17 15:14:29 -0700455 if (rightCorner) {
456 mHumanInteractionClassifier.setType(Classifier.RIGHT_AFFORDANCE);
457 } else {
458 mHumanInteractionClassifier.setType(Classifier.LEFT_AFFORDANCE);
459 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700460 mDataCollector.onAffordanceSwipingStarted(rightCorner);
461 }
462
463 public void onAffordanceSwipingAborted() {
464 mDataCollector.onAffordanceSwipingAborted();
465 }
466
467 public void onUnlockHintStarted() {
468 mDataCollector.onUnlockHintStarted();
469 }
470
471 public void onCameraHintStarted() {
472 mDataCollector.onCameraHintStarted();
473 }
474
475 public void onLeftAffordanceHintStarted() {
476 mDataCollector.onLeftAffordanceHintStarted();
477 }
478
479 public void onTouchEvent(MotionEvent event, int width, int height) {
Adrian Roos004437e2017-08-16 11:58:02 +0200480 if (event.getAction() == MotionEvent.ACTION_DOWN) {
481 mIsTouchScreen = event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN);
Siarhei Vishniakou81e1ffd2018-05-04 16:08:22 -0700482 // If the bouncer was not shown during the down event,
483 // we want the entire gesture going to HumanInteractionClassifier
484 mBouncerOffOnDown = !mBouncerOn;
Adrian Roos004437e2017-08-16 11:58:02 +0200485 }
Siarhei Vishniakou81e1ffd2018-05-04 16:08:22 -0700486 if (mSessionActive) {
487 if (!mBouncerOn) {
488 // In case bouncer is "visible", but onFullyShown has not yet been called,
489 // avoid adding the event to DataCollector
490 mDataCollector.onTouchEvent(event, width, height);
491 }
492 if (mBouncerOffOnDown) {
493 mHumanInteractionClassifier.onTouchEvent(event);
494 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700495 }
496 }
Adrian Roos401caae2016-03-04 13:35:21 -0800497
498 public void dump(PrintWriter pw) {
499 pw.println("FALSING MANAGER");
500 pw.print("classifierEnabled="); pw.println(isClassiferEnabled() ? 1 : 0);
501 pw.print("mSessionActive="); pw.println(mSessionActive ? 1 : 0);
502 pw.print("mBouncerOn="); pw.println(mSessionActive ? 1 : 0);
503 pw.print("mState="); pw.println(StatusBarState.toShortString(mState));
504 pw.print("mScreenOn="); pw.println(mScreenOn ? 1 : 0);
505 pw.println();
506 }
Adrian Roos7bb38a92016-07-21 11:44:01 -0700507
508 public Uri reportRejectedTouch() {
509 if (mDataCollector.isEnabled()) {
510 return mDataCollector.reportRejectedTouch();
511 }
512 return null;
513 }
514
515 public boolean isReportingEnabled() {
516 return mDataCollector.isReportingEnabled();
517 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700518}