Add Tests for the BrightLineFalsingManager.
Sets up some more dagger injection and removes all the "new Classifier(...)" from its constructor, allowing them to come from outside. Bug: 172655679 Test: atest SystemUITests Change-Id: I916de7d5ee60ec2183c6401ec222867fc5eff823
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,44 +14,39 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.systemui.classifier.FalsingManagerProxy.FALSING_SUCCESS;
|
||||
import static com.android.systemui.classifier.FalsingModule.BRIGHT_LINE_GESTURE_CLASSIFERS;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.IndentingPrintWriter;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.classifier.Classifier;
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
import com.android.systemui.classifier.FalsingDataProvider.SessionListener;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.dagger.qualifiers.TestHarness;
|
||||
import com.android.systemui.dock.DockManager;
|
||||
import com.android.systemui.plugins.FalsingManager;
|
||||
import com.android.systemui.statusbar.phone.NotificationTapHelper;
|
||||
import com.android.systemui.util.DeviceConfigProxy;
|
||||
import com.android.systemui.util.sensors.ThresholdSensor;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
* FalsingManager designed to make clear why a touch was rejected.
|
||||
@@ -68,6 +63,7 @@ public class BrightLineFalsingManager implements FalsingManager {
|
||||
private final DockManager mDockManager;
|
||||
private final SingleTapClassifier mSingleTapClassifier;
|
||||
private final DoubleTapClassifier mDoubleTapClassifier;
|
||||
private final boolean mTestHarness;
|
||||
private final MetricsLogger mMetricsLogger;
|
||||
private int mIsFalseTouchCalls;
|
||||
private static final Queue<String> RECENT_INFO_LOG =
|
||||
@@ -75,7 +71,7 @@ public class BrightLineFalsingManager implements FalsingManager {
|
||||
private static final Queue<DebugSwipeRecord> RECENT_SWIPES =
|
||||
new ArrayDeque<>(RECENT_SWIPE_LOG_SIZE + 1);
|
||||
|
||||
private final List<FalsingClassifier> mClassifiers;
|
||||
private final Collection<FalsingClassifier> mClassifiers;
|
||||
|
||||
private final SessionListener mSessionListener = new SessionListener() {
|
||||
@Override
|
||||
@@ -93,29 +89,17 @@ public class BrightLineFalsingManager implements FalsingManager {
|
||||
|
||||
@Inject
|
||||
public BrightLineFalsingManager(FalsingDataProvider falsingDataProvider,
|
||||
DeviceConfigProxy deviceConfigProxy, @Main Resources resources,
|
||||
ViewConfiguration viewConfiguration, DockManager dockManager) {
|
||||
DockManager dockManager, MetricsLogger metricsLogger,
|
||||
@Named(BRIGHT_LINE_GESTURE_CLASSIFERS) Set<FalsingClassifier> classifiers,
|
||||
SingleTapClassifier singleTapClassifier, DoubleTapClassifier doubleTapClassifier,
|
||||
@TestHarness boolean testHarness) {
|
||||
mDataProvider = falsingDataProvider;
|
||||
mDockManager = dockManager;
|
||||
|
||||
mMetricsLogger = new MetricsLogger();
|
||||
mClassifiers = new ArrayList<>();
|
||||
DistanceClassifier distanceClassifier =
|
||||
new DistanceClassifier(mDataProvider, deviceConfigProxy);
|
||||
ProximityClassifier proximityClassifier =
|
||||
new ProximityClassifier(distanceClassifier, mDataProvider, deviceConfigProxy);
|
||||
mClassifiers.add(new PointerCountClassifier(mDataProvider));
|
||||
mClassifiers.add(new TypeClassifier(mDataProvider));
|
||||
mClassifiers.add(new DiagonalClassifier(mDataProvider, deviceConfigProxy));
|
||||
mClassifiers.add(distanceClassifier);
|
||||
mClassifiers.add(proximityClassifier);
|
||||
mClassifiers.add(new ZigZagClassifier(mDataProvider, deviceConfigProxy));
|
||||
|
||||
mSingleTapClassifier = new SingleTapClassifier(
|
||||
mDataProvider, viewConfiguration.getScaledTouchSlop());
|
||||
mDoubleTapClassifier = new DoubleTapClassifier(mDataProvider, mSingleTapClassifier,
|
||||
resources.getDimension(R.dimen.double_tap_slop),
|
||||
NotificationTapHelper.DOUBLE_TAP_TIMEOUT_MS);
|
||||
mMetricsLogger = metricsLogger;
|
||||
mClassifiers = classifiers;
|
||||
mSingleTapClassifier = singleTapClassifier;
|
||||
mDoubleTapClassifier = doubleTapClassifier;
|
||||
mTestHarness = testHarness;
|
||||
|
||||
mDataProvider.addSessionListener(mSessionListener);
|
||||
}
|
||||
@@ -132,7 +116,7 @@ public class BrightLineFalsingManager implements FalsingManager {
|
||||
return mPreviousResult;
|
||||
}
|
||||
|
||||
mPreviousResult = !ActivityManager.isRunningInUserTestHarness()
|
||||
mPreviousResult = !mTestHarness
|
||||
&& !mDataProvider.isJustUnlockedWithFace() && !mDockManager.isDocked()
|
||||
&& mClassifiers.stream().anyMatch(falsingClassifier -> {
|
||||
boolean result = falsingClassifier.isFalseTouch();
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.BRIGHTLINE_FALSING_DIAGONAL_HORIZONTAL_ANGLE_RANGE;
|
||||
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.BRIGHTLINE_FALSING_DIAGONAL_VERTICAL_ANGLE_RANGE;
|
||||
@@ -23,11 +23,12 @@ import static com.android.systemui.classifier.Classifier.RIGHT_AFFORDANCE;
|
||||
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
import com.android.systemui.util.DeviceConfigProxy;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* False on swipes that are too close to 45 degrees.
|
||||
*
|
||||
@@ -47,6 +48,7 @@ class DiagonalClassifier extends FalsingClassifier {
|
||||
private final float mHorizontalAngleRange;
|
||||
private final float mVerticalAngleRange;
|
||||
|
||||
@Inject
|
||||
DiagonalClassifier(FalsingDataProvider dataProvider, DeviceConfigProxy deviceConfigProxy) {
|
||||
super(dataProvider);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.BRIGHTLINE_FALSING_DISTANCE_HORIZONTAL_FLING_THRESHOLD_IN;
|
||||
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.BRIGHTLINE_FALSING_DISTANCE_HORIZONTAL_SWIPE_THRESHOLD_IN;
|
||||
@@ -27,12 +27,13 @@ import android.provider.DeviceConfig;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.VelocityTracker;
|
||||
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
import com.android.systemui.util.DeviceConfigProxy;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Ensure that the swipe + momentum covers a minimum distance.
|
||||
*/
|
||||
@@ -54,6 +55,7 @@ class DistanceClassifier extends FalsingClassifier {
|
||||
private boolean mDistanceDirty;
|
||||
private DistanceVectors mCachedDistance;
|
||||
|
||||
@Inject
|
||||
DistanceClassifier(FalsingDataProvider dataProvider, DeviceConfigProxy deviceConfigProxy) {
|
||||
super(dataProvider);
|
||||
|
||||
@@ -14,15 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.systemui.classifier.FalsingModule.DOUBLE_TAP_TIMEOUT_MS;
|
||||
import static com.android.systemui.classifier.FalsingModule.DOUBLE_TAP_TOUCH_SLOP;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
* Returns a false touch if the most two recent gestures are not taps or are too far apart.
|
||||
*/
|
||||
@@ -34,8 +38,10 @@ public class DoubleTapClassifier extends FalsingClassifier {
|
||||
|
||||
private StringBuilder mReason = new StringBuilder();
|
||||
|
||||
@Inject
|
||||
DoubleTapClassifier(FalsingDataProvider dataProvider, SingleTapClassifier singleTapClassifier,
|
||||
float doubleTapSlop, long doubleTapTimeMs) {
|
||||
@Named(DOUBLE_TAP_TOUCH_SLOP) float doubleTapSlop,
|
||||
@Named(DOUBLE_TAP_TIMEOUT_MS) long doubleTapTimeMs) {
|
||||
super(dataProvider);
|
||||
mSingleTapClassifier = singleTapClassifier;
|
||||
mDoubleTapSlop = doubleTapSlop;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,12 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.systemui.classifier.Classifier;
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
import com.android.systemui.util.sensors.ProximitySensor;
|
||||
|
||||
import java.util.List;
|
||||
@@ -21,9 +21,6 @@ import android.view.MotionEvent;
|
||||
import android.view.MotionEvent.PointerCoords;
|
||||
import android.view.MotionEvent.PointerProperties;
|
||||
|
||||
import com.android.systemui.classifier.brightline.BrightLineFalsingManager;
|
||||
import com.android.systemui.classifier.brightline.FalsingClassifier;
|
||||
import com.android.systemui.classifier.brightline.TimeLimitedMotionEventBuffer;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
import com.android.systemui.util.time.SystemClock;
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.view.MotionEvent;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.systemui.Dumpable;
|
||||
import com.android.systemui.classifier.brightline.BrightLineFalsingManager;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.dump.DumpManager;
|
||||
|
||||
@@ -16,16 +16,69 @@
|
||||
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.statusbar.phone.NotificationTapHelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.multibindings.ElementsIntoSet;
|
||||
|
||||
/** Dagger Module for Falsing. */
|
||||
@Module
|
||||
public interface FalsingModule {
|
||||
String BRIGHT_LINE_GESTURE_CLASSIFERS = "bright_line_gesture_classifiers";
|
||||
String SINGLE_TAP_TOUCH_SLOP = "falsing_single_tap_touch_slop";
|
||||
String DOUBLE_TAP_TOUCH_SLOP = "falsing_double_tap_touch_slop";
|
||||
String DOUBLE_TAP_TIMEOUT_MS = "falsing_double_tap_timeout_ms";
|
||||
|
||||
/** */
|
||||
@Binds
|
||||
@SysUISingleton
|
||||
FalsingCollector bindsFalsingCollector(FalsingCollectorImpl impl);
|
||||
|
||||
/** */
|
||||
@Provides
|
||||
@ElementsIntoSet
|
||||
@Named(BRIGHT_LINE_GESTURE_CLASSIFERS)
|
||||
static Set<FalsingClassifier> providesBrightLineGestureClassifiers(
|
||||
DistanceClassifier distanceClassifier, ProximityClassifier proximityClassifier,
|
||||
PointerCountClassifier pointerCountClassifier, TypeClassifier typeClassifier,
|
||||
DiagonalClassifier diagonalClassifier, ZigZagClassifier zigZagClassifier) {
|
||||
return new HashSet<>(Arrays.asList(
|
||||
pointerCountClassifier, typeClassifier, diagonalClassifier, distanceClassifier,
|
||||
proximityClassifier, zigZagClassifier));
|
||||
}
|
||||
|
||||
/** */
|
||||
@Provides
|
||||
@Named(DOUBLE_TAP_TIMEOUT_MS)
|
||||
static long providesDoubleTapTimeoutMs() {
|
||||
return NotificationTapHelper.DOUBLE_TAP_TIMEOUT_MS;
|
||||
}
|
||||
|
||||
/** */
|
||||
@Provides
|
||||
@Named(DOUBLE_TAP_TOUCH_SLOP)
|
||||
static float providesDoubleTapTouchSlop(@Main Resources resources) {
|
||||
return resources.getDimension(R.dimen.double_tap_slop);
|
||||
}
|
||||
|
||||
/** */
|
||||
@Provides
|
||||
@Named(SINGLE_TAP_TOUCH_SLOP)
|
||||
static float providesSingleTapTouchSlop(ViewConfiguration viewConfiguration) {
|
||||
return viewConfiguration.getScaledTouchSlop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,17 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.systemui.classifier.Classifier.NOTIFICATION_DRAG_DOWN;
|
||||
import static com.android.systemui.classifier.Classifier.QUICK_SETTINGS;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* False touch if more than one finger touches the screen.
|
||||
*
|
||||
@@ -37,6 +37,7 @@ class PointerCountClassifier extends FalsingClassifier {
|
||||
private static final int MAX_ALLOWED_POINTERS_SWIPE_DOWN = 2;
|
||||
private int mMaxPointerCount;
|
||||
|
||||
@Inject
|
||||
PointerCountClassifier(FalsingDataProvider dataProvider) {
|
||||
super(dataProvider);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.BRIGHTLINE_FALSING_PROXIMITY_PERCENT_COVERED_THRESHOLD;
|
||||
import static com.android.systemui.classifier.Classifier.QUICK_SETTINGS;
|
||||
@@ -22,12 +22,13 @@ import static com.android.systemui.classifier.Classifier.QUICK_SETTINGS;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
import com.android.systemui.util.DeviceConfigProxy;
|
||||
import com.android.systemui.util.sensors.ProximitySensor;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
||||
/**
|
||||
* False touch if proximity sensor is covered for more than a certain percentage of the gesture.
|
||||
@@ -47,10 +48,11 @@ class ProximityClassifier extends FalsingClassifier {
|
||||
private long mNearDurationNs;
|
||||
private float mPercentNear;
|
||||
|
||||
@Inject
|
||||
ProximityClassifier(DistanceClassifier distanceClassifier,
|
||||
FalsingDataProvider dataProvider, DeviceConfigProxy deviceConfigProxy) {
|
||||
super(dataProvider);
|
||||
this.mDistanceClassifier = distanceClassifier;
|
||||
mDistanceClassifier = distanceClassifier;
|
||||
|
||||
mPercentCoveredThreshold = deviceConfigProxy.getFloat(
|
||||
DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
@@ -14,14 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.systemui.classifier.FalsingModule.SINGLE_TAP_TOUCH_SLOP;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
* Falsing classifier that accepts or rejects a single gesture as a tap.
|
||||
*/
|
||||
@@ -29,7 +32,9 @@ public class SingleTapClassifier extends FalsingClassifier {
|
||||
private final float mTouchSlop;
|
||||
private String mReason;
|
||||
|
||||
SingleTapClassifier(FalsingDataProvider dataProvider, float touchSlop) {
|
||||
@Inject
|
||||
SingleTapClassifier(FalsingDataProvider dataProvider,
|
||||
@Named(SINGLE_TAP_TOUCH_SLOP) float touchSlop) {
|
||||
super(dataProvider);
|
||||
mTouchSlop = touchSlop;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
|
||||
import static com.android.systemui.classifier.Classifier.BOUNCER_UNLOCK;
|
||||
@@ -26,12 +26,13 @@ import static com.android.systemui.classifier.Classifier.QUICK_SETTINGS;
|
||||
import static com.android.systemui.classifier.Classifier.RIGHT_AFFORDANCE;
|
||||
import static com.android.systemui.classifier.Classifier.UNLOCK;
|
||||
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Ensure that the swipe direction generally matches that of the interaction type.
|
||||
*/
|
||||
public class TypeClassifier extends FalsingClassifier {
|
||||
@Inject
|
||||
TypeClassifier(FalsingDataProvider dataProvider) {
|
||||
super(dataProvider);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.BRIGHTLINE_FALSING_ZIGZAG_X_PRIMARY_DEVIANCE;
|
||||
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.BRIGHTLINE_FALSING_ZIGZAG_X_SECONDARY_DEVIANCE;
|
||||
@@ -25,13 +25,14 @@ import android.graphics.Point;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
import com.android.systemui.util.DeviceConfigProxy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Penalizes gestures that change direction in either the x or y too much.
|
||||
*/
|
||||
@@ -56,6 +57,7 @@ class ZigZagClassifier extends FalsingClassifier {
|
||||
private float mLastMaxXDeviance;
|
||||
private float mLastMaxYDeviance;
|
||||
|
||||
@Inject
|
||||
ZigZagClassifier(FalsingDataProvider dataProvider, DeviceConfigProxy deviceConfigProxy) {
|
||||
super(dataProvider);
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
|
||||
package com.android.systemui.dagger;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.internal.logging.UiEventLoggerImpl;
|
||||
import com.android.systemui.dagger.qualifiers.TestHarness;
|
||||
import com.android.systemui.util.concurrency.GlobalConcurrencyModule;
|
||||
import com.android.wm.shell.animation.FlingAnimationUtils;
|
||||
|
||||
@@ -66,4 +68,10 @@ public class GlobalModule {
|
||||
static UiEventLogger provideUiEventLogger() {
|
||||
return new UiEventLoggerImpl();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@TestHarness
|
||||
static boolean provideIsTestHarness() {
|
||||
return ActivityManager.isRunningInUserTestHarness();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.dagger.qualifiers;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
|
||||
/**
|
||||
* An annotation for injecting whether or not we are running in a test environment.
|
||||
*/
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
public @interface TestHarness {
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.systemui.util.mockito.KotlinMockitoHelpersKt.any;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.internal.logging.testing.FakeMetricsLogger;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.dock.DockManagerFake;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
public class BrightLineClassifierTest extends SysuiTestCase {
|
||||
private BrightLineFalsingManager mBrightLineFalsingManager;
|
||||
@Mock
|
||||
private FalsingDataProvider mFalsingDataProvider;
|
||||
private final DockManagerFake mDockManager = new DockManagerFake();
|
||||
private final MetricsLogger mMetricsLogger = new FakeMetricsLogger();
|
||||
private final Set<FalsingClassifier> mClassifiers = new HashSet<>();
|
||||
@Mock
|
||||
private SingleTapClassifier mSingleTapClassfier;
|
||||
@Mock
|
||||
private DoubleTapClassifier mDoubleTapClassifier;
|
||||
@Mock
|
||||
private FalsingClassifier mClassifierA;
|
||||
@Mock
|
||||
private FalsingClassifier mClassifierB;
|
||||
private final List<MotionEvent> mMotionEventList = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mClassifiers.add(mClassifierA);
|
||||
mClassifiers.add(mClassifierB);
|
||||
when(mFalsingDataProvider.isDirty()).thenReturn(true);
|
||||
when(mFalsingDataProvider.getRecentMotionEvents()).thenReturn(mMotionEventList);
|
||||
mBrightLineFalsingManager = new BrightLineFalsingManager(mFalsingDataProvider, mDockManager,
|
||||
mMetricsLogger, mClassifiers, mSingleTapClassfier, mDoubleTapClassifier, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterSessionListener() {
|
||||
verify(mFalsingDataProvider).addSessionListener(
|
||||
any(FalsingDataProvider.SessionListener.class));
|
||||
|
||||
mBrightLineFalsingManager.cleanup();
|
||||
verify(mFalsingDataProvider).removeSessionListener(
|
||||
any(FalsingDataProvider.SessionListener.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFalseTouch_NoClassifiers() {
|
||||
mClassifiers.clear();
|
||||
|
||||
assertThat(mBrightLineFalsingManager.isFalseTouch(0)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFalseTouch_ClassffiersPass() {
|
||||
assertThat(mBrightLineFalsingManager.isFalseTouch(0)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFalseTouch_ClassifierARejects() {
|
||||
when(mClassifierA.isFalseTouch()).thenReturn(true);
|
||||
assertThat(mBrightLineFalsingManager.isFalseTouch(0)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFalseTouch_ClassifierBRejects() {
|
||||
when(mClassifierB.isFalseTouch()).thenReturn(true);
|
||||
assertThat(mBrightLineFalsingManager.isFalseTouch(0)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFalseTouch_FaceAuth() {
|
||||
// Even when the classifiers report a false, we should allow.
|
||||
when(mClassifierA.isFalseTouch()).thenReturn(true);
|
||||
when(mFalsingDataProvider.isJustUnlockedWithFace()).thenReturn(true);
|
||||
|
||||
assertThat(mBrightLineFalsingManager.isFalseTouch(0)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFalseTouch_Docked() {
|
||||
// Even when the classifiers report a false, we should allow.
|
||||
when(mClassifierA.isFalseTouch()).thenReturn(true);
|
||||
mDockManager.setIsDocked(true);
|
||||
|
||||
assertThat(mBrightLineFalsingManager.isFalseTouch(0)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFalseTap_BasicCheck() {
|
||||
when(mSingleTapClassfier.isTap(mMotionEventList)).thenReturn(false);
|
||||
|
||||
assertThat(mBrightLineFalsingManager.isFalseTap(false)).isTrue();
|
||||
|
||||
when(mSingleTapClassfier.isTap(mMotionEventList)).thenReturn(true);
|
||||
|
||||
assertThat(mBrightLineFalsingManager.isFalseTap(false)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFalseTap_RobustCheck_NoFaceAuth() {
|
||||
when(mSingleTapClassfier.isTap(mMotionEventList)).thenReturn(true);
|
||||
mFalsingDataProvider.setJustUnlockedWithFace(false);
|
||||
assertThat(mBrightLineFalsingManager.isFalseTap(true)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFalseTap_RobustCheck_FaceAuth() {
|
||||
when(mSingleTapClassfier.isTap(mMotionEventList)).thenReturn(true);
|
||||
when(mFalsingDataProvider.isJustUnlockedWithFace()).thenReturn(true);
|
||||
assertThat(mBrightLineFalsingManager.isFalseTap(true)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsFalseDoubleTap() {
|
||||
when(mDoubleTapClassifier.isFalseTouch()).thenReturn(false);
|
||||
|
||||
assertThat(mBrightLineFalsingManager.isFalseDoubleTap()).isFalse();
|
||||
|
||||
when(mDoubleTapClassifier.isFalseTouch()).thenReturn(true);
|
||||
|
||||
assertThat(mBrightLineFalsingManager.isFalseDoubleTap()).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.systemui.classifier.Classifier.LEFT_AFFORDANCE;
|
||||
import static com.android.systemui.classifier.Classifier.RIGHT_AFFORDANCE;
|
||||
@@ -27,8 +27,6 @@ import android.testing.AndroidTestingRunner;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.classifier.ClassifierTest;
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
import com.android.systemui.util.DeviceConfigProxyFake;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -23,8 +23,6 @@ import android.testing.AndroidTestingRunner;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.classifier.ClassifierTest;
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
import com.android.systemui.util.DeviceConfigProxyFake;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -27,9 +27,6 @@ import android.view.MotionEvent;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.classifier.ClassifierTest;
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.systemui.classifier.Classifier.QUICK_SETTINGS;
|
||||
|
||||
@@ -26,8 +26,6 @@ import android.view.MotionEvent;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.classifier.ClassifierTest;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.systemui.classifier.Classifier.GENERIC;
|
||||
import static com.android.systemui.classifier.Classifier.QUICK_SETTINGS;
|
||||
@@ -28,8 +28,6 @@ import android.view.MotionEvent;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.classifier.ClassifierTest;
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
import com.android.systemui.util.DeviceConfigProxyFake;
|
||||
import com.android.systemui.util.sensors.ProximitySensor;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -25,9 +25,6 @@ import android.view.MotionEvent;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.classifier.ClassifierTest;
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static com.android.systemui.classifier.Classifier.BOUNCER_UNLOCK;
|
||||
import static com.android.systemui.classifier.Classifier.LEFT_AFFORDANCE;
|
||||
@@ -33,9 +33,6 @@ import android.testing.AndroidTestingRunner;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.classifier.ClassifierTest;
|
||||
import com.android.systemui.classifier.FalsingDataProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.classifier.brightline;
|
||||
package com.android.systemui.classifier;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -23,7 +23,6 @@ import android.testing.AndroidTestingRunner;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.classifier.ClassifierTest;
|
||||
import com.android.systemui.util.DeviceConfigProxyFake;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -22,6 +22,7 @@ package com.android.systemui.dock;
|
||||
public class DockManagerFake implements DockManager {
|
||||
DockEventListener mCallback;
|
||||
AlignmentStateListener mAlignmentListener;
|
||||
private boolean mDocked;
|
||||
|
||||
@Override
|
||||
public void addListener(DockEventListener callback) {
|
||||
@@ -45,7 +46,11 @@ public class DockManagerFake implements DockManager {
|
||||
|
||||
@Override
|
||||
public boolean isDocked() {
|
||||
return false;
|
||||
return mDocked;
|
||||
}
|
||||
|
||||
public void setIsDocked(boolean docked) {
|
||||
mDocked = docked;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user