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

Commit b1683ee4 authored by Arpan Kaphle's avatar Arpan Kaphle
Browse files

Chosen Phase Data Type Iteration and Injection..

into the framework. Will be followed by more iteration and injection,
but this allows us to dually discuss the type and how to place it into
the framework, which may make more a more efficient review process.

Bug: 270403549
Test: Builds
Change-Id: I51a31843274481a4494bb7adbaa4a9f93b18b8cc
parent 4df2f384
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta
    private void respondToClientWithResponseAndFinish() {
        Log.i(TAG, "respondToClientWithResponseAndFinish");
        if (isSessionCancelled()) {
            mChosenProviderMetric.setChosenProviderStatus(
            mChosenProviderFinalPhaseMetric.setChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_SUCCESS.getMetricCode());
            logApiCall(ApiName.CLEAR_CREDENTIAL, /* apiStatus */
                    ApiStatus.CLIENT_CANCELED);
@@ -134,7 +134,7 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta
            logApiCall(ApiName.CLEAR_CREDENTIAL, /* apiStatus */
                    ApiStatus.SUCCESS);
        } catch (RemoteException e) {
            mChosenProviderMetric.setChosenProviderStatus(
            mChosenProviderFinalPhaseMetric.setChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_FAILURE.getMetricCode());
            Log.i(TAG, "Issue while propagating the response to the client");
            logApiCall(ApiName.CLEAR_CREDENTIAL, /* apiStatus */
+9 −2
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR

    @Override
    protected void launchUiWithProviderData(ArrayList<ProviderData> providerDataList) {
        mChosenProviderFinalPhaseMetric.setUiCallStartTimeNanoseconds(System.nanoTime());
        try {
            mClientCallback.onPendingIntent(mCredentialManagerUi.createPendingIntent(
                    RequestInfo.newCreateRequestInfo(
@@ -90,6 +91,7 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
                            mClientAppInfo.getPackageName()),
                    providerDataList));
        } catch (RemoteException e) {
            mChosenProviderFinalPhaseMetric.setUiReturned(false);
            respondToClientWithErrorAndFinish(
                    CreateCredentialException.TYPE_UNKNOWN,
                    "Unable to invoke selector");
@@ -99,14 +101,16 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
    @Override
    public void onFinalResponseReceived(ComponentName componentName,
            @Nullable CreateCredentialResponse response) {
        mChosenProviderFinalPhaseMetric.setUiReturned(true);
        mChosenProviderFinalPhaseMetric.setUiCallEndTimeNanoseconds(System.nanoTime());
        Log.i(TAG, "onFinalCredentialReceived from: " + componentName.flattenToString());
        setChosenMetric(componentName);
        if (response != null) {
            mChosenProviderMetric.setChosenProviderStatus(
            mChosenProviderFinalPhaseMetric.setChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_SUCCESS.getMetricCode());
            respondToClientWithResponseAndFinish(response);
        } else {
            mChosenProviderMetric.setChosenProviderStatus(
            mChosenProviderFinalPhaseMetric.setChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_FAILURE.getMetricCode());
            respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_NO_CREATE_OPTIONS,
                    "Invalid response");
@@ -138,6 +142,8 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR

    private void respondToClientWithResponseAndFinish(CreateCredentialResponse response) {
        Log.i(TAG, "respondToClientWithResponseAndFinish");
        // TODO immediately add exception bit to chosen provider and do final emits across all
        // including sequenceCounter!
        if (mRequestSessionStatus == RequestSessionStatus.COMPLETE) {
            Log.i(TAG, "Request has already been completed. This is strange.");
            return;
@@ -162,6 +168,7 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR

    private void respondToClientWithErrorAndFinish(String errorType, String errorMsg) {
        Log.i(TAG, "respondToClientWithErrorAndFinish");

        if (mRequestSessionStatus == RequestSessionStatus.COMPLETE) {
            Log.i(TAG, "Request has already been completed. This is strange.");
            return;
+6 −2
Original line number Diff line number Diff line
@@ -82,12 +82,14 @@ public class GetRequestSession extends RequestSession<GetCredentialRequest,

    @Override
    protected void launchUiWithProviderData(ArrayList<ProviderData> providerDataList) {
        mChosenProviderFinalPhaseMetric.setUiCallStartTimeNanoseconds(System.nanoTime());
        try {
            mClientCallback.onPendingIntent(mCredentialManagerUi.createPendingIntent(
                    RequestInfo.newGetRequestInfo(
                    mRequestId, mClientRequest, mClientAppInfo.getPackageName()),
                    providerDataList));
        } catch (RemoteException e) {
            mChosenProviderFinalPhaseMetric.setUiReturned(false);
            respondToClientWithErrorAndFinish(
                    GetCredentialException.TYPE_UNKNOWN, "Unable to instantiate selector");
        }
@@ -96,14 +98,16 @@ public class GetRequestSession extends RequestSession<GetCredentialRequest,
    @Override
    public void onFinalResponseReceived(ComponentName componentName,
            @Nullable GetCredentialResponse response) {
        mChosenProviderFinalPhaseMetric.setUiReturned(true);
        mChosenProviderFinalPhaseMetric.setUiCallEndTimeNanoseconds(System.nanoTime());
        Log.i(TAG, "onFinalCredentialReceived from: " + componentName.flattenToString());
        setChosenMetric(componentName);
        if (response != null) {
            mChosenProviderMetric.setChosenProviderStatus(
            mChosenProviderFinalPhaseMetric.setChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_SUCCESS.getMetricCode());
            respondToClientWithResponseAndFinish(response);
        } else {
            mChosenProviderMetric.setChosenProviderStatus(
            mChosenProviderFinalPhaseMetric.setChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_FAILURE.getMetricCode());
            respondToClientWithErrorAndFinish(GetCredentialException.TYPE_NO_CREDENTIAL,
                    "Invalid response from provider");
+8 −7
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ 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.CandidatePhaseMetric;
import com.android.server.credentials.metrics.ChosenProviderMetric;
import com.android.server.credentials.metrics.ChosenProviderFinalPhaseMetric;
import com.android.server.credentials.metrics.InitialPhaseMetric;

import java.util.Map;
@@ -89,11 +89,11 @@ public class MetricUtilities {
     * @param apiStatus            the api status to log
     * @param providers            a map with known providers
     * @param callingUid           the calling UID of the client app
     * @param chosenProviderMetric the metric data type of the final chosen provider
     * @param chosenProviderFinalPhaseMetric the metric data type of the final chosen provider
     */
    protected static void logApiCalled(ApiName apiName, ApiStatus apiStatus,
            Map<String, ProviderSession> providers, int callingUid,
            ChosenProviderMetric chosenProviderMetric) {
            ChosenProviderFinalPhaseMetric chosenProviderFinalPhaseMetric) {
        try {
            var providerSessions = providers.values();
            int providerSize = providerSessions.size();
@@ -102,7 +102,7 @@ public class MetricUtilities {
            int[] candidateStatusList = new int[providerSize];
            int index = 0;
            for (var session : providerSessions) {
                CandidatePhaseMetric metric = session.mCandidateProviderMetric;
                CandidatePhaseMetric metric = session.mCandidatePhasePerProviderMetric;
                candidateUidList[index] = metric.getCandidateUid();
                candidateQueryRoundTripTimeList[index] = metric.getQueryLatencyMicroseconds();
                candidateStatusList[index] = metric.getProviderQueryStatus();
@@ -116,12 +116,13 @@ public class MetricUtilities {
                    /* repeated_candidate_provider_round_trip_time_query_microseconds */
                    candidateQueryRoundTripTimeList,
                    /* repeated_candidate_provider_status */ candidateStatusList,
                    /* chosen_provider_uid */ chosenProviderMetric.getChosenUid(),
                    /* chosen_provider_uid */ chosenProviderFinalPhaseMetric.getChosenUid(),
                    /* chosen_provider_round_trip_time_overall_microseconds */
                    chosenProviderMetric.getEntireProviderLatencyMicroseconds(),
                    chosenProviderFinalPhaseMetric.getEntireProviderLatencyMicroseconds(),
                    /* chosen_provider_final_phase_microseconds (backwards compat only) */
                    DEFAULT_INT_32,
                    /* chosen_provider_status */ chosenProviderMetric.getChosenProviderStatus());
                    /* chosen_provider_status */ chosenProviderFinalPhaseMetric
                            .getChosenProviderStatus());
        } catch (Exception e) {
            Log.w(TAG, "Unexpected error during metric logging: " + e);
        }
+8 −1
Original line number Diff line number Diff line
@@ -120,7 +120,14 @@ public final class ProviderClearSession extends ProviderSession<ClearCredential
    @Override
    protected void invokeSession() {
        if (mRemoteCredentialService != null) {
            mCandidateProviderMetric.setStartQueryTimeNanoseconds(System.nanoTime());
            /*
            InitialPhaseMetric initMetric = ((RequestSession)mCallbacks).initMetric;
            TODO immediately once the other change patched through
            mCandidateProviderMetric.setSessionId(initMetric
            .mInitialPhaseMetric.getSessionId());
            mCandidateProviderMetric.setStartTime(initMetric.getStartTime())
             */
            mCandidatePhasePerProviderMetric.setStartQueryTimeNanoseconds(System.nanoTime());
            mRemoteCredentialService.onClearCredentialState(mProviderRequest, this);
        }
    }
Loading