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

Commit 3911e101 authored by Nergi Rahardi's avatar Nergi Rahardi
Browse files

Prevent sending the same KeyRepeatInfo multiple times

Bug: 286078544
Test: atest InputManagerServiceTests
Change-Id: Ifab820d35399b7ea76681d7b137bed2994d974e4
parent 88c708b6
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@ class InputSettingsObserver extends ContentObserver {
    private final NativeInputManagerService mNative;
    private final Map<Uri, Consumer<String /* reason*/>> mObservers;

    // Cache prevent notifying same KeyRepeatInfo data to native code multiple times.
    private KeyRepeatInfo mLastKeyRepeatInfoSettingsUpdate;

    InputSettingsObserver(Context context, Handler handler, InputManagerService service,
            NativeInputManagerService nativeIms) {
        super(handler);
@@ -195,7 +198,11 @@ class InputSettingsObserver extends ContentObserver {
        final int delayMs = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.KEY_REPEAT_DELAY_MS, ViewConfiguration.getKeyRepeatDelay(),
                UserHandle.USER_CURRENT);
        if (mLastKeyRepeatInfoSettingsUpdate == null || !mLastKeyRepeatInfoSettingsUpdate.isEqualTo(
                timeoutMs, delayMs)) {
            mNative.setKeyRepeatConfiguration(timeoutMs, delayMs);
            mLastKeyRepeatInfoSettingsUpdate = new KeyRepeatInfo(timeoutMs, delayMs);
        }
    }

    // Not using ViewConfiguration.getLongPressTimeout here because it may return a stale value.
@@ -214,4 +221,19 @@ class InputSettingsObserver extends ContentObserver {
        }
        mNative.setMaximumObscuringOpacityForTouch(opacity);
    }

    private static class KeyRepeatInfo {
        private final int mKeyRepeatTimeoutMs;
        private final int mKeyRepeatDelayMs;

        private KeyRepeatInfo(int keyRepeatTimeoutMs, int keyRepeatDelayMs) {
            this.mKeyRepeatTimeoutMs = keyRepeatTimeoutMs;
            this.mKeyRepeatDelayMs = keyRepeatDelayMs;
        }

        public boolean isEqualTo(int keyRepeatTimeoutMs, int keyRepeatDelayMs) {
            return mKeyRepeatTimeoutMs == keyRepeatTimeoutMs
                    && mKeyRepeatDelayMs == keyRepeatDelayMs;
        }
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -133,8 +133,7 @@ class InputManagerServiceTests {
        verify(native).setMotionClassifierEnabled(anyBoolean())
        verify(native).setMaximumObscuringOpacityForTouch(anyFloat())
        verify(native).setStylusPointerIconEnabled(anyBoolean())
        // TODO(b/286078544): There is no need to call this more than once.
        verify(native, times(3)).setKeyRepeatConfiguration(anyInt(), anyInt())
        verify(native).setKeyRepeatConfiguration(anyInt(), anyInt())
    }

    @Test