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

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

Merge "Do more stuff w/o ImfLock in onFinishPackageChangesInternal()" into main

parents e864831b 36419b61
Loading
Loading
Loading
Loading
+54 −47
Original line number Diff line number Diff line
@@ -797,11 +797,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            final int userId = getChangingUserId();
            final var userData = getUserData(userId);

            // Instantiating InputMethodInfo requires disk I/O.
            // Do them before acquiring the lock to minimize the chances of ANR (b/340221861).
            userData.mRawInputMethodMap.set(queryRawInputMethodServiceMap(mContext, userId));

            synchronized (ImfLock.class) {
            final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);

            InputMethodInfo curIm = null;
@@ -809,6 +806,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            final List<InputMethodInfo> methodList = settings.getMethodList();

            final ArrayList<String> imesToClearAdditionalSubtypes = new ArrayList<>();
            final ArrayList<String> imesToBeDisabled = new ArrayList<>();
            final int numImes = methodList.size();
            for (int i = 0; i < numImes; i++) {
                InputMethodInfo imi = methodList.get(i);
@@ -822,7 +820,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                int change = isPackageDisappearing(imi.getPackageName());
                if (change == PACKAGE_PERMANENT_CHANGE) {
                    Slog.i(TAG, "Input method uninstalled, disabling: " + imi.getComponent());
                        setInputMethodEnabledLocked(imi.getId(), false, userId);
                    imesToBeDisabled.add(imi.getId());
                } else if (change == PACKAGE_UPDATING) {
                    Slog.i(TAG, "Input method reinstalling, clearing additional subtypes: "
                            + imi.getComponent());
@@ -846,14 +844,23 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    DirectBootAwareness.AUTO,
                    mUserManagerInternal.isUserUnlockingOrUnlocked(userId));

                if (InputMethodMap.areSame(settings.getMethodMap(), newMethodMap)) {
                    // No update in the actual IME map.
            final boolean noUpdate = InputMethodMap.areSame(settings.getMethodMap(), newMethodMap);
            if (noUpdate && imesToBeDisabled.isEmpty()) {
                return;
            }

                final InputMethodSettings newSettings =
                        InputMethodSettings.create(newMethodMap, userId);
                InputMethodSettingsRepository.put(userId, newSettings);
            // Here we start remaining tasks that need to be done with the lock (b/340221861).
            synchronized (ImfLock.class) {
                final int numImesToBeDisabled = imesToBeDisabled.size();
                for (int i = 0; i < numImesToBeDisabled; ++i) {
                    setInputMethodEnabledLocked(imesToBeDisabled.get(i), false /* enabled */,
                            userId);
                }
                if (noUpdate) {
                    return;
                }
                InputMethodSettingsRepository.put(userId,
                        InputMethodSettings.create(newMethodMap, userId));
                postInputMethodSettingUpdatedLocked(false /* resetDefaultEnabledIme */, userId);

                boolean changed = false;