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

Commit e5c72cf3 authored by Omer Ozer's avatar Omer Ozer Committed by Automerger Merge Worker
Browse files

Merge "Add metrics coverage to Cred Reg flow." into udc-dev am: c7ac88d4

parents 5a7f5c47 c7ac88d4
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -256,6 +256,7 @@ public class ProviderRegistryGetSession extends ProviderSession<CredentialOption


    @Override
    @Override
    protected void invokeSession() {
    protected void invokeSession() {
        startCandidateMetrics();
        mProviderResponse = mCredentialDescriptionRegistry
        mProviderResponse = mCredentialDescriptionRegistry
                .getFilteredResultForProvider(mCredentialProviderPackageName,
                .getFilteredResultForProvider(mCredentialProviderPackageName,
                        mElementKeys);
                        mElementKeys);
@@ -266,7 +267,7 @@ public class ProviderRegistryGetSession extends ProviderSession<CredentialOption
                .collect(Collectors.toList());
                .collect(Collectors.toList());
        updateStatusAndInvokeCallback(Status.CREDENTIALS_RECEIVED,
        updateStatusAndInvokeCallback(Status.CREDENTIALS_RECEIVED,
                /*source=*/ CredentialsSource.REGISTRY);
                /*source=*/ CredentialsSource.REGISTRY);
        // TODO(b/273353677) : metric should be emitted similarly to sibling classes
        mProviderSessionMetric.collectCandidateEntryMetrics(mCredentialEntries);
    }
    }


    @Nullable
    @Nullable
+29 −0
Original line number Original line Diff line number Diff line
@@ -22,12 +22,14 @@ import static com.android.server.credentials.MetricUtilities.generateMetricKey;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.service.credentials.BeginCreateCredentialResponse;
import android.service.credentials.BeginCreateCredentialResponse;
import android.service.credentials.BeginGetCredentialResponse;
import android.service.credentials.BeginGetCredentialResponse;
import android.service.credentials.CredentialEntry;
import android.util.Slog;
import android.util.Slog;


import com.android.server.credentials.MetricUtilities;
import com.android.server.credentials.MetricUtilities;
import com.android.server.credentials.metrics.shared.ResponseCollective;
import com.android.server.credentials.metrics.shared.ResponseCollective;


import java.util.LinkedHashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map;


/**
/**
@@ -149,6 +151,33 @@ public class ProviderSessionMetric {
        }
        }
    }
    }


    /**
     * Once entries are received from the registry, this helps collect their info for metric
     * purposes.
     *
     * @param entries contains matching entries from the Credential Registry.
     */
    public void collectCandidateEntryMetrics(List<CredentialEntry> entries) {
        int numCredEntries = entries.size();
        int numRemoteEntry = MetricUtilities.ZERO;
        int numActionEntries = MetricUtilities.ZERO;
        int numAuthEntries = MetricUtilities.ZERO;
        Map<EntryEnum, Integer> entryCounts = new LinkedHashMap<>();
        Map<String, Integer> responseCounts = new LinkedHashMap<>();
        entryCounts.put(EntryEnum.REMOTE_ENTRY, numRemoteEntry);
        entryCounts.put(EntryEnum.CREDENTIAL_ENTRY, numCredEntries);
        entryCounts.put(EntryEnum.ACTION_ENTRY, numActionEntries);
        entryCounts.put(EntryEnum.AUTHENTICATION_ENTRY, numAuthEntries);

        entries.forEach(entry -> {
            String entryKey = generateMetricKey(entry.getType(), DELTA_CUT);
            responseCounts.put(entryKey, responseCounts.getOrDefault(entryKey, 0) + 1);
        });

        ResponseCollective responseCollective = new ResponseCollective(responseCounts, entryCounts);
        mCandidatePhasePerProviderMetric.setResponseCollective(responseCollective);
    }

    private void beginCreateCredentialResponseCollectionCandidateEntryMetrics(
    private void beginCreateCredentialResponseCollectionCandidateEntryMetrics(
            BeginCreateCredentialResponse response) {
            BeginCreateCredentialResponse response) {
        Map<EntryEnum, Integer> entryCounts = new LinkedHashMap<>();
        Map<EntryEnum, Integer> entryCounts = new LinkedHashMap<>();