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

Commit 9c3b9340 authored by Harry Cutts's avatar Harry Cutts
Browse files

TouchpadInputMapper: dedup successive swipe lift gestures in metrics

In tests, the Gestures library occasionally outputs two lift gestures in
a row, which can cause inaccurate metrics reporting. To work around
this, keep track of the previous gesture the metrics collector saw, and
don't report additional swipe gestures if we see multiple lifts in a
row.

Bug: 397219482
Test: $ atest \
        CtsInputHostTestCases:android.input.cts.hostside.InputAtomsTest
Flag: TEST_ONLY
Change-Id: Iac2b6ae68dc62e3a106a743b667eddd96a1a7a74
parent 6b3c3bda
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -144,28 +144,39 @@ public:
    // records it if so.
    void processGesture(const TouchpadInputMapper::MetricsIdentifier& id, const Gesture& gesture) {
        std::scoped_lock lock(mLock);
        Counters& counters = mCounters[id];
        switch (gesture.type) {
            case kGestureTypeFling:
                if (gesture.details.fling.fling_state == GESTURES_FLING_START) {
                    // Indicates the end of a two-finger scroll gesture.
                    mCounters[id].twoFingerSwipeGestures++;
                    counters.twoFingerSwipeGestures++;
                }
                break;
            case kGestureTypeSwipeLift:
                mCounters[id].threeFingerSwipeGestures++;
                // The Gestures library occasionally outputs two lift gestures in a row, which can
                // cause inaccurate metrics reporting. To work around this, deduplicate successive
                // lift gestures.
                // TODO(b/404529050): fix the Gestures library, and remove this check.
                if (counters.lastGestureType != kGestureTypeSwipeLift) {
                    counters.threeFingerSwipeGestures++;
                }
                break;
            case kGestureTypeFourFingerSwipeLift:
                mCounters[id].fourFingerSwipeGestures++;
                // TODO(b/404529050): fix the Gestures library, and remove this check.
                if (counters.lastGestureType != kGestureTypeFourFingerSwipeLift) {
                    counters.fourFingerSwipeGestures++;
                }
                break;
            case kGestureTypePinch:
                if (gesture.details.pinch.zoom_state == GESTURES_ZOOM_END) {
                    mCounters[id].pinchGestures++;
                    counters.pinchGestures++;
                }
                break;
            default:
                // We're not interested in any other gestures.
                break;
        }
        counters.lastGestureType = gesture.type;
    }

private:
@@ -214,6 +225,10 @@ private:
        int32_t threeFingerSwipeGestures = 0;
        int32_t fourFingerSwipeGestures = 0;
        int32_t pinchGestures = 0;

        // Records the last type of gesture received for this device, for deduplication purposes.
        // TODO(b/404529050): fix the Gestures library and remove this field.
        GestureType lastGestureType = kGestureTypeContactInitiated;
    };

    // Metrics are aggregated by device model and version, so if two devices of the same model and