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

Commit aa9ec856 authored by Tim Yu's avatar Tim Yu
Browse files

Autofill Refactor Presentation Logging

Refactor some of the presentation event logging code
Track session start time inside of Presentation Event, to avoid doing
maths directly in Session

Test: na, refactor only
Bug: na, refactor only
Flag: na, refactor only

Change-Id: I30550d280a5108a68191c80c7347c559963e416b
parent a6e674a5
Loading
Loading
Loading
Loading
+40 −3
Original line number Original line Diff line number Diff line
@@ -62,6 +62,7 @@ import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.os.SystemClock;
import android.provider.Settings;
import android.provider.Settings;
import android.service.autofill.Dataset;
import android.service.autofill.Dataset;
import android.text.TextUtils;
import android.text.TextUtils;
@@ -218,10 +219,12 @@ public final class PresentationStatsEventLogger {
     */
     */
    private final int mCallingAppUid;
    private final int mCallingAppUid;
    private Optional<PresentationStatsEventInternal> mEventInternal;
    private Optional<PresentationStatsEventInternal> mEventInternal;
    private final long mSessionStartTimestamp;


    private PresentationStatsEventLogger(int sessionId, int callingAppUid) {
    private PresentationStatsEventLogger(int sessionId, int callingAppUid, long timestamp ) {
        mSessionId = sessionId;
        mSessionId = sessionId;
        mCallingAppUid = callingAppUid;
        mCallingAppUid = callingAppUid;
        mSessionStartTimestamp = timestamp;
        mEventInternal = Optional.empty();
        mEventInternal = Optional.empty();
    }
    }


@@ -229,8 +232,8 @@ public final class PresentationStatsEventLogger {
     * Create PresentationStatsEventLogger, populated with sessionId and the callingAppUid
     * Create PresentationStatsEventLogger, populated with sessionId and the callingAppUid
     */
     */
    public static PresentationStatsEventLogger createPresentationLog(
    public static PresentationStatsEventLogger createPresentationLog(
            int sessionId, int callingAppUid) {
            int sessionId, int callingAppUid, long timestamp ) {
        return new PresentationStatsEventLogger(sessionId, callingAppUid);
        return new PresentationStatsEventLogger(sessionId, callingAppUid, timestamp);
    }
    }


    public void startNewEvent() {
    public void startNewEvent() {
@@ -370,24 +373,40 @@ public final class PresentationStatsEventLogger {
        });
        });
    }
    }


    public void maybeSetFillRequestSentTimestampMs() {
        maybeSetFillRequestSentTimestampMs(getElapsedTime());
    }

    public void maybeSetFillResponseReceivedTimestampMs(int timestamp) {
    public void maybeSetFillResponseReceivedTimestampMs(int timestamp) {
        mEventInternal.ifPresent(event -> {
        mEventInternal.ifPresent(event -> {
            event.mFillResponseReceivedTimestampMs = timestamp;
            event.mFillResponseReceivedTimestampMs = timestamp;
        });
        });
    }
    }


    public void maybeSetFillResponseReceivedTimestampMs() {
        maybeSetFillResponseReceivedTimestampMs(getElapsedTime());
    }

    public void maybeSetSuggestionSentTimestampMs(int timestamp) {
    public void maybeSetSuggestionSentTimestampMs(int timestamp) {
        mEventInternal.ifPresent(event -> {
        mEventInternal.ifPresent(event -> {
            event.mSuggestionSentTimestampMs = timestamp;
            event.mSuggestionSentTimestampMs = timestamp;
        });
        });
    }
    }


    public void maybeSetSuggestionSentTimestampMs() {
        maybeSetSuggestionSentTimestampMs(getElapsedTime());
    }

    public void maybeSetSuggestionPresentedTimestampMs(int timestamp) {
    public void maybeSetSuggestionPresentedTimestampMs(int timestamp) {
        mEventInternal.ifPresent(event -> {
        mEventInternal.ifPresent(event -> {
            event.mSuggestionPresentedTimestampMs = timestamp;
            event.mSuggestionPresentedTimestampMs = timestamp;
        });
        });
    }
    }


    public void maybeSetSuggestionPresentedTimestampMs() {
        maybeSetSuggestionPresentedTimestampMs(getElapsedTime());
    }

    public void maybeSetSelectedDatasetId(int selectedDatasetId) {
    public void maybeSetSelectedDatasetId(int selectedDatasetId) {
        mEventInternal.ifPresent(event -> {
        mEventInternal.ifPresent(event -> {
            event.mSelectedDatasetId = selectedDatasetId;
            event.mSelectedDatasetId = selectedDatasetId;
@@ -479,6 +498,11 @@ public final class PresentationStatsEventLogger {
        });
        });
    }
    }


    /** Set latency_authentication_ui_display_millis as long as mEventInternal presents. */
    public void maybeSetLatencyAuthenticationUiDisplayMillis() {
        maybeSetLatencyAuthenticationUiDisplayMillis(getElapsedTime());
    }

    /**
    /**
     * Set latency_dataset_display_millis as long as mEventInternal presents.
     * Set latency_dataset_display_millis as long as mEventInternal presents.
     */
     */
@@ -488,6 +512,11 @@ public final class PresentationStatsEventLogger {
        });
        });
    }
    }


    /** Set latency_dataset_display_millis as long as mEventInternal presents. */
    public void maybeSetLatencyDatasetDisplayMillis() {
        maybeSetLatencyDatasetDisplayMillis(getElapsedTime());
    }

    /**
    /**
     * Set available_pcc_count.
     * Set available_pcc_count.
     */
     */
@@ -524,6 +553,14 @@ public final class PresentationStatsEventLogger {
        });
        });
    }
    }


    /**
     * Returns timestamp (relative to mSessionStartTimestamp)
     */
    private int getElapsedTime() {
        return (int)(SystemClock.elapsedRealtime() - mSessionStartTimestamp);
    }


    private int convertDatasetPickReason(@Dataset.DatasetEligibleReason int val) {
    private int convertDatasetPickReason(@Dataset.DatasetEligibleReason int val) {
        switch (val) {
        switch (val) {
            case 0:
            case 0:
+3 −24
Original line number Original line Diff line number Diff line
@@ -1552,7 +1552,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        mLatencyBaseTime = mStartTime;
        mLatencyBaseTime = mStartTime;
        mRequestCount = 0;
        mRequestCount = 0;
        mPresentationStatsEventLogger = PresentationStatsEventLogger.createPresentationLog(
        mPresentationStatsEventLogger = PresentationStatsEventLogger.createPresentationLog(
                sessionId, uid);
                sessionId, uid, mLatencyBaseTime);
        mFillRequestEventLogger = FillRequestEventLogger.forSessionId(sessionId);
        mFillRequestEventLogger = FillRequestEventLogger.forSessionId(sessionId);
        mFillResponseEventLogger = FillResponseEventLogger.forSessionId(sessionId);
        mFillResponseEventLogger = FillResponseEventLogger.forSessionId(sessionId);
        mSessionCommittedEventLogger = SessionCommittedEventLogger.forSessionId(sessionId);
        mSessionCommittedEventLogger = SessionCommittedEventLogger.forSessionId(sessionId);
@@ -1574,14 +1574,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                    @Override
                    @Override
                    public void notifyInlineUiShown(AutofillId autofillId) {
                    public void notifyInlineUiShown(AutofillId autofillId) {
                        notifyFillUiShown(autofillId);
                        notifyFillUiShown(autofillId);

                        synchronized (mLock) {
                            // TODO(b/262448552): Log when chip inflates instead of here
                            final long inlineUiShownRelativeTimestamp =
                                    SystemClock.elapsedRealtime() - mLatencyBaseTime;
                            mPresentationStatsEventLogger.maybeSetSuggestionPresentedTimestampMs(
                                    (int) (inlineUiShownRelativeTimestamp));
                        }
                    }
                    }


                    @Override
                    @Override
@@ -2677,6 +2669,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                mLoggedInlineDatasetShown = true;
                mLoggedInlineDatasetShown = true;
            }
            }
            mService.logDatasetShown(this.id, mClientState, uiType);
            mService.logDatasetShown(this.id, mClientState, uiType);
            mPresentationStatsEventLogger.maybeSetSuggestionPresentedTimestampMs();
            Slog.d(TAG, "onShown(): " + uiType);
            Slog.d(TAG, "onShown(): " + uiType);
        }
        }
    }
    }
@@ -4899,10 +4892,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState


        synchronized (mLock) {
        synchronized (mLock) {
            // Time passed since Session was created
            // Time passed since Session was created
            final long suggestionSentRelativeTimestamp =
            mPresentationStatsEventLogger.maybeSetSuggestionSentTimestampMs();
                    SystemClock.elapsedRealtime() - mLatencyBaseTime;
            mPresentationStatsEventLogger.maybeSetSuggestionSentTimestampMs(
                    (int) (suggestionSentRelativeTimestamp));
        }
        }


        final AutofillId[] ids = response.getFillDialogTriggerIds();
        final AutofillId[] ids = response.getFillDialogTriggerIds();
@@ -4919,13 +4909,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                // Note: Cannot disable before requestShowFillDialog() because the method
                // Note: Cannot disable before requestShowFillDialog() because the method
                //       need to check whether fill dialog enabled.
                //       need to check whether fill dialog enabled.
                setFillDialogDisabled();
                setFillDialogDisabled();
                synchronized (mLock) {
                    // Logs when fill dialog ui is shown; time since Session was created
                    final long fillDialogUiShownRelativeTimestamp =
                            SystemClock.elapsedRealtime() - mLatencyBaseTime;
                    mPresentationStatsEventLogger.maybeSetSuggestionPresentedTimestampMs(
                            (int) (fillDialogUiShownRelativeTimestamp));
                }
                return;
                return;
            } else {
            } else {
                setFillDialogDisabled();
                setFillDialogDisabled();
@@ -4967,10 +4950,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                // Log first time UI is shown.
                // Log first time UI is shown.
                mUiShownTime = SystemClock.elapsedRealtime();
                mUiShownTime = SystemClock.elapsedRealtime();
                final long duration = mUiShownTime - mStartTime;
                final long duration = mUiShownTime - mStartTime;
                // This logs when dropdown ui was shown. Timestamp is relative to
                // when the session was created
                mPresentationStatsEventLogger.maybeSetSuggestionPresentedTimestampMs(
                        (int) (mUiShownTime - mLatencyBaseTime));


                if (sDebug) {
                if (sDebug) {
                    final StringBuilder msg = new StringBuilder("1st UI for ")
                    final StringBuilder msg = new StringBuilder("1st UI for ")