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; |
| 38 | import com.android.systemui.statusbar.StatusBarState; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 39 | import com.android.systemui.statusbar.StatusBarStateController; |
| 40 | import com.android.systemui.statusbar.StatusBarStateController.StateListener; |
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 | */ |
| 51 | public class FalsingManager implements SensorEventListener { |
| 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 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 87 | private final StateListener mStateListener = this::setStatusBarState; |
| 88 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 89 | 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 Roos | 7a8ae8a | 2017-08-02 16:26:50 +0200 | [diff] [blame] | 98 | mSensorManager = Dependency.get(AsyncSensorManager.class); |
Adrian Roos | ca664b9 | 2016-04-18 14:40:27 -0700 | [diff] [blame] | 99 | mAccessibilityManager = context.getSystemService(AccessibilityManager.class); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 100 | mDataCollector = DataCollector.getInstance(mContext); |
| 101 | mHumanInteractionClassifier = HumanInteractionClassifier.getInstance(mContext); |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 102 | mUiOffloadThread = Dependency.get(UiOffloadThread.class); |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 103 | mScreenOn = context.getSystemService(PowerManager.class).isInteractive(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 104 | |
| 105 | mContext.getContentResolver().registerContentObserver( |
| 106 | Settings.Secure.getUriFor(ENFORCE_BOUNCER), false, |
| 107 | mSettingsObserver, |
| 108 | UserHandle.USER_ALL); |
| 109 | |
| 110 | updateConfiguration(); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 111 | Dependency.get(StatusBarStateController.class).addListener(mStateListener); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 112 | } |
| 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 Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 126 | private boolean shouldSessionBeActive() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 127 | 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 Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 134 | return isEnabled() && mScreenOn && (mState == StatusBarState.KEYGUARD) && !mShowingAod; |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 137 | private boolean sessionEntrypoint() { |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 138 | if (!mSessionActive && shouldSessionBeActive()) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 139 | onSessionStart(); |
| 140 | return true; |
| 141 | } |
| 142 | return false; |
| 143 | } |
| 144 | |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 145 | private void sessionExitpoint(boolean force) { |
| 146 | if (mSessionActive && (force || !shouldSessionBeActive())) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 147 | mSessionActive = false; |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 148 | |
| 149 | // This can be expensive, and doesn't need to happen on the main thread. |
| 150 | mUiOffloadThread.submit(() -> { |
| 151 | mSensorManager.unregisterListener(this); |
| 152 | }); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
Adrian Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 156 | public void updateSessionActive() { |
| 157 | if (shouldSessionBeActive()) { |
| 158 | sessionEntrypoint(); |
| 159 | } else { |
| 160 | sessionExitpoint(false /* force */); |
| 161 | } |
| 162 | } |
| 163 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 164 | private void onSessionStart() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 165 | if (FalsingLog.ENABLED) { |
| 166 | FalsingLog.i("onSessionStart", "classifierEnabled=" + isClassiferEnabled()); |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 167 | clearPendingWtf(); |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 168 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 169 | mBouncerOn = false; |
| 170 | mSessionActive = true; |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 171 | |
| 172 | if (mHumanInteractionClassifier.isEnabled()) { |
| 173 | registerSensors(CLASSIFIER_SENSORS); |
| 174 | } |
Adrian Roos | 7bb38a9 | 2016-07-21 11:44:01 -0700 | [diff] [blame] | 175 | if (mDataCollector.isEnabledFull()) { |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 176 | registerSensors(COLLECTOR_SENSORS); |
| 177 | } |
Selim Cinek | 1ed5004 | 2018-01-18 17:12:32 -0800 | [diff] [blame] | 178 | if (mDataCollector.isEnabled()) { |
| 179 | mDataCollector.onFalsingSessionStarted(); |
| 180 | } |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | private void registerSensors(int [] sensors) { |
| 184 | for (int sensorType : sensors) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 185 | Sensor s = mSensorManager.getDefaultSensor(sensorType); |
| 186 | if (s != null) { |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 187 | |
| 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 Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 196 | public boolean isClassiferEnabled() { |
| 197 | return mHumanInteractionClassifier.isEnabled(); |
| 198 | } |
| 199 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 200 | private boolean isEnabled() { |
| 201 | return mHumanInteractionClassifier.isEnabled() || mDataCollector.isEnabled(); |
| 202 | } |
| 203 | |
Dave Mankoff | c88d622 | 2018-10-25 15:31:20 -0400 | [diff] [blame^] | 204 | public boolean isUnlockingDisabled() { |
| 205 | return mDataCollector.isUnlockingDisabled(); |
| 206 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 207 | /** |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 208 | * @return true if the classifier determined that this is not a human interacting with the phone |
| 209 | */ |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 210 | public boolean isFalseTouch() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 211 | if (FalsingLog.ENABLED) { |
Adrian Roos | 6a04cb1 | 2016-03-14 20:21:02 -0700 | [diff] [blame] | 212 | // 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 Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 214 | 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 Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 221 | .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] | 222 | .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 Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 226 | .toString()); |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 227 | |
| 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 Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 243 | } |
| 244 | } |
Adrian Roos | ca664b9 | 2016-04-18 14:40:27 -0700 | [diff] [blame] | 245 | if (mAccessibilityManager.isTouchExplorationEnabled()) { |
| 246 | // Touch exploration triggers false positives in the classifier and |
| 247 | // already sufficiently prevents false unlocks. |
| 248 | return false; |
| 249 | } |
Adrian Roos | 004437e | 2017-08-16 11:58:02 +0200 | [diff] [blame] | 250 | if (!mIsTouchScreen) { |
| 251 | // Unlocking with input devices besides the touchscreen should already be sufficiently |
| 252 | // anti-falsed. |
| 253 | return false; |
| 254 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 255 | return mHumanInteractionClassifier.isFalseTouch(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 258 | private void clearPendingWtf() { |
| 259 | if (mPendingWtf != null) { |
| 260 | mHandler.removeCallbacks(mPendingWtf); |
| 261 | mPendingWtf = null; |
| 262 | } |
| 263 | } |
| 264 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 265 | @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 Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 280 | public void setShowingAod(boolean showingAod) { |
| 281 | mShowingAod = showingAod; |
| 282 | updateSessionActive(); |
| 283 | } |
| 284 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 285 | private void setStatusBarState(int state) { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 286 | 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 Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 292 | mState = state; |
Adrian Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 293 | updateSessionActive(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | public void onScreenTurningOn() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 297 | if (FalsingLog.ENABLED) { |
| 298 | FalsingLog.i("onScreenTurningOn", new StringBuilder() |
| 299 | .append("from=").append(mScreenOn ? 1 : 0) |
| 300 | .toString()); |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 301 | clearPendingWtf(); |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 302 | } |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 303 | mScreenOn = true; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 304 | if (sessionEntrypoint()) { |
| 305 | mDataCollector.onScreenTurningOn(); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | public void onScreenOnFromTouch() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 310 | if (FalsingLog.ENABLED) { |
| 311 | FalsingLog.i("onScreenOnFromTouch", new StringBuilder() |
| 312 | .append("from=").append(mScreenOn ? 1 : 0) |
| 313 | .toString()); |
| 314 | } |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 315 | mScreenOn = true; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 316 | if (sessionEntrypoint()) { |
| 317 | mDataCollector.onScreenOnFromTouch(); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | public void onScreenOff() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 322 | if (FalsingLog.ENABLED) { |
| 323 | FalsingLog.i("onScreenOff", new StringBuilder() |
| 324 | .append("from=").append(mScreenOn ? 1 : 0) |
| 325 | .toString()); |
| 326 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 327 | mDataCollector.onScreenOff(); |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 328 | mScreenOn = false; |
| 329 | sessionExitpoint(false /* force */); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | public void onSucccessfulUnlock() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 333 | if (FalsingLog.ENABLED) { |
| 334 | FalsingLog.i("onSucccessfulUnlock", ""); |
| 335 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 336 | mDataCollector.onSucccessfulUnlock(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | public void onBouncerShown() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 340 | if (FalsingLog.ENABLED) { |
| 341 | FalsingLog.i("onBouncerShown", new StringBuilder() |
| 342 | .append("from=").append(mBouncerOn ? 1 : 0) |
| 343 | .toString()); |
| 344 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 345 | if (!mBouncerOn) { |
| 346 | mBouncerOn = true; |
| 347 | mDataCollector.onBouncerShown(); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | public void onBouncerHidden() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 352 | if (FalsingLog.ENABLED) { |
| 353 | FalsingLog.i("onBouncerHidden", new StringBuilder() |
| 354 | .append("from=").append(mBouncerOn ? 1 : 0) |
| 355 | .toString()); |
| 356 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 357 | if (mBouncerOn) { |
| 358 | mBouncerOn = false; |
| 359 | mDataCollector.onBouncerHidden(); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | public void onQsDown() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 364 | if (FalsingLog.ENABLED) { |
| 365 | FalsingLog.i("onQsDown", ""); |
| 366 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 367 | mHumanInteractionClassifier.setType(Classifier.QUICK_SETTINGS); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 368 | mDataCollector.onQsDown(); |
| 369 | } |
| 370 | |
| 371 | public void setQsExpanded(boolean expanded) { |
| 372 | mDataCollector.setQsExpanded(expanded); |
| 373 | } |
| 374 | |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 375 | public void onTrackingStarted(boolean secure) { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 376 | if (FalsingLog.ENABLED) { |
| 377 | FalsingLog.i("onTrackingStarted", ""); |
| 378 | } |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 379 | mHumanInteractionClassifier.setType(secure ? |
| 380 | Classifier.BOUNCER_UNLOCK : Classifier.UNLOCK); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 381 | mDataCollector.onTrackingStarted(); |
| 382 | } |
| 383 | |
| 384 | public void onTrackingStopped() { |
| 385 | mDataCollector.onTrackingStopped(); |
| 386 | } |
| 387 | |
| 388 | public void onNotificationActive() { |
| 389 | mDataCollector.onNotificationActive(); |
| 390 | } |
| 391 | |
Adrian Roos | 9f0b002 | 2016-11-09 15:56:50 -0800 | [diff] [blame] | 392 | 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 Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 397 | mDataCollector.onNotificationDoubleTap(); |
| 398 | } |
| 399 | |
| 400 | public void setNotificationExpanded() { |
| 401 | mDataCollector.setNotificationExpanded(); |
| 402 | } |
| 403 | |
| 404 | public void onNotificatonStartDraggingDown() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 405 | if (FalsingLog.ENABLED) { |
| 406 | FalsingLog.i("onNotificatonStartDraggingDown", ""); |
| 407 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 408 | mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DRAG_DOWN); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 409 | 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 Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 421 | if (FalsingLog.ENABLED) { |
| 422 | FalsingLog.i("onNotificatonStartDismissing", ""); |
| 423 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 424 | mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DISMISS); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 425 | 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 Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 441 | if (FalsingLog.ENABLED) { |
| 442 | FalsingLog.i("onAffordanceSwipingStarted", ""); |
| 443 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 444 | if (rightCorner) { |
| 445 | mHumanInteractionClassifier.setType(Classifier.RIGHT_AFFORDANCE); |
| 446 | } else { |
| 447 | mHumanInteractionClassifier.setType(Classifier.LEFT_AFFORDANCE); |
| 448 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 449 | 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 Roos | 004437e | 2017-08-16 11:58:02 +0200 | [diff] [blame] | 469 | if (event.getAction() == MotionEvent.ACTION_DOWN) { |
| 470 | mIsTouchScreen = event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN); |
Siarhei Vishniakou | 81e1ffd | 2018-05-04 16:08:22 -0700 | [diff] [blame] | 471 | // If the bouncer was not shown during the down event, |
| 472 | // we want the entire gesture going to HumanInteractionClassifier |
| 473 | mBouncerOffOnDown = !mBouncerOn; |
Adrian Roos | 004437e | 2017-08-16 11:58:02 +0200 | [diff] [blame] | 474 | } |
Siarhei Vishniakou | 81e1ffd | 2018-05-04 16:08:22 -0700 | [diff] [blame] | 475 | 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 Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 484 | } |
| 485 | } |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 486 | |
| 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 Roos | 7bb38a9 | 2016-07-21 11:44:01 -0700 | [diff] [blame] | 496 | |
| 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 Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 507 | } |