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

Commit 3dbafcf0 authored by Yohei Yukawa's avatar Yohei Yukawa Committed by Android (Google) Code Review
Browse files

Merge "Deprecate InputMethodSettings#switchCurrentUser()" into main

parents 60b6a74d a56463ba
Loading
Loading
Loading
Loading
+4 −8
Original line number Original line Diff line number Diff line
@@ -279,7 +279,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    final Context mContext;
    final Context mContext;
    final Resources mRes;
    final Resources mRes;
    private final Handler mHandler;
    private final Handler mHandler;
    private final InputMethodSettings mSettings;
    @NonNull
    private InputMethodSettings mSettings;
    final SettingsObserver mSettingsObserver;
    final SettingsObserver mSettingsObserver;
    private final SparseBooleanArray mLoggedDeniedGetInputMethodWindowVisibleHeightForUid =
    private final SparseBooleanArray mLoggedDeniedGetInputMethodWindowVisibleHeightForUid =
            new SparseBooleanArray(0);
            new SparseBooleanArray(0);
@@ -1630,7 +1631,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            if (userId != currentUserId) {
            if (userId != currentUserId) {
                return;
                return;
            }
            }
            mSettings.switchCurrentUser(currentUserId);
            mSettings = new InputMethodSettings(mMethodMap, userId);
            if (mSystemReady) {
            if (mSystemReady) {
                // We need to rebuild IMEs.
                // We need to rebuild IMEs.
                buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
                buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
@@ -1832,11 +1833,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        // ContentObserver should be registered again when the user is changed
        // ContentObserver should be registered again when the user is changed
        mSettingsObserver.registerContentObserverLocked(newUserId);
        mSettingsObserver.registerContentObserverLocked(newUserId);


        // If the system is not ready or the device is not yed unlocked by the user, then we use
        mSettings = new InputMethodSettings(mMethodMap, newUserId);
        // copy-on-write settings.
        final boolean useCopyOnWriteSettings =
                !mSystemReady || !mUserManagerInternal.isUserUnlockingOrUnlocked(newUserId);
        mSettings.switchCurrentUser(newUserId);
        // Additional subtypes should be reset when the user is changed
        // Additional subtypes should be reset when the user is changed
        AdditionalSubtypeUtils.load(mAdditionalSubtypeMap, newUserId);
        AdditionalSubtypeUtils.load(mAdditionalSubtypeMap, newUserId);
        final String defaultImiId = mSettings.getSelectedInputMethod();
        final String defaultImiId = mSettings.getSelectedInputMethod();
@@ -1898,7 +1895,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            if (!mSystemReady) {
            if (!mSystemReady) {
                mSystemReady = true;
                mSystemReady = true;
                final int currentUserId = mSettings.getCurrentUserId();
                final int currentUserId = mSettings.getCurrentUserId();
                mSettings.switchCurrentUser(currentUserId);
                mStatusBarManagerInternal =
                mStatusBarManagerInternal =
                        LocalServices.getService(StatusBarManagerInternal.class);
                        LocalServices.getService(StatusBarManagerInternal.class);
                hideStatusBarIconLocked();
                hideStatusBarIconLocked();
+1 −13
Original line number Original line Diff line number Diff line
@@ -215,7 +215,7 @@ final class InputMethodUtils {
        private final ArrayMap<String, InputMethodInfo> mMethodMap;
        private final ArrayMap<String, InputMethodInfo> mMethodMap;


        @UserIdInt
        @UserIdInt
        private int mCurrentUserId;
        private final int mCurrentUserId;


        private static void buildEnabledInputMethodsSettingString(
        private static void buildEnabledInputMethodsSettingString(
                StringBuilder builder, Pair<String, ArrayList<String>> ime) {
                StringBuilder builder, Pair<String, ArrayList<String>> ime) {
@@ -229,18 +229,6 @@ final class InputMethodUtils {


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

        /**
         * Must be called when the current user is changed.
         *
         * @param userId The user ID.
         */
        void switchCurrentUser(@UserIdInt int userId) {
            if (DEBUG) {
                Slog.d(TAG, "--- Switch the current user from " + mCurrentUserId + " to " + userId);
            }
            mCurrentUserId = userId;
            mCurrentUserId = userId;
            String ime = getSelectedInputMethod();
            String ime = getSelectedInputMethod();
            String defaultDeviceIme = getSelectedDefaultDeviceInputMethod();
            String defaultDeviceIme = getSelectedDefaultDeviceInputMethod();
+0 −31
Original line number Original line Diff line number Diff line
@@ -25,10 +25,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


import android.content.ContentResolver;
import android.content.ContentResolver;
@@ -1223,35 +1221,6 @@ public class InputMethodUtilsTest {
                StartInputFlags.VIEW_HAS_FOCUS | StartInputFlags.IS_TEXT_EDITOR));
                StartInputFlags.VIEW_HAS_FOCUS | StartInputFlags.IS_TEXT_EDITOR));
    }
    }


    @Test
    public void testInputMethodSettings_SwitchCurrentUser() {
        TestContext ownerUserContext = createMockContext(0 /* userId */);
        final InputMethodInfo systemIme = createFakeInputMethodInfo(
                "SystemIme", "fake.latin", true /* isSystem */);
        final InputMethodInfo nonSystemIme = createFakeInputMethodInfo("NonSystemIme",
                "fake.voice0", false /* isSystem */);
        final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>();
        methodMap.put(systemIme.getId(), systemIme);

        // 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 */);
        assertEquals(0, settings.getCurrentUserId());

        settings.getEnabledInputMethodSubtypeListLocked(nonSystemIme, true);
        verify(ownerUserContext.getResources(), atLeastOnce()).getConfiguration();

        // 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 */);
        assertEquals(10, settings.getCurrentUserId());

        settings.getEnabledInputMethodSubtypeListLocked(nonSystemIme, true);
        verify(TestContext.getSecondaryUserContext().getResources(),
                atLeastOnce()).getConfiguration();
    }

    private static IntArray createSubtypeHashCodeArrayFromStr(String subtypeHashCodesStr) {
    private static IntArray createSubtypeHashCodeArrayFromStr(String subtypeHashCodesStr) {
        final IntArray subtypes = new IntArray();
        final IntArray subtypes = new IntArray();
        final TextUtils.SimpleStringSplitter imeSubtypeSplitter =
        final TextUtils.SimpleStringSplitter imeSubtypeSplitter =