Skip to content

Commit 5d4d23e

Browse files
satok16Android (Google) Code Review
authored andcommitted
Merge "Consolidate the initialization of InputMethodManagerService not to use resource values until system ready" into jb-dev
2 parents cf39bdf + 0a1bcf4 commit 5d4d23e

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed

services/java/com/android/server/InputMethodManagerService.java

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
195195
private PendingIntent mImeSwitchPendingIntent;
196196
private boolean mShowOngoingImeSwitcherForPhones;
197197
private boolean mNotificationShown;
198+
private final boolean mImeSelectedOnBoot;
198199

199200
class SessionState {
200201
final ClientState client;
@@ -590,7 +591,6 @@ public void executeMessage(Message msg) {
590591
mImeSwitcherNotification.vibrate = null;
591592
Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER);
592593
mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
593-
mLastSystemLocale = mRes.getConfiguration().locale;
594594

595595
mShowOngoingImeSwitcherForPhones = false;
596596

@@ -612,11 +612,17 @@ public void executeMessage(Message msg) {
612612
// mSettings should be created before buildInputMethodListLocked
613613
mSettings = new InputMethodSettings(
614614
mRes, context.getContentResolver(), mMethodMap, mMethodList);
615+
616+
// Just checking if defaultImiId is empty or not
617+
final String defaultImiId = Settings.Secure.getString(
618+
mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
619+
mImeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId);
620+
615621
buildInputMethodListLocked(mMethodList, mMethodMap);
616622
mSettings.enableAllIMEsIfThereIsNoEnabledIME();
617623

618-
if (TextUtils.isEmpty(Settings.Secure.getString(
619-
mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) {
624+
if (!mImeSelectedOnBoot) {
625+
Slog.w(TAG, "No IME selected. Choose the most applicable IME.");
620626
resetDefaultImeLocked(context);
621627
}
622628

@@ -639,6 +645,10 @@ public void onReceive(Context context, Intent intent) {
639645
}
640646

641647
private void checkCurrentLocaleChangedLocked() {
648+
if (!mSystemReady) {
649+
// not system ready
650+
return;
651+
}
642652
final Locale newLocale = mRes.getConfiguration().locale;
643653
if (newLocale != null && !newLocale.equals(mLastSystemLocale)) {
644654
if (DEBUG) {
@@ -675,7 +685,10 @@ private void resetDefaultImeLocked(Context context) {
675685
}
676686
}
677687

678-
private static boolean isValidSystemDefaultIme(InputMethodInfo imi, Context context) {
688+
private boolean isValidSystemDefaultIme(InputMethodInfo imi, Context context) {
689+
if (!mSystemReady) {
690+
return false;
691+
}
679692
if (!isSystemIme(imi)) {
680693
return false;
681694
}
@@ -738,7 +751,6 @@ public void systemReady(StatusBarManagerService statusBar) {
738751
mContext.getSystemService(Context.KEYGUARD_SERVICE);
739752
mNotificationManager = (NotificationManager)
740753
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
741-
mLastSystemLocale = mContext.getResources().getConfiguration().locale;
742754
mStatusBar = statusBar;
743755
statusBar.setIconVisibility("ime", false);
744756
updateImeWindowStatusLocked();
@@ -748,6 +760,12 @@ public void systemReady(StatusBarManagerService statusBar) {
748760
mWindowManagerService.setOnHardKeyboardStatusChangeListener(
749761
mHardKeyboardListener);
750762
}
763+
buildInputMethodListLocked(mMethodList, mMethodMap);
764+
if (!mImeSelectedOnBoot) {
765+
Slog.w(TAG, "Reset the default IME as \"Resource\" is ready here.");
766+
checkCurrentLocaleChangedLocked();
767+
}
768+
mLastSystemLocale = mRes.getConfiguration().locale;
751769
try {
752770
startInputInnerLocked();
753771
} catch (RuntimeException e) {
@@ -2137,7 +2155,6 @@ private static ArrayList<InputMethodSubtype> getSubtypes(InputMethodInfo imi) {
21372155
return subtypes;
21382156
}
21392157

2140-
21412158
private static ArrayList<InputMethodSubtype> getOverridingImplicitlyEnabledSubtypes(
21422159
InputMethodInfo imi, String mode) {
21432160
ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
@@ -2155,15 +2172,19 @@ private InputMethodInfo getMostApplicableDefaultIMELocked() {
21552172
List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
21562173
if (enabled != null && enabled.size() > 0) {
21572174
// We'd prefer to fall back on a system IME, since that is safer.
2158-
int i=enabled.size();
2175+
int i = enabled.size();
2176+
int firstFoundSystemIme = -1;
21592177
while (i > 0) {
21602178
i--;
21612179
final InputMethodInfo imi = enabled.get(i);
2162-
if (isSystemIme(imi) && !imi.isAuxiliaryIme()) {
2163-
break;
2180+
if (isSystemImeThatHasEnglishSubtype(imi) && !imi.isAuxiliaryIme()) {
2181+
return imi;
2182+
}
2183+
if (firstFoundSystemIme < 0 && isSystemIme(imi) && !imi.isAuxiliaryIme()) {
2184+
firstFoundSystemIme = i;
21642185
}
21652186
}
2166-
return enabled.get(i);
2187+
return enabled.get(Math.max(firstFoundSystemIme, 0));
21672188
}
21682189
return null;
21692190
}
@@ -2238,11 +2259,17 @@ void buildInputMethodListLocked(ArrayList<InputMethodInfo> list,
22382259
}
22392260
}
22402261

2241-
String defaultIme = Settings.Secure.getString(mContext
2262+
final String defaultImiId = Settings.Secure.getString(mContext
22422263
.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
2243-
if (!TextUtils.isEmpty(defaultIme) && !map.containsKey(defaultIme)) {
2244-
if (chooseNewDefaultIMELocked()) {
2245-
updateFromSettingsLocked();
2264+
if (!TextUtils.isEmpty(defaultImiId)) {
2265+
if (!map.containsKey(defaultImiId)) {
2266+
Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
2267+
if (chooseNewDefaultIMELocked()) {
2268+
updateFromSettingsLocked();
2269+
}
2270+
} else {
2271+
// Double check that the default IME is certainly enabled.
2272+
setInputMethodEnabledLocked(defaultImiId, true);
22462273
}
22472274
}
22482275
}
@@ -3007,8 +3034,8 @@ public InputMethodAndSubtypeListManager(Context context, InputMethodManagerServi
30073034
mContext = context;
30083035
mPm = context.getPackageManager();
30093036
mImms = imms;
3010-
mSystemLocaleStr =
3011-
imms.mLastSystemLocale != null ? imms.mLastSystemLocale.toString() : "";
3037+
final Locale locale = context.getResources().getConfiguration().locale;
3038+
mSystemLocaleStr = locale != null ? locale.toString() : "";
30123039
}
30133040

30143041
private final TreeMap<InputMethodInfo, List<InputMethodSubtype>> mSortedImmis =

0 commit comments

Comments
 (0)