@@ -171,8 +171,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
171171 final SettingsObserver mSettingsObserver ;
172172 final IWindowManager mIWindowManager ;
173173 final HandlerCaller mCaller ;
174- private final InputMethodFileManager mFileManager ;
175- private final InputMethodAndSubtypeListManager mImListManager ;
174+ private InputMethodFileManager mFileManager ;
175+ private InputMethodAndSubtypeListManager mImListManager ;
176176 private final HardKeyboardListener mHardKeyboardListener ;
177177 private final WindowManagerService mWindowManagerService ;
178178
@@ -625,11 +625,6 @@ public void executeMessage(Message msg) {
625625
626626 mShowOngoingImeSwitcherForPhones = false ;
627627
628- synchronized (mMethodMap ) {
629- mFileManager = new InputMethodFileManager (mMethodMap );
630- }
631- mImListManager = new InputMethodAndSubtypeListManager (context , this );
632-
633628 final IntentFilter broadcastFilter = new IntentFilter ();
634629 broadcastFilter .addAction (Intent .ACTION_SCREEN_ON );
635630 broadcastFilter .addAction (Intent .ACTION_SCREEN_OFF );
@@ -643,7 +638,9 @@ public void executeMessage(Message msg) {
643638 new IUserSwitchObserver .Stub () {
644639 @ Override
645640 public void onUserSwitching (int newUserId , IRemoteCallback reply ) {
646- switchUser (newUserId );
641+ synchronized (mMethodMap ) {
642+ switchUserLocked (newUserId );
643+ }
647644 if (reply != null ) {
648645 try {
649646 reply .sendResult (null );
@@ -665,6 +662,8 @@ public void onUserSwitchComplete(int newUserId) throws RemoteException {
665662 // mSettings should be created before buildInputMethodListLocked
666663 mSettings = new InputMethodSettings (
667664 mRes , context .getContentResolver (), mMethodMap , mMethodList , userId );
665+ mFileManager = new InputMethodFileManager (mMethodMap , userId );
666+ mImListManager = new InputMethodAndSubtypeListManager (context , this );
668667
669668 // Just checking if defaultImiId is empty or not
670669 final String defaultImiId = mSettings .getSelectedInputMethod ();
@@ -736,6 +735,8 @@ private void resetAllInternalStateLocked(boolean updateOnlyWhenLocaleChanged) {
736735 if (DEBUG ) {
737736 Slog .i (TAG , "Locale has been changed to " + newLocale );
738737 }
738+ // InputMethodAndSubtypeListManager should be reset when the locale is changed.
739+ mImListManager = new InputMethodAndSubtypeListManager (mContext , this );
739740 buildInputMethodListLocked (mMethodList , mMethodMap );
740741 if (!updateOnlyWhenLocaleChanged ) {
741742 final String selectedImiId = mSettings .getSelectedInputMethod ();
@@ -761,8 +762,10 @@ private void checkCurrentLocaleChangedLocked() {
761762 resetAllInternalStateLocked (true );
762763 }
763764
764- private void switchUser (int newUserId ) {
765+ private void switchUserLocked (int newUserId ) {
765766 mSettings .setCurrentUserId (newUserId );
767+ // InputMethodFileManager should be reset when the user is changed
768+ mFileManager = new InputMethodFileManager (mMethodMap , newUserId );
766769 resetAllInternalStateLocked (false );
767770 }
768771
@@ -3816,6 +3819,7 @@ public int getCurrentUserId() {
38163819 }
38173820 }
38183821
3822+ // TODO: Cache the state for each user and reset when the cached user is removed.
38193823 private static class InputMethodFileManager {
38203824 private static final String SYSTEM_PATH = "system" ;
38213825 private static final String INPUT_METHOD_PATH = "inputmethod" ;
@@ -3834,12 +3838,14 @@ private static class InputMethodFileManager {
38343838 private final HashMap <String , InputMethodInfo > mMethodMap ;
38353839 private final HashMap <String , List <InputMethodSubtype >> mAdditionalSubtypesMap =
38363840 new HashMap <String , List <InputMethodSubtype >>();
3837- public InputMethodFileManager (HashMap <String , InputMethodInfo > methodMap ) {
3841+ public InputMethodFileManager (HashMap <String , InputMethodInfo > methodMap , int userId ) {
38383842 if (methodMap == null ) {
38393843 throw new NullPointerException ("methodMap is null" );
38403844 }
38413845 mMethodMap = methodMap ;
3842- final File systemDir = new File (Environment .getDataDirectory (), SYSTEM_PATH );
3846+ final File systemDir = userId == UserHandle .USER_OWNER
3847+ ? new File (Environment .getDataDirectory (), SYSTEM_PATH )
3848+ : Environment .getUserSystemDirectory (userId );
38433849 final File inputMethodDir = new File (systemDir , INPUT_METHOD_PATH );
38443850 if (!inputMethodDir .mkdirs ()) {
38453851 Slog .w (TAG , "Couldn't create dir.: " + inputMethodDir .getAbsolutePath ());
0 commit comments