Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0a1bcf4e authored by satok's avatar satok
Browse files

Consolidate the initialization of InputMethodManagerService not to use...

Consolidate the initialization of InputMethodManagerService not to use resource values until system ready

Bug: 6477193
InputMethodManagerService have used the resource value of "isDefault" in the constructor. We should wait to use that value until system ready.
Change-Id: I682fc109c303d8c7fd33d494c59e8e28d6dc6fa5
parent dabb19fc
Loading
Loading
Loading
Loading
+43 −16
Original line number Diff line number Diff line
@@ -195,6 +195,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private PendingIntent mImeSwitchPendingIntent;
    private boolean mShowOngoingImeSwitcherForPhones;
    private boolean mNotificationShown;
    private final boolean mImeSelectedOnBoot;

    class SessionState {
        final ClientState client;
@@ -590,7 +591,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        mImeSwitcherNotification.vibrate = null;
        Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER);
        mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
        mLastSystemLocale = mRes.getConfiguration().locale;

        mShowOngoingImeSwitcherForPhones = false;

@@ -612,11 +612,17 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        // mSettings should be created before buildInputMethodListLocked
        mSettings = new InputMethodSettings(
                mRes, context.getContentResolver(), mMethodMap, mMethodList);

        // Just checking if defaultImiId is empty or not
        final String defaultImiId = Settings.Secure.getString(
                mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
        mImeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId);

        buildInputMethodListLocked(mMethodList, mMethodMap);
        mSettings.enableAllIMEsIfThereIsNoEnabledIME();

        if (TextUtils.isEmpty(Settings.Secure.getString(
                mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) {
        if (!mImeSelectedOnBoot) {
            Slog.w(TAG, "No IME selected. Choose the most applicable IME.");
            resetDefaultImeLocked(context);
        }

@@ -639,6 +645,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    }

    private void checkCurrentLocaleChangedLocked() {
        if (!mSystemReady) {
            // not system ready
            return;
        }
        final Locale newLocale = mRes.getConfiguration().locale;
        if (newLocale != null && !newLocale.equals(mLastSystemLocale)) {
            if (DEBUG) {
@@ -675,7 +685,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        }
    }

    private static boolean isValidSystemDefaultIme(InputMethodInfo imi, Context context) {
    private boolean isValidSystemDefaultIme(InputMethodInfo imi, Context context) {
        if (!mSystemReady) {
            return false;
        }
        if (!isSystemIme(imi)) {
            return false;
        }
@@ -738,7 +751,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                        mContext.getSystemService(Context.KEYGUARD_SERVICE);
                mNotificationManager = (NotificationManager)
                        mContext.getSystemService(Context.NOTIFICATION_SERVICE);
                mLastSystemLocale = mContext.getResources().getConfiguration().locale;
                mStatusBar = statusBar;
                statusBar.setIconVisibility("ime", false);
                updateImeWindowStatusLocked();
@@ -748,6 +760,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    mWindowManagerService.setOnHardKeyboardStatusChangeListener(
                            mHardKeyboardListener);
                }
                buildInputMethodListLocked(mMethodList, mMethodMap);
                if (!mImeSelectedOnBoot) {
                    Slog.w(TAG, "Reset the default IME as \"Resource\" is ready here.");
                    checkCurrentLocaleChangedLocked();
                }
                mLastSystemLocale = mRes.getConfiguration().locale;
                try {
                    startInputInnerLocked();
                } catch (RuntimeException e) {
@@ -2137,7 +2155,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        return subtypes;
    }


    private static ArrayList<InputMethodSubtype> getOverridingImplicitlyEnabledSubtypes(
            InputMethodInfo imi, String mode) {
        ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
@@ -2156,14 +2173,18 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        if (enabled != null && enabled.size() > 0) {
            // We'd prefer to fall back on a system IME, since that is safer.
            int i = enabled.size();
            int firstFoundSystemIme = -1;
            while (i > 0) {
                i--;
                final InputMethodInfo imi = enabled.get(i);
                if (isSystemIme(imi) && !imi.isAuxiliaryIme()) {
                    break;
                if (isSystemImeThatHasEnglishSubtype(imi) && !imi.isAuxiliaryIme()) {
                    return imi;
                }
                if (firstFoundSystemIme < 0 && isSystemIme(imi) && !imi.isAuxiliaryIme()) {
                    firstFoundSystemIme = i;
                }
            }
            return enabled.get(i);
            return enabled.get(Math.max(firstFoundSystemIme, 0));
        }
        return null;
    }
@@ -2238,12 +2259,18 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            }
        }

        String defaultIme = Settings.Secure.getString(mContext
        final String defaultImiId = Settings.Secure.getString(mContext
                .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
        if (!TextUtils.isEmpty(defaultIme) && !map.containsKey(defaultIme)) {
        if (!TextUtils.isEmpty(defaultImiId)) {
            if (!map.containsKey(defaultImiId)) {
                Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
                if (chooseNewDefaultIMELocked()) {
                    updateFromSettingsLocked();
                }
            } else {
                // Double check that the default IME is certainly enabled.
                setInputMethodEnabledLocked(defaultImiId, true);
            }
        }
    }

@@ -3007,8 +3034,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            mContext = context;
            mPm = context.getPackageManager();
            mImms = imms;
            mSystemLocaleStr =
                    imms.mLastSystemLocale != null ? imms.mLastSystemLocale.toString() : "";
            final Locale locale = context.getResources().getConfiguration().locale;
            mSystemLocaleStr = locale != null ? locale.toString() : "";
        }

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