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

Commit 849443c2 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Simplify IMMS#updateSystemUiLocked()

With my previous CL [1], it is now obvious that
InputMethodManagerService#updateSystemUiLocked() is always called with
InputMethodManagerService#mCurToken.  With that, this CL mechanically
simplifies InputMethodManagerService#updateSystemUiLocked().

There should be no behavior change.

 [1]: I086dc0381078fc292db8132bc64d920ef7646c1c
      6fee8818

Bug: 34851776
Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases
Change-Id: I86cae337ec3f982774a626f996db1b1d62cc529f
parent 9f6cfc33
Loading
Loading
Loading
Loading
+11 −12
Original line number Original line Diff line number Diff line
@@ -1243,7 +1243,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                            // Uh oh, current input method is no longer around!
                            // Uh oh, current input method is no longer around!
                            // Pick another one...
                            // Pick another one...
                            Slog.i(TAG, "Current input method removed: " + curInputMethodId);
                            Slog.i(TAG, "Current input method removed: " + curInputMethodId);
                            updateSystemUiLocked(mCurToken, 0 /* vis */, mBackDisposition);
                            updateSystemUiLocked(0 /* vis */, mBackDisposition);
                            if (!chooseNewDefaultIMELocked()) {
                            if (!chooseNewDefaultIMELocked()) {
                                changed = true;
                                changed = true;
                                curIm = null;
                                curIm = null;
@@ -1572,7 +1572,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                if (mStatusBar != null) {
                if (mStatusBar != null) {
                    mStatusBar.setIconVisibility(mSlotIme, false);
                    mStatusBar.setIconVisibility(mSlotIme, false);
                }
                }
                updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition);
                updateSystemUiLocked(mImeWindowVis, mBackDisposition);
                mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
                mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
                        com.android.internal.R.bool.show_ongoing_ime_switcher);
                        com.android.internal.R.bool.show_ongoing_ime_switcher);
                if (mShowOngoingImeSwitcherForPhones) {
                if (mShowOngoingImeSwitcherForPhones) {
@@ -2260,7 +2260,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    sessionState.session.finishSession();
                    sessionState.session.finishSession();
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    Slog.w(TAG, "Session failed to close due to remote exception", e);
                    Slog.w(TAG, "Session failed to close due to remote exception", e);
                    updateSystemUiLocked(mCurToken, 0 /* vis */, mBackDisposition);
                    updateSystemUiLocked(0 /* vis */, mBackDisposition);
                }
                }
                sessionState.session = null;
                sessionState.session = null;
            }
            }
@@ -2426,7 +2426,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            }
            }
            mImeWindowVis = vis;
            mImeWindowVis = vis;
            mBackDisposition = backDisposition;
            mBackDisposition = backDisposition;
            updateSystemUiLocked(mCurToken, vis, backDisposition);
            updateSystemUiLocked(vis, backDisposition);
        }
        }


        final boolean dismissImeOnBackKeyPressed;
        final boolean dismissImeOnBackKeyPressed;
@@ -2461,11 +2461,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    }
    }


    // Caution! This method is called in this class. Handle multi-user carefully
    // Caution! This method is called in this class. Handle multi-user carefully
    private void updateSystemUiLocked(IBinder token, int vis, int backDisposition) {
    private void updateSystemUiLocked(int vis, int backDisposition) {
        if (!calledWithValidTokenLocked(token)) {
        if (mCurToken == null) {
            return;
            return;
        }
        }

        // TODO: Move this clearing calling identity block to setImeWindowStatus after making sure
        // TODO: Move this clearing calling identity block to setImeWindowStatus after making sure
        // all updateSystemUi happens on system previlege.
        // all updateSystemUi happens on system previlege.
        final long ident = Binder.clearCallingIdentity();
        final long ident = Binder.clearCallingIdentity();
@@ -2477,7 +2476,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            // mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked().
            // mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked().
            final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis);
            final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis);
            if (mStatusBar != null) {
            if (mStatusBar != null) {
                mStatusBar.setImeWindowStatus(token, vis, backDisposition,
                mStatusBar.setImeWindowStatus(mCurToken, vis, backDisposition,
                        needsToShowImeSwitcher);
                        needsToShowImeSwitcher);
            }
            }
            final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
            final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
@@ -2667,7 +2666,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true);
                setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true);
                if (mCurMethod != null) {
                if (mCurMethod != null) {
                    try {
                    try {
                        updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition);
                        updateSystemUiLocked(mImeWindowVis, mBackDisposition);
                        mCurMethod.changeInputMethodSubtype(newSubtype);
                        mCurMethod.changeInputMethodSubtype(newSubtype);
                    } catch (RemoteException e) {
                    } catch (RemoteException e) {
                        Slog.w(TAG, "Failed to call changeInputMethodSubtype");
                        Slog.w(TAG, "Failed to call changeInputMethodSubtype");
@@ -3712,7 +3711,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private void handleSetInteractive(final boolean interactive) {
    private void handleSetInteractive(final boolean interactive) {
        synchronized (mMethodMap) {
        synchronized (mMethodMap) {
            mIsInteractive = interactive;
            mIsInteractive = interactive;
            updateSystemUiLocked(mCurToken, interactive ? mImeWindowVis : 0, mBackDisposition);
            updateSystemUiLocked(interactive ? mImeWindowVis : 0, mBackDisposition);


            // Inform the current client of the change in active status
            // Inform the current client of the change in active status
            if (mCurClient != null && mCurClient.client != null) {
            if (mCurClient != null && mCurClient.client != null) {
@@ -4043,7 +4042,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            attrs.privateFlags |= PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
            attrs.privateFlags |= PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
            attrs.setTitle("Select input method");
            attrs.setTitle("Select input method");
            w.setAttributes(attrs);
            w.setAttributes(attrs);
            updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition);
            updateSystemUiLocked(mImeWindowVis, mBackDisposition);
            mSwitchingDialog.show();
            mSwitchingDialog.show();
        }
        }
    }
    }
@@ -4103,7 +4102,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            mSwitchingDialogTitleView = null;
            mSwitchingDialogTitleView = null;
        }
        }


        updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition);
        updateSystemUiLocked(mImeWindowVis, mBackDisposition);
        mDialogBuilder = null;
        mDialogBuilder = null;
        mIms = null;
        mIms = null;
    }
    }