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

Commit 35509db0 authored by Arpan Kaphle's avatar Arpan Kaphle
Browse files

Auth Entry Metric Exceptions and Status

This collects status and exception information for the auth entry metric
and continues the combination of this metric with the total candidate
metric.

Bug: 271135048
Test: Build and Won't Submit without E2E Test
Change-Id: Ib3db0b2723189d02f4af84b3101d0d45e24cd936
parent 6ca8ce8a
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -217,11 +217,12 @@ public class MetricUtilities {
                    /* auth_per_entry_counts */
                    authenticationMetric.getAuthEntryCollective().getUniqueEntryCounts(),
                    /* framework_exception_unique_classtype */
                    DEFAULT_STRING,
                    /* exception_specified */ false,
                    /* auth_provider_status TODO(immediately) change */ DEFAULT_INT_32,
                    authenticationMetric.getFrameworkException(),
                    /* exception_specified */ authenticationMetric.isHasException(),
                    /* auth_provider_status */
                    authenticationMetric.getProviderStatus(),
                    /* query_returned */
                    false
                    authenticationMetric.isQueryReturned()
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during candidate get metric logging: " + e);
+2 −0
Original line number Diff line number Diff line
@@ -269,6 +269,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
            case AUTHENTICATION_ACTION_ENTRY_KEY:
                Action authenticationEntry = mProviderResponseDataHandler
                        .getAuthenticationAction(entryKey);
                mProviderSessionMetric.createAuthenticationBrowsingMetric();
                if (authenticationEntry == null) {
                    Slog.i(TAG, "Unexpected authenticationEntry key");
                    invokeCallbackOnInternalInvalidState();
@@ -423,6 +424,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
                providerPendingIntentResponse);
        if (exception != null) {
            // TODO (b/271135048), for AuthenticationEntry callback selection, set error
            mProviderSessionMetric.collectAuthenticationExceptionStatus(/*hasException*/true);
            invokeCallbackWithError(exception.getType(),
                    exception.getMessage());
            // Additional content received is in the form of an exception which ends the flow.
+43 −0
Original line number Diff line number Diff line
@@ -32,7 +32,18 @@ public class BrowsedAuthenticationMetric {
    // The provider associated with the press, defaults to -1
    private int mProviderUid = -1;

    // The response objects collected for this authentication entry click, default empty
    private ResponseCollective mAuthEntryCollective = new ResponseCollective(Map.of(), Map.of());

    // Indicates if an exception was thrown by this provider, false by default
    private boolean mHasException = false;
    // Indicates the framework only exception belonging to this provider, defaults to empty string
    private String mFrameworkException = "";
    // The status of this particular provider
    private int mProviderStatus = -1;
    // Indicates if this provider returned from the authentication entry query, default false
    private boolean mQueryReturned = false;

    // TODO(b/271135048) - Match the atom and provide a clean per provider session metric
    // encapsulation.

@@ -60,4 +71,36 @@ public class BrowsedAuthenticationMetric {
    public ResponseCollective getAuthEntryCollective() {
        return mAuthEntryCollective;
    }

    public void setHasException(boolean hasException) {
        mHasException = hasException;
    }

    public void setFrameworkException(String frameworkException) {
        mFrameworkException = frameworkException;
    }

    public void setProviderStatus(int providerStatus) {
        mProviderStatus = providerStatus;
    }

    public void setQueryReturned(boolean queryReturned) {
        mQueryReturned = queryReturned;
    }

    public boolean isQueryReturned() {
        return mQueryReturned;
    }

    public int getProviderStatus() {
        return mProviderStatus;
    }

    public String getFrameworkException() {
        return mFrameworkException;
    }

    public boolean isHasException() {
        return mHasException;
    }
}
+10 −2
Original line number Diff line number Diff line
@@ -31,10 +31,14 @@ public class CandidateAggregateMetric {
    private static final String TAG = "CandidateProviderMetric";
    // The session id of this provider metric
    private final int mSessionIdProvider;
    // Indicates if this provider returned from the query phase, default false
    // Indicates if this provider returned from the candidate query phase,
    // true if at least one provider returns validly, even if empty, default false
    private boolean mQueryReturned = false;
    // Indicates the total number of providers this aggregate captures information for, default 0
    private int mNumProviders = 0;
    // Indicates if the authentication entry returned, true if at least one entry returns validly,
    // even if empty, default false
    private boolean mAuthReturned = false;
    // Indicates the total number of authentication entries that were tapped in aggregate, default 0
    private int mNumAuthEntriesTapped = 0;
    // The combined aggregate collective across the candidate get/create
@@ -89,9 +93,9 @@ public class CandidateAggregateMetric {
        for (var session : providerSessions) {
            var sessionMetric = session.getProviderSessionMetric();
            var authMetrics = sessionMetric.getBrowsedAuthenticationMetric();
            mQueryReturned = mQueryReturned; // TODO add rest of auth info
            mNumAuthEntriesTapped += authMetrics.size();
            for (var authMetric : authMetrics) {
                mAuthReturned = mAuthReturned || authMetric.isQueryReturned();
                ResponseCollective authCollective = authMetric.getAuthEntryCollective();
                ResponseCollective.combineTypeCountMaps(responseCountAuth,
                        authCollective.getResponseCountsMap());
@@ -122,4 +126,8 @@ public class CandidateAggregateMetric {
    public ResponseCollective getAggregateCollectiveAuth() {
        return mAggregateCollectiveAuth;
    }

    public boolean isAuthReturned() {
        return mAuthReturned;
    }
}
+42 −10
Original line number Diff line number Diff line
@@ -82,7 +82,30 @@ public class ProviderSessionMetric {
     * @param hasException indicates if the candidate provider associated with an exception
     */
    public void collectCandidateExceptionStatus(boolean hasException) {
        try {
            mCandidatePhasePerProviderMetric.setHasException(hasException);
        } catch (Exception e) {
            Slog.i(TAG, "Error while setting candidate metric exception " + e);
        }
    }

    /**
     * This collects for ProviderSessions, with respect to the authentication entry provider,
     * if an exception occurred in the authentication entry click. It's expected that these
     * collections always occur after at least 1 authentication metric has been collected
     * for the provider associated with this metric encapsulation.
     *
     * @param hasException indicates if the candidate provider from an authentication entry
     *                     associated with an exception
     */
    public void collectAuthenticationExceptionStatus(boolean hasException) {
        try {
            var mostRecentAuthenticationMetric = mBrowsedAuthenticationMetric
                    .get(mBrowsedAuthenticationMetric.size() - 1);
            mostRecentAuthenticationMetric.setHasException(hasException);
        } catch (Exception e) {
            Slog.i(TAG, "Error while setting authentication metric exception " + e);
        }
    }

    /**
@@ -107,13 +130,13 @@ public class ProviderSessionMetric {
        mostRecentAuthenticationMetric.setProviderUid(providerSessionUid);
        // TODO(immediately) - add timestamps (no longer needed!!) but also update below values!
        if (isFailureStatus) {
            mCandidatePhasePerProviderMetric.setQueryReturned(false);
            mCandidatePhasePerProviderMetric.setProviderQueryStatus(
            mostRecentAuthenticationMetric.setQueryReturned(false);
            mostRecentAuthenticationMetric.setProviderStatus(
                    ProviderStatusForMetrics.QUERY_FAILURE
                            .getMetricCode());
        } else if (isCompletionStatus) {
            mCandidatePhasePerProviderMetric.setQueryReturned(true);
            mCandidatePhasePerProviderMetric.setProviderQueryStatus(
            mostRecentAuthenticationMetric.setQueryReturned(true);
            mostRecentAuthenticationMetric.setProviderStatus(
                    ProviderStatusForMetrics.QUERY_SUCCESS
                            .getMetricCode());
        }
@@ -223,6 +246,17 @@ public class ProviderSessionMetric {
        mCandidatePhasePerProviderMetric.setResponseCollective(responseCollective);
    }

    /**
     * This sets up an authentication metric collector to the flow. This must be called before
     * any logical edits are done in a new authentication entry metric collection.
     */
    public void createAuthenticationBrowsingMetric() {
        BrowsedAuthenticationMetric browsedAuthenticationMetric =
                new BrowsedAuthenticationMetric(mCandidatePhasePerProviderMetric
                        .getSessionIdProvider());
        mBrowsedAuthenticationMetric.add(browsedAuthenticationMetric);
    }

    private void beginCreateCredentialResponseCollectionCandidateEntryMetrics(
            BeginCreateCredentialResponse response) {
        Map<EntryEnum, Integer> entryCounts = new LinkedHashMap<>();
@@ -266,12 +300,10 @@ public class ProviderSessionMetric {
        if (!isAuthEntry) {
            mCandidatePhasePerProviderMetric.setResponseCollective(responseCollective);
        } else {
            BrowsedAuthenticationMetric browsedAuthenticationMetric =
                    new BrowsedAuthenticationMetric(mCandidatePhasePerProviderMetric
                            .getSessionIdProvider());
            // to receive an auth entry, the candidate phase must have succeeded
            // The most recent auth entry must be created already
            var browsedAuthenticationMetric =
                    mBrowsedAuthenticationMetric.get(mBrowsedAuthenticationMetric.size() - 1);
            browsedAuthenticationMetric.setAuthEntryCollective(responseCollective);
            mBrowsedAuthenticationMetric.add(browsedAuthenticationMetric);
        }
    }
}
Loading