Merge "Prevent sending the same KeyRepeatInfo multiple times"

This commit is contained in:
Nergi Rahardi
2023-06-30 04:34:09 +00:00
committed by Android (Google) Code Review
2 changed files with 24 additions and 3 deletions

View File

@@ -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);
mNative.setKeyRepeatConfiguration(timeoutMs, delayMs);
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;
}
}
}

View File

@@ -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