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

Commit 7785cb0a authored by Omer Ozer's avatar Omer Ozer
Browse files

Add metrics coverage to Cred Reg flow.

Bug: 273353677
Bug: 274494843
Test: manual
Change-Id: I138a8e7bfd03160de1350a99318aa02ee145f183
parent c858b2c6
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -256,6 +256,7 @@ public class ProviderRegistryGetSession extends ProviderSession<CredentialOption

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

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

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

import java.util.LinkedHashMap;
import java.util.List;
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(
            BeginCreateCredentialResponse response) {
        Map<EntryEnum, Integer> entryCounts = new LinkedHashMap<>();