From 6413ad2c2e3aba955517a7df47d20d13cbbe0327 Mon Sep 17 00:00:00 2001 From: Josep del Rio Date: Wed, 21 Jun 2023 13:27:26 +0000 Subject: [PATCH] Handle pointer location setting in InputSettingsObserver We got a report that the pointer location developer option is not being properly set per user; testing it confirmed that show touches worked as expected while pointer location did not. After investigating, the pointer location setting was being applied in `WindowManagerService`, which generally deals with global settings, while all the input settings are handled in `InputSettingsObserver`. This CL moves the handling of the pointer location setting to `InputSettingsObserver`, which seems more natural. Test: confirmed that pointer location is now properly set on all users Bug: 288023565 Change-Id: Ic2ecd890bd32e60a2fae4d5d40d4ff8f785ee3cc --- .../server/input/InputManagerService.java | 9 +++++++ .../server/input/InputSettingsObserver.java | 7 ++++++ .../server/wm/InputManagerCallback.java | 15 ++++++++++++ .../server/wm/WindowManagerService.java | 24 ------------------- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 6a177e03102fd..3a8f9d5c35e68 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -2799,6 +2799,11 @@ public class InputManagerService extends IInputManager.Stub */ void notifyConfigurationChanged(); + /** + * This callback is invoked when the pointer location changes. + */ + void notifyPointerLocationChanged(boolean pointerLocationEnabled); + /** * This callback is invoked when the camera lens cover switch changes state. * @param whenNanos the time when the change occurred @@ -3381,6 +3386,10 @@ public class InputManagerService extends IInputManager.Stub } } + void updatePointerLocationEnabled(boolean enabled) { + mWindowManagerCallbacks.notifyPointerLocationChanged(enabled); + } + void updateFocusEventDebugViewEnabled(boolean enabled) { FocusEventDebugView view; synchronized (mFocusEventDebugViewLock) { diff --git a/services/core/java/com/android/server/input/InputSettingsObserver.java b/services/core/java/com/android/server/input/InputSettingsObserver.java index 42591f40b22eb..a608b4f480821 100644 --- a/services/core/java/com/android/server/input/InputSettingsObserver.java +++ b/services/core/java/com/android/server/input/InputSettingsObserver.java @@ -67,6 +67,8 @@ class InputSettingsObserver extends ContentObserver { (reason) -> updateTouchpadRightClickZoneEnabled()), Map.entry(Settings.System.getUriFor(Settings.System.SHOW_TOUCHES), (reason) -> updateShowTouches()), + Map.entry(Settings.System.getUriFor(Settings.System.POINTER_LOCATION), + (reason) -> updatePointerLocation()), Map.entry( Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON), (reason) -> updateAccessibilityLargePointer()), @@ -149,6 +151,11 @@ class InputSettingsObserver extends ContentObserver { mNative.setShowTouches(getBoolean(Settings.System.SHOW_TOUCHES, false)); } + private void updatePointerLocation() { + mService.updatePointerLocationEnabled( + getBoolean(Settings.System.POINTER_LOCATION, false)); + } + private void updateShowKeyPresses() { mService.updateFocusEventDebugViewEnabled( getBoolean(Settings.System.SHOW_KEY_PRESSES, false)); diff --git a/services/core/java/com/android/server/wm/InputManagerCallback.java b/services/core/java/com/android/server/wm/InputManagerCallback.java index 0a47fe09dbd99..20595eaa1e3cd 100644 --- a/services/core/java/com/android/server/wm/InputManagerCallback.java +++ b/services/core/java/com/android/server/wm/InputManagerCallback.java @@ -128,6 +128,21 @@ final class InputManagerCallback implements InputManagerService.WindowManagerCal } } + /** Notifies that the pointer location configuration has changed. */ + @Override + public void notifyPointerLocationChanged(boolean pointerLocationEnabled) { + if (mService.mPointerLocationEnabled == pointerLocationEnabled) { + return; + } + + synchronized (mService.mGlobalLock) { + mService.mPointerLocationEnabled = pointerLocationEnabled; + mService.mRoot.forAllDisplayPolicies( + p -> p.setPointerLocationEnabled(mService.mPointerLocationEnabled) + ); + } + } + /** Notifies that the lid switch changed state. */ @Override public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index bb3d109127245..35030dc318b9f 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -763,8 +763,6 @@ public class WindowManagerService extends IWindowManager.Stub Settings.Secure.getUriFor(Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS); private final Uri mPolicyControlUri = Settings.Global.getUriFor(Settings.Global.POLICY_CONTROL); - private final Uri mPointerLocationUri = - Settings.System.getUriFor(Settings.System.POINTER_LOCATION); private final Uri mForceDesktopModeOnExternalDisplaysUri = Settings.Global.getUriFor( Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS); private final Uri mFreeformWindowUri = Settings.Global.getUriFor( @@ -792,7 +790,6 @@ public class WindowManagerService extends IWindowManager.Stub resolver.registerContentObserver(mImmersiveModeConfirmationsUri, false, this, UserHandle.USER_ALL); resolver.registerContentObserver(mPolicyControlUri, false, this, UserHandle.USER_ALL); - resolver.registerContentObserver(mPointerLocationUri, false, this, UserHandle.USER_ALL); resolver.registerContentObserver(mForceDesktopModeOnExternalDisplaysUri, false, this, UserHandle.USER_ALL); resolver.registerContentObserver(mFreeformWindowUri, false, this, UserHandle.USER_ALL); @@ -816,11 +813,6 @@ public class WindowManagerService extends IWindowManager.Stub return; } - if (mPointerLocationUri.equals(uri)) { - updatePointerLocation(); - return; - } - if (mForceDesktopModeOnExternalDisplaysUri.equals(uri)) { updateForceDesktopModeOnExternalDisplays(); return; @@ -869,7 +861,6 @@ public class WindowManagerService extends IWindowManager.Stub void loadSettings() { updateSystemUiSettings(false /* handleChange */); - updatePointerLocation(); updateMaximumObscuringOpacityForTouch(); } @@ -900,21 +891,6 @@ public class WindowManagerService extends IWindowManager.Stub } } - void updatePointerLocation() { - ContentResolver resolver = mContext.getContentResolver(); - final boolean enablePointerLocation = Settings.System.getIntForUser(resolver, - Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT) != 0; - - if (mPointerLocationEnabled == enablePointerLocation) { - return; - } - mPointerLocationEnabled = enablePointerLocation; - synchronized (mGlobalLock) { - mRoot.forAllDisplayPolicies( - p -> p.setPointerLocationEnabled(mPointerLocationEnabled)); - } - } - void updateForceDesktopModeOnExternalDisplays() { ContentResolver resolver = mContext.getContentResolver(); final boolean enableForceDesktopMode = Settings.Global.getInt(resolver,