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