Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06483f83 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove ImfLock dependency from IMM#get*InputMethod()" into main

parents 69c37a08 20f35402
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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,
+68 −95
Original line number Diff line number Diff line
@@ -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,17 +1485,15 @@ 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(
            return InputMethodInfoSafeList.create(getInputMethodListInternal(
                    userId, directBootAwareness, callingUid));
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
    }

    @BinderThread
    @NonNull
@@ -1509,17 +1506,15 @@ 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));
                    getEnabledInputMethodListInternal(userId, callingUid));
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
    }

    @BinderThread
    @NonNull
@@ -1533,16 +1528,14 @@ 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);
            return getInputMethodListInternal(userId, directBootAwareness, callingUid);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
    }

    @BinderThread
    @NonNull
@@ -1555,16 +1548,14 @@ 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);
            return getEnabledInputMethodListInternal(userId, callingUid);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
    }

    @Override
    public boolean isStylusHandwritingAvailableAsUser(
@@ -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,
            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,31 +5825,28 @@ 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,
            return getEnabledInputMethodSubtypeListInternal(imiId, allowsImplicitlyEnabledSubtypes,
                    userId, Process.SYSTEM_UID);
        }
        }

        @Override
        public void onCreateInlineSuggestionsRequest(@UserIdInt int userId,
@@ -6619,15 +6591,17 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    break;
            }
        }
        final int[] userIds;
        synchronized (ImfLock.class) {
            final int[] userIds = InputMethodUtils.resolveUserId(userIdToBeResolved,
                    mCurrentUserId, shellCommand.getErrPrintWriter());
            userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, mCurrentUserId,
                    shellCommand.getErrPrintWriter());
        }
        try (PrintWriter pr = shellCommand.getOutPrintWriter()) {
            for (int userId : userIds) {
                final List<InputMethodInfo> methods = all
                            ? getInputMethodListLocked(
                        ? getInputMethodListInternal(
                                userId, DirectBootAwareness.AUTO, Process.SHELL_UID)
                            : getEnabledInputMethodListLocked(userId, Process.SHELL_UID);
                        : getEnabledInputMethodListInternal(userId, Process.SHELL_UID);
                if (userIds.length > 1) {
                    pr.print("User #");
                    pr.print(userId);
@@ -6644,7 +6618,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                }
            }
        }
        }
        return ShellCommandResult.SUCCESS;
    }