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

Commit 2501e749 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Clear additional subtypes upon background APK updates

Previously

  MyPackageMonitor#onFinishPackageChangesInternal()

took effect when and only when the APK change was for the current
user, which means that additional subtypes would remain unchanged if
the APK update happened while the user is not
InputMethodManagerService's current IME user.

With this commit, additional subtypes start being cleared even for a
background APK update.

See the corresponding CTS change [1] about detailed behavior change.

 [1]: Iecce1e7c035bb20961b3ac68414f212c4b748da6

Bug: 322062773
Fix: 27859687
Test: atest CtsInputMethodInstallTestCases:AdditionalSubtypeLifecycleTest
Change-Id: I10aa547f0de607ef3c0ba26764dac0585c40c843
parent 0c5feb22
Loading
Loading
Loading
Loading
+33 −14
Original line number Original line Diff line number Diff line
@@ -1397,16 +1397,22 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub


        private void onFinishPackageChangesInternal() {
        private void onFinishPackageChangesInternal() {
            synchronized (ImfLock.class) {
            synchronized (ImfLock.class) {
                if (!isChangingPackagesOfCurrentUserLocked()) {
                final int userId = getChangingUserId();
                    return;
                final boolean isCurrentUser = (userId == mSettings.getUserId());
                }
                AdditionalSubtypeMap additionalSubtypeMap;
                if (!shouldRebuildInputMethodListLocked()) {
                final InputMethodSettings settings;
                    return;
                if (isCurrentUser) {
                    additionalSubtypeMap = mAdditionalSubtypeMap;
                    settings = mSettings;
                } else {
                    additionalSubtypeMap = AdditionalSubtypeUtils.load(userId);
                    settings = queryInputMethodServicesInternal(mContext, userId,
                            additionalSubtypeMap, DirectBootAwareness.AUTO);
                }
                }


                InputMethodInfo curIm = null;
                InputMethodInfo curIm = null;
                String curInputMethodId = mSettings.getSelectedInputMethod();
                String curInputMethodId = settings.getSelectedInputMethod();
                final List<InputMethodInfo> methodList = mSettings.getMethodList();
                final List<InputMethodInfo> methodList = settings.getMethodList();
                final int numImes = methodList.size();
                final int numImes = methodList.size();
                for (int i = 0; i < numImes; i++) {
                for (int i = 0; i < numImes; i++) {
                    InputMethodInfo imi = methodList.get(i);
                    InputMethodInfo imi = methodList.get(i);
@@ -1414,21 +1420,34 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                    if (imiId.equals(curInputMethodId)) {
                    if (imiId.equals(curInputMethodId)) {
                        curIm = imi;
                        curIm = imi;
                    }
                    }

                    int change = isPackageDisappearing(imi.getPackageName());
                    int change = isPackageDisappearing(imi.getPackageName());
                    if (change == PACKAGE_TEMPORARY_CHANGE || change == PACKAGE_PERMANENT_CHANGE) {
                    if (change == PACKAGE_TEMPORARY_CHANGE || change == PACKAGE_PERMANENT_CHANGE) {
                        Slog.i(TAG, "Input method uninstalled, disabling: " + imi.getComponent());
                        Slog.i(TAG, "Input method uninstalled, disabling: " + imi.getComponent());
                        if (isCurrentUser) {
                            setInputMethodEnabledLocked(imi.getId(), false);
                            setInputMethodEnabledLocked(imi.getId(), false);
                        } else {
                            settings.buildAndPutEnabledInputMethodsStrRemovingId(
                                    new StringBuilder(),
                                    settings.getEnabledInputMethodsAndSubtypeList(),
                                    imi.getId());
                        }
                    } else if (change == PACKAGE_UPDATING) {
                    } else if (change == PACKAGE_UPDATING) {
                        Slog.i(TAG, "Input method reinstalling, clearing additional subtypes: "
                        Slog.i(TAG, "Input method reinstalling, clearing additional subtypes: "
                                + imi.getComponent());
                                + imi.getComponent());
                        mAdditionalSubtypeMap =
                        additionalSubtypeMap =
                                mAdditionalSubtypeMap.cloneWithRemoveOrSelf(imi.getId());
                                additionalSubtypeMap.cloneWithRemoveOrSelf(imi.getId());
                        AdditionalSubtypeUtils.save(mAdditionalSubtypeMap,
                        AdditionalSubtypeUtils.save(additionalSubtypeMap,
                                mSettings.getMethodMap(), mSettings.getUserId());
                                settings.getMethodMap(), userId);
                        if (isCurrentUser) {
                            mAdditionalSubtypeMap = additionalSubtypeMap;
                        }
                    }
                    }
                }
                }


                if (!isCurrentUser || !shouldRebuildInputMethodListLocked()) {
                    return;
                }

                buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
                buildInputMethodListLocked(false /* resetDefaultEnabledIme */);


                boolean changed = false;
                boolean changed = false;
@@ -1438,7 +1457,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                    if (change == PACKAGE_TEMPORARY_CHANGE
                    if (change == PACKAGE_TEMPORARY_CHANGE
                            || change == PACKAGE_PERMANENT_CHANGE) {
                            || change == PACKAGE_PERMANENT_CHANGE) {
                        final PackageManager userAwarePackageManager =
                        final PackageManager userAwarePackageManager =
                                getPackageManagerForUser(mContext, mSettings.getUserId());
                                getPackageManagerForUser(mContext, userId);
                        ServiceInfo si = null;
                        ServiceInfo si = null;
                        try {
                        try {
                            si = userAwarePackageManager.getServiceInfo(curIm.getComponent(),
                            si = userAwarePackageManager.getServiceInfo(curIm.getComponent(),