diff options
| -rw-r--r-- | services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java | 10 | ||||
| -rw-r--r-- | services/core/java/com/android/server/inputmethod/InputMethodManagerService.java | 163 |
2 files changed, 78 insertions, 95 deletions
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java index cc9f63048843..13209d861e8b 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java @@ -90,6 +90,8 @@ public abstract class InputMethodManagerInternal { * @param userId the user ID to be queried * @return a list of {@link InputMethodInfo}. VR-only IMEs are already excluded */ + @ImfLockFree + @NonNull public abstract List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId); /** @@ -98,6 +100,8 @@ public abstract class InputMethodManagerInternal { * @param userId the user ID to be queried * @return a list of {@link InputMethodInfo} that are enabled for {@code userId} */ + @ImfLockFree + @NonNull public abstract List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId); /** @@ -108,6 +112,7 @@ public abstract class InputMethodManagerInternal { * @param userId the user ID to be queried about * @return a list of {@link InputMethodSubtype} that are enabled for {@code userId} */ + @ImfLockFree @NonNull public abstract List<InputMethodSubtype> getEnabledInputMethodSubtypeListAsUser( String imiId, boolean allowsImplicitlyEnabledSubtypes, @UserIdInt int userId); @@ -314,17 +319,22 @@ public abstract class InputMethodManagerInternal { int originatingDisplayId) { } + @ImfLockFree + @NonNull @Override public List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId) { return Collections.emptyList(); } + @ImfLockFree + @NonNull @Override public List<InputMethodInfo> getEnabledInputMethodListAsUser( @UserIdInt int userId) { return Collections.emptyList(); } + @ImfLockFree @NonNull @Override public List<InputMethodSubtype> getEnabledInputMethodSubtypeListAsUser(String imiId, diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index e8c15987751a..a9723ccc2576 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -1469,9 +1469,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. mContext.enforceCallingOrSelfPermission( Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); } - synchronized (ImfLock.class) { - return queryDefaultInputMethodForUserIdLocked(userId); - } + final InputMethodSettings settings = InputMethodSettingsRepository.get(userId); + return settings.getMethodMap().get(settings.getSelectedInputMethod()); } @BinderThread @@ -1486,15 +1485,13 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. if (!mUserManagerInternal.exists(userId)) { return InputMethodInfoSafeList.empty(); } - synchronized (ImfLock.class) { - final int callingUid = Binder.getCallingUid(); - final long ident = Binder.clearCallingIdentity(); - try { - return InputMethodInfoSafeList.create(getInputMethodListLocked( - userId, directBootAwareness, callingUid)); - } finally { - Binder.restoreCallingIdentity(ident); - } + final int callingUid = Binder.getCallingUid(); + final long ident = Binder.clearCallingIdentity(); + try { + return InputMethodInfoSafeList.create(getInputMethodListInternal( + userId, directBootAwareness, callingUid)); + } finally { + Binder.restoreCallingIdentity(ident); } } @@ -1509,15 +1506,13 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. if (!mUserManagerInternal.exists(userId)) { return InputMethodInfoSafeList.empty(); } - synchronized (ImfLock.class) { - final int callingUid = Binder.getCallingUid(); - final long ident = Binder.clearCallingIdentity(); - try { - return InputMethodInfoSafeList.create( - getEnabledInputMethodListLocked(userId, callingUid)); - } finally { - Binder.restoreCallingIdentity(ident); - } + final int callingUid = Binder.getCallingUid(); + final long ident = Binder.clearCallingIdentity(); + try { + return InputMethodInfoSafeList.create( + getEnabledInputMethodListInternal(userId, callingUid)); + } finally { + Binder.restoreCallingIdentity(ident); } } @@ -1533,14 +1528,12 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. if (!mUserManagerInternal.exists(userId)) { return Collections.emptyList(); } - synchronized (ImfLock.class) { - final int callingUid = Binder.getCallingUid(); - final long ident = Binder.clearCallingIdentity(); - try { - return getInputMethodListLocked(userId, directBootAwareness, callingUid); - } finally { - Binder.restoreCallingIdentity(ident); - } + final int callingUid = Binder.getCallingUid(); + final long ident = Binder.clearCallingIdentity(); + try { + return getInputMethodListInternal(userId, directBootAwareness, callingUid); + } finally { + Binder.restoreCallingIdentity(ident); } } @@ -1555,14 +1548,12 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. if (!mUserManagerInternal.exists(userId)) { return Collections.emptyList(); } - synchronized (ImfLock.class) { - final int callingUid = Binder.getCallingUid(); - final long ident = Binder.clearCallingIdentity(); - try { - return getEnabledInputMethodListLocked(userId, callingUid); - } finally { - Binder.restoreCallingIdentity(ident); - } + final int callingUid = Binder.getCallingUid(); + final long ident = Binder.clearCallingIdentity(); + try { + return getEnabledInputMethodListInternal(userId, callingUid); + } finally { + Binder.restoreCallingIdentity(ident); } } @@ -1606,8 +1597,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. return true; } - @GuardedBy("ImfLock.class") - private List<InputMethodInfo> getInputMethodListLocked(@UserIdInt int userId, + private List<InputMethodInfo> getInputMethodListInternal(@UserIdInt int userId, @DirectBootAwareness int directBootAwareness, int callingUid) { final InputMethodSettings settings; if (directBootAwareness == DirectBootAwareness.AUTO) { @@ -1626,8 +1616,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. return methodList; } - @GuardedBy("ImfLock.class") - private List<InputMethodInfo> getEnabledInputMethodListLocked(@UserIdInt int userId, + private List<InputMethodInfo> getEnabledInputMethodListInternal(@UserIdInt int userId, int callingUid) { final InputMethodSettings settings = InputMethodSettingsRepository.get(userId); final ArrayList<InputMethodInfo> methodList = settings.getEnabledInputMethodList(); @@ -1654,20 +1643,17 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); } - synchronized (ImfLock.class) { - final int callingUid = Binder.getCallingUid(); - final long ident = Binder.clearCallingIdentity(); - try { - return getEnabledInputMethodSubtypeListLocked(imiId, - allowsImplicitlyEnabledSubtypes, userId, callingUid); - } finally { - Binder.restoreCallingIdentity(ident); - } + final int callingUid = Binder.getCallingUid(); + final long ident = Binder.clearCallingIdentity(); + try { + return getEnabledInputMethodSubtypeListInternal(imiId, + allowsImplicitlyEnabledSubtypes, userId, callingUid); + } finally { + Binder.restoreCallingIdentity(ident); } } - @GuardedBy("ImfLock.class") - private List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(String imiId, + private List<InputMethodSubtype> getEnabledInputMethodSubtypeListInternal(String imiId, boolean allowsImplicitlyEnabledSubtypes, @UserIdInt int userId, int callingUid) { final InputMethodSettings settings = InputMethodSettingsRepository.get(userId); final InputMethodInfo imi = settings.getMethodMap().get(imiId); @@ -5703,17 +5689,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. } } - /** - * Returns the default {@link InputMethodInfo} for the specific userId. - * - * @param userId user ID to query - */ - @GuardedBy("ImfLock.class") - private InputMethodInfo queryDefaultInputMethodForUserIdLocked(@UserIdInt int userId) { - final InputMethodSettings settings = InputMethodSettingsRepository.get(userId); - return settings.getMethodMap().get(settings.getSelectedInputMethod()); - } - @GuardedBy("ImfLock.class") private boolean switchToInputMethodLocked(@NonNull String imeId, int subtypeId, @UserIdInt int userId) { @@ -5850,30 +5825,27 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. mHandler.obtainMessage(MSG_HIDE_ALL_INPUT_METHODS, reason).sendToTarget(); } + @ImfLockFree + @NonNull @Override public List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId) { - synchronized (ImfLock.class) { - return getInputMethodListLocked(userId, DirectBootAwareness.AUTO, - Process.SYSTEM_UID); - } + return getInputMethodListInternal(userId, DirectBootAwareness.AUTO, Process.SYSTEM_UID); } + @ImfLockFree + @NonNull @Override public List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId) { - synchronized (ImfLock.class) { - return getEnabledInputMethodListLocked(userId, Process.SYSTEM_UID); - } + return getEnabledInputMethodListInternal(userId, Process.SYSTEM_UID); } + @ImfLockFree @NonNull @Override public List<InputMethodSubtype> getEnabledInputMethodSubtypeListAsUser( String imiId, boolean allowsImplicitlyEnabledSubtypes, @UserIdInt int userId) { - synchronized (ImfLock.class) { - return getEnabledInputMethodSubtypeListLocked(imiId, - allowsImplicitlyEnabledSubtypes, - userId, Process.SYSTEM_UID); - } + return getEnabledInputMethodSubtypeListInternal(imiId, allowsImplicitlyEnabledSubtypes, + userId, Process.SYSTEM_UID); } @Override @@ -6619,28 +6591,29 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. break; } } + final int[] userIds; synchronized (ImfLock.class) { - final int[] userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, - mCurrentUserId, shellCommand.getErrPrintWriter()); - try (PrintWriter pr = shellCommand.getOutPrintWriter()) { - for (int userId : userIds) { - final List<InputMethodInfo> methods = all - ? getInputMethodListLocked( - userId, DirectBootAwareness.AUTO, Process.SHELL_UID) - : getEnabledInputMethodListLocked(userId, Process.SHELL_UID); - if (userIds.length > 1) { - pr.print("User #"); - pr.print(userId); + userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, mCurrentUserId, + shellCommand.getErrPrintWriter()); + } + try (PrintWriter pr = shellCommand.getOutPrintWriter()) { + for (int userId : userIds) { + final List<InputMethodInfo> methods = all + ? getInputMethodListInternal( + userId, DirectBootAwareness.AUTO, Process.SHELL_UID) + : getEnabledInputMethodListInternal(userId, Process.SHELL_UID); + if (userIds.length > 1) { + pr.print("User #"); + pr.print(userId); + pr.println(":"); + } + for (InputMethodInfo info : methods) { + if (brief) { + pr.println(info.getId()); + } else { + pr.print(info.getId()); pr.println(":"); - } - for (InputMethodInfo info : methods) { - if (brief) { - pr.println(info.getId()); - } else { - pr.print(info.getId()); - pr.println(":"); - info.dump(pr::println, " "); - } + info.dump(pr::println, " "); } } } |