Loading services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +4 −8 Original line number Original line Diff line number Diff line Loading @@ -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); Loading Loading @@ -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 */); Loading Loading @@ -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(); Loading Loading @@ -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(); Loading services/core/java/com/android/server/inputmethod/InputMethodUtils.java +1 −13 Original line number Original line Diff line number Diff line Loading @@ -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) { Loading @@ -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(); Loading services/tests/servicestests/src/com/android/server/inputmethod/InputMethodUtilsTest.java +0 −31 Original line number Original line Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 = Loading Loading
services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +4 −8 Original line number Original line Diff line number Diff line Loading @@ -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); Loading Loading @@ -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 */); Loading Loading @@ -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(); Loading Loading @@ -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(); Loading
services/core/java/com/android/server/inputmethod/InputMethodUtils.java +1 −13 Original line number Original line Diff line number Diff line Loading @@ -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) { Loading @@ -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(); Loading
services/tests/servicestests/src/com/android/server/inputmethod/InputMethodUtilsTest.java +0 −31 Original line number Original line Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 = Loading