Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.classifier; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.database.ContentObserver; |
| 21 | import android.hardware.Sensor; |
| 22 | import android.hardware.SensorEvent; |
| 23 | import android.hardware.SensorEventListener; |
| 24 | import android.hardware.SensorManager; |
Adrian Roos | 7bb38a9 | 2016-07-21 11:44:01 -0700 | [diff] [blame] | 25 | import android.net.Uri; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 26 | import android.os.Handler; |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 27 | import android.os.Looper; |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 28 | import android.os.PowerManager; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 29 | import android.os.UserHandle; |
| 30 | import android.provider.Settings; |
Adrian Roos | 004437e | 2017-08-16 11:58:02 +0200 | [diff] [blame] | 31 | import android.view.InputDevice; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 32 | import android.view.MotionEvent; |
Adrian Roos | ca664b9 | 2016-04-18 14:40:27 -0700 | [diff] [blame] | 33 | import android.view.accessibility.AccessibilityManager; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 34 | |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 35 | import com.android.systemui.Dependency; |
| 36 | import com.android.systemui.UiOffloadThread; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 37 | import com.android.systemui.analytics.DataCollector; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame^] | 38 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 39 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 40 | import com.android.systemui.statusbar.StatusBarState; |
Adrian Roos | 7a8ae8a | 2017-08-02 16:26:50 +0200 | [diff] [blame] | 41 | import com.android.systemui.util.AsyncSensorManager; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 42 | |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 43 | import java.io.PrintWriter; |
| 44 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 45 | /** |
| 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 Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 51 | public class FalsingManager implements SensorEventListener, StateListener { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 52 | private static final String ENFORCE_BOUNCER = "falsing_manager_enforce_bouncer"; |
| 53 | |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 54 | private static final int[] CLASSIFIER_SENSORS = new int[] { |
| 55 | Sensor.TYPE_PROXIMITY, |
| 56 | }; |
| 57 | |
| 58 | private static final int[] COLLECTOR_SENSORS = new int[] { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 59 | Sensor.TYPE_ACCELEROMETER, |
| 60 | Sensor.TYPE_GYROSCOPE, |
| 61 | Sensor.TYPE_PROXIMITY, |
| 62 | Sensor.TYPE_LIGHT, |
| 63 | Sensor.TYPE_ROTATION_VECTOR, |
| 64 | }; |
| 65 | |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 66 | private final Handler mHandler = new Handler(Looper.getMainLooper()); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 67 | private final Context mContext; |
| 68 | |
| 69 | private final SensorManager mSensorManager; |
| 70 | private final DataCollector mDataCollector; |
| 71 | private final HumanInteractionClassifier mHumanInteractionClassifier; |
Adrian Roos | ca664b9 | 2016-04-18 14:40:27 -0700 | [diff] [blame] | 72 | private final AccessibilityManager mAccessibilityManager; |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 73 | private final UiOffloadThread mUiOffloadThread; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 74 | |
| 75 | private static FalsingManager sInstance = null; |
| 76 | |
| 77 | private boolean mEnforceBouncer = false; |
| 78 | private boolean mBouncerOn = false; |
Siarhei Vishniakou | 81e1ffd | 2018-05-04 16:08:22 -0700 | [diff] [blame] | 79 | private boolean mBouncerOffOnDown = false; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 80 | private boolean mSessionActive = false; |
Adrian Roos | 004437e | 2017-08-16 11:58:02 +0200 | [diff] [blame] | 81 | private boolean mIsTouchScreen = true; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 82 | private int mState = StatusBarState.SHADE; |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 83 | private boolean mScreenOn; |
Adrian Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 84 | private boolean mShowingAod; |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 85 | private Runnable mPendingWtf; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 86 | |
| 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 Roos | 7a8ae8a | 2017-08-02 16:26:50 +0200 | [diff] [blame] | 96 | mSensorManager = Dependency.get(AsyncSensorManager.class); |
Adrian Roos | ca664b9 | 2016-04-18 14:40:27 -0700 | [diff] [blame] | 97 | mAccessibilityManager = context.getSystemService(AccessibilityManager.class); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 98 | mDataCollector = DataCollector.getInstance(mContext); |
| 99 | mHumanInteractionClassifier = HumanInteractionClassifier.getInstance(mContext); |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 100 | mUiOffloadThread = Dependency.get(UiOffloadThread.class); |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 101 | mScreenOn = context.getSystemService(PowerManager.class).isInteractive(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 102 | |
| 103 | mContext.getContentResolver().registerContentObserver( |
| 104 | Settings.Secure.getUriFor(ENFORCE_BOUNCER), false, |
| 105 | mSettingsObserver, |
| 106 | UserHandle.USER_ALL); |
| 107 | |
| 108 | updateConfiguration(); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 109 | Dependency.get(StatusBarStateController.class).addCallback(this); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 110 | } |
| 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 Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 124 | private boolean shouldSessionBeActive() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 125 | 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 Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 132 | return isEnabled() && mScreenOn && (mState == StatusBarState.KEYGUARD) && !mShowingAod; |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 135 | private boolean sessionEntrypoint() { |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 136 | if (!mSessionActive && shouldSessionBeActive()) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 137 | onSessionStart(); |
| 138 | return true; |
| 139 | } |
| 140 | return false; |
| 141 | } |
| 142 | |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 143 | private void sessionExitpoint(boolean force) { |
| 144 | if (mSessionActive && (force || !shouldSessionBeActive())) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 145 | mSessionActive = false; |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 146 | |
| 147 | // This can be expensive, and doesn't need to happen on the main thread. |
| 148 | mUiOffloadThread.submit(() -> { |
| 149 | mSensorManager.unregisterListener(this); |
| 150 | }); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Adrian Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 154 | public void updateSessionActive() { |
| 155 | if (shouldSessionBeActive()) { |
| 156 | sessionEntrypoint(); |
| 157 | } else { |
| 158 | sessionExitpoint(false /* force */); |
| 159 | } |
| 160 | } |
| 161 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 162 | private void onSessionStart() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 163 | if (FalsingLog.ENABLED) { |
| 164 | FalsingLog.i("onSessionStart", "classifierEnabled=" + isClassiferEnabled()); |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 165 | clearPendingWtf(); |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 166 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 167 | mBouncerOn = false; |
| 168 | mSessionActive = true; |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 169 | |
| 170 | if (mHumanInteractionClassifier.isEnabled()) { |
| 171 | registerSensors(CLASSIFIER_SENSORS); |
| 172 | } |
Adrian Roos | 7bb38a9 | 2016-07-21 11:44:01 -0700 | [diff] [blame] | 173 | if (mDataCollector.isEnabledFull()) { |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 174 | registerSensors(COLLECTOR_SENSORS); |
| 175 | } |
Selim Cinek | 1ed5004 | 2018-01-18 17:12:32 -0800 | [diff] [blame] | 176 | if (mDataCollector.isEnabled()) { |
| 177 | mDataCollector.onFalsingSessionStarted(); |
| 178 | } |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | private void registerSensors(int [] sensors) { |
| 182 | for (int sensorType : sensors) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 183 | Sensor s = mSensorManager.getDefaultSensor(sensorType); |
| 184 | if (s != null) { |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 185 | |
| 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 Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 194 | public boolean isClassiferEnabled() { |
| 195 | return mHumanInteractionClassifier.isEnabled(); |
| 196 | } |
| 197 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 198 | private boolean isEnabled() { |
| 199 | return mHumanInteractionClassifier.isEnabled() || mDataCollector.isEnabled(); |
| 200 | } |
| 201 | |
Dave Mankoff | c88d622 | 2018-10-25 15:31:20 -0400 | [diff] [blame] | 202 | public boolean isUnlockingDisabled() { |
| 203 | return mDataCollector.isUnlockingDisabled(); |
| 204 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 205 | /** |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 206 | * @return true if the classifier determined that this is not a human interacting with the phone |
| 207 | */ |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 208 | public boolean isFalseTouch() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 209 | if (FalsingLog.ENABLED) { |
Adrian Roos | 6a04cb1 | 2016-03-14 20:21:02 -0700 | [diff] [blame] | 210 | // 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 Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 212 | 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 Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 219 | .append("Session is not active, yet there's a query for a false touch.") |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 220 | .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 Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 224 | .toString()); |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 225 | |
| 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 Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 241 | } |
| 242 | } |
Adrian Roos | ca664b9 | 2016-04-18 14:40:27 -0700 | [diff] [blame] | 243 | if (mAccessibilityManager.isTouchExplorationEnabled()) { |
| 244 | // Touch exploration triggers false positives in the classifier and |
| 245 | // already sufficiently prevents false unlocks. |
| 246 | return false; |
| 247 | } |
Adrian Roos | 004437e | 2017-08-16 11:58:02 +0200 | [diff] [blame] | 248 | if (!mIsTouchScreen) { |
| 249 | // Unlocking with input devices besides the touchscreen should already be sufficiently |
| 250 | // anti-falsed. |
| 251 | return false; |
| 252 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 253 | return mHumanInteractionClassifier.isFalseTouch(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 256 | private void clearPendingWtf() { |
| 257 | if (mPendingWtf != null) { |
| 258 | mHandler.removeCallbacks(mPendingWtf); |
| 259 | mPendingWtf = null; |
| 260 | } |
| 261 | } |
| 262 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 263 | @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 Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 278 | public void setShowingAod(boolean showingAod) { |
| 279 | mShowingAod = showingAod; |
| 280 | updateSessionActive(); |
| 281 | } |
| 282 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 283 | @Override |
| 284 | public void onStateChanged(int newState) { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 285 | if (FalsingLog.ENABLED) { |
| 286 | FalsingLog.i("setStatusBarState", new StringBuilder() |
| 287 | .append("from=").append(StatusBarState.toShortString(mState)) |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 288 | .append(" to=").append(StatusBarState.toShortString(newState)) |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 289 | .toString()); |
| 290 | } |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 291 | mState = newState; |
Adrian Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 292 | updateSessionActive(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | public void onScreenTurningOn() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 296 | if (FalsingLog.ENABLED) { |
| 297 | FalsingLog.i("onScreenTurningOn", new StringBuilder() |
| 298 | .append("from=").append(mScreenOn ? 1 : 0) |
| 299 | .toString()); |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 300 | clearPendingWtf(); |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 301 | } |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 302 | mScreenOn = true; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 303 | if (sessionEntrypoint()) { |
| 304 | mDataCollector.onScreenTurningOn(); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | public void onScreenOnFromTouch() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 309 | if (FalsingLog.ENABLED) { |
| 310 | FalsingLog.i("onScreenOnFromTouch", new StringBuilder() |
| 311 | .append("from=").append(mScreenOn ? 1 : 0) |
| 312 | .toString()); |
| 313 | } |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 314 | mScreenOn = true; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 315 | if (sessionEntrypoint()) { |
| 316 | mDataCollector.onScreenOnFromTouch(); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | public void onScreenOff() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 321 | if (FalsingLog.ENABLED) { |
| 322 | FalsingLog.i("onScreenOff", new StringBuilder() |
| 323 | .append("from=").append(mScreenOn ? 1 : 0) |
| 324 | .toString()); |
| 325 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 326 | mDataCollector.onScreenOff(); |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 327 | mScreenOn = false; |
| 328 | sessionExitpoint(false /* force */); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | public void onSucccessfulUnlock() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 332 | if (FalsingLog.ENABLED) { |
| 333 | FalsingLog.i("onSucccessfulUnlock", ""); |
| 334 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 335 | mDataCollector.onSucccessfulUnlock(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | public void onBouncerShown() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 339 | if (FalsingLog.ENABLED) { |
| 340 | FalsingLog.i("onBouncerShown", new StringBuilder() |
| 341 | .append("from=").append(mBouncerOn ? 1 : 0) |
| 342 | .toString()); |
| 343 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 344 | if (!mBouncerOn) { |
| 345 | mBouncerOn = true; |
| 346 | mDataCollector.onBouncerShown(); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | public void onBouncerHidden() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 351 | if (FalsingLog.ENABLED) { |
| 352 | FalsingLog.i("onBouncerHidden", new StringBuilder() |
| 353 | .append("from=").append(mBouncerOn ? 1 : 0) |
| 354 | .toString()); |
| 355 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 356 | if (mBouncerOn) { |
| 357 | mBouncerOn = false; |
| 358 | mDataCollector.onBouncerHidden(); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | public void onQsDown() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 363 | if (FalsingLog.ENABLED) { |
| 364 | FalsingLog.i("onQsDown", ""); |
| 365 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 366 | mHumanInteractionClassifier.setType(Classifier.QUICK_SETTINGS); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 367 | mDataCollector.onQsDown(); |
| 368 | } |
| 369 | |
| 370 | public void setQsExpanded(boolean expanded) { |
| 371 | mDataCollector.setQsExpanded(expanded); |
| 372 | } |
| 373 | |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 374 | public void onTrackingStarted(boolean secure) { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 375 | if (FalsingLog.ENABLED) { |
| 376 | FalsingLog.i("onTrackingStarted", ""); |
| 377 | } |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 378 | mHumanInteractionClassifier.setType(secure ? |
| 379 | Classifier.BOUNCER_UNLOCK : Classifier.UNLOCK); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 380 | mDataCollector.onTrackingStarted(); |
| 381 | } |
| 382 | |
| 383 | public void onTrackingStopped() { |
| 384 | mDataCollector.onTrackingStopped(); |
| 385 | } |
| 386 | |
| 387 | public void onNotificationActive() { |
| 388 | mDataCollector.onNotificationActive(); |
| 389 | } |
| 390 | |
Adrian Roos | 9f0b002 | 2016-11-09 15:56:50 -0800 | [diff] [blame] | 391 | 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 Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 396 | mDataCollector.onNotificationDoubleTap(); |
| 397 | } |
| 398 | |
| 399 | public void setNotificationExpanded() { |
| 400 | mDataCollector.setNotificationExpanded(); |
| 401 | } |
| 402 | |
| 403 | public void onNotificatonStartDraggingDown() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 404 | if (FalsingLog.ENABLED) { |
| 405 | FalsingLog.i("onNotificatonStartDraggingDown", ""); |
| 406 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 407 | mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DRAG_DOWN); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 408 | mDataCollector.onNotificatonStartDraggingDown(); |
| 409 | } |
| 410 | |
| 411 | public void onNotificatonStopDraggingDown() { |
| 412 | mDataCollector.onNotificatonStopDraggingDown(); |
| 413 | } |
| 414 | |
| 415 | public void onNotificationDismissed() { |
| 416 | mDataCollector.onNotificationDismissed(); |
| 417 | } |
| 418 | |
| 419 | public void onNotificatonStartDismissing() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 420 | if (FalsingLog.ENABLED) { |
| 421 | FalsingLog.i("onNotificatonStartDismissing", ""); |
| 422 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 423 | mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DISMISS); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 424 | mDataCollector.onNotificatonStartDismissing(); |
| 425 | } |
| 426 | |
| 427 | public void onNotificatonStopDismissing() { |
| 428 | mDataCollector.onNotificatonStopDismissing(); |
| 429 | } |
| 430 | |
| 431 | public void onCameraOn() { |
| 432 | mDataCollector.onCameraOn(); |
| 433 | } |
| 434 | |
| 435 | public void onLeftAffordanceOn() { |
| 436 | mDataCollector.onLeftAffordanceOn(); |
| 437 | } |
| 438 | |
| 439 | public void onAffordanceSwipingStarted(boolean rightCorner) { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 440 | if (FalsingLog.ENABLED) { |
| 441 | FalsingLog.i("onAffordanceSwipingStarted", ""); |
| 442 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 443 | if (rightCorner) { |
| 444 | mHumanInteractionClassifier.setType(Classifier.RIGHT_AFFORDANCE); |
| 445 | } else { |
| 446 | mHumanInteractionClassifier.setType(Classifier.LEFT_AFFORDANCE); |
| 447 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 448 | mDataCollector.onAffordanceSwipingStarted(rightCorner); |
| 449 | } |
| 450 | |
| 451 | public void onAffordanceSwipingAborted() { |
| 452 | mDataCollector.onAffordanceSwipingAborted(); |
| 453 | } |
| 454 | |
| 455 | public void onUnlockHintStarted() { |
| 456 | mDataCollector.onUnlockHintStarted(); |
| 457 | } |
| 458 | |
| 459 | public void onCameraHintStarted() { |
| 460 | mDataCollector.onCameraHintStarted(); |
| 461 | } |
| 462 | |
| 463 | public void onLeftAffordanceHintStarted() { |
| 464 | mDataCollector.onLeftAffordanceHintStarted(); |
| 465 | } |
| 466 | |
| 467 | public void onTouchEvent(MotionEvent event, int width, int height) { |
Adrian Roos | 004437e | 2017-08-16 11:58:02 +0200 | [diff] [blame] | 468 | if (event.getAction() == MotionEvent.ACTION_DOWN) { |
| 469 | mIsTouchScreen = event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN); |
Siarhei Vishniakou | 81e1ffd | 2018-05-04 16:08:22 -0700 | [diff] [blame] | 470 | // If the bouncer was not shown during the down event, |
| 471 | // we want the entire gesture going to HumanInteractionClassifier |
| 472 | mBouncerOffOnDown = !mBouncerOn; |
Adrian Roos | 004437e | 2017-08-16 11:58:02 +0200 | [diff] [blame] | 473 | } |
Siarhei Vishniakou | 81e1ffd | 2018-05-04 16:08:22 -0700 | [diff] [blame] | 474 | if (mSessionActive) { |
| 475 | if (!mBouncerOn) { |
| 476 | // In case bouncer is "visible", but onFullyShown has not yet been called, |
| 477 | // avoid adding the event to DataCollector |
| 478 | mDataCollector.onTouchEvent(event, width, height); |
| 479 | } |
| 480 | if (mBouncerOffOnDown) { |
| 481 | mHumanInteractionClassifier.onTouchEvent(event); |
| 482 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 483 | } |
| 484 | } |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 485 | |
| 486 | public void dump(PrintWriter pw) { |
| 487 | pw.println("FALSING MANAGER"); |
| 488 | pw.print("classifierEnabled="); pw.println(isClassiferEnabled() ? 1 : 0); |
| 489 | pw.print("mSessionActive="); pw.println(mSessionActive ? 1 : 0); |
| 490 | pw.print("mBouncerOn="); pw.println(mSessionActive ? 1 : 0); |
| 491 | pw.print("mState="); pw.println(StatusBarState.toShortString(mState)); |
| 492 | pw.print("mScreenOn="); pw.println(mScreenOn ? 1 : 0); |
| 493 | pw.println(); |
| 494 | } |
Adrian Roos | 7bb38a9 | 2016-07-21 11:44:01 -0700 | [diff] [blame] | 495 | |
| 496 | public Uri reportRejectedTouch() { |
| 497 | if (mDataCollector.isEnabled()) { |
| 498 | return mDataCollector.reportRejectedTouch(); |
| 499 | } |
| 500 | return null; |
| 501 | } |
| 502 | |
| 503 | public boolean isReportingEnabled() { |
| 504 | return mDataCollector.isReportingEnabled(); |
| 505 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 506 | } |