From e7d0682b9ec37a973930ed54abc52c9309f593f8 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 5 Oct 2022 17:11:23 -0700 Subject: [PATCH] Stop relying on IActivityManager#getCurrentUser() in IMMS There is no good reason for InputMethodManagerService to continue using IActivityManager#getCurrentUser() to get the current user ID because such information is already available through ActivityManagerInternal#getCurrentUserId(). There should be no observable behavior change in this CL. Bug: 234882948 Test: presubmit Change-Id: Id386400df4d45c0b710902e60bb0715c6e1fc3bb --- .../server/inputmethod/InputMethodManagerService.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index ab05e034562b2..e82de04ff6fad 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -297,6 +297,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub private final SparseBooleanArray mLoggedDeniedGetInputMethodWindowVisibleHeightForUid = new SparseBooleanArray(0); final WindowManagerInternal mWindowManagerInternal; + private final ActivityManagerInternal mActivityManagerInternal; final PackageManagerInternal mPackageManagerInternal; final InputManagerInternal mInputManagerInternal; final ImePlatformCompatUtils mImePlatformCompatUtils; @@ -1722,6 +1723,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mIWindowManager = IWindowManager.Stub.asInterface( ServiceManager.getService(Context.WINDOW_SERVICE)); mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); + mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class); mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); mImePlatformCompatUtils = new ImePlatformCompatUtils(); @@ -1756,12 +1758,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mShowOngoingImeSwitcherForPhones = false; mNotificationShown = false; - int userId = 0; - try { - userId = ActivityManager.getService().getCurrentUser().id; - } catch (RemoteException e) { - Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e); - } + final int userId = mActivityManagerInternal.getCurrentUserId(); mLastSwitchUserId = userId; @@ -3313,7 +3310,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub // setSelectedInputMethodAndSubtypeLocked(). setSelectedMethodIdLocked(id); - if (LocalServices.getService(ActivityManagerInternal.class).isSystemReady()) { + if (mActivityManagerInternal.isSystemReady()) { Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.putExtra("input_method_id", id);