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

Commit 69a6ce97 authored by Daniel Kim's avatar Daniel Kim Committed by Android (Google) Code Review
Browse files

Merge "Fix Authentication flow for secondary provider" into main

parents ad67f12a acc7af7e
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;