Merge "Notify dispatcher when its configuration needs to be updated" into udc-dev
diff --git a/services/core/java/com/android/server/input/InputSettingsObserver.java b/services/core/java/com/android/server/input/InputSettingsObserver.java
index 5b21669..153e9c1 100644
--- a/services/core/java/com/android/server/input/InputSettingsObserver.java
+++ b/services/core/java/com/android/server/input/InputSettingsObserver.java
@@ -52,25 +52,27 @@
         mHandler = handler;
         mNative = nativeIms;
         mObservers = Map.ofEntries(
-            Map.entry(Settings.System.getUriFor(Settings.System.POINTER_SPEED),
-                    (reason) -> updateMousePointerSpeed()),
-            Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_POINTER_SPEED),
-                    (reason) -> updateTouchpadPointerSpeed()),
-            Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_NATURAL_SCROLLING),
-                    (reason) -> updateTouchpadNaturalScrollingEnabled()),
-            Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_TAP_TO_CLICK),
-                    (reason) -> updateTouchpadTapToClickEnabled()),
-            Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_RIGHT_CLICK_ZONE),
-                    (reason) -> updateTouchpadRightClickZoneEnabled()),
-            Map.entry(Settings.System.getUriFor(Settings.System.SHOW_TOUCHES),
-                    (reason) -> updateShowTouches()),
-            Map.entry(Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON),
-                    (reason) -> updateAccessibilityLargePointer()),
-            Map.entry(Settings.Secure.getUriFor(Settings.Secure.LONG_PRESS_TIMEOUT),
-                    (reason) -> updateDeepPressStatus(reason)),
-            Map.entry(
-                    Settings.Global.getUriFor(Settings.Global.MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH),
-                    (reason) -> updateMaximumObscuringOpacityForTouch()));
+                Map.entry(Settings.System.getUriFor(Settings.System.POINTER_SPEED),
+                        (reason) -> updateMousePointerSpeed()),
+                Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_POINTER_SPEED),
+                        (reason) -> updateTouchpadPointerSpeed()),
+                Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_NATURAL_SCROLLING),
+                        (reason) -> updateTouchpadNaturalScrollingEnabled()),
+                Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_TAP_TO_CLICK),
+                        (reason) -> updateTouchpadTapToClickEnabled()),
+                Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_RIGHT_CLICK_ZONE),
+                        (reason) -> updateTouchpadRightClickZoneEnabled()),
+                Map.entry(Settings.System.getUriFor(Settings.System.SHOW_TOUCHES),
+                        (reason) -> updateShowTouches()),
+                Map.entry(
+                        Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON),
+                        (reason) -> updateAccessibilityLargePointer()),
+                Map.entry(Settings.Secure.getUriFor(Settings.Secure.LONG_PRESS_TIMEOUT),
+                        (reason) -> updateLongPressTimeout(reason)),
+                Map.entry(
+                        Settings.Global.getUriFor(
+                                Settings.Global.MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH),
+                        (reason) -> updateMaximumObscuringOpacityForTouch()));
     }
 
     /**
@@ -151,8 +153,13 @@
         mNative.reloadPointerIcons();
     }
 
-    private void updateDeepPressStatus(String reason) {
-        // Not using ViewConfiguration.getLongPressTimeout here because it may return a stale value
+    private void updateLongPressTimeout(String reason) {
+        // Some key gesture timeouts are based on the long press timeout, so update key gesture
+        // timeouts when the value changes. See ViewConfiguration#getKeyRepeatTimeout().
+        mNative.notifyKeyGestureTimeoutsChanged();
+
+        // Update the deep press status.
+        // Not using ViewConfiguration.getLongPressTimeout here because it may return a stale value.
         final int timeout = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                 Settings.Secure.LONG_PRESS_TIMEOUT, ViewConfiguration.DEFAULT_LONG_PRESS_TIMEOUT,
                 UserHandle.USER_CURRENT);
diff --git a/services/core/java/com/android/server/input/NativeInputManagerService.java b/services/core/java/com/android/server/input/NativeInputManagerService.java
index aeb2477..363bc94 100644
--- a/services/core/java/com/android/server/input/NativeInputManagerService.java
+++ b/services/core/java/com/android/server/input/NativeInputManagerService.java
@@ -28,6 +28,7 @@
 import android.view.InputEvent;
 import android.view.PointerIcon;
 import android.view.VerifiedInputEvent;
+import android.view.ViewConfiguration;
 
 import java.util.List;
 
@@ -198,8 +199,6 @@
 
     void changeKeyboardLayoutAssociation();
 
-    void notifyPointerDisplayIdChanged();
-
     void setDisplayEligibilityForPointerCapture(int displayId, boolean enabled);
 
     void setMotionClassifierEnabled(boolean enabled);
@@ -243,6 +242,15 @@
      */
     void sysfsNodeChanged(String sysfsNodePath);
 
+    /**
+     * Notify there is a change in any of the key gesture timeouts, such as the key
+     * repeat timeout or key repeat delay.
+     *
+     * @see ViewConfiguration#getKeyRepeatTimeout()
+     * @see ViewConfiguration#getKeyRepeatDelay()
+     */
+    void notifyKeyGestureTimeoutsChanged();
+
     /** The native implementation of InputManagerService methods. */
     class NativeImpl implements NativeInputManagerService {
         /** Pointer to native input manager service object, used by native code. */
@@ -452,9 +460,6 @@
         public native void changeKeyboardLayoutAssociation();
 
         @Override
-        public native void notifyPointerDisplayIdChanged();
-
-        @Override
         public native void setDisplayEligibilityForPointerCapture(int displayId, boolean enabled);
 
         @Override
@@ -493,5 +498,8 @@
 
         @Override
         public native void sysfsNodeChanged(String sysfsNodePath);
+
+        @Override
+        public native void notifyKeyGestureTimeoutsChanged();
     }
 }
diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp
index cf57b33..369c974 100644
--- a/services/core/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/core/jni/com_android_server_input_InputManagerService.cpp
@@ -2567,6 +2567,11 @@
     im->setStylusPointerIconEnabled(enabled);
 }
 
+static void nativeNotifyKeyGestureTimeoutsChanged(JNIEnv* env, jobject nativeImplObj) {
+    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
+    im->getInputManager()->getDispatcher().requestRefreshConfiguration();
+}
+
 // ----------------------------------------------------------------------------
 
 static const JNINativeMethod gInputManagerMethods[] = {
@@ -2663,6 +2668,7 @@
          (void*)nativeSetStylusButtonMotionEventsEnabled},
         {"getMouseCursorPosition", "()[F", (void*)nativeGetMouseCursorPosition},
         {"setStylusPointerIconEnabled", "(Z)V", (void*)nativeSetStylusPointerIconEnabled},
+        {"notifyKeyGestureTimeoutsChanged", "()V", (void*)nativeNotifyKeyGestureTimeoutsChanged},
 };
 
 #define FIND_CLASS(var, className) \