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

Commit 052562c4 authored by Felipe Leme's avatar Felipe Leme
Browse files

Calls CancellationSignal when onFillRequest() times out.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases -t android.autofillservice.cts.LoginActivityTest#testCancellationSignalCalledAfterTimeout
Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases

Fixes: 64034169

Change-Id: I501653405e8244543a4c27f736bacfa23d22e6f7
parent 57ae4db2
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -18,16 +18,15 @@ package android.service.autofill;
import android.annotation.CallSuper;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.RemoteException;
import android.provider.Settings;

import com.android.internal.os.HandlerCaller;
import android.annotation.SdkConstant;
import android.app.Service;import android.content.Intent;
import android.app.Service;
import android.content.Intent;
import android.os.CancellationSignal;
import android.os.IBinder;
import android.os.ICancellationSignal;
import android.os.Looper;
import android.os.RemoteException;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.view.ViewStructure;
@@ -35,6 +34,7 @@ import android.view.autofill.AutofillId;
import android.view.autofill.AutofillManager;
import android.view.autofill.AutofillValue;

import com.android.internal.os.HandlerCaller;
import com.android.internal.os.SomeArgs;

/**
+20 −7
Original line number Diff line number Diff line
@@ -290,7 +290,7 @@ final class RemoteFillService implements DeathRecipient {
    }

    private void dispatchOnFillRequestFailure(PendingRequest pendingRequest,
            CharSequence message) {
            @Nullable CharSequence message) {
        mHandler.getHandler().post(() -> {
            if (handleResponseCallbackCommon(pendingRequest)) {
                mCallbacks.onFillRequestFailure(message, mComponentName.getPackageName());
@@ -298,6 +298,16 @@ final class RemoteFillService implements DeathRecipient {
        });
    }

    private void dispatchOnFillTimeout(@NonNull ICancellationSignal cancellationSignal) {
        mHandler.getHandler().post(() -> {
            try {
                cancellationSignal.cancel();
            } catch (RemoteException e) {
                Slog.w(LOG_TAG, "Error calling cancellation signal: " + e);
            }
        });
    }

    private void dispatchOnSaveRequestSuccess(PendingRequest pendingRequest) {
        mHandler.getHandler().post(() -> {
            if (handleResponseCallbackCommon(pendingRequest)) {
@@ -307,7 +317,7 @@ final class RemoteFillService implements DeathRecipient {
    }

    private void dispatchOnSaveRequestFailure(PendingRequest pendingRequest,
            CharSequence message) {
            @Nullable CharSequence message) {
        mHandler.getHandler().post(() -> {
            if (handleResponseCallbackCommon(pendingRequest)) {
                mCallbacks.onSaveRequestFailure(message, mComponentName.getPackageName());
@@ -432,7 +442,7 @@ final class RemoteFillService implements DeathRecipient {
                if (remoteService != null) {
                    Slog.w(LOG_TAG, getClass().getSimpleName() + " timed out after "
                            + TIMEOUT_REMOTE_REQUEST_MILLIS + " ms");
                    fail(remoteService);
                    onTimeout(remoteService);
                }
            };
            mServiceHandler.postAtTime(mTimeoutTrigger,
@@ -485,7 +495,7 @@ final class RemoteFillService implements DeathRecipient {
         * Called by the self-destructure timeout when the AutofilllService didn't reply to the
         * request on time.
         */
        abstract void fail(RemoteFillService remoteService);
        abstract void onTimeout(RemoteFillService remoteService);

        /**
         * @return whether this request leads to a final state where no
@@ -549,7 +559,10 @@ final class RemoteFillService implements DeathRecipient {
        }

        @Override
        void fail(RemoteFillService remoteService) {
        void onTimeout(RemoteFillService remoteService) {
            // NOTE: Must make these 2 calls asynchronously, because the cancellation signal is
            // handled by the service, which could block.
            remoteService.dispatchOnFillTimeout(mCancellation);
            remoteService.dispatchOnFillRequestFailure(PendingFillRequest.this, null);
        }

@@ -617,7 +630,7 @@ final class RemoteFillService implements DeathRecipient {
        }

        @Override
        void fail(RemoteFillService remoteService) {
        void onTimeout(RemoteFillService remoteService) {
            remoteService.dispatchOnSaveRequestFailure(PendingSaveRequest.this, null);
        }

@@ -630,7 +643,7 @@ final class RemoteFillService implements DeathRecipient {
                } catch (RemoteException e) {
                    Slog.e(LOG_TAG, "Error calling on save request", e);

                    remoteService.dispatchOnFillRequestFailure(PendingSaveRequest.this, null);
                    remoteService.dispatchOnSaveRequestFailure(PendingSaveRequest.this, null);
                }
            }
        }