@@ -655,7 +655,7 @@ public List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(InputMeth
655655 List <InputMethodSubtype > enabledSubtypes =
656656 mSettings .getEnabledInputMethodSubtypeListLocked (imi );
657657 if (allowsImplicitlySelectedSubtypes && enabledSubtypes .isEmpty ()) {
658- enabledSubtypes = getApplicableSubtypesLocked (mRes , getSubtypes ( imi ) );
658+ enabledSubtypes = getImplicitlyApplicableSubtypesLocked (mRes , imi );
659659 }
660660 return InputMethodSubtype .sort (mContext , 0 , imi , enabledSubtypes );
661661 }
@@ -1903,6 +1903,20 @@ private static ArrayList<InputMethodSubtype> getSubtypes(InputMethodInfo imi) {
19031903 return subtypes ;
19041904 }
19051905
1906+
1907+ private static ArrayList <InputMethodSubtype > getOverridingImplicitlyEnabledSubtypes (
1908+ InputMethodInfo imi , String mode ) {
1909+ ArrayList <InputMethodSubtype > subtypes = new ArrayList <InputMethodSubtype >();
1910+ final int subtypeCount = imi .getSubtypeCount ();
1911+ for (int i = 0 ; i < subtypeCount ; ++i ) {
1912+ final InputMethodSubtype subtype = imi .getSubtypeAt (i );
1913+ if (subtype .overridesImplicitlyEnabledSubtype () && subtype .getMode ().equals (mode )) {
1914+ subtypes .add (subtype );
1915+ }
1916+ }
1917+ return subtypes ;
1918+ }
1919+
19061920 private boolean chooseNewDefaultIMELocked () {
19071921 List <InputMethodInfo > enabled = mSettings .getEnabledInputMethodListLocked ();
19081922 if (enabled != null && enabled .size () > 0 ) {
@@ -2357,14 +2371,28 @@ private int getSubtypeIdFromHashCode(InputMethodInfo imi, int subtypeHashCode) {
23572371 return NOT_A_SUBTYPE_ID ;
23582372 }
23592373
2360- private static ArrayList <InputMethodSubtype > getApplicableSubtypesLocked (
2361- Resources res , List <InputMethodSubtype > subtypes ) {
2374+ private static ArrayList <InputMethodSubtype > getImplicitlyApplicableSubtypesLocked (
2375+ Resources res , InputMethodInfo imi ) {
2376+ final List <InputMethodSubtype > subtypes = getSubtypes (imi );
23622377 final String systemLocale = res .getConfiguration ().locale .toString ();
23632378 if (TextUtils .isEmpty (systemLocale )) return new ArrayList <InputMethodSubtype >();
23642379 HashMap <String , InputMethodSubtype > applicableModeAndSubtypesMap =
23652380 new HashMap <String , InputMethodSubtype >();
23662381 final int N = subtypes .size ();
23672382 boolean containsKeyboardSubtype = false ;
2383+ for (int i = 0 ; i < N ; ++i ) {
2384+ // scan overriding implicitly enabled subtypes.
2385+ InputMethodSubtype subtype = subtypes .get (i );
2386+ if (subtype .overridesImplicitlyEnabledSubtype ()) {
2387+ final String mode = subtype .getMode ();
2388+ if (!applicableModeAndSubtypesMap .containsKey (mode )) {
2389+ applicableModeAndSubtypesMap .put (mode , subtype );
2390+ }
2391+ }
2392+ }
2393+ if (applicableModeAndSubtypesMap .size () > 0 ) {
2394+ return new ArrayList <InputMethodSubtype >(applicableModeAndSubtypesMap .values ());
2395+ }
23682396 for (int i = 0 ; i < N ; ++i ) {
23692397 InputMethodSubtype subtype = subtypes .get (i );
23702398 final String locale = subtype .getLocale ();
@@ -2489,16 +2517,21 @@ private static InputMethodSubtype findLastResortApplicableSubtypeLocked(
24892517 subtype = findLastResortApplicableSubtypeLocked (
24902518 mRes , enabledSubtypes , mode , null , true );
24912519 }
2520+ final ArrayList <InputMethodSubtype > overridingImplicitlyEnabledSubtypes =
2521+ getOverridingImplicitlyEnabledSubtypes (imi , mode );
2522+ final ArrayList <InputMethodSubtype > subtypesForSearch =
2523+ overridingImplicitlyEnabledSubtypes .isEmpty ()
2524+ ? getSubtypes (imi ) : overridingImplicitlyEnabledSubtypes ;
24922525 // 4. Search by the current subtype's locale from all subtypes.
24932526 if (subtype == null && mCurrentSubtype != null ) {
24942527 subtype = findLastResortApplicableSubtypeLocked (
2495- mRes , getSubtypes ( imi ) , mode , mCurrentSubtype .getLocale (), false );
2528+ mRes , subtypesForSearch , mode , mCurrentSubtype .getLocale (), false );
24962529 }
24972530 // 5. Search by the system locale from all subtypes.
24982531 // 6. Search the first enabled subtype matched with mode from all subtypes.
24992532 if (subtype == null ) {
25002533 subtype = findLastResortApplicableSubtypeLocked (
2501- mRes , getSubtypes ( imi ) , mode , null , true );
2534+ mRes , subtypesForSearch , mode , null , true );
25022535 }
25032536 if (subtype != null ) {
25042537 if (imiId .equals (mCurMethodId )) {
@@ -2945,12 +2978,12 @@ private String getEnabledSubtypeHashCodeForInputMethodAndSubtypeLocked(List<Pair
29452978 if (explicitlyEnabledSubtypes .size () == 0 ) {
29462979 // If there are no explicitly enabled subtypes, applicable subtypes are
29472980 // enabled implicitly.
2948- InputMethodInfo ime = mMethodMap .get (imeId );
2981+ InputMethodInfo imi = mMethodMap .get (imeId );
29492982 // If IME is enabled and no subtypes are enabled, applicable subtypes
29502983 // are enabled implicitly, so needs to treat them to be enabled.
2951- if (ime != null && ime .getSubtypeCount () > 0 ) {
2984+ if (imi != null && imi .getSubtypeCount () > 0 ) {
29522985 List <InputMethodSubtype > implicitlySelectedSubtypes =
2953- getApplicableSubtypesLocked (mRes , getSubtypes ( ime ) );
2986+ getImplicitlyApplicableSubtypesLocked (mRes , imi );
29542987 if (implicitlySelectedSubtypes != null ) {
29552988 final int N = implicitlySelectedSubtypes .size ();
29562989 for (int i = 0 ; i < N ; ++i ) {
0 commit comments