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

Commit 8977e069 authored by Yohei Yukawa's avatar Yohei Yukawa Committed by Android (Google) Code Review
Browse files

Merge "Delay tasks from IMMS constructor to later phase"

parents 5c5e0ac4 7924782c
Loading
Loading
Loading
Loading
+0 −16
Original line number Original line Diff line number Diff line
@@ -1080,22 +1080,6 @@ public class InputMethodUtils {
            return enabledSubtypes;
            return enabledSubtypes;
        }
        }


        // At the initial boot, the settings for input methods are not set,
        // so we need to enable IME in that case.
        public void enableAllIMEsIfThereIsNoEnabledIME() {
            if (TextUtils.isEmpty(getEnabledInputMethodsStr())) {
                StringBuilder sb = new StringBuilder();
                final int N = mMethodList.size();
                for (int i = 0; i < N; i++) {
                    InputMethodInfo imi = mMethodList.get(i);
                    Slog.i(TAG, "Adding: " + imi.getId());
                    if (i > 0) sb.append(':');
                    sb.append(imi.getId());
                }
                putEnabledInputMethodsStr(sb.toString());
            }
        }

        public List<Pair<String, ArrayList<String>>> getEnabledInputMethodsAndSubtypeListLocked() {
        public List<Pair<String, ArrayList<String>>> getEnabledInputMethodsAndSubtypeListLocked() {
            return buildInputMethodsAndSubtypeList(getEnabledInputMethodsStr(),
            return buildInputMethodsAndSubtypeList(getEnabledInputMethodsStr(),
                    mInputMethodSplitter,
                    mInputMethodSplitter,
+39 −63
Original line number Original line Diff line number Diff line
@@ -243,7 +243,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private PendingIntent mImeSwitchPendingIntent;
    private PendingIntent mImeSwitchPendingIntent;
    private boolean mShowOngoingImeSwitcherForPhones;
    private boolean mShowOngoingImeSwitcherForPhones;
    private boolean mNotificationShown;
    private boolean mNotificationShown;
    private final boolean mImeSelectedOnBoot;


    static class SessionState {
    static class SessionState {
        final ClientState client;
        final ClientState client;
@@ -566,7 +565,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        }
        }
    }
    }


    class ImmsBroadcastReceiver extends android.content.BroadcastReceiver {
    class ImmsBroadcastReceiver extends BroadcastReceiver {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            final String action = intent.getAction();
@@ -587,6 +586,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                            Intent.EXTRA_SETTING_NEW_VALUE);
                            Intent.EXTRA_SETTING_NEW_VALUE);
                    restoreEnabledInputMethods(mContext, prevValue, newValue);
                    restoreEnabledInputMethods(mContext, prevValue, newValue);
                }
                }
            } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
                synchronized (mMethodMap) {
                    resetStateIfCurrentLocaleChangedLocked();
                }
            } else {
            } else {
                Slog.w(TAG, "Unexpected intent " + intent);
                Slog.w(TAG, "Unexpected intent " + intent);
            }
            }
@@ -845,11 +848,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                return;
                return;
            }
            }
            mSettings.switchCurrentUser(currentUserId, !mSystemReady);
            mSettings.switchCurrentUser(currentUserId, !mSystemReady);
            if (mSystemReady) {
                // We need to rebuild IMEs.
                // We need to rebuild IMEs.
                buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
                buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
                updateInputMethodsFromSettingsLocked(true /* enabledChanged */);
                updateInputMethodsFromSettingsLocked(true /* enabledChanged */);
            }
            }
        }
        }
    }


    void onSwitchUser(@UserIdInt int userId) {
    void onSwitchUser(@UserIdInt int userId) {
        synchronized (mMethodMap) {
        synchronized (mMethodMap) {
@@ -897,13 +902,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub


        mShowOngoingImeSwitcherForPhones = false;
        mShowOngoingImeSwitcherForPhones = false;


        final IntentFilter broadcastFilter = new IntentFilter();
        broadcastFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        broadcastFilter.addAction(Intent.ACTION_USER_ADDED);
        broadcastFilter.addAction(Intent.ACTION_USER_REMOVED);
        broadcastFilter.addAction(Intent.ACTION_SETTING_RESTORED);
        mContext.registerReceiver(new ImmsBroadcastReceiver(), broadcastFilter);

        mNotificationShown = false;
        mNotificationShown = false;
        int userId = 0;
        int userId = 0;
        try {
        try {
@@ -911,7 +909,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e);
            Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e);
        }
        }
        mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true);


        // mSettings should be created before buildInputMethodListLocked
        // mSettings should be created before buildInputMethodListLocked
        mSettings = new InputMethodSettings(
        mSettings = new InputMethodSettings(
@@ -919,50 +916,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub


        updateCurrentProfileIds();
        updateCurrentProfileIds();
        mFileManager = new InputMethodFileManager(mMethodMap, userId);
        mFileManager = new InputMethodFileManager(mMethodMap, userId);
        synchronized (mMethodMap) {
        mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked(
        mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked(
                mSettings, context);
                mSettings, context);
    }
    }


        // Just checking if defaultImiId is empty or not
        final String defaultImiId = mSettings.getSelectedInputMethod();
        if (DEBUG) {
            Slog.d(TAG, "Initial default ime = " + defaultImiId);
        }
        mImeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId);

        synchronized (mMethodMap) {
            buildInputMethodListLocked(!mImeSelectedOnBoot /* resetDefaultEnabledIme */);
        }
        mSettings.enableAllIMEsIfThereIsNoEnabledIME();

        if (!mImeSelectedOnBoot) {
            Slog.w(TAG, "No IME selected. Choose the most applicable IME.");
            synchronized (mMethodMap) {
                resetDefaultImeLocked(context);
            }
        }

        synchronized (mMethodMap) {
            mSettingsObserver.registerContentObserverLocked(userId);
            updateFromSettingsLocked(true);
        }

        // IMMS wants to receive Intent.ACTION_LOCALE_CHANGED in order to update the current IME
        // according to the new system locale.
        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_LOCALE_CHANGED);
        mContext.registerReceiver(
                new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        synchronized(mMethodMap) {
                            resetStateIfCurrentLocaleChangedLocked();
                        }
                    }
                }, filter);
    }

    private void resetDefaultImeLocked(Context context) {
    private void resetDefaultImeLocked(Context context) {
        // Do not reset the default (current) IME when it is a 3rd-party IME
        // Do not reset the default (current) IME when it is a 3rd-party IME
        if (mCurMethodId != null && !InputMethodUtils.isSystemIme(mMethodMap.get(mCurMethodId))) {
        if (mCurMethodId != null && !InputMethodUtils.isSystemIme(mMethodMap.get(mCurMethodId))) {
@@ -1089,6 +1046,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            }
            }
            if (!mSystemReady) {
            if (!mSystemReady) {
                mSystemReady = true;
                mSystemReady = true;
                mLastSystemLocales = mRes.getConfiguration().getLocales();
                final int currentUserId = mSettings.getCurrentUserId();
                final int currentUserId = mSettings.getCurrentUserId();
                mSettings.switchCurrentUser(currentUserId,
                mSettings.switchCurrentUser(currentUserId,
                        !mUserManager.isUserUnlockingOrUnlocked(currentUserId));
                        !mUserManager.isUserUnlockingOrUnlocked(currentUserId));
@@ -1105,14 +1063,25 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    mWindowManagerInternal.setOnHardKeyboardStatusChangeListener(
                    mWindowManagerInternal.setOnHardKeyboardStatusChangeListener(
                            mHardKeyboardListener);
                            mHardKeyboardListener);
                }
                }
                if (!mImeSelectedOnBoot) {

                    Slog.w(TAG, "Reset the default IME as \"Resource\" is ready here.");
                mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true);
                    resetStateIfCurrentLocaleChangedLocked();
                mSettingsObserver.registerContentObserverLocked(currentUserId);

                final IntentFilter broadcastFilter = new IntentFilter();
                broadcastFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
                broadcastFilter.addAction(Intent.ACTION_USER_ADDED);
                broadcastFilter.addAction(Intent.ACTION_USER_REMOVED);
                broadcastFilter.addAction(Intent.ACTION_SETTING_RESTORED);
                broadcastFilter.addAction(Intent.ACTION_LOCALE_CHANGED);
                mContext.registerReceiver(new ImmsBroadcastReceiver(), broadcastFilter);

                buildInputMethodListLocked(true /* resetDefaultEnabledIme */);
                resetDefaultImeLocked(mContext);
                updateFromSettingsLocked(true);
                InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager,
                InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager,
                            mSettings.getEnabledInputMethodListLocked(),
                        mSettings.getEnabledInputMethodListLocked(), currentUserId,
                            mSettings.getCurrentUserId(), mContext.getBasePackageName());
                        mContext.getBasePackageName());
                }

                mLastSystemLocales = mRes.getConfiguration().getLocales();
                try {
                try {
                    startInputInnerLocked();
                    startInputInnerLocked();
                } catch (RuntimeException e) {
                } catch (RuntimeException e) {
@@ -2624,6 +2593,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        // additional input method subtypes to the IME.
        // additional input method subtypes to the IME.
        if (TextUtils.isEmpty(imiId) || subtypes == null) return;
        if (TextUtils.isEmpty(imiId) || subtypes == null) return;
        synchronized (mMethodMap) {
        synchronized (mMethodMap) {
            if (!mSystemReady) {
                return;
            }
            final InputMethodInfo imi = mMethodMap.get(imiId);
            final InputMethodInfo imi = mMethodMap.get(imiId);
            if (imi == null) return;
            if (imi == null) return;
            final String[] packageInfos;
            final String[] packageInfos;
@@ -3048,6 +3020,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme
            Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme
                    + " \n ------ caller=" + Debug.getCallers(10));
                    + " \n ------ caller=" + Debug.getCallers(10));
        }
        }
        if (!mSystemReady) {
            Slog.e(TAG, "buildInputMethodListLocked is not allowed until system is ready");
            return;
        }
        mMethodList.clear();
        mMethodList.clear();
        mMethodMap.clear();
        mMethodMap.clear();