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

Commit 6f963fc9 authored by Nergi Rahardi's avatar Nergi Rahardi Committed by Android (Google) Code Review
Browse files

Merge "Prevent sending the same KeyRepeatInfo multiple times"

parents 0546fec1 3911e101
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