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; |
Adrian Roos | 7a8ae8a | 2017-08-02 16:26:50 +0200 | [diff] [blame] | 39 | import com.android.systemui.util.AsyncSensorManager; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 40 | |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 41 | import java.io.PrintWriter; |
| 42 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 43 | /** |
| 44 | * When the phone is locked, listens to touch, sensor and phone events and sends them to |
| 45 | * DataCollector and HumanInteractionClassifier. |
| 46 | * |
| 47 | * It does not collect touch events when the bouncer shows up. |
| 48 | */ |
| 49 | public class FalsingManager implements SensorEventListener { |
| 50 | private static final String ENFORCE_BOUNCER = "falsing_manager_enforce_bouncer"; |
| 51 | |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 52 | private static final int[] CLASSIFIER_SENSORS = new int[] { |
| 53 | Sensor.TYPE_PROXIMITY, |
| 54 | }; |
| 55 | |
| 56 | private static final int[] COLLECTOR_SENSORS = new int[] { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 57 | Sensor.TYPE_ACCELEROMETER, |
| 58 | Sensor.TYPE_GYROSCOPE, |
| 59 | Sensor.TYPE_PROXIMITY, |
| 60 | Sensor.TYPE_LIGHT, |
| 61 | Sensor.TYPE_ROTATION_VECTOR, |
| 62 | }; |
| 63 | |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 64 | private final Handler mHandler = new Handler(Looper.getMainLooper()); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 65 | private final Context mContext; |
| 66 | |
| 67 | private final SensorManager mSensorManager; |
| 68 | private final DataCollector mDataCollector; |
| 69 | private final HumanInteractionClassifier mHumanInteractionClassifier; |
Adrian Roos | ca664b9 | 2016-04-18 14:40:27 -0700 | [diff] [blame] | 70 | private final AccessibilityManager mAccessibilityManager; |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 71 | private final UiOffloadThread mUiOffloadThread; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 72 | |
| 73 | private static FalsingManager sInstance = null; |
| 74 | |
| 75 | private boolean mEnforceBouncer = false; |
| 76 | private boolean mBouncerOn = false; |
| 77 | private boolean mSessionActive = false; |
Adrian Roos | 004437e | 2017-08-16 11:58:02 +0200 | [diff] [blame] | 78 | private boolean mIsTouchScreen = true; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 79 | private int mState = StatusBarState.SHADE; |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 80 | private boolean mScreenOn; |
Adrian Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 81 | private boolean mShowingAod; |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 82 | private Runnable mPendingWtf; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 83 | |
| 84 | protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) { |
| 85 | @Override |
| 86 | public void onChange(boolean selfChange) { |
| 87 | updateConfiguration(); |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | private FalsingManager(Context context) { |
| 92 | mContext = context; |
Adrian Roos | 7a8ae8a | 2017-08-02 16:26:50 +0200 | [diff] [blame] | 93 | mSensorManager = Dependency.get(AsyncSensorManager.class); |
Adrian Roos | ca664b9 | 2016-04-18 14:40:27 -0700 | [diff] [blame] | 94 | mAccessibilityManager = context.getSystemService(AccessibilityManager.class); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 95 | mDataCollector = DataCollector.getInstance(mContext); |
| 96 | mHumanInteractionClassifier = HumanInteractionClassifier.getInstance(mContext); |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 97 | mUiOffloadThread = Dependency.get(UiOffloadThread.class); |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 98 | mScreenOn = context.getSystemService(PowerManager.class).isInteractive(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 99 | |
| 100 | mContext.getContentResolver().registerContentObserver( |
| 101 | Settings.Secure.getUriFor(ENFORCE_BOUNCER), false, |
| 102 | mSettingsObserver, |
| 103 | UserHandle.USER_ALL); |
| 104 | |
| 105 | updateConfiguration(); |
| 106 | } |
| 107 | |
| 108 | public static FalsingManager getInstance(Context context) { |
| 109 | if (sInstance == null) { |
| 110 | sInstance = new FalsingManager(context); |
| 111 | } |
| 112 | return sInstance; |
| 113 | } |
| 114 | |
| 115 | private void updateConfiguration() { |
| 116 | mEnforceBouncer = 0 != Settings.Secure.getInt(mContext.getContentResolver(), |
| 117 | ENFORCE_BOUNCER, 0); |
| 118 | } |
| 119 | |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 120 | private boolean shouldSessionBeActive() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 121 | if (FalsingLog.ENABLED && FalsingLog.VERBOSE) |
| 122 | FalsingLog.v("shouldBeActive", new StringBuilder() |
| 123 | .append("enabled=").append(isEnabled() ? 1 : 0) |
| 124 | .append(" mScreenOn=").append(mScreenOn ? 1 : 0) |
| 125 | .append(" mState=").append(StatusBarState.toShortString(mState)) |
| 126 | .toString() |
| 127 | ); |
Adrian Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 128 | return isEnabled() && mScreenOn && (mState == StatusBarState.KEYGUARD) && !mShowingAod; |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 131 | private boolean sessionEntrypoint() { |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 132 | if (!mSessionActive && shouldSessionBeActive()) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 133 | onSessionStart(); |
| 134 | return true; |
| 135 | } |
| 136 | return false; |
| 137 | } |
| 138 | |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 139 | private void sessionExitpoint(boolean force) { |
| 140 | if (mSessionActive && (force || !shouldSessionBeActive())) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 141 | mSessionActive = false; |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 142 | |
| 143 | // This can be expensive, and doesn't need to happen on the main thread. |
| 144 | mUiOffloadThread.submit(() -> { |
| 145 | mSensorManager.unregisterListener(this); |
| 146 | }); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
Adrian Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 150 | public void updateSessionActive() { |
| 151 | if (shouldSessionBeActive()) { |
| 152 | sessionEntrypoint(); |
| 153 | } else { |
| 154 | sessionExitpoint(false /* force */); |
| 155 | } |
| 156 | } |
| 157 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 158 | private void onSessionStart() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 159 | if (FalsingLog.ENABLED) { |
| 160 | FalsingLog.i("onSessionStart", "classifierEnabled=" + isClassiferEnabled()); |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 161 | clearPendingWtf(); |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 162 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 163 | mBouncerOn = false; |
| 164 | mSessionActive = true; |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 165 | |
| 166 | if (mHumanInteractionClassifier.isEnabled()) { |
| 167 | registerSensors(CLASSIFIER_SENSORS); |
| 168 | } |
Adrian Roos | 7bb38a9 | 2016-07-21 11:44:01 -0700 | [diff] [blame] | 169 | if (mDataCollector.isEnabledFull()) { |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 170 | registerSensors(COLLECTOR_SENSORS); |
| 171 | } |
Selim Cinek | 1ed5004 | 2018-01-18 17:12:32 -0800 | [diff] [blame] | 172 | if (mDataCollector.isEnabled()) { |
| 173 | mDataCollector.onFalsingSessionStarted(); |
| 174 | } |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | private void registerSensors(int [] sensors) { |
| 178 | for (int sensorType : sensors) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 179 | Sensor s = mSensorManager.getDefaultSensor(sensorType); |
| 180 | if (s != null) { |
Jorim Jaggi | e549a8d | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 181 | |
| 182 | // This can be expensive, and doesn't need to happen on the main thread. |
| 183 | mUiOffloadThread.submit(() -> { |
| 184 | mSensorManager.registerListener(this, s, SensorManager.SENSOR_DELAY_GAME); |
| 185 | }); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
Blazej Magnowski | 6dc59b4 | 2015-09-22 15:14:20 -0700 | [diff] [blame] | 190 | public boolean isClassiferEnabled() { |
| 191 | return mHumanInteractionClassifier.isEnabled(); |
| 192 | } |
| 193 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 194 | private boolean isEnabled() { |
| 195 | return mHumanInteractionClassifier.isEnabled() || mDataCollector.isEnabled(); |
| 196 | } |
| 197 | |
| 198 | /** |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 199 | * @return true if the classifier determined that this is not a human interacting with the phone |
| 200 | */ |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 201 | public boolean isFalseTouch() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 202 | if (FalsingLog.ENABLED) { |
Adrian Roos | 6a04cb1 | 2016-03-14 20:21:02 -0700 | [diff] [blame] | 203 | // We're getting some false wtfs from touches that happen after the device went |
| 204 | // 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] | 205 | if (!mSessionActive && mContext.getSystemService(PowerManager.class).isInteractive() |
| 206 | && mPendingWtf == null) { |
| 207 | int enabled = isEnabled() ? 1 : 0; |
| 208 | int screenOn = mScreenOn ? 1 : 0; |
| 209 | String state = StatusBarState.toShortString(mState); |
| 210 | Throwable here = new Throwable("here"); |
| 211 | FalsingLog.wLogcat("isFalseTouch", new StringBuilder() |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 212 | .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] | 213 | .append(" enabled=").append(enabled) |
| 214 | .append(" mScreenOn=").append(screenOn) |
| 215 | .append(" mState=").append(state) |
| 216 | .append(". Escalating to WTF if screen does not turn on soon.") |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 217 | .toString()); |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 218 | |
| 219 | // Unfortunately we're also getting false positives for touches that happen right |
| 220 | // after the screen turns on, but before that notification has made it to us. |
| 221 | // Unfortunately there's no good way to catch that, except to wait and see if we get |
| 222 | // the screen on notification soon. |
| 223 | mPendingWtf = () -> FalsingLog.wtf("isFalseTouch", new StringBuilder() |
| 224 | .append("Session did not become active after query for a false touch.") |
| 225 | .append(" enabled=").append(enabled) |
| 226 | .append('/').append(isEnabled() ? 1 : 0) |
| 227 | .append(" mScreenOn=").append(screenOn) |
| 228 | .append('/').append(mScreenOn ? 1 : 0) |
| 229 | .append(" mState=").append(state) |
| 230 | .append('/').append(StatusBarState.toShortString(mState)) |
| 231 | .append(". Look for warnings ~1000ms earlier to see root cause.") |
| 232 | .toString(), here); |
| 233 | mHandler.postDelayed(mPendingWtf, 1000); |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 234 | } |
| 235 | } |
Adrian Roos | ca664b9 | 2016-04-18 14:40:27 -0700 | [diff] [blame] | 236 | if (mAccessibilityManager.isTouchExplorationEnabled()) { |
| 237 | // Touch exploration triggers false positives in the classifier and |
| 238 | // already sufficiently prevents false unlocks. |
| 239 | return false; |
| 240 | } |
Adrian Roos | 004437e | 2017-08-16 11:58:02 +0200 | [diff] [blame] | 241 | if (!mIsTouchScreen) { |
| 242 | // Unlocking with input devices besides the touchscreen should already be sufficiently |
| 243 | // anti-falsed. |
| 244 | return false; |
| 245 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 246 | return mHumanInteractionClassifier.isFalseTouch(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 249 | private void clearPendingWtf() { |
| 250 | if (mPendingWtf != null) { |
| 251 | mHandler.removeCallbacks(mPendingWtf); |
| 252 | mPendingWtf = null; |
| 253 | } |
| 254 | } |
| 255 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 256 | @Override |
| 257 | public synchronized void onSensorChanged(SensorEvent event) { |
| 258 | mDataCollector.onSensorChanged(event); |
| 259 | mHumanInteractionClassifier.onSensorChanged(event); |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public void onAccuracyChanged(Sensor sensor, int accuracy) { |
| 264 | mDataCollector.onAccuracyChanged(sensor, accuracy); |
| 265 | } |
| 266 | |
| 267 | public boolean shouldEnforceBouncer() { |
| 268 | return mEnforceBouncer; |
| 269 | } |
| 270 | |
Adrian Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 271 | public void setShowingAod(boolean showingAod) { |
| 272 | mShowingAod = showingAod; |
| 273 | updateSessionActive(); |
| 274 | } |
| 275 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 276 | public void setStatusBarState(int state) { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 277 | if (FalsingLog.ENABLED) { |
| 278 | FalsingLog.i("setStatusBarState", new StringBuilder() |
| 279 | .append("from=").append(StatusBarState.toShortString(mState)) |
| 280 | .append(" to=").append(StatusBarState.toShortString(state)) |
| 281 | .toString()); |
| 282 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 283 | mState = state; |
Adrian Roos | e395b5d | 2017-06-28 16:52:37 +0200 | [diff] [blame] | 284 | updateSessionActive(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | public void onScreenTurningOn() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 288 | if (FalsingLog.ENABLED) { |
| 289 | FalsingLog.i("onScreenTurningOn", new StringBuilder() |
| 290 | .append("from=").append(mScreenOn ? 1 : 0) |
| 291 | .toString()); |
Adrian Roos | 8e291a5 | 2016-12-09 16:10:19 -0800 | [diff] [blame] | 292 | clearPendingWtf(); |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 293 | } |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 294 | mScreenOn = true; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 295 | if (sessionEntrypoint()) { |
| 296 | mDataCollector.onScreenTurningOn(); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | public void onScreenOnFromTouch() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 301 | if (FalsingLog.ENABLED) { |
| 302 | FalsingLog.i("onScreenOnFromTouch", new StringBuilder() |
| 303 | .append("from=").append(mScreenOn ? 1 : 0) |
| 304 | .toString()); |
| 305 | } |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 306 | mScreenOn = true; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 307 | if (sessionEntrypoint()) { |
| 308 | mDataCollector.onScreenOnFromTouch(); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | public void onScreenOff() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 313 | if (FalsingLog.ENABLED) { |
| 314 | FalsingLog.i("onScreenOff", new StringBuilder() |
| 315 | .append("from=").append(mScreenOn ? 1 : 0) |
| 316 | .toString()); |
| 317 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 318 | mDataCollector.onScreenOff(); |
Adrian Roos | c5584ce | 2016-02-24 14:17:19 -0800 | [diff] [blame] | 319 | mScreenOn = false; |
| 320 | sessionExitpoint(false /* force */); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | public void onSucccessfulUnlock() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 324 | if (FalsingLog.ENABLED) { |
| 325 | FalsingLog.i("onSucccessfulUnlock", ""); |
| 326 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 327 | mDataCollector.onSucccessfulUnlock(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | public void onBouncerShown() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 331 | if (FalsingLog.ENABLED) { |
| 332 | FalsingLog.i("onBouncerShown", new StringBuilder() |
| 333 | .append("from=").append(mBouncerOn ? 1 : 0) |
| 334 | .toString()); |
| 335 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 336 | if (!mBouncerOn) { |
| 337 | mBouncerOn = true; |
| 338 | mDataCollector.onBouncerShown(); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | public void onBouncerHidden() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 343 | if (FalsingLog.ENABLED) { |
| 344 | FalsingLog.i("onBouncerHidden", new StringBuilder() |
| 345 | .append("from=").append(mBouncerOn ? 1 : 0) |
| 346 | .toString()); |
| 347 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 348 | if (mBouncerOn) { |
| 349 | mBouncerOn = false; |
| 350 | mDataCollector.onBouncerHidden(); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | public void onQsDown() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 355 | if (FalsingLog.ENABLED) { |
| 356 | FalsingLog.i("onQsDown", ""); |
| 357 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 358 | mHumanInteractionClassifier.setType(Classifier.QUICK_SETTINGS); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 359 | mDataCollector.onQsDown(); |
| 360 | } |
| 361 | |
| 362 | public void setQsExpanded(boolean expanded) { |
| 363 | mDataCollector.setQsExpanded(expanded); |
| 364 | } |
| 365 | |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 366 | public void onTrackingStarted(boolean secure) { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 367 | if (FalsingLog.ENABLED) { |
| 368 | FalsingLog.i("onTrackingStarted", ""); |
| 369 | } |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 370 | mHumanInteractionClassifier.setType(secure ? |
| 371 | Classifier.BOUNCER_UNLOCK : Classifier.UNLOCK); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 372 | mDataCollector.onTrackingStarted(); |
| 373 | } |
| 374 | |
| 375 | public void onTrackingStopped() { |
| 376 | mDataCollector.onTrackingStopped(); |
| 377 | } |
| 378 | |
| 379 | public void onNotificationActive() { |
| 380 | mDataCollector.onNotificationActive(); |
| 381 | } |
| 382 | |
Adrian Roos | 9f0b002 | 2016-11-09 15:56:50 -0800 | [diff] [blame] | 383 | public void onNotificationDoubleTap(boolean accepted, float dx, float dy) { |
| 384 | if (FalsingLog.ENABLED) { |
| 385 | FalsingLog.i("onNotificationDoubleTap", "accepted=" + accepted |
| 386 | + " dx=" + dx + " dy=" + dy + " (px)"); |
| 387 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 388 | mDataCollector.onNotificationDoubleTap(); |
| 389 | } |
| 390 | |
| 391 | public void setNotificationExpanded() { |
| 392 | mDataCollector.setNotificationExpanded(); |
| 393 | } |
| 394 | |
| 395 | public void onNotificatonStartDraggingDown() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 396 | if (FalsingLog.ENABLED) { |
| 397 | FalsingLog.i("onNotificatonStartDraggingDown", ""); |
| 398 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 399 | mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DRAG_DOWN); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 400 | mDataCollector.onNotificatonStartDraggingDown(); |
| 401 | } |
| 402 | |
| 403 | public void onNotificatonStopDraggingDown() { |
| 404 | mDataCollector.onNotificatonStopDraggingDown(); |
| 405 | } |
| 406 | |
| 407 | public void onNotificationDismissed() { |
| 408 | mDataCollector.onNotificationDismissed(); |
| 409 | } |
| 410 | |
| 411 | public void onNotificatonStartDismissing() { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 412 | if (FalsingLog.ENABLED) { |
| 413 | FalsingLog.i("onNotificatonStartDismissing", ""); |
| 414 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 415 | mHumanInteractionClassifier.setType(Classifier.NOTIFICATION_DISMISS); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 416 | mDataCollector.onNotificatonStartDismissing(); |
| 417 | } |
| 418 | |
| 419 | public void onNotificatonStopDismissing() { |
| 420 | mDataCollector.onNotificatonStopDismissing(); |
| 421 | } |
| 422 | |
| 423 | public void onCameraOn() { |
| 424 | mDataCollector.onCameraOn(); |
| 425 | } |
| 426 | |
| 427 | public void onLeftAffordanceOn() { |
| 428 | mDataCollector.onLeftAffordanceOn(); |
| 429 | } |
| 430 | |
| 431 | public void onAffordanceSwipingStarted(boolean rightCorner) { |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 432 | if (FalsingLog.ENABLED) { |
| 433 | FalsingLog.i("onAffordanceSwipingStarted", ""); |
| 434 | } |
Blazej Magnowski | 9f01c5b | 2015-09-17 15:14:29 -0700 | [diff] [blame] | 435 | if (rightCorner) { |
| 436 | mHumanInteractionClassifier.setType(Classifier.RIGHT_AFFORDANCE); |
| 437 | } else { |
| 438 | mHumanInteractionClassifier.setType(Classifier.LEFT_AFFORDANCE); |
| 439 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 440 | mDataCollector.onAffordanceSwipingStarted(rightCorner); |
| 441 | } |
| 442 | |
| 443 | public void onAffordanceSwipingAborted() { |
| 444 | mDataCollector.onAffordanceSwipingAborted(); |
| 445 | } |
| 446 | |
| 447 | public void onUnlockHintStarted() { |
| 448 | mDataCollector.onUnlockHintStarted(); |
| 449 | } |
| 450 | |
| 451 | public void onCameraHintStarted() { |
| 452 | mDataCollector.onCameraHintStarted(); |
| 453 | } |
| 454 | |
| 455 | public void onLeftAffordanceHintStarted() { |
| 456 | mDataCollector.onLeftAffordanceHintStarted(); |
| 457 | } |
| 458 | |
| 459 | public void onTouchEvent(MotionEvent event, int width, int height) { |
Adrian Roos | 004437e | 2017-08-16 11:58:02 +0200 | [diff] [blame] | 460 | if (event.getAction() == MotionEvent.ACTION_DOWN) { |
| 461 | mIsTouchScreen = event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 462 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 463 | if (mSessionActive && !mBouncerOn) { |
| 464 | mDataCollector.onTouchEvent(event, width, height); |
| 465 | mHumanInteractionClassifier.onTouchEvent(event); |
| 466 | } |
| 467 | } |
Adrian Roos | 401caae | 2016-03-04 13:35:21 -0800 | [diff] [blame] | 468 | |
| 469 | public void dump(PrintWriter pw) { |
| 470 | pw.println("FALSING MANAGER"); |
| 471 | pw.print("classifierEnabled="); pw.println(isClassiferEnabled() ? 1 : 0); |
| 472 | pw.print("mSessionActive="); pw.println(mSessionActive ? 1 : 0); |
| 473 | pw.print("mBouncerOn="); pw.println(mSessionActive ? 1 : 0); |
| 474 | pw.print("mState="); pw.println(StatusBarState.toShortString(mState)); |
| 475 | pw.print("mScreenOn="); pw.println(mScreenOn ? 1 : 0); |
| 476 | pw.println(); |
| 477 | } |
Adrian Roos | 7bb38a9 | 2016-07-21 11:44:01 -0700 | [diff] [blame] | 478 | |
| 479 | public Uri reportRejectedTouch() { |
| 480 | if (mDataCollector.isEnabled()) { |
| 481 | return mDataCollector.reportRejectedTouch(); |
| 482 | } |
| 483 | return null; |
| 484 | } |
| 485 | |
| 486 | public boolean isReportingEnabled() { |
| 487 | return mDataCollector.isReportingEnabled(); |
| 488 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 489 | } |