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

Commit 323255dd authored by Feng Cao's avatar Feng Cao
Browse files

Fixed deadlock in InlineSuggestionSession.

* by using the same lock from the autofill Session

Test: manual
Test: atest android.autofillservice.cts.inline
Bug: 151580124

Change-Id: Ia34b1d0ea85c24eddf1cf1b89d07c331bb411023
parent 99852d7d
Loading
Loading
Loading
Loading
+15 −21
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ import java.util.function.Consumer;
 * side flow.
 *
 * <p>
 * This class is thread safe.
 * This class should hold the same lock as {@link Session} as they call into each other.
 */
final class InlineSuggestionSession {

@@ -105,12 +105,12 @@ final class InlineSuggestionSession {
    private boolean mImeInputViewStarted = false;

    InlineSuggestionSession(InputMethodManagerInternal inputMethodManagerInternal,
            int userId, ComponentName componentName, Handler handler) {
            int userId, ComponentName componentName, Handler handler, Object lock) {
        mInputMethodManagerInternal = inputMethodManagerInternal;
        mUserId = userId;
        mComponentName = componentName;
        mHandler = handler;
        mLock = new Object();
        mLock = lock;
        mImeStatusListener = new ImeStatusListener() {
            @Override
            public void onInputMethodStartInputView(AutofillId imeFieldId) {
@@ -261,14 +261,13 @@ final class InlineSuggestionSession {
            mHandler = handler;
            mTimeoutCallback = () -> {
                Log.w(TAG, "Timed out waiting for IME callback InlineSuggestionsRequest.");
                synchronized (mLock) {
                    completeIfNotLocked(null);
                }
                completeIfNot(null);
            };
            mHandler.postDelayed(mTimeoutCallback, INLINE_REQUEST_TIMEOUT_MS);
        }

        private void completeIfNotLocked(@Nullable ImeResponse response) {
        private void completeIfNot(@Nullable ImeResponse response) {
            synchronized (mLock) {
                if (mResponse.isDone()) {
                    return;
                }
@@ -276,14 +275,13 @@ final class InlineSuggestionSession {
                mRequestConsumer.accept(response == null ? null : response.mRequest);
                mHandler.removeCallbacks(mTimeoutCallback);
            }
        }

        @BinderThread
        @Override
        public void onInlineSuggestionsUnsupported() throws RemoteException {
            if (sDebug) Log.d(TAG, "onInlineSuggestionsUnsupported() called.");
            synchronized (mLock) {
                completeIfNotLocked(null);
            }
            completeIfNot(null);
        }

        @BinderThread
@@ -302,13 +300,9 @@ final class InlineSuggestionSession {
                mImeStatusListener.onInputMethodFinishInputView(imeFieldId);
            }
            if (request != null && callback != null) {
                synchronized (mLock) {
                    completeIfNotLocked(new ImeResponse(request, callback));
                }
                completeIfNot(new ImeResponse(request, callback));
            } else {
                synchronized (mLock) {
                    completeIfNotLocked(null);
                }
                completeIfNot(null);
            }
        }

+1 −1
Original line number Diff line number Diff line
@@ -756,7 +756,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        setClientLocked(client);

        mInlineSuggestionSession = new InlineSuggestionSession(inputMethodManagerInternal, userId,
                componentName, handler);
                componentName, handler, mLock);

        mMetricsLogger.write(newLogMaker(MetricsEvent.AUTOFILL_SESSION_STARTED)
                .addTaggedData(MetricsEvent.FIELD_AUTOFILL_FLAGS, flags));