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

Commit 7b1399ec authored by Arpan Kaphle's avatar Arpan Kaphle
Browse files

Metric System Cleanup

This fixes any final issues in the metric collection and emission
system, including logs. The fixes primarily focus on ensuring the
timestamps are properly recorded, the aggregations are done properly for
the total canddiate, and that all types and values are recorded or
collected as they should be and emitted when they should be.
Statuses and TODOs are also fixed here, alongside any final logs.

Bug: 271135048
Bug: 270568738
Test: Build, won't submit without E2E Test (No Affect + Validate Metric Emits)
Change-Id: I3637bf4a84596ba72bdab9ef225e4e5c77ab0bb6
parent 1e1ead7e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta
    public void onFinalResponseReceived(
            ComponentName componentName,
            Void response) {
        mRequestSessionMetric.collectUiResponseData(/*uiReturned=*/ true, System.nanoTime());
        mRequestSessionMetric.updateMetricsOnResponseReceived(mProviders, componentName,
                isPrimaryProviderViaProviderInfo(componentName));
        respondToClientWithResponseAndFinish(null);
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
                RequestInfo.TYPE_CREATE,
                callingAppInfo, enabledProviders, cancellationSignal, startedTimestamp);
        mRequestSessionMetric.collectCreateFlowInitialMetricInfo(
                /*origin=*/request.getOrigin() != null);
                /*origin=*/request.getOrigin() != null, request);
        mPrimaryProviders = primaryProviders;
    }

+0 −5
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.ResultReceiver;
import android.service.credentials.CredentialProviderInfoFactory;
import android.util.Log;
import android.util.Slog;

import java.util.ArrayList;
@@ -72,7 +71,6 @@ public class CredentialManagerUi {
    };

    private void handleUiResult(int resultCode, Bundle resultData) {
        Log.i("reemademo", "handleUiResult with resultCOde: " + resultCode);

        switch (resultCode) {
            case UserSelectionDialogResult.RESULT_CODE_DIALOG_COMPLETE_WITH_SELECTION:
@@ -86,13 +84,11 @@ public class CredentialManagerUi {
                }
                break;
            case UserSelectionDialogResult.RESULT_CODE_DIALOG_USER_CANCELED:
                Log.i("reemademo", "RESULT_CODE_DIALOG_USER_CANCELED");

                mStatus = UiStatus.TERMINATED;
                mCallbacks.onUiCancellation(/* isUserCancellation= */ true);
                break;
            case UserSelectionDialogResult.RESULT_CODE_CANCELED_AND_LAUNCHED_SETTINGS:
                Log.i("reemademo", "RESULT_CODE_CANCELED_AND_LAUNCHED_SETTINGS");

                mStatus = UiStatus.TERMINATED;
                mCallbacks.onUiCancellation(/* isUserCancellation= */ false);
@@ -102,7 +98,6 @@ public class CredentialManagerUi {
                mCallbacks.onUiSelectorInvocationFailure();
                break;
            default:
                Log.i("reemademo", "Unknown error code returned from the UI");
                mStatus = UiStatus.IN_PROGRESS;
                mCallbacks.onUiSelectorInvocationFailure();
                break;
+1 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ 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());
        mRequestSessionMetric.updateMetricsOnResponseReceived(mProviders, componentName,
                isPrimaryProviderViaProviderInfo(componentName));
        if (response != null) {
+19 −22
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import java.util.Map;
/**
 * For all future metric additions, this will contain their names for local usage after importing
 * from {@link com.android.internal.util.FrameworkStatsLog}.
 * TODO(b/271135048) - Emit all atoms, including all V4 atoms (specifically the rest of track 1).
 */
public class MetricUtilities {
    private static final boolean LOG_FLAG = true;
@@ -101,7 +100,9 @@ public class MetricUtilities {
     */
    protected static int getMetricTimestampDifferenceMicroseconds(long t2, long t1) {
        if (t2 - t1 > Integer.MAX_VALUE) {
            throw new ArithmeticException("Input timestamps are too far apart and unsupported");
            Slog.i(TAG, "Input timestamps are too far apart and unsupported, "
                    + "falling back to default int");
            return DEFAULT_INT_32;
        }
        if (t2 < t1) {
            Slog.i(TAG, "The timestamps aren't in expected order, falling back to default int");
@@ -229,7 +230,7 @@ public class MetricUtilities {
                    authenticationMetric.isAuthReturned()
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during candidate get metric logging: " + e);
            Slog.w(TAG, "Unexpected error during candidate auth metric logging: " + e);
        }
    }

@@ -252,7 +253,6 @@ public class MetricUtilities {
            }
            var sessions = providers.values();
            for (var session : sessions) {
                try {
                var metric = session.getProviderSessionMetric()
                        .getCandidatePhasePerProviderMetric();
                FrameworkStatsLog.write(
@@ -265,9 +265,6 @@ public class MetricUtilities {
                        /* per_classtype_counts */
                        metric.getResponseCollective().getUniqueResponseCounts()
                );
                } catch (Exception e) {
                    Slog.w(TAG, "Unexpected exception during get metric logging" + e);
                }
            }
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during candidate get metric logging: " + e);
@@ -399,7 +396,7 @@ public class MetricUtilities {
                    /* caller_uid */ callingUid,
                    /* api_status */ apiStatus.getMetricCode());
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during metric logging: " + e);
            Slog.w(TAG, "Unexpected error during simple v2 metric logging: " + e);
        }
    }

@@ -505,7 +502,7 @@ public class MetricUtilities {
                    candidateAggregateMetric.isAuthReturned()
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during metric logging: " + e);
            Slog.w(TAG, "Unexpected error during total candidate metric logging: " + e);
        }
    }

@@ -570,7 +567,7 @@ public class MetricUtilities {
                    /* primary_indicated */ finalPhaseMetric.isPrimary()
            );
        } catch (Exception e) {
            Slog.w(TAG, "Unexpected error during metric logging: " + e);
            Slog.w(TAG, "Unexpected error during final no uid metric logging: " + e);
        }
    }

Loading