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

Commit a2d5f0eb authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Remove unused InputMethodSettings#mCopyOnWrite

Now that

  InputMethodSettings#mCopyOnWrite

has no side effect thus can be safely removed.

Bug: 309837937
Test: presubmit
Change-Id: I915c7a997f2c413f3bf98f4712029fd0ce83cd52
parent c39dcef3
Loading
Loading
Loading
Loading
+17 −20
Original line number Diff line number Diff line
@@ -1619,7 +1619,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            if (userId != currentUserId) {
                return;
            }
            mSettings.switchCurrentUser(currentUserId, !mSystemReady);
            mSettings.switchCurrentUser(currentUserId);
            if (mSystemReady) {
                // We need to rebuild IMEs.
                buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
@@ -1693,7 +1693,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        mLastSwitchUserId = userId;

        // mSettings should be created before buildInputMethodListLocked
        mSettings = new InputMethodSettings(mMethodMap, userId, !mSystemReady);
        mSettings = new InputMethodSettings(mMethodMap, userId);

        AdditionalSubtypeUtils.load(mAdditionalSubtypeMap, userId);
        mSwitchingController =
@@ -1811,7 +1811,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        // copy-on-write settings.
        final boolean useCopyOnWriteSettings =
                !mSystemReady || !mUserManagerInternal.isUserUnlockingOrUnlocked(newUserId);
        mSettings.switchCurrentUser(newUserId, useCopyOnWriteSettings);
        mSettings.switchCurrentUser(newUserId);
        // Additional subtypes should be reset when the user is changed
        AdditionalSubtypeUtils.load(mAdditionalSubtypeMap, newUserId);
        final String defaultImiId = mSettings.getSelectedInputMethod();
@@ -1873,8 +1873,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            if (!mSystemReady) {
                mSystemReady = true;
                final int currentUserId = mSettings.getCurrentUserId();
                mSettings.switchCurrentUser(currentUserId,
                        !mUserManagerInternal.isUserUnlockingOrUnlocked(currentUserId));
                mSettings.switchCurrentUser(currentUserId);
                mStatusBarManagerInternal =
                        LocalServices.getService(StatusBarManagerInternal.class);
                hideStatusBarIconLocked();
@@ -2023,7 +2022,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            //TODO(b/197848765): This can be optimized by caching multi-user methodMaps/methodList.
            //TODO(b/210039666): use cache.
            final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
            final InputMethodSettings settings = new InputMethodSettings(methodMap, userId, true);
            final InputMethodSettings settings = new InputMethodSettings(methodMap, userId);
            final InputMethodInfo imi = methodMap.get(settings.getSelectedInputMethod());
            return imi != null && imi.supportsStylusHandwriting();
        }
@@ -2059,7 +2058,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            AdditionalSubtypeUtils.load(additionalSubtypeMap, userId);
            queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap,
                    methodList, directBootAwareness);
            settings = new InputMethodSettings(methodMap, userId, true /* copyOnWrite */);
            settings = new InputMethodSettings(methodMap, userId);
        }
        // filter caller's access to input methods
        methodList.removeIf(imi ->
@@ -2077,7 +2076,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            settings = mSettings;
        } else {
            final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
            settings = new InputMethodSettings(methodMap, userId, true /* copyOnWrite */);
            settings = new InputMethodSettings(methodMap, userId);
            methodList = settings.getEnabledInputMethodListLocked();
        }
        // filter caller's access to input methods
@@ -2157,7 +2156,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        if (imi == null) {
            return Collections.emptyList();
        }
        final InputMethodSettings settings = new InputMethodSettings(methodMap, userId, true);
        final InputMethodSettings settings = new InputMethodSettings(methodMap, userId);
        if (!canCallerAccessInputMethod(imi.getPackageName(), callingUid, userId, settings)) {
            return Collections.emptyList();
        }
@@ -4134,7 +4133,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            }

            final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
            final InputMethodSettings settings = new InputMethodSettings(methodMap, userId, false);
            final InputMethodSettings settings = new InputMethodSettings(methodMap, userId);
            return settings.getLastInputMethodSubtypeLocked();
        }
    }
@@ -4186,7 +4185,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            AdditionalSubtypeUtils.load(additionalSubtypeMap, userId);
            queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap,
                    methodList, DirectBootAwareness.AUTO);
            final InputMethodSettings settings = new InputMethodSettings(methodMap, userId, false);
            final InputMethodSettings settings = new InputMethodSettings(methodMap, userId);
            settings.setAdditionalInputMethodSubtypes(imiId, toBeAdded, additionalSubtypeMap,
                    mPackageManagerInternal, callingUid);
        }
@@ -4215,8 +4214,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                final boolean currentUser = (mSettings.getCurrentUserId() == userId);
                final InputMethodSettings settings = currentUser
                        ? mSettings
                        : new InputMethodSettings(queryMethodMapForUser(userId), userId,
                                !mUserManagerInternal.isUserUnlocked(userId));
                        : new InputMethodSettings(queryMethodMapForUser(userId), userId);
                if (!settings.setEnabledInputMethodSubtypes(imeId, subtypeHashCodes)) {
                    return;
                }
@@ -5365,7 +5363,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            }

            final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
            final InputMethodSettings settings = new InputMethodSettings(methodMap, userId, false);
            final InputMethodSettings settings = new InputMethodSettings(methodMap, userId);
            return settings.getCurrentInputMethodSubtypeForNonCurrentUsers();
        }
    }
@@ -5438,7 +5436,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        AdditionalSubtypeUtils.load(additionalSubtypeMap, userId);
        queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap,
                methodList, DirectBootAwareness.AUTO);
        InputMethodSettings settings = new InputMethodSettings(methodMap, userId, true);
        InputMethodSettings settings = new InputMethodSettings(methodMap, userId);
        return methodMap.get(settings.getSelectedInputMethod());
    }

@@ -5465,7 +5463,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            return true;
        }
        final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
        final InputMethodSettings settings = new InputMethodSettings(methodMap, userId, false);
        final InputMethodSettings settings = new InputMethodSettings(methodMap, userId);
        if (!methodMap.containsKey(imeId)
                || !settings.getEnabledInputMethodListLocked().contains(methodMap.get(imeId))) {
            return false; // IME is not found or not enabled.
@@ -5604,8 +5602,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                    return true;
                }
                final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
                final InputMethodSettings settings = new InputMethodSettings(methodMap,
                        userId, false);
                final InputMethodSettings settings = new InputMethodSettings(methodMap, userId);
                if (!methodMap.containsKey(imeId)) {
                    return false; // IME is not found.
                }
@@ -6348,7 +6345,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            }
        } else {
            final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
            final InputMethodSettings settings = new InputMethodSettings(methodMap, userId, false);
            final InputMethodSettings settings = new InputMethodSettings(methodMap, userId);
            if (enabled) {
                if (!methodMap.containsKey(imeId)) {
                    failedToEnableUnknownIme = true;
@@ -6491,7 +6488,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                        queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap,
                                methodMap, methodList, DirectBootAwareness.AUTO);
                        final InputMethodSettings settings = new InputMethodSettings(
                                methodMap, userId, false);
                                methodMap, userId);

                        nextEnabledImes = InputMethodInfoUtils.getDefaultEnabledImes(mContext,
                                methodList);
+3 −10
Original line number Diff line number Diff line
@@ -213,7 +213,6 @@ final class InputMethodUtils {
    public static class InputMethodSettings {
        private final ArrayMap<String, InputMethodInfo> mMethodMap;

        private boolean mCopyOnWrite = false;
        @UserIdInt
        private int mCurrentUserId;

@@ -227,26 +226,21 @@ final class InputMethodUtils {
            }
        }

        InputMethodSettings(ArrayMap<String, InputMethodInfo> methodMap, @UserIdInt int userId,
                boolean copyOnWrite) {
        InputMethodSettings(ArrayMap<String, InputMethodInfo> methodMap, @UserIdInt int userId) {
            mMethodMap = methodMap;
            switchCurrentUser(userId, copyOnWrite);
            switchCurrentUser(userId);
        }

        /**
         * Must be called when the current user is changed.
         *
         * @param userId The user ID.
         * @param copyOnWrite If {@code true}, for each settings key
         * (e.g. {@link Settings.Secure#ACTION_INPUT_METHOD_SUBTYPE_SETTINGS}) we use the actual
         * settings on the {@link Settings.Secure} until we do the first write operation.
         */
        void switchCurrentUser(@UserIdInt int userId, boolean copyOnWrite) {
        void switchCurrentUser(@UserIdInt int userId) {
            if (DEBUG) {
                Slog.d(TAG, "--- Switch the current user from " + mCurrentUserId + " to " + userId);
            }
            mCurrentUserId = userId;
            mCopyOnWrite = copyOnWrite;
        }

        private void putString(@NonNull String key, @Nullable String str) {
@@ -840,7 +834,6 @@ final class InputMethodUtils {

        public void dumpLocked(final Printer pw, final String prefix) {
            pw.println(prefix + "mCurrentUserId=" + mCurrentUserId);
            pw.println(prefix + "mCopyOnWrite=" + mCopyOnWrite);
        }
    }

+2 −2
Original line number Diff line number Diff line
@@ -1236,7 +1236,7 @@ public class InputMethodUtilsTest {
        // Init InputMethodSettings for the owner user (userId=0), verify calls can get the
        // corresponding user's context, contentResolver and the resources configuration.
        InputMethodUtils.InputMethodSettings settings = new InputMethodUtils.InputMethodSettings(
                methodMap, 0 /* userId */, true);
                methodMap, 0 /* userId */);
        assertEquals(0, settings.getCurrentUserId());

        settings.isShowImeWithHardKeyboardEnabled();
@@ -1247,7 +1247,7 @@ public class InputMethodUtilsTest {

        // Calling switchCurrentUser to the secondary user (userId=10), verify calls can get the
        // corresponding user's context, contentResolver and the resources configuration.
        settings.switchCurrentUser(10 /* userId */, true);
        settings.switchCurrentUser(10 /* userId */);
        assertEquals(10, settings.getCurrentUserId());

        settings.isShowImeWithHardKeyboardEnabled();