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

Commit 3fdc0c48 authored by Arpan Kaphle's avatar Arpan Kaphle Committed by Android (Google) Code Review
Browse files

Merge changes If8cf0831,Ib3203643,I8e7455dd into udc-dev

* changes:
  Sets up Final Phase Emit for Calling App Track
  Adds to Aggregate Candidate Metric query and count
  Candidate Aggregate Metrics Setup + sessId Focus
parents 4380b2c2 59f28d48
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import android.os.RemoteException;
import android.service.credentials.CallingAppInfo;
import android.util.Slog;

import com.android.server.credentials.metrics.ProviderSessionMetric;

import java.util.ArrayList;
import java.util.Set;

@@ -93,9 +95,12 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta
    public void onFinalResponseReceived(
            ComponentName componentName,
            Void response) {
        mRequestSessionMetric.collectChosenMetricViaCandidateTransfer(
                mProviders.get(componentName.flattenToString()).mProviderSessionMetric
        if (mProviders.get(componentName.flattenToString()) != null) {
            ProviderSessionMetric providerSessionMetric =
                    mProviders.get(componentName.flattenToString()).mProviderSessionMetric;
            mRequestSessionMetric.collectChosenMetricViaCandidateTransfer(providerSessionMetric
                    .getCandidatePhasePerProviderMetric());
        }
        respondToClientWithResponseAndFinish(null);
    }

+7 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.service.credentials.CallingAppInfo;
import android.service.credentials.PermissionUtils;
import android.util.Slog;

import com.android.server.credentials.metrics.ProviderSessionMetric;
import com.android.server.credentials.metrics.ProviderStatusForMetrics;

import java.util.ArrayList;
@@ -131,9 +132,12 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
            @Nullable CreateCredentialResponse response) {
        Slog.i(TAG, "Final credential received from: " + componentName.flattenToString());
        mRequestSessionMetric.collectUiResponseData(/*uiReturned=*/ true, System.nanoTime());
        mRequestSessionMetric.collectChosenMetricViaCandidateTransfer(mProviders.get(
                componentName.flattenToString()).mProviderSessionMetric
        if (mProviders.get(componentName.flattenToString()) != null) {
            ProviderSessionMetric providerSessionMetric =
                    mProviders.get(componentName.flattenToString()).mProviderSessionMetric;
            mRequestSessionMetric.collectChosenMetricViaCandidateTransfer(providerSessionMetric
                    .getCandidatePhasePerProviderMetric());
        }
        if (response != null) {
            mRequestSessionMetric.collectChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_SUCCESS.getMetricCode());
+7 −3
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.RemoteException;
import android.service.credentials.CallingAppInfo;
import android.util.Slog;

import com.android.server.credentials.metrics.ProviderSessionMetric;
import com.android.server.credentials.metrics.ProviderStatusForMetrics;

import java.util.ArrayList;
@@ -130,9 +131,12 @@ public class GetRequestSession extends RequestSession<GetCredentialRequest,
            @Nullable GetCredentialResponse response) {
        Slog.i(TAG, "onFinalResponseReceived from: " + componentName.flattenToString());
        mRequestSessionMetric.collectUiResponseData(/*uiReturned=*/ true, System.nanoTime());
        mRequestSessionMetric.collectChosenMetricViaCandidateTransfer(
                mProviders.get(componentName.flattenToString())
                        .mProviderSessionMetric.getCandidatePhasePerProviderMetric());
        if (mProviders.get(componentName.flattenToString()) != null) {
            ProviderSessionMetric providerSessionMetric =
                    mProviders.get(componentName.flattenToString()).mProviderSessionMetric;
            mRequestSessionMetric.collectChosenMetricViaCandidateTransfer(providerSessionMetric
                    .getCandidatePhasePerProviderMetric());
        }
        if (response != null) {
            mRequestSessionMetric.collectChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_SUCCESS.getMetricCode());
+140 −5
Original line number Diff line number Diff line
@@ -24,12 +24,14 @@ import android.util.Slog;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.credentials.metrics.ApiName;
import com.android.server.credentials.metrics.ApiStatus;
import com.android.server.credentials.metrics.CandidateAggregateMetric;
import com.android.server.credentials.metrics.CandidateBrowsingPhaseMetric;
import com.android.server.credentials.metrics.CandidatePhaseMetric;
import com.android.server.credentials.metrics.ChosenProviderFinalPhaseMetric;
import com.android.server.credentials.metrics.EntryEnum;
import com.android.server.credentials.metrics.InitialPhaseMetric;

import java.security.SecureRandom;
import java.util.List;
import java.util.Map;

@@ -78,6 +80,15 @@ public class MetricUtilities {
        return sessUid;
    }

    /**
     * Used to help generate random sequences for local sessions, in the time-scale of credential
     * manager flows.
     * @return a high entropy int useful to use in reasonable time-frame sessions.
     */
    public static int getHighlyUniqueInteger() {
        return new SecureRandom().nextInt();
    }

    /**
     * Given any two timestamps in nanoseconds, this gets the difference and converts to
     * milliseconds. Assumes the difference is not larger than the maximum int size.
@@ -130,7 +141,7 @@ public class MetricUtilities {
                index++;
            }
            FrameworkStatsLog.write(FrameworkStatsLog.CREDENTIAL_MANAGER_FINAL_PHASE_REPORTED,
                    /* session_id */ finalPhaseMetric.getSessionId(),
                    /* session_id */ finalPhaseMetric.getSessionIdProvider(),
                    /* sequence_num */ emitSequenceId,
                    /* ui_returned_final_start */ finalPhaseMetric.isUiReturned(),
                    /* chosen_provider_uid */ finalPhaseMetric.getChosenUid(),
@@ -170,8 +181,7 @@ public class MetricUtilities {
                    finalPhaseMetric.getResponseCollective().getUniqueResponseCounts(),
                    /* framework_exception_unique_classtype */
                    finalPhaseMetric.getFrameworkException(),
                    /* primary_indicated */
                    false
                    /* primary_indicated */ false
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during final provider uid emit: " + e);
@@ -215,7 +225,7 @@ public class MetricUtilities {
                CandidatePhaseMetric metric = session.mProviderSessionMetric
                        .getCandidatePhasePerProviderMetric();
                if (sessionId == -1) {
                    sessionId = metric.getSessionId();
                    sessionId = metric.getSessionIdProvider();
                }
                if (!queryReturned) {
                    queryReturned = metric.isQueryReturned();
@@ -319,7 +329,7 @@ public class MetricUtilities {
            FrameworkStatsLog.write(FrameworkStatsLog.CREDENTIAL_MANAGER_INIT_PHASE_REPORTED,
                    /* api_name */ initialPhaseMetric.getApiName(),
                    /* caller_uid */ initialPhaseMetric.getCallerUid(),
                    /* session_id */ initialPhaseMetric.getSessionId(),
                    /* session_id */ initialPhaseMetric.getSessionIdCaller(),
                    /* sequence_num */ sequenceNum,
                    /* initial_timestamp_reference_nanoseconds */
                    initialPhaseMetric.getCredentialServiceStartedTimeNanoseconds(),
@@ -336,4 +346,129 @@ public class MetricUtilities {
            Slog.w(TAG, "Unexpected error during initial metric emit: " + e);
        }
    }

    /**
     * A logging utility focused on track 1, where the calling app is known. This captures all
     * aggregate information for the candidate phase.
     *
     * @param candidateAggregateMetric the aggregate candidate metric information collected
     * @param sequenceNum the sequence number for this api call session emit
     */
    public static void logApiCalledAggregateCandidate(
            CandidateAggregateMetric candidateAggregateMetric,
            int sequenceNum) {
        try {
            if (!LOG_FLAG) {
                FrameworkStatsLog.write(FrameworkStatsLog.CREDENTIAL_MANAGER_TOTAL_REPORTED,
                        /*session_id*/ candidateAggregateMetric.getSessionIdProvider(),
                        /*sequence_num*/ sequenceNum,
                        /*query_returned*/ candidateAggregateMetric.isQueryReturned(),
                        /*num_providers*/ candidateAggregateMetric.getNumProviders(),
                        /*min_query_start_timestamp_microseconds*/
                        DEFAULT_INT_32,
                        /*max_query_end_timestamp_microseconds*/
                        DEFAULT_INT_32,
                        /*query_response_unique_classtypes*/
                        DEFAULT_REPEATED_STR,
                        /*query_per_classtype_counts*/
                        DEFAULT_REPEATED_INT_32,
                        /*query_unique_entries*/
                        DEFAULT_REPEATED_INT_32,
                        /*query_per_entry_counts*/
                        DEFAULT_REPEATED_INT_32,
                        /*query_total_candidate_failure*/
                        DEFAULT_INT_32,
                        /*query_framework_exception_unique_classtypes*/
                        DEFAULT_REPEATED_STR,
                        /*query_per_exception_classtype_counts*/
                        DEFAULT_REPEATED_INT_32,
                        /*auth_response_unique_classtypes*/
                        DEFAULT_REPEATED_STR,
                        /*auth_per_classtype_counts*/
                        DEFAULT_REPEATED_INT_32,
                        /*auth_unique_entries*/
                        DEFAULT_REPEATED_INT_32,
                        /*auth_per_entry_counts*/
                        DEFAULT_REPEATED_INT_32,
                        /*auth_total_candidate_failure*/
                        DEFAULT_INT_32,
                        /*auth_framework_exception_unique_classtypes*/
                        DEFAULT_REPEATED_STR,
                        /*auth_per_exception_classtype_counts*/
                        DEFAULT_REPEATED_INT_32,
                        /*num_auth_clicks*/
                        DEFAULT_INT_32,
                        /*auth_returned*/ false
                );
            }
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during metric logging: " + e);
        }
    }

    /**
     * A logging utility used primarily for the final phase of the current metric setup for track 1.
     *
     * @param finalPhaseMetric     the coalesced data of the chosen provider
     * @param browsingPhaseMetrics the coalesced data of the browsing phase
     * @param apiStatus            the final status of this particular api call
     * @param emitSequenceId       an emitted sequence id for the current session
     */
    public static void logApiCalledNoUidFinal(ChosenProviderFinalPhaseMetric finalPhaseMetric,
            List<CandidateBrowsingPhaseMetric> browsingPhaseMetrics, int apiStatus,
            int emitSequenceId) {
        try {
            if (!LOG_FLAG) {
                return;
            }
            int browsedSize = browsingPhaseMetrics.size();
            int[] browsedClickedEntries = new int[browsedSize];
            int[] browsedProviderUid = new int[browsedSize];
            int index = 0;
            for (CandidateBrowsingPhaseMetric metric : browsingPhaseMetrics) {
                browsedClickedEntries[index] = metric.getEntryEnum();
                browsedProviderUid[index] = metric.getProviderUid();
                index++;
            }
            FrameworkStatsLog.write(FrameworkStatsLog.CREDENTIAL_MANAGER_FINALNOUID_REPORTED,
                    /* session_id */ finalPhaseMetric.getSessionIdCaller(),
                    /* sequence_num */ emitSequenceId,
                    /* ui_returned_final_start */ finalPhaseMetric.isUiReturned(),
                    /* chosen_provider_query_start_timestamp_microseconds */
                    finalPhaseMetric.getTimestampFromReferenceStartMicroseconds(finalPhaseMetric
                            .getQueryStartTimeNanoseconds()),
                    /* chosen_provider_query_end_timestamp_microseconds */
                    finalPhaseMetric.getTimestampFromReferenceStartMicroseconds(finalPhaseMetric
                            .getQueryEndTimeNanoseconds()),
                    /* chosen_provider_ui_invoked_timestamp_microseconds */
                    finalPhaseMetric.getTimestampFromReferenceStartMicroseconds(finalPhaseMetric
                            .getUiCallStartTimeNanoseconds()),
                    /* chosen_provider_ui_finished_timestamp_microseconds */
                    finalPhaseMetric.getTimestampFromReferenceStartMicroseconds(finalPhaseMetric
                            .getUiCallEndTimeNanoseconds()),
                    /* chosen_provider_finished_timestamp_microseconds */
                    finalPhaseMetric.getTimestampFromReferenceStartMicroseconds(finalPhaseMetric
                            .getFinalFinishTimeNanoseconds()),
                    /* chosen_provider_status */ finalPhaseMetric.getChosenProviderStatus(),
                    /* chosen_provider_has_exception */ finalPhaseMetric.isHasException(),
                    /* unique_entries */
                    finalPhaseMetric.getResponseCollective().getUniqueEntries(),
                    /* per_entry_counts */
                    finalPhaseMetric.getResponseCollective().getUniqueEntryCounts(),
                    /* unique_response_classtypes */
                    finalPhaseMetric.getResponseCollective().getUniqueResponseStrings(),
                    /* per_classtype_counts */
                    finalPhaseMetric.getResponseCollective().getUniqueResponseCounts(),
                    /* framework_exception_unique_classtype */
                    finalPhaseMetric.getFrameworkException(),
                    /* clicked_entries */ browsedClickedEntries,
                    /* provider_of_clicked_entry */ browsedProviderUid,
                    /* api_status */ apiStatus,
                    /* primary_indicated */ false
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during metric logging: " + e);
        }
    }

}
+2 −2
Original line number Diff line number Diff line
@@ -193,11 +193,11 @@ public final class ProviderCreateSession extends ProviderSession<
        mProviderResponseDataHandler.addResponseContent(response.getCreateEntries(),
                response.getRemoteCreateEntry());
        if (mProviderResponseDataHandler.isEmptyResponse(response)) {
            mProviderSessionMetric.collectCandidateEntryMetrics(response);
            mProviderSessionMetric.collectCandidateEntryMetrics(response, /*isAuthEntry*/false);
            updateStatusAndInvokeCallback(Status.EMPTY_RESPONSE,
                    /*source=*/ CredentialsSource.REMOTE_PROVIDER);
        } else {
            mProviderSessionMetric.collectCandidateEntryMetrics(response);
            mProviderSessionMetric.collectCandidateEntryMetrics(response, /*isAuthEntry*/false);
            updateStatusAndInvokeCallback(Status.SAVE_ENTRIES_RECEIVED,
                    /*source=*/ CredentialsSource.REMOTE_PROVIDER);
        }
Loading