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

Commit 265d3aac authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix potential NPE in autofill Session" into rvc-dev am: 35193303

Change-Id: I62f3e218ffd0279a5d66ce54a221ab92fa55b5df
parents cc544cfe 35193303
Loading
Loading
Loading
Loading
+18 −7
Original line number Original line Diff line number Diff line
@@ -311,6 +311,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
     */
     */
    private final AssistDataReceiverImpl mAssistReceiver = new AssistDataReceiverImpl();
    private final AssistDataReceiverImpl mAssistReceiver = new AssistDataReceiverImpl();


    /**
     * TODO(b/151867668): improve how asynchronous data dependencies are handled, without using
     * CountDownLatch.
     */
    private final class AssistDataReceiverImpl extends IAssistDataReceiver.Stub {
    private final class AssistDataReceiverImpl extends IAssistDataReceiver.Stub {


        @GuardedBy("mLock")
        @GuardedBy("mLock")
@@ -318,7 +322,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        @GuardedBy("mLock")
        @GuardedBy("mLock")
        private FillRequest mPendingFillRequest;
        private FillRequest mPendingFillRequest;
        @GuardedBy("mLock")
        @GuardedBy("mLock")
        private CountDownLatch mCountDownLatch;
        private CountDownLatch mCountDownLatch = new CountDownLatch(0);


        @Nullable Consumer<InlineSuggestionsRequest> newAutofillRequestLocked(
        @Nullable Consumer<InlineSuggestionsRequest> newAutofillRequestLocked(
                boolean isInlineRequest) {
                boolean isInlineRequest) {
@@ -327,6 +331,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            mPendingInlineSuggestionsRequest = null;
            mPendingInlineSuggestionsRequest = null;
            return isInlineRequest ? (inlineSuggestionsRequest) -> {
            return isInlineRequest ? (inlineSuggestionsRequest) -> {
                synchronized (mLock) {
                synchronized (mLock) {
                    if (mCountDownLatch.getCount() == 0) {
                        return;
                    }
                    mPendingInlineSuggestionsRequest = inlineSuggestionsRequest;
                    mPendingInlineSuggestionsRequest = inlineSuggestionsRequest;
                    mCountDownLatch.countDown();
                    mCountDownLatch.countDown();
                    maybeRequestFillLocked();
                    maybeRequestFillLocked();
@@ -335,8 +342,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        }
        }


        void maybeRequestFillLocked() {
        void maybeRequestFillLocked() {
            if (mCountDownLatch == null || mCountDownLatch.getCount() > 0
            if (mCountDownLatch.getCount() > 0 || mPendingFillRequest == null) {
                    || mPendingFillRequest == null) {
                return;
                return;
            }
            }
            if (mPendingInlineSuggestionsRequest != null) {
            if (mPendingInlineSuggestionsRequest != null) {
@@ -347,7 +353,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            mRemoteFillService.onFillRequest(mPendingFillRequest);
            mRemoteFillService.onFillRequest(mPendingFillRequest);
            mPendingInlineSuggestionsRequest = null;
            mPendingInlineSuggestionsRequest = null;
            mPendingFillRequest = null;
            mPendingFillRequest = null;
            mCountDownLatch = null;
        }
        }


        @Override
        @Override
@@ -447,9 +452,15 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                request = new FillRequest(requestId, contexts, mClientState, flags,
                request = new FillRequest(requestId, contexts, mClientState, flags,
                        /*inlineSuggestionsRequest=*/null);
                        /*inlineSuggestionsRequest=*/null);


                if (mCountDownLatch.getCount() > 0) {
                    mPendingFillRequest = request;
                    mPendingFillRequest = request;
                    mCountDownLatch.countDown();
                    mCountDownLatch.countDown();
                    maybeRequestFillLocked();
                    maybeRequestFillLocked();
                } else {
                    // TODO(b/151867668): ideally this case should not happen, but it was
                    //  observed, we should figure out why and fix.
                    mRemoteFillService.onFillRequest(request);
                }
            }
            }


            if (mActivityToken != null) {
            if (mActivityToken != null) {