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

Commit 4fc89d86 authored by Arpan's avatar Arpan
Browse files

[Metrics] Log the Selected Type

This logs the selected credential type, by focusing on the response.
This will lose metadata on half-way clicks/mid clicks/etc... - those
might be explorable via the list of tapped entries. In the future,
depending on product need, adding the rest of the string classtypes can
be explored.

Bug: 364444783
Test: Stats_d, eventually chained, build
Flag: android.credentials.flags.fix_metric_duplication_emits
Change-Id: I274692b2d3fe016142ea81c9fe34cbf31aab5566
parent 26865aff
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.credentials.CreateCredentialResponse;
import android.credentials.CredentialManager;
import android.credentials.CredentialProviderInfo;
import android.credentials.ICreateCredentialCallback;
import android.credentials.flags.Flags;
import android.credentials.selection.ProviderData;
import android.credentials.selection.RequestInfo;
import android.os.CancellationSignal;
@@ -145,6 +146,9 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
        if (response != null) {
            mRequestSessionMetric.collectChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_SUCCESS.getMetricCode());
            if (Flags.fixMetricDuplicationEmits()) {
                mRequestSessionMetric.collectChosenClassType(mClientRequest.getType());
            }
            respondToClientWithResponseAndFinish(response);
        } else {
            mRequestSessionMetric.collectChosenProviderStatus(
+7 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.credentials.GetCredentialException;
import android.credentials.GetCredentialRequest;
import android.credentials.GetCredentialResponse;
import android.credentials.IGetCredentialCallback;
import android.credentials.flags.Flags;
import android.credentials.selection.ProviderData;
import android.credentials.selection.RequestInfo;
import android.os.Binder;
@@ -146,6 +147,12 @@ public class GetRequestSession extends RequestSession<GetCredentialRequest,
        if (response != null) {
            mRequestSessionMetric.collectChosenProviderStatus(
                    ProviderStatusForMetrics.FINAL_SUCCESS.getMetricCode());
            if (Flags.fixMetricDuplicationEmits()) {
                if (response.getCredential() != null) {
                    mRequestSessionMetric.collectChosenClassType(response.getCredential()
                            .getType());
                }
            }
            respondToClientWithResponseAndFinish(response);
        } else {
            mRequestSessionMetric.collectChosenProviderStatus(
+4 −2
Original line number Diff line number Diff line
@@ -201,7 +201,8 @@ public class MetricUtilities {
                    finalPhaseMetric.getResponseCollective().getUniqueResponseCounts(),
                    /* framework_exception_unique_classtype */
                    finalPhaseMetric.getFrameworkException(),
                    /* primary_indicated */ finalPhaseMetric.isPrimary()
                    /* primary_indicated */ finalPhaseMetric.isPrimary(),
                    /* chosen_classtype */ finalPhaseMetric.getChosenClassType()
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during final provider uid emit: " + e);
@@ -583,7 +584,8 @@ public class MetricUtilities {
                    /* primary_indicated */ finalPhaseMetric.isPrimary(),
                    /* oem_credential_manager_ui_uid */ finalPhaseMetric.getOemUiUid(),
                    /* fallback_credential_manager_ui_uid */ finalPhaseMetric.getFallbackUiUid(),
                    /* oem_ui_usage_status */ finalPhaseMetric.getOemUiUsageStatus()
                    /* oem_ui_usage_status */ finalPhaseMetric.getOemUiUsageStatus(),
                    /* chosen_classtype */ finalPhaseMetric.getChosenClassType()
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during final no uid metric logging: " + e);
+12 −0
Original line number Diff line number Diff line
@@ -83,12 +83,24 @@ public class ChosenProviderFinalPhaseMetric {
    // Indicates if this chosen provider was the primary provider, false by default
    private boolean mIsPrimary = false;

    private String mChosenClassType = "";


    public ChosenProviderFinalPhaseMetric(int sessionIdCaller, int sessionIdProvider) {
        mSessionIdCaller = sessionIdCaller;
        mSessionIdProvider = sessionIdProvider;
    }

    /* ------------------- Chosen Credential ------------------- */

    public void setChosenClassType(String clickedClassType) {
        mChosenClassType = clickedClassType;
    }

    public String getChosenClassType() {
        return mChosenClassType;
    }

    /* ------------------- UID ------------------- */

    public int getChosenUid() {
+15 −0
Original line number Diff line number Diff line
@@ -245,6 +245,21 @@ public class RequestSessionMetric {
        }
    }

    /**
     * This collects the final chosen class type. While it is possible to collect this during
     * browsing, note this only collects the final tapped bit.
     *
     * @param createOrCredentialType the string type to collect when an entry is tapped by the user
     */
    public void collectChosenClassType(String createOrCredentialType) {
        String truncatedType = generateMetricKey(createOrCredentialType, DELTA_EXCEPTION_CUT);
        try {
            mChosenProviderFinalPhaseMetric.setChosenClassType(truncatedType);
        } catch (Exception e) {
            Slog.i(TAG, "Unexpected error collecting chosen class type metadata: " + e);
        }
    }

    /**
     * Updates the final phase metric with the designated bit.
     *