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

Commit e3021d70 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Remove device state when device is reset

When device reset is received in MotionClassifier, don't just set the
classification for that device to 'none'.
Instead, remove all state related to that device.

This prevents growing indefinitely the unordered_maps
that contain device-related state.

Also, log the feature state to the InputClassifier dump.

Bug: 150419367
Test: run several touch integration tests several times, and then do
'dumpsys input'. Ensure that the list doesn't grow as the tests are
executed multiple times.

Change-Id: I2e1ac359458a321f87e4599bb19350623afc9b2b
parent 7e221c91
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -45,10 +45,7 @@ public:
    T pop() {
        std::unique_lock lock(mLock);
        android::base::ScopedLockAssertion assumeLock(mLock);
        mHasElements.wait(lock, [this]{
                android::base::ScopedLockAssertion assumeLock(mLock);
                return !this->mQueue.empty();
        });
        mHasElements.wait(lock, [this]() REQUIRES(mLock) { return !this->mQueue.empty(); });
        T t = std::move(mQueue.front());
        mQueue.erase(mQueue.begin());
        return t;
+8 −1
Original line number Diff line number Diff line
@@ -250,7 +250,7 @@ void MotionClassifier::callInputClassifierHal() {
            case ClassifierEventType::DEVICE_RESET: {
                const int32_t deviceId = *(event.getDeviceId());
                halResponseOk = mService->resetDevice(deviceId).isOk();
                setClassification(deviceId, MotionClassification::NONE);
                clearDeviceState(deviceId);
                break;
            }
            case ClassifierEventType::HAL_RESET: {
@@ -321,6 +321,12 @@ void MotionClassifier::updateLastDownTime(int32_t deviceId, nsecs_t downTime) {
    mClassifications[deviceId] = MotionClassification::NONE;
}

void MotionClassifier::clearDeviceState(int32_t deviceId) {
    std::scoped_lock lock(mLock);
    mClassifications.erase(deviceId);
    mLastDownTimes.erase(deviceId);
}

MotionClassification MotionClassifier::classify(const NotifyMotionArgs& args) {
    if ((args.action & AMOTION_EVENT_ACTION_MASK) == AMOTION_EVENT_ACTION_DOWN) {
        updateLastDownTime(args.deviceId, args.downTime);
@@ -455,6 +461,7 @@ void InputClassifier::serviceDied(uint64_t /*cookie*/,
void InputClassifier::dump(std::string& dump) {
    std::scoped_lock lock(mLock);
    dump += "Input Classifier State:\n";
    dump += StringPrintf(INDENT1 "Deep press: %s\n", deepPressEnabled() ? "enabled" : "disabled");

    dump += INDENT1 "Motion Classifier:\n";
    if (mMotionClassifier) {
+2 −0
Original line number Diff line number Diff line
@@ -212,6 +212,8 @@ private:

    void updateLastDownTime(int32_t deviceId, nsecs_t downTime);

    void clearDeviceState(int32_t deviceId);

    /**
     * Exit the InputClassifier HAL thread.
     * Useful for tests to ensure proper cleanup.