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