From b75b54ff254b801ec69c54abef8a06d4a86a270f Mon Sep 17 00:00:00 2001 From: Asmita Poddar Date: Thu, 16 Feb 2023 14:12:25 +0000 Subject: [PATCH] Replace InputManager.getInstance() with getSystemService() from context InputManager.getInstance(Context) method was added to create/obtain the InputManager as part of b/266013036. For backwards compatibility with the getInstance() method (without the Context parameter) was then deprecated, this made the Context member in InputManager nullable. Here, all usages of InputManager.getInstance() method have been updated to use the getSystemService() method of the context parameter, wherever the context parameter is available. Bug: b/266709559 Test: Replaced one method with another. Existing unit tests still pass. Change-Id: Iecf0022cb014d57d651615295c16aba082aa7e60 (cherry picked from commit 47585203f68f1f0fb3ec5382af1742b3b55f51e2) Merged-In: Iecf0022cb014d57d651615295c16aba082aa7e60 --- .../com/android/wm/shell/back/BackAnimationController.java | 2 +- .../wm/shell/bubbles/BubblesNavBarGestureTracker.java | 4 ++-- .../android/wm/shell/pip/phone/PipResizeGestureHandler.java | 2 +- .../shell/windowdecor/DesktopModeWindowDecorViewModel.java | 2 +- .../com/android/wm/shell/windowdecor/TaskOperations.java | 2 +- .../com/android/systemui/accessibility/SystemActions.java | 6 +++--- .../navigationbar/gestural/EdgeBackGestureHandler.java | 4 ++-- .../com/android/systemui/statusbar/KeyboardShortcuts.java | 2 +- .../android/server/accessibility/SystemActionPerformer.java | 2 +- .../java/com/android/server/wm/WindowManagerService.java | 3 ++- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java index ee5d205498c30..acf17e6700412 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java @@ -403,7 +403,7 @@ public class BackAnimationController implements RemoteCallable { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java index de5f2f467e997..75bc985556659 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java @@ -505,7 +505,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { } private void createInputChannel(int displayId) { - final InputManager inputManager = InputManager.getInstance(); + final InputManager inputManager = mContext.getSystemService(InputManager.class); final InputMonitor inputMonitor = mInputMonitorFactory.create(inputManager, mContext); final EventReceiver eventReceiver = new EventReceiver(inputMonitor, diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/TaskOperations.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/TaskOperations.java index aea3404643040..d0fcd8651481a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/TaskOperations.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/TaskOperations.java @@ -65,7 +65,7 @@ class TaskOperations { InputDevice.SOURCE_KEYBOARD); ev.setDisplayId(mContext.getDisplay().getDisplayId()); - if (!InputManager.getInstance() + if (!mContext.getSystemService(InputManager.class) .injectInputEvent(ev, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC)) { Log.e(TAG, "Inject input event fail"); } diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/SystemActions.java b/packages/SystemUI/src/com/android/systemui/accessibility/SystemActions.java index 00f5ac2ffa235..12b5705190d9f 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/SystemActions.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/SystemActions.java @@ -58,13 +58,13 @@ import com.android.systemui.statusbar.phone.CentralSurfaces; import com.android.systemui.statusbar.phone.StatusBarWindowCallback; import com.android.systemui.util.Assert; +import dagger.Lazy; + import java.util.Locale; import java.util.Optional; import javax.inject.Inject; -import dagger.Lazy; - /** * Class to register system actions with accessibility framework. */ @@ -473,7 +473,7 @@ public class SystemActions implements CoreStartable { KeyEvent event = KeyEvent.obtain(downTime, time, action, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM, InputDevice.SOURCE_KEYBOARD, null); - InputManager.getInstance() + mContext.getSystemService(InputManager.class) .injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); event.recycle(); } diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java index 389034af8a330..f3d60145a0578 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java @@ -580,7 +580,7 @@ public class EdgeBackGestureHandler implements PluginListener