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

Commit b8bf1b12 authored by Nikolas Havrikov's avatar Nikolas Havrikov Committed by Android (Google) Code Review
Browse files

Merge "Add "Locked" suffix to IMMS methods"

parents a132ea4d f0c3ce1a
Loading
Loading
Loading
Loading
+58 −44
Original line number Diff line number Diff line
@@ -72,16 +72,16 @@ final class InputMethodBindingController {
    @NonNull private final WindowManagerInternal mWindowManagerInternal;
    @NonNull private final Resources mRes;

    private long mLastBindTime;
    private boolean mHasConnection;
    @Nullable private String mCurId;
    @Nullable private String mSelectedMethodId;
    @Nullable private Intent mCurIntent;
    @Nullable private IInputMethod mCurMethod;
    private int mCurMethodUid = Process.INVALID_UID;
    private IBinder mCurToken;
    private int mCurSeq;
    private boolean mVisibleBound;
    @GuardedBy("mMethodMap") private long mLastBindTime;
    @GuardedBy("mMethodMap") private boolean mHasConnection;
    @GuardedBy("mMethodMap") @Nullable private String mCurId;
    @GuardedBy("mMethodMap") @Nullable private String mSelectedMethodId;
    @GuardedBy("mMethodMap") @Nullable private Intent mCurIntent;
    @GuardedBy("mMethodMap") @Nullable private IInputMethod mCurMethod;
    @GuardedBy("mMethodMap") private int mCurMethodUid = Process.INVALID_UID;
    @GuardedBy("mMethodMap") private IBinder mCurToken;
    @GuardedBy("mMethodMap") private int mCurSeq;
    @GuardedBy("mMethodMap") private boolean mVisibleBound;
    private boolean mSupportsStylusHw;

    /**
@@ -146,6 +146,7 @@ final class InputMethodBindingController {
     * Time that we last initiated a bind to the input method, to determine
     * if we should try to disconnect and reconnect to it.
     */
    @GuardedBy("mMethodMap")
    long getLastBindTime() {
        return mLastBindTime;
    }
@@ -154,6 +155,7 @@ final class InputMethodBindingController {
     * Set to true if our ServiceConnection is currently actively bound to
     * a service (whether or not we have gotten its IBinder back yet).
     */
    @GuardedBy("mMethodMap")
    boolean hasConnection() {
        return mHasConnection;
    }
@@ -166,6 +168,7 @@ final class InputMethodBindingController {
     *
     * @see #getSelectedMethodId()
     */
    @GuardedBy("mMethodMap")
    @Nullable
    String getCurId() {
        return mCurId;
@@ -184,11 +187,13 @@ final class InputMethodBindingController {
     *
     * @see #getCurId()
     */
    @GuardedBy("mMethodMap")
    @Nullable
    String getSelectedMethodId() {
        return mSelectedMethodId;
    }

    @GuardedBy("mMethodMap")
    void setSelectedMethodId(@Nullable String selectedMethodId) {
        mSelectedMethodId = selectedMethodId;
    }
@@ -197,6 +202,7 @@ final class InputMethodBindingController {
     * The token we have made for the currently active input method, to
     * identify it in the future.
     */
    @GuardedBy("mMethodMap")
    IBinder getCurToken() {
        return mCurToken;
    }
@@ -204,6 +210,7 @@ final class InputMethodBindingController {
    /**
     * The Intent used to connect to the current input method.
     */
    @GuardedBy("mMethodMap")
    @Nullable
    Intent getCurIntent() {
        return mCurIntent;
@@ -213,6 +220,7 @@ final class InputMethodBindingController {
     * The current binding sequence number, incremented every time there is
     * a new bind performed.
     */
    @GuardedBy("mMethodMap")
    int getSequenceNumber() {
        return mCurSeq;
    }
@@ -221,6 +229,7 @@ final class InputMethodBindingController {
     * Increase the current binding sequence number by one.
     * Reset to 1 on overflow.
     */
    @GuardedBy("mMethodMap")
    void advanceSequenceNumber() {
        mCurSeq += 1;
        if (mCurSeq <= 0) {
@@ -232,6 +241,7 @@ final class InputMethodBindingController {
     * If non-null, this is the input method service we are currently connected
     * to.
     */
    @GuardedBy("mMethodMap")
    @Nullable
    IInputMethod getCurMethod() {
        return mCurMethod;
@@ -240,6 +250,7 @@ final class InputMethodBindingController {
    /**
     * If not {@link Process#INVALID_UID}, then the UID of {@link #getCurIntent()}.
     */
    @GuardedBy("mMethodMap")
    int getCurMethodUid() {
        return mCurMethodUid;
    }
@@ -247,6 +258,7 @@ final class InputMethodBindingController {
    /**
     * Indicates whether {@link #mVisibleConnection} is currently in use.
     */
    @GuardedBy("mMethodMap")
    boolean isVisibleBound() {
        return mVisibleBound;
    }
@@ -254,11 +266,12 @@ final class InputMethodBindingController {
    /**
     * Used to bring IME service up to visible adjustment while it is being shown.
     */
    @GuardedBy("mMethodMap")
    private final ServiceConnection mVisibleConnection = new ServiceConnection() {
        @Override public void onBindingDied(ComponentName name) {
            synchronized (mMethodMap) {
                if (mVisibleBound) {
                    unbindVisibleConnectionLocked();
                    unbindVisibleConnection();
                }
            }
        }
@@ -273,6 +286,7 @@ final class InputMethodBindingController {
    /**
     * Used to bind the IME while it is not currently being shown.
     */
    @GuardedBy("mMethodMap")
    private final ServiceConnection mMainConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
@@ -280,10 +294,10 @@ final class InputMethodBindingController {
            synchronized (mMethodMap) {
                if (mCurIntent != null && name.equals(mCurIntent.getComponent())) {
                    mCurMethod = IInputMethod.Stub.asInterface(service);
                    updateCurrentMethodUidLocked();
                    updateCurrentMethodUid();
                    if (mCurToken == null) {
                        Slog.w(TAG, "Service connected without a token!");
                        unbindCurrentMethodLocked();
                        unbindCurrentMethod();
                        Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
                        return;
                    }
@@ -305,7 +319,7 @@ final class InputMethodBindingController {
        }

        @GuardedBy("mMethodMap")
        private void updateCurrentMethodUidLocked() {
        private void updateCurrentMethodUid() {
            final String curMethodPackage = mCurIntent.getComponent().getPackageName();
            final int curMethodUid = mPackageManagerInternal.getPackageUid(
                    curMethodPackage, 0 /* flags */, mSettings.getCurrentUserId());
@@ -339,7 +353,7 @@ final class InputMethodBindingController {
                    // We consider this to be a new bind attempt, since the system
                    // should now try to restart the service for us.
                    mLastBindTime = SystemClock.uptimeMillis();
                    clearCurMethodAndSessionsLocked();
                    clearCurMethodAndSessions();
                    mService.clearInputShowRequestLocked();
                    mService.unbindCurrentClientLocked(UnbindReason.DISCONNECT_IME);
                }
@@ -348,34 +362,34 @@ final class InputMethodBindingController {
    };

    @GuardedBy("mMethodMap")
    void unbindCurrentMethodLocked() {
    void unbindCurrentMethod() {
        if (mVisibleBound) {
            unbindVisibleConnectionLocked();
            unbindVisibleConnection();
        }

        if (mHasConnection) {
            unbindMainConnectionLocked();
            unbindMainConnection();
        }

        if (mCurToken != null) {
            removeCurrentTokenLocked();
            removeCurrentToken();
            mService.resetSystemUiLocked();
        }

        mCurId = null;
        clearCurMethodAndSessionsLocked();
        clearCurMethodAndSessions();
    }

    @GuardedBy("mMethodMap")
    private void clearCurMethodAndSessionsLocked() {
    private void clearCurMethodAndSessions() {
        mService.clearClientSessionsLocked();
        mCurMethod = null;
        mCurMethodUid = Process.INVALID_UID;
    }

    @GuardedBy("mMethodMap")
    private void removeCurrentTokenLocked() {
        int curTokenDisplayId = mService.getCurTokenDisplayId();
    private void removeCurrentToken() {
        int curTokenDisplayId = mService.getCurTokenDisplayIdLocked();

        if (DEBUG) {
            Slog.v(TAG,
@@ -388,7 +402,7 @@ final class InputMethodBindingController {

    @GuardedBy("mMethodMap")
    @NonNull
    InputBindResult bindCurrentMethodLocked() {
    InputBindResult bindCurrentMethod() {
        InputMethodInfo info = mMethodMap.get(mSelectedMethodId);
        if (info == null) {
            throw new IllegalArgumentException("Unknown id: " + mSelectedMethodId);
@@ -396,11 +410,11 @@ final class InputMethodBindingController {

        mCurIntent = createImeBindingIntent(info.getComponent());

        if (bindCurrentInputMethodServiceMainConnectionLocked()) {
        if (bindCurrentInputMethodServiceMainConnection()) {
            mCurId = info.getId();
            mLastBindTime = SystemClock.uptimeMillis();

            addFreshWindowTokenLocked();
            addFreshWindowToken();
            return new InputBindResult(
                    InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING,
                    null, null, mCurId, mCurSeq, false);
@@ -425,11 +439,11 @@ final class InputMethodBindingController {
    }

    @GuardedBy("mMethodMap")
    private void addFreshWindowTokenLocked() {
        int displayIdToShowIme = mService.getDisplayIdToShowIme();
    private void addFreshWindowToken() {
        int displayIdToShowIme = mService.getDisplayIdToShowImeLocked();
        mCurToken = new Binder();

        mService.setCurTokenDisplayId(displayIdToShowIme);
        mService.setCurTokenDisplayIdLocked(displayIdToShowIme);

        try {
            if (DEBUG) {
@@ -445,19 +459,19 @@ final class InputMethodBindingController {
    }

    @GuardedBy("mMethodMap")
    private void unbindMainConnectionLocked() {
    private void unbindMainConnection() {
        mContext.unbindService(mMainConnection);
        mHasConnection = false;
    }

    @GuardedBy("mMethodMap")
    void unbindVisibleConnectionLocked() {
    void unbindVisibleConnection() {
        mContext.unbindService(mVisibleConnection);
        mVisibleBound = false;
    }

    @GuardedBy("mMethodMap")
    private boolean bindCurrentInputMethodServiceLocked(ServiceConnection conn, int flags) {
    private boolean bindCurrentInputMethodService(ServiceConnection conn, int flags) {
        if (mCurIntent == null || conn == null) {
            Slog.e(TAG, "--- bind failed: service = " + mCurIntent + ", conn = " + conn);
            return false;
@@ -467,15 +481,15 @@ final class InputMethodBindingController {
    }

    @GuardedBy("mMethodMap")
    private boolean bindCurrentInputMethodServiceVisibleConnectionLocked() {
        mVisibleBound = bindCurrentInputMethodServiceLocked(mVisibleConnection,
    private boolean bindCurrentInputMethodServiceVisibleConnection() {
        mVisibleBound = bindCurrentInputMethodService(mVisibleConnection,
                IME_VISIBLE_BIND_FLAGS);
        return mVisibleBound;
    }

    @GuardedBy("mMethodMap")
    private boolean bindCurrentInputMethodServiceMainConnectionLocked() {
        mHasConnection = bindCurrentInputMethodServiceLocked(mMainConnection,
    private boolean bindCurrentInputMethodServiceMainConnection() {
        mHasConnection = bindCurrentInputMethodService(mMainConnection,
                mImeConnectionBindFlags);
        return mHasConnection;
    }
@@ -487,11 +501,11 @@ final class InputMethodBindingController {
     * Performs a rebind if no binding is achieved in {@link #TIME_TO_RECONNECT} milliseconds.
     */
    @GuardedBy("mMethodMap")
    void setCurrentMethodVisibleLocked() {
    void setCurrentMethodVisible() {
        if (mCurMethod != null) {
            if (DEBUG) Slog.d(TAG, "setCurrentMethodVisibleLocked: mCurToken=" + mCurToken);
            if (DEBUG) Slog.d(TAG, "setCurrentMethodVisible: mCurToken=" + mCurToken);
            if (mHasConnection && !mVisibleBound) {
                bindCurrentInputMethodServiceVisibleConnectionLocked();
                bindCurrentInputMethodServiceVisibleConnection();
            }
            return;
        }
@@ -504,9 +518,9 @@ final class InputMethodBindingController {
            // to try to prod things along.
            EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, getSelectedMethodId(),
                    bindingDuration, 1);
            Slog.w(TAG, "Force disconnect/connect to the IME in setCurrentMethodVisibleLocked()");
            unbindMainConnectionLocked();
            bindCurrentInputMethodServiceMainConnectionLocked();
            Slog.w(TAG, "Force disconnect/connect to the IME in setCurrentMethodVisible()");
            unbindMainConnection();
            bindCurrentInputMethodServiceMainConnection();
        } else {
            if (DEBUG) {
                Slog.d(TAG, "Can't show input: connection = " + mHasConnection + ", time = "
@@ -519,9 +533,9 @@ final class InputMethodBindingController {
     * Remove the binding needed for the IME to be shown.
     */
    @GuardedBy("mMethodMap")
    void setCurrentMethodNotVisibleLocked() {
    void setCurrentMethodNotVisible() {
        if (mVisibleBound) {
            unbindVisibleConnectionLocked();
            unbindVisibleConnection();
        }
    }
}
+117 −98

File changed.

Preview size limit exceeded, changes collapsed.