Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ba2237d authored by Juan Lang's avatar Juan Lang
Browse files

Count and log the number of consecutive rapid power button presses.

Here, "rapid" is defined as 500ms.
The histogram will allow us to measure the basal rate at which multiple
rapid power button presses occur, in order to estimate the false positive
rate a consecutive rapid power button sequence would generate.

Test: Unit tests for all values logged.
Also, manual testing of existing power button feature and inspection of
logcat output.
Manual test cases executed:
1. Screen off, power button tap turns screen on.
2. Screen on, power button tap turns screen off.
3. Screen off, power button double tap triggers camera.
4. Screen on, keyguard visible, power button double tap triggers camera.
5. Screen on, bouncer visible, power button double tap triggers camera.
6. Screen on, launcher visible, power button double tap triggers camera.
7. Screen off, power button long press turns screen on.
8. Screen on, keyguard visible, power button long press shows power off
   / restart menu.
9. Screen on, bouncer visible, power button long press shows power off
   / restart menu.
10. Screen on, launcher visible, power button long press shows power off
    / restart menu.

Change-Id: I3d96f55ab7c541338106b43bc48e6a93a0444891
parent 36f46243
Loading
Loading
Loading
Loading
+25 −6
Original line number Original line Diff line number Diff line
@@ -61,6 +61,14 @@ public class GestureLauncherService extends SystemService {
     */
     */
    @VisibleForTesting static final long CAMERA_POWER_DOUBLE_TAP_MAX_TIME_MS = 300;
    @VisibleForTesting static final long CAMERA_POWER_DOUBLE_TAP_MAX_TIME_MS = 300;


    /**
     * Interval in milliseconds in which the power button must be depressed in succession to be
     * considered part of an extended sequence of taps. Note that this is a looser threshold than
     * the camera launch gesture, because the purpose of this threshold is to measure the
     * frequency of consecutive taps, for evaluation for future gestures.
     */
    @VisibleForTesting static final long POWER_SHORT_TAP_SEQUENCE_MAX_INTERVAL_MS = 500;

    /** The listener that receives the gesture event. */
    /** The listener that receives the gesture event. */
    private final GestureEventListener mGestureListener = new GestureEventListener();
    private final GestureEventListener mGestureListener = new GestureEventListener();


@@ -108,6 +116,7 @@ public class GestureLauncherService extends SystemService {
     */
     */
    private boolean mCameraDoubleTapPowerEnabled;
    private boolean mCameraDoubleTapPowerEnabled;
    private long mLastPowerDown;
    private long mLastPowerDown;
    private int mPowerButtonConsecutiveTaps;


    public GestureLauncherService(Context context) {
    public GestureLauncherService(Context context) {
        this(context, new MetricsLogger());
        this(context, new MetricsLogger());
@@ -265,27 +274,37 @@ public class GestureLauncherService extends SystemService {
            MutableBoolean outLaunched) {
            MutableBoolean outLaunched) {
        boolean launched = false;
        boolean launched = false;
        boolean intercept = false;
        boolean intercept = false;
        long doubleTapInterval;
        long powerTapInterval;
        synchronized (this) {
        synchronized (this) {
            doubleTapInterval = event.getEventTime() - mLastPowerDown;
            powerTapInterval = event.getEventTime() - mLastPowerDown;
            if (mCameraDoubleTapPowerEnabled
            if (mCameraDoubleTapPowerEnabled
                    && doubleTapInterval < CAMERA_POWER_DOUBLE_TAP_MAX_TIME_MS) {
                    && powerTapInterval < CAMERA_POWER_DOUBLE_TAP_MAX_TIME_MS) {
                launched = true;
                launched = true;
                intercept = interactive;
                intercept = interactive;
                mPowerButtonConsecutiveTaps++;
            } else if (powerTapInterval < POWER_SHORT_TAP_SEQUENCE_MAX_INTERVAL_MS) {
                mPowerButtonConsecutiveTaps++;
            } else {
                mPowerButtonConsecutiveTaps = 1;
            }
            }
            mLastPowerDown = event.getEventTime();
            mLastPowerDown = event.getEventTime();
        }
        }
        if (DBG && mPowerButtonConsecutiveTaps > 1) {
            Slog.i(TAG, Long.valueOf(mPowerButtonConsecutiveTaps) +
                    " consecutive power button taps detected");
        }
        if (launched) {
        if (launched) {
            Slog.i(TAG, "Power button double tap gesture detected, launching camera. Interval="
            Slog.i(TAG, "Power button double tap gesture detected, launching camera. Interval="
                    + doubleTapInterval + "ms");
                    + powerTapInterval + "ms");
            launched = handleCameraLaunchGesture(false /* useWakelock */,
            launched = handleCameraLaunchGesture(false /* useWakelock */,
                    StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP);
                    StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP);
            if (launched) {
            if (launched) {
                mMetricsLogger.action(MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE,
                mMetricsLogger.action(MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE,
                        (int) doubleTapInterval);
                        (int) powerTapInterval);
            }
            }
        }
        }
        mMetricsLogger.histogram("power_double_tap_interval", (int) doubleTapInterval);
        mMetricsLogger.histogram("power_consecutive_short_tap_count", mPowerButtonConsecutiveTaps);
        mMetricsLogger.histogram("power_double_tap_interval", (int) powerTapInterval);
        outLaunched.value = launched;
        outLaunched.value = launched;
        return intercept && launched;
        return intercept && launched;
    }
    }
+345 −13

File changed.

Preview size limit exceeded, changes collapsed.