summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Prabir Pradhan <prabirmsp@google.com> 2023-11-15 23:52:13 +0000
committer Prabir Pradhan <prabirmsp@google.com> 2023-11-16 05:11:25 +0000
commite99ea6a91be626b61eb6beefe20d5271c79de5e2 (patch)
treea0c212485616c23114bfb169bc10b284de93988e
parent5128949634c682b630a9a94517f4a6df0b5dfc21 (diff)
InputSettingsObserver: Decouple key repeat settings from long press
Key repeat settings are now independent from long press settings, so remove the code that handled the case where key repeat settings were dependent on the long press settings as a fallback. Bug: 310657006 Test: adb shell settings put secure key_repeat_timeout <value> Change-Id: I16f1276cf04c7b2b4b794900cc498d3a1174feed
-rw-r--r--services/core/java/com/android/server/input/InputSettingsObserver.java56
-rw-r--r--tests/Input/src/com/android/server/input/InputManagerServiceTests.kt4
2 files changed, 15 insertions, 45 deletions
diff --git a/services/core/java/com/android/server/input/InputSettingsObserver.java b/services/core/java/com/android/server/input/InputSettingsObserver.java
index aab491ee1def..8e0289ef1b43 100644
--- a/services/core/java/com/android/server/input/InputSettingsObserver.java
+++ b/services/core/java/com/android/server/input/InputSettingsObserver.java
@@ -47,9 +47,6 @@ 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);
@@ -84,9 +81,9 @@ class InputSettingsObserver extends ContentObserver {
Map.entry(Settings.System.getUriFor(Settings.System.SHOW_KEY_PRESSES),
(reason) -> updateShowKeyPresses()),
Map.entry(Settings.Secure.getUriFor(Settings.Secure.KEY_REPEAT_TIMEOUT_MS),
- (reason) -> updateKeyRepeatInfo(getLatestLongPressTimeoutValue())),
+ (reason) -> updateKeyRepeatInfo()),
Map.entry(Settings.Secure.getUriFor(Settings.Secure.KEY_REPEAT_DELAY_MS),
- (reason) -> updateKeyRepeatInfo(getLatestLongPressTimeoutValue())),
+ (reason) -> updateKeyRepeatInfo()),
Map.entry(Settings.System.getUriFor(Settings.System.SHOW_ROTARY_INPUT),
(reason) -> updateShowRotaryInput()));
}
@@ -182,46 +179,32 @@ class InputSettingsObserver extends ContentObserver {
}
private void updateLongPressTimeout(String reason) {
- final int longPressTimeoutValue = getLatestLongPressTimeoutValue();
-
- // Before the key repeat timeout was introduced, some users relied on changing
- // LONG_PRESS_TIMEOUT settings to also change the key repeat timeout. To support this
- // backward compatibility, we'll preemptively update key repeat info here, in case where
- // key repeat timeout was never set, and user is still relying on long press timeout value.
- updateKeyRepeatInfo(longPressTimeoutValue);
+ // Not using ViewConfiguration.getLongPressTimeout here because it may return a stale value.
+ final int longPressTimeoutMs = Settings.Secure.getIntForUser(mContext.getContentResolver(),
+ Settings.Secure.LONG_PRESS_TIMEOUT, ViewConfiguration.DEFAULT_LONG_PRESS_TIMEOUT,
+ UserHandle.USER_CURRENT);
final boolean featureEnabledFlag =
DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_INPUT_NATIVE_BOOT,
DEEP_PRESS_ENABLED, true /* default */);
final boolean enabled =
featureEnabledFlag
- && longPressTimeoutValue <= ViewConfiguration.DEFAULT_LONG_PRESS_TIMEOUT;
+ && longPressTimeoutMs <= ViewConfiguration.DEFAULT_LONG_PRESS_TIMEOUT;
Log.i(TAG, (enabled ? "Enabling" : "Disabling") + " motion classifier because " + reason
+ ": feature " + (featureEnabledFlag ? "enabled" : "disabled")
- + ", long press timeout = " + longPressTimeoutValue);
+ + ", long press timeout = " + longPressTimeoutMs + " ms");
mNative.setMotionClassifierEnabled(enabled);
}
- private void updateKeyRepeatInfo(int fallbackKeyRepeatTimeoutValue) {
- // Not using ViewConfiguration.getKeyRepeatTimeout here because it may return a stale value.
+ private void updateKeyRepeatInfo() {
+ // Use ViewConfiguration getters only as fallbacks because they may return stale values.
final int timeoutMs = Settings.Secure.getIntForUser(mContext.getContentResolver(),
- Settings.Secure.KEY_REPEAT_TIMEOUT_MS, fallbackKeyRepeatTimeoutValue,
+ Settings.Secure.KEY_REPEAT_TIMEOUT_MS, ViewConfiguration.getKeyRepeatTimeout(),
UserHandle.USER_CURRENT);
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.
- private int getLatestLongPressTimeoutValue() {
- return Settings.Secure.getIntForUser(mContext.getContentResolver(),
- Settings.Secure.LONG_PRESS_TIMEOUT, ViewConfiguration.DEFAULT_LONG_PRESS_TIMEOUT,
- UserHandle.USER_CURRENT);
+ mNative.setKeyRepeatConfiguration(timeoutMs, delayMs);
}
private void updateMaximumObscuringOpacityForTouch() {
@@ -233,19 +216,4 @@ 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;
- }
- }
}
diff --git a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt
index 93a558287bd6..c1784f3b42e7 100644
--- a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt
+++ b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt
@@ -149,7 +149,9 @@ class InputManagerServiceTests {
verify(native).setMotionClassifierEnabled(anyBoolean())
verify(native).setMaximumObscuringOpacityForTouch(anyFloat())
verify(native).setStylusPointerIconEnabled(anyBoolean())
- verify(native).setKeyRepeatConfiguration(anyInt(), anyInt())
+ // Called twice at boot, since there are individual callbacks to update the
+ // key repeat timeout and the key repeat delay.
+ verify(native, times(2)).setKeyRepeatConfiguration(anyInt(), anyInt())
}
@Test