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

Commit 59f28d48 authored by Arpan Kaphle's avatar Arpan Kaphle
Browse files

Sets up Final Phase Emit for Calling App Track

When we know the calling app, this sets up the final phase emit, where
we do not know the providers. The session ID is properly transferred and
different. We call this the 'track one' emit for the final phase.

Bug: 271135048
Test: Build and won't submit without E2E test.

Change-Id: If8cf0831f49eec7171c549fab1db471825fe6282
parent f3b471ad
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
@@ -31,6 +31,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;
@@ -118,9 +119,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());
+70 −4
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ public class MetricUtilities {
                index++;
            }
            FrameworkStatsLog.write(FrameworkStatsLog.CREDENTIAL_MANAGER_FINAL_PHASE_REPORTED,
                    /* session_id */ finalPhaseMetric.getSessionIdTrackTwo(),
                    /* session_id */ finalPhaseMetric.getSessionIdProvider(),
                    /* sequence_num */ emitSequenceId,
                    /* ui_returned_final_start */ finalPhaseMetric.isUiReturned(),
                    /* chosen_provider_uid */ finalPhaseMetric.getChosenUid(),
@@ -225,7 +225,7 @@ public class MetricUtilities {
                CandidatePhaseMetric metric = session.mProviderSessionMetric
                        .getCandidatePhasePerProviderMetric();
                if (sessionId == -1) {
                    sessionId = metric.getSessionIdTrackTwo();
                    sessionId = metric.getSessionIdProvider();
                }
                if (!queryReturned) {
                    queryReturned = metric.isQueryReturned();
@@ -329,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(),
@@ -360,7 +360,7 @@ public class MetricUtilities {
        try {
            if (!LOG_FLAG) {
                FrameworkStatsLog.write(FrameworkStatsLog.CREDENTIAL_MANAGER_TOTAL_REPORTED,
                        /*session_id*/ candidateAggregateMetric.getSessionId(),
                        /*session_id*/ candidateAggregateMetric.getSessionIdProvider(),
                        /*sequence_num*/ sequenceNum,
                        /*query_returned*/ candidateAggregateMetric.isQueryReturned(),
                        /*num_providers*/ candidateAggregateMetric.getNumProviders(),
@@ -405,4 +405,70 @@ public class MetricUtilities {
            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);
        }
    }

}
+1 −2
Original line number Diff line number Diff line
@@ -138,8 +138,7 @@ abstract class RequestSession<T, U, V> implements CredentialManagerUi.Credential
        mRequestSessionMetric = new RequestSessionMetric(mUniqueSessionInteger,
                MetricUtilities.getHighlyUniqueInteger());
        mRequestSessionMetric.collectInitialPhaseMetricInfo(timestampStarted,
                mCallingUid, ApiName.getMetricCodeFromRequestInfo(mRequestType),
                mUniqueSessionInteger);
                mCallingUid, ApiName.getMetricCodeFromRequestInfo(mRequestType));
        setCancellationListener();
    }

Loading