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

Commit acc7af7e authored by Daniel's avatar Daniel
Browse files

Fix Authentication flow for secondary provider

When the authentication is complete, based on request id, fill response
is retrieved. For secondary providers, the fill response needs to be
retrieved from secondary fill responses. To do that, assign odd numbers
for secondary providers and even numbers for primary providers to
distinguish the providers from the request id.

Bug: 328621938
Test: atest CtsAutoFillServiceTestCases:android.autofillservice.cts.inline.InlineLoginMixedCredentialActivityTest
Change-Id: Ibafb56f80071dd9d279a7f179f053bde14a56222
parent e54bdfb4
Loading
Loading
Loading
Loading
+29 −8
Original line number Diff line number Diff line
@@ -1246,7 +1246,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    @GuardedBy("mLock")
    private void requestNewFillResponseLocked(@NonNull ViewState viewState, int newState,
            int flags) {
        final FillResponse existingResponse = shouldRequestSecondaryProvider(flags)
        boolean isSecondary = shouldRequestSecondaryProvider(flags);
        final FillResponse existingResponse = isSecondary
                ? viewState.getSecondaryResponse() : viewState.getResponse();
        mFillRequestEventLogger.startLogForNewRequest();
        mRequestCount++;
@@ -1283,12 +1284,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        }

        viewState.setState(newState);

        int requestId;
        // TODO(b/158623971): Update this to prevent possible overflow
        do {
            requestId = sIdCounter.getAndIncrement();
        } while (requestId == INVALID_REQUEST_ID);
        int requestId = getRequestId(isSecondary);

        // Create a metrics log for the request
        final int ordinal = mRequestLogs.size() + 1;
@@ -1367,6 +1363,25 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        requestAssistStructureLocked(requestId, flags);
    }

    private static int getRequestId(boolean isSecondary) {
        // For authentication flows, there needs to be a way to know whether to retrieve the Fill
        // Response from the primary provider or the secondary provider from the requestId. A simple
        // way to achieve this is by assigning odd number request ids to secondary provider and
        // even numbers to primary provider.
        int requestId;
        // TODO(b/158623971): Update this to prevent possible overflow
        if (isSecondary) {
            do {
                requestId = sIdCounter.getAndIncrement();
            } while (!isSecondaryProviderRequestId(requestId));
        } else {
            do {
                requestId = sIdCounter.getAndIncrement();
            } while (requestId == INVALID_REQUEST_ID || isSecondaryProviderRequestId(requestId));
        }
        return requestId;
    }

    private boolean isRequestSupportFillDialog(int flags) {
        return (flags & FLAG_SUPPORTS_FILL_DIALOG) != 0;
    }
@@ -2790,7 +2805,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            removeFromService();
            return;
        }
        final FillResponse authenticatedResponse = mResponses.get(requestId);
        final FillResponse authenticatedResponse = isSecondaryProviderRequestId(requestId)
                ? mSecondaryResponses.get(requestId)
                : mResponses.get(requestId);
        if (authenticatedResponse == null || data == null) {
            Slog.w(TAG, "no authenticated response");
            mPresentationStatsEventLogger.maybeSetAuthenticationResult(
@@ -2915,6 +2932,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        }
    }

    private static boolean isSecondaryProviderRequestId(int requestId) {
        return requestId % 2 == 1;
    }

    private Dataset getDatasetFromCredentialResponse(GetCredentialResponse result) {
        if (result == null) {
            return null;