@@ -657,6 +657,7 @@ private void checkCurrentLocaleChangedLocked() {
657657 buildInputMethodListLocked (mMethodList , mMethodMap );
658658 // Reset the current ime to the proper one
659659 resetDefaultImeLocked (mContext );
660+ updateFromSettingsLocked ();
660661 mLastSystemLocale = newLocale ;
661662 }
662663 }
@@ -1439,34 +1440,41 @@ void updateFromSettingsLocked() {
14391440 throw new IllegalArgumentException ("Unknown id: " + id );
14401441 }
14411442
1443+ // See if we need to notify a subtype change within the same IME.
14421444 if (id .equals (mCurMethodId )) {
1443- InputMethodSubtype subtype = null ;
1444- if (subtypeId > = 0 && subtypeId < info . getSubtypeCount () ) {
1445- subtype = info . getSubtypeAt ( subtypeId ) ;
1445+ final int subtypeCount = info . getSubtypeCount () ;
1446+ if (subtypeCount < = 0 ) {
1447+ return ;
14461448 }
1447- if (subtype != mCurrentSubtype ) {
1448- synchronized (mMethodMap ) {
1449- if (subtype != null ) {
1450- setSelectedInputMethodAndSubtypeLocked (info , subtypeId , true );
1451- }
1452- if (mCurMethod != null ) {
1453- try {
1454- refreshImeWindowVisibilityLocked ();
1455- // If subtype is null, try to find the most applicable one from
1456- // getCurrentInputMethodSubtype.
1457- if (subtype == null ) {
1458- subtype = getCurrentInputMethodSubtype ();
1459- }
1460- mCurMethod .changeInputMethodSubtype (subtype );
1461- } catch (RemoteException e ) {
1462- return ;
1463- }
1449+ final InputMethodSubtype oldSubtype = mCurrentSubtype ;
1450+ final InputMethodSubtype newSubtype ;
1451+ if (subtypeId >= 0 && subtypeId < subtypeCount ) {
1452+ newSubtype = info .getSubtypeAt (subtypeId );
1453+ } else {
1454+ // If subtype is null, try to find the most applicable one from
1455+ // getCurrentInputMethodSubtype.
1456+ newSubtype = getCurrentInputMethodSubtype ();
1457+ }
1458+ if (newSubtype == null || oldSubtype == null ) {
1459+ Slog .w (TAG , "Illegal subtype state: old subtype = " + oldSubtype
1460+ + ", new subtype = " + newSubtype );
1461+ return ;
1462+ }
1463+ if (newSubtype != oldSubtype ) {
1464+ setSelectedInputMethodAndSubtypeLocked (info , subtypeId , true );
1465+ if (mCurMethod != null ) {
1466+ try {
1467+ refreshImeWindowVisibilityLocked ();
1468+ mCurMethod .changeInputMethodSubtype (newSubtype );
1469+ } catch (RemoteException e ) {
1470+ Slog .w (TAG , "Failed to call changeInputMethodSubtype" );
14641471 }
14651472 }
14661473 }
14671474 return ;
14681475 }
14691476
1477+ // Changing to a different IME.
14701478 final long ident = Binder .clearCallingIdentity ();
14711479 try {
14721480 // Set a subtype to this input method.
@@ -2653,7 +2661,8 @@ private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int sub
26532661 mCurrentSubtype = subtype ;
26542662 } else {
26552663 mSettings .putSelectedSubtype (NOT_A_SUBTYPE_ID );
2656- mCurrentSubtype = null ;
2664+ // If the subtype is not specified, choose the most applicable one
2665+ mCurrentSubtype = getCurrentInputMethodSubtype ();
26572666 }
26582667 }
26592668
0 commit comments