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

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

Merge changes I52efc7fd,I531c1be0,Ib3870fb1,I94e95ead,I72140e75 into udc-dev

* changes:
  Emit Simple Metrics for Set/GetCredProvider APIs
  Primary Info in Candidate Metric
  Adding isPrimary to Final Phase Metrics
  Setting up the emit of the aggregate phase
  Completely emitting aggr candidate+auth metrics
parents 2c1d1981 c3627997
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@ 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;

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

+2 −7
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ 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;
@@ -132,12 +131,8 @@ 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());
        if (mProviders.get(componentName.flattenToString()) != null) {
            ProviderSessionMetric providerSessionMetric =
                    mProviders.get(componentName.flattenToString()).mProviderSessionMetric;
            mRequestSessionMetric.collectChosenMetricViaCandidateTransfer(providerSessionMetric
                    .getCandidatePhasePerProviderMetric());
        }
        mRequestSessionMetric.updateMetricsOnResponseReceived(mProviders, componentName,
                isPrimaryProviderViaProviderInfo(componentName));
        if (response != null) {
            mRequestSessionMetric.collectChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_SUCCESS.getMetricCode());
+27 −3
Original line number Diff line number Diff line
@@ -706,11 +706,18 @@ public final class CredentialManagerService
        public void setEnabledProviders(
                List<String>  primaryProviders, List<String> providers, int userId,
                ISetEnabledProvidersCallback callback) {
            final int callingUid = Binder.getCallingUid();
            if (!hasWriteSecureSettingsPermission()) {
                try {
                    MetricUtilities.logApiCalledSimpleV2(
                            ApiName.SET_ENABLED_PROVIDERS,
                            ApiStatus.FAILURE, callingUid);
                    callback.onError(
                            PERMISSION_DENIED_ERROR, PERMISSION_DENIED_WRITE_SECURE_SETTINGS_ERROR);
                } catch (RemoteException e) {
                    MetricUtilities.logApiCalledSimpleV2(
                            ApiName.SET_ENABLED_PROVIDERS,
                            ApiStatus.FAILURE, callingUid);
                    Slog.e(TAG, "Issue with invoking response: ", e);
                }
                return;
@@ -744,10 +751,16 @@ public final class CredentialManagerService
            if (!writeEnabledStatus || !writePrimaryStatus) {
                Slog.e(TAG, "Failed to store setting containing enabled or primary providers");
                try {
                    MetricUtilities.logApiCalledSimpleV2(
                            ApiName.SET_ENABLED_PROVIDERS,
                            ApiStatus.FAILURE, callingUid);
                    callback.onError(
                            "failed_setting_store",
                            "Failed to store setting containing enabled or primary providers");
                } catch (RemoteException e) {
                    MetricUtilities.logApiCalledSimpleV2(
                            ApiName.SET_ENABLED_PROVIDERS,
                            ApiStatus.FAILURE, callingUid);
                    Slog.e(TAG, "Issue with invoking error response: ", e);
                    return;
                }
@@ -755,8 +768,14 @@ public final class CredentialManagerService

            // Call the callback.
            try {
                MetricUtilities.logApiCalledSimpleV2(
                        ApiName.SET_ENABLED_PROVIDERS,
                        ApiStatus.SUCCESS, callingUid);
                callback.onResponse();
            } catch (RemoteException e) {
                MetricUtilities.logApiCalledSimpleV2(
                        ApiName.SET_ENABLED_PROVIDERS,
                        ApiStatus.FAILURE, callingUid);
                Slog.e(TAG, "Issue with invoking response: ", e);
                // TODO: Propagate failure
            }
@@ -805,10 +824,15 @@ public final class CredentialManagerService
        public List<CredentialProviderInfo> getCredentialProviderServices(
                int userId, int providerFilter) {
            verifyGetProvidersPermission();

            return CredentialProviderInfoFactory.getCredentialProviderServices(
            final int callingUid = Binder.getCallingUid();
            MetricUtilities.logApiCalledSimpleV2(
                    ApiName.GET_CREDENTIAL_PROVIDER_SERVICES,
                    ApiStatus.SUCCESS, callingUid);
            return CredentialProviderInfoFactory
            .getCredentialProviderServices(
                mContext, userId, providerFilter, getEnabledProvidersForUser(userId),
                getPrimaryProvidersForUserId(mContext, userId));

        }

        @Override
+2 −8
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ 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;
@@ -134,13 +133,8 @@ public class GetRequestSession extends RequestSession<GetCredentialRequest,
    public void onFinalResponseReceived(ComponentName componentName,
            @Nullable GetCredentialResponse response) {
        Slog.i(TAG, "onFinalResponseReceived from: " + componentName.flattenToString());
        mRequestSessionMetric.collectUiResponseData(/*uiReturned=*/ true, System.nanoTime());
        if (mProviders.get(componentName.flattenToString()) != null) {
            ProviderSessionMetric providerSessionMetric =
                    mProviders.get(componentName.flattenToString()).mProviderSessionMetric;
            mRequestSessionMetric.collectChosenMetricViaCandidateTransfer(providerSessionMetric
                    .getCandidatePhasePerProviderMetric());
        }
        mRequestSessionMetric.updateMetricsOnResponseReceived(mProviders, componentName,
                isPrimaryProviderViaProviderInfo(componentName));
        if (response != null) {
            mRequestSessionMetric.collectChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_SUCCESS.getMetricCode());
+24 −13
Original line number Diff line number Diff line
@@ -103,6 +103,10 @@ public class MetricUtilities {
        if (t2 - t1 > Integer.MAX_VALUE) {
            throw new ArithmeticException("Input timestamps are too far apart and unsupported");
        }
        if (t2 < t1) {
            Slog.i(TAG, "The timestamps aren't in expected order, falling back to default int");
            return DEFAULT_INT_32;
        }
        return (int) ((t2 - t1) / 1000);
    }

@@ -184,7 +188,7 @@ public class MetricUtilities {
                    finalPhaseMetric.getResponseCollective().getUniqueResponseCounts(),
                    /* framework_exception_unique_classtype */
                    finalPhaseMetric.getFrameworkException(),
                    /* primary_indicated */ false
                    /* primary_indicated */ finalPhaseMetric.isPrimary()
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during final provider uid emit: " + e);
@@ -222,7 +226,7 @@ public class MetricUtilities {
                    /* auth_provider_status */
                    authenticationMetric.getProviderStatus(),
                    /* query_returned */
                    authenticationMetric.isQueryReturned()
                    authenticationMetric.isAuthReturned()
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during candidate get metric logging: " + e);
@@ -303,6 +307,7 @@ public class MetricUtilities {
            int[] candidateAuthEntryCountList = new int[providerSize];
            int[] candidateRemoteEntryCountList = new int[providerSize];
            String[] frameworkExceptionList = new String[providerSize];
            boolean[] candidatePrimaryProviderList = new boolean[providerSize];
            int index = 0;
            for (var session : providerSessions) {
                CandidatePhaseMetric metric = session.mProviderSessionMetric
@@ -335,6 +340,7 @@ public class MetricUtilities {
                candidateRemoteEntryCountList[index] = metric.getResponseCollective()
                        .getCountForEntry(EntryEnum.REMOTE_ENTRY);
                frameworkExceptionList[index] = metric.getFrameworkException();
                candidatePrimaryProviderList[index] = metric.isPrimary();
                index++;
            }
            FrameworkStatsLog.write(FrameworkStatsLog.CREDENTIAL_MANAGER_CANDIDATE_PHASE_REPORTED,
@@ -368,7 +374,7 @@ public class MetricUtilities {
                    /* api_name */
                    initialPhaseMetric.getApiName(),
                    /* primary_candidates_indicated */
                    DEFAULT_REPEATED_BOOL
                    candidatePrimaryProviderList
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during candidate provider uid metric emit: " + e);
@@ -450,9 +456,13 @@ public class MetricUtilities {
                    /*query_returned*/ candidateAggregateMetric.isQueryReturned(),
                    /*num_query_providers*/ candidateAggregateMetric.getNumProviders(),
                    /*min_query_start_timestamp_microseconds*/
                    DEFAULT_INT_32,
                    getMetricTimestampDifferenceMicroseconds(
                            candidateAggregateMetric.getMinProviderTimestampNanoseconds(),
                            candidateAggregateMetric.getServiceBeganTimeNanoseconds()),
                    /*max_query_end_timestamp_microseconds*/
                    DEFAULT_INT_32,
                    getMetricTimestampDifferenceMicroseconds(
                            candidateAggregateMetric.getMaxProviderTimestampNanoseconds(),
                            candidateAggregateMetric.getServiceBeganTimeNanoseconds()),
                    /*query_response_unique_classtypes*/
                    candidateAggregateMetric.getAggregateCollectiveQuery()
                            .getUniqueResponseStrings(),
@@ -466,11 +476,11 @@ public class MetricUtilities {
                    candidateAggregateMetric.getAggregateCollectiveQuery()
                            .getUniqueEntryCounts(),
                    /*query_total_candidate_failure*/
                    DEFAULT_INT_32,
                    candidateAggregateMetric.getTotalQueryFailures(),
                    /*query_framework_exception_unique_classtypes*/
                    DEFAULT_REPEATED_STR,
                    candidateAggregateMetric.getUniqueExceptionStringsQuery(),
                    /*query_per_exception_classtype_counts*/
                    DEFAULT_REPEATED_INT_32,
                    candidateAggregateMetric.getUniqueExceptionCountsQuery(),
                    /*auth_response_unique_classtypes*/
                    candidateAggregateMetric.getAggregateCollectiveAuth()
                            .getUniqueResponseStrings(),
@@ -484,14 +494,15 @@ public class MetricUtilities {
                    candidateAggregateMetric.getAggregateCollectiveAuth()
                            .getUniqueEntryCounts(),
                    /*auth_total_candidate_failure*/
                    DEFAULT_INT_32,
                    candidateAggregateMetric.getTotalAuthFailures(),
                    /*auth_framework_exception_unique_classtypes*/
                    DEFAULT_REPEATED_STR,
                    candidateAggregateMetric.getUniqueExceptionStringsAuth(),
                    /*auth_per_exception_classtype_counts*/
                    DEFAULT_REPEATED_INT_32,
                    candidateAggregateMetric.getUniqueExceptionCountsAuth(),
                    /*num_auth_clicks*/
                    candidateAggregateMetric.getNumAuthEntriesTapped(),
                    /*auth_returned*/ false
                    /*auth_returned*/
                    candidateAggregateMetric.isAuthReturned()
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during metric logging: " + e);
@@ -556,7 +567,7 @@ public class MetricUtilities {
                    /* clicked_entries */ browsedClickedEntries,
                    /* provider_of_clicked_entry */ browsedProviderUid,
                    /* api_status */ apiStatus,
                    /* primary_indicated */ false
                    /* primary_indicated */ finalPhaseMetric.isPrimary()
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during metric logging: " + e);
Loading