summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jiewen Lei <jiewenlei@google.com> 2023-03-29 02:19:21 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-03-29 02:19:21 +0000
commit19fa3e2070830edd66db6dcfe8c547c60f9797af (patch)
treef2ec10444d53e77fd1a90c6795d28647f966d113
parent58aab277ff478fd7e3198f81c7f152f470dc13ea (diff)
parentc9a38ca3e48ba8a7d1b8de35292aa05054634c89 (diff)
Merge "Add two more logging helper classes. One for SaveEventReported and one for SessionCommitted. They will be used in the follow-up cr." into udc-dev
-rw-r--r--services/autofill/java/com/android/server/autofill/SaveEventLogger.java318
-rw-r--r--services/autofill/java/com/android/server/autofill/SessionCommittedEventLogger.java160
2 files changed, 478 insertions, 0 deletions
diff --git a/services/autofill/java/com/android/server/autofill/SaveEventLogger.java b/services/autofill/java/com/android/server/autofill/SaveEventLogger.java
new file mode 100644
index 000000000000..4b7d5bdf0002
--- /dev/null
+++ b/services/autofill/java/com/android/server/autofill/SaveEventLogger.java
@@ -0,0 +1,318 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.autofill;
+
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_DATASET_MATCH;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_FIELD_VALIDATION_FAILED;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_HAS_EMPTY_REQUIRED;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_NONE;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_NO_SAVE_INFO;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_NO_VALUE_CHANGED;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_UNKNOWN;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_WITH_DELAY_SAVE_FLAG;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_SHOWN_REASON__SAVE_UI_SHOWN_REASON_OPTIONAL_ID_CHANGE;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_SHOWN_REASON__SAVE_UI_SHOWN_REASON_REQUIRED_ID_CHANGE;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_SHOWN_REASON__SAVE_UI_SHOWN_REASON_TRIGGER_ID_SET;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_SHOWN_REASON__SAVE_UI_SHOWN_REASON_UNKNOWN;
+import static com.android.server.autofill.Helper.sVerbose;
+
+import android.annotation.IntDef;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.util.Slog;
+
+import com.android.internal.util.FrameworkStatsLog;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.Optional;
+
+/**
+ * Helper class to log Autofill Save event stats.
+ */
+public final class SaveEventLogger {
+ private static final String TAG = "SaveEventLogger";
+
+ /**
+ * Reasons why presentation was not shown. These are wrappers around
+ * {@link com.android.os.AtomsProto.AutofillSaveEventReported.SaveUiShownReason}.
+ */
+ @IntDef(prefix = {"SAVE_UI_SHOWN_REASON"}, value = {
+ SAVE_UI_SHOWN_REASON_UNKNOWN,
+ SAVE_UI_SHOWN_REASON_REQUIRED_ID_CHANGE,
+ SAVE_UI_SHOWN_REASON_OPTIONAL_ID_CHANGE,
+ SAVE_UI_SHOWN_REASON_TRIGGER_ID_SET
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface SaveUiShownReason {
+ }
+
+ /**
+ * Reasons why presentation was not shown. These are wrappers around
+ * {@link com.android.os.AtomsProto.AutofillSaveEventReported.SaveUiNotShownReason}.
+ */
+ @IntDef(prefix = {"SAVE_UI_NOT_SHOWN_REASON"}, value = {
+ NO_SAVE_REASON_UNKNOWN,
+ NO_SAVE_REASON_NONE,
+ NO_SAVE_REASON_NO_SAVE_INFO,
+ NO_SAVE_REASON_WITH_DELAY_SAVE_FLAG,
+ NO_SAVE_REASON_HAS_EMPTY_REQUIRED,
+ NO_SAVE_REASON_NO_VALUE_CHANGED,
+ NO_SAVE_REASON_FIELD_VALIDATION_FAILED,
+ NO_SAVE_REASON_DATASET_MATCH
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface SaveUiNotShownReason {
+ }
+
+ public static final int SAVE_UI_SHOWN_REASON_UNKNOWN =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_SHOWN_REASON__SAVE_UI_SHOWN_REASON_UNKNOWN;
+ public static final int SAVE_UI_SHOWN_REASON_REQUIRED_ID_CHANGE =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_SHOWN_REASON__SAVE_UI_SHOWN_REASON_REQUIRED_ID_CHANGE;
+ public static final int SAVE_UI_SHOWN_REASON_OPTIONAL_ID_CHANGE =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_SHOWN_REASON__SAVE_UI_SHOWN_REASON_OPTIONAL_ID_CHANGE;
+ public static final int SAVE_UI_SHOWN_REASON_TRIGGER_ID_SET =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_SHOWN_REASON__SAVE_UI_SHOWN_REASON_TRIGGER_ID_SET;
+
+ public static final int NO_SAVE_REASON_UNKNOWN =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_UNKNOWN;
+ public static final int NO_SAVE_REASON_NONE =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_NONE;
+ public static final int NO_SAVE_REASON_NO_SAVE_INFO =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_NO_SAVE_INFO;
+ public static final int NO_SAVE_REASON_WITH_DELAY_SAVE_FLAG =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_WITH_DELAY_SAVE_FLAG;
+ public static final int NO_SAVE_REASON_HAS_EMPTY_REQUIRED =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_HAS_EMPTY_REQUIRED;
+ public static final int NO_SAVE_REASON_NO_VALUE_CHANGED =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_NO_VALUE_CHANGED;
+ public static final int NO_SAVE_REASON_FIELD_VALIDATION_FAILED =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_FIELD_VALIDATION_FAILED;
+ public static final int NO_SAVE_REASON_DATASET_MATCH =
+ AUTOFILL_SAVE_EVENT_REPORTED__SAVE_UI_NOT_SHOWN_REASON__NO_SAVE_REASON_DATASET_MATCH;
+
+ private final int mSessionId;
+ private Optional<SaveEventInternal> mEventInternal;
+
+ private SaveEventLogger(int sessionId) {
+ mSessionId = sessionId;
+ mEventInternal = Optional.of(new SaveEventInternal());
+ }
+
+ /**
+ * A factory constructor to create FillRequestEventLogger.
+ */
+ public static SaveEventLogger forSessionId(int sessionId) {
+ return new SaveEventLogger(sessionId);
+ }
+
+ /**
+ * Set request_id as long as mEventInternal presents.
+ */
+ public void maybeSetRequestId(int requestId) {
+ mEventInternal.ifPresent(event -> event.mRequestId = requestId);
+ }
+
+ /**
+ * Set app_package_uid as long as mEventInternal presents.
+ */
+ public void maybeSetAppPackageUid(int val) {
+ mEventInternal.ifPresent(event -> {
+ event.mAppPackageUid = val;
+ });
+ }
+
+ /**
+ * Set save_ui_trigger_ids as long as mEventInternal presents.
+ */
+ public void maybeSetSaveUiTriggerIds(int val) {
+ mEventInternal.ifPresent(event -> {
+ event.mSaveUiTriggerIds = val;
+ });
+ }
+
+ /**
+ * Set flag as long as mEventInternal presents.
+ */
+ public void maybeSetFlag(int val) {
+ mEventInternal.ifPresent(event -> {
+ event.mFlag = val;
+ });
+ }
+
+ /**
+ * Set is_new_field as long as mEventInternal presents.
+ */
+ public void maybeSetIsNewField(boolean val) {
+ mEventInternal.ifPresent(event -> {
+ event.mIsNewField = val;
+ });
+ }
+
+ /**
+ * Set save_ui_shown_reason as long as mEventInternal presents.
+ */
+ public void maybeSetSaveUiShownReason(@SaveUiShownReason int reason) {
+ mEventInternal.ifPresent(event -> {
+ event.mSaveUiShownReason = reason;
+ });
+ }
+
+ /**
+ * Set save_ui_not_shown_reason as long as mEventInternal presents.
+ */
+ public void maybeSetSaveUiNotShownReason(@SaveUiNotShownReason int reason) {
+ mEventInternal.ifPresent(event -> {
+ event.mSaveUiNotShownReason = reason;
+ });
+ }
+
+ /**
+ * Set save_button_clicked as long as mEventInternal presents.
+ */
+ public void maybeSetSaveButtonClicked(boolean val) {
+ mEventInternal.ifPresent(event -> {
+ event.mSaveButtonClicked = val;
+ });
+ }
+
+ /**
+ * Set cancel_button_clicked as long as mEventInternal presents.
+ */
+ public void maybeSetCancelButtonClicked(boolean val) {
+ mEventInternal.ifPresent(event -> {
+ event.mCancelButtonClicked = val;
+ });
+ }
+
+ /**
+ * Set dialog_dismissed as long as mEventInternal presents.
+ */
+ public void maybeSetDialogDismissed(boolean val) {
+ mEventInternal.ifPresent(event -> {
+ event.mDialogDismissed = val;
+ });
+ }
+
+ /**
+ * Set is_saved as long as mEventInternal presents.
+ */
+ public void maybeSetIsSaved(boolean val) {
+ mEventInternal.ifPresent(event -> {
+ event.mIsSaved = val;
+ });
+ }
+
+ /**
+ * Set latency_save_ui_display_millis as long as mEventInternal presents.
+ */
+ public void maybeSetLatencySaveUiDisplayMillis(long timestamp) {
+ mEventInternal.ifPresent(event -> {
+ event.mLatencySaveUiDisplayMillis = timestamp;
+ });
+ }
+
+ /**
+ * Set latency_save_request_millis as long as mEventInternal presents.
+ */
+ public void maybeSetLatencySaveRequestMillis(long timestamp) {
+ mEventInternal.ifPresent(event -> {
+ event.mLatencySaveRequestMillis = timestamp;
+ });
+ }
+
+ /**
+ * Set latency_save_finish_millis as long as mEventInternal presents.
+ */
+ public void maybeSetLatencySaveFinishMillis(long timestamp) {
+ mEventInternal.ifPresent(event -> {
+ event.mLatencySaveFinishMillis = timestamp;
+ });
+ }
+
+ /**
+ * Log an AUTOFILL_SAVE_EVENT_REPORTED event.
+ */
+ public void logAndEndEvent() {
+ if (!mEventInternal.isPresent()) {
+ Slog.w(TAG, "Shouldn't be logging AutofillSaveEventReported again for same "
+ + "event");
+ return;
+ }
+ SaveEventInternal event = mEventInternal.get();
+ if (sVerbose) {
+ Slog.v(TAG, "Log AutofillSaveEventReported:"
+ + " requestId=" + event.mRequestId
+ + " sessionId=" + mSessionId
+ + " mAppPackageUid=" + event.mAppPackageUid
+ + " mSaveUiTriggerIds=" + event.mSaveUiTriggerIds
+ + " mFlag=" + event.mFlag
+ + " mIsNewField=" + event.mIsNewField
+ + " mSaveUiShownReason=" + event.mSaveUiShownReason
+ + " mSaveUiNotShownReason=" + event.mSaveUiNotShownReason
+ + " mSaveButtonClicked=" + event.mSaveButtonClicked
+ + " mCancelButtonClicked=" + event.mCancelButtonClicked
+ + " mDialogDismissed=" + event.mDialogDismissed
+ + " mIsSaved=" + event.mIsSaved
+ + " mLatencySaveUiDisplayMillis=" + event.mLatencySaveUiDisplayMillis
+ + " mLatencySaveRequestMillis=" + event.mLatencySaveRequestMillis
+ + " mLatencySaveFinishMillis=" + event.mLatencySaveFinishMillis);
+ }
+ FrameworkStatsLog.write(
+ AUTOFILL_SAVE_EVENT_REPORTED,
+ event.mRequestId,
+ mSessionId,
+ event.mAppPackageUid,
+ event.mSaveUiTriggerIds,
+ event.mFlag,
+ event.mIsNewField,
+ event.mSaveUiShownReason,
+ event.mSaveUiNotShownReason,
+ event.mSaveButtonClicked,
+ event.mCancelButtonClicked,
+ event.mDialogDismissed,
+ event.mIsSaved,
+ event.mLatencySaveUiDisplayMillis,
+ event.mLatencySaveRequestMillis,
+ event.mLatencySaveFinishMillis);
+ mEventInternal = Optional.empty();
+ }
+
+ private static final class SaveEventInternal {
+ int mRequestId;
+ int mAppPackageUid = -1;
+ int mSaveUiTriggerIds = -1;
+ long mFlag = -1;
+ boolean mIsNewField = false;
+ int mSaveUiShownReason = SAVE_UI_SHOWN_REASON_UNKNOWN;
+ int mSaveUiNotShownReason = NO_SAVE_REASON_UNKNOWN;
+ boolean mSaveButtonClicked = false;
+ boolean mCancelButtonClicked = false;
+ boolean mDialogDismissed = false;
+ boolean mIsSaved = false;
+ long mLatencySaveUiDisplayMillis = 0;
+ long mLatencySaveRequestMillis = 0;
+ long mLatencySaveFinishMillis = 0;
+
+ SaveEventInternal() {
+ }
+ }
+}
diff --git a/services/autofill/java/com/android/server/autofill/SessionCommittedEventLogger.java b/services/autofill/java/com/android/server/autofill/SessionCommittedEventLogger.java
new file mode 100644
index 000000000000..92d72ac828f3
--- /dev/null
+++ b/services/autofill/java/com/android/server/autofill/SessionCommittedEventLogger.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.autofill;
+
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SESSION_COMMITTED;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SESSION_COMMITTED__COMMIT_REASON__COMMIT_REASON_ACTIVITY_FINISHED;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SESSION_COMMITTED__COMMIT_REASON__COMMIT_REASON_UNKNOWN;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SESSION_COMMITTED__COMMIT_REASON__COMMIT_REASON_VIEW_CHANGED;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SESSION_COMMITTED__COMMIT_REASON__COMMIT_REASON_VIEW_CLICKED;
+import static com.android.internal.util.FrameworkStatsLog.AUTOFILL_SESSION_COMMITTED__COMMIT_REASON__COMMIT_REASON_VIEW_COMMITTED;
+import static com.android.server.autofill.Helper.sVerbose;
+
+import android.annotation.IntDef;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.util.Slog;
+
+import com.android.internal.util.FrameworkStatsLog;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.Optional;
+
+/**
+ * Helper class to log Autofill session committed event stats.
+ */
+public final class SessionCommittedEventLogger {
+ private static final String TAG = "SessionCommittedEventLogger";
+
+ /**
+ * Reasons why presentation was not shown. These are wrappers around
+ * {@link com.android.os.AtomsProto.AutofillSessionCommitted.AutofillCommitReason}.
+ */
+ @IntDef(prefix = {"COMMIT_REASON"}, value = {
+ COMMIT_REASON_UNKNOWN,
+ COMMIT_REASON_ACTIVITY_FINISHED,
+ COMMIT_REASON_VIEW_COMMITTED,
+ COMMIT_REASON_VIEW_CLICKED,
+ COMMIT_REASON_VIEW_CHANGED
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface CommitReason {
+ }
+
+ public static final int COMMIT_REASON_UNKNOWN =
+ AUTOFILL_SESSION_COMMITTED__COMMIT_REASON__COMMIT_REASON_UNKNOWN;
+ public static final int COMMIT_REASON_ACTIVITY_FINISHED =
+ AUTOFILL_SESSION_COMMITTED__COMMIT_REASON__COMMIT_REASON_ACTIVITY_FINISHED;
+ public static final int COMMIT_REASON_VIEW_COMMITTED =
+ AUTOFILL_SESSION_COMMITTED__COMMIT_REASON__COMMIT_REASON_VIEW_COMMITTED;
+ public static final int COMMIT_REASON_VIEW_CLICKED =
+ AUTOFILL_SESSION_COMMITTED__COMMIT_REASON__COMMIT_REASON_VIEW_CLICKED;
+ public static final int COMMIT_REASON_VIEW_CHANGED =
+ AUTOFILL_SESSION_COMMITTED__COMMIT_REASON__COMMIT_REASON_VIEW_CHANGED;
+
+ private final int mSessionId;
+ private Optional<SessionCommittedEventInternal> mEventInternal;
+
+ private SessionCommittedEventLogger(int sessionId) {
+ mSessionId = sessionId;
+ mEventInternal = Optional.of(new SessionCommittedEventInternal());
+ }
+
+ /**
+ * A factory constructor to create SessionCommittedEventLogger.
+ */
+ public static SessionCommittedEventLogger forSessionId(int sessionId) {
+ return new SessionCommittedEventLogger(sessionId);
+ }
+
+ /**
+ * Set component_package_uid as long as mEventInternal presents.
+ */
+ public void maybeSetComponentPackageUid(int val) {
+ mEventInternal.ifPresent(event -> {
+ event.mComponentPackageUid = val;
+ });
+ }
+
+ /**
+ * Set request_count as long as mEventInternal presents.
+ */
+ public void maybeSetRequestCount(int val) {
+ mEventInternal.ifPresent(event -> {
+ event.mRequestCount = val;
+ });
+ }
+
+ /**
+ * Set commit_reason as long as mEventInternal presents.
+ */
+ public void maybeSetCommitReason(@CommitReason int val) {
+ mEventInternal.ifPresent(event -> {
+ event.mCommitReason = val;
+ });
+ }
+
+ /**
+ * Set session_duration_millis as long as mEventInternal presents.
+ */
+ public void maybeSetSessionDurationMillis(long timestamp) {
+ mEventInternal.ifPresent(event -> {
+ event.mSessionDurationMillis = timestamp;
+ });
+ }
+
+ /**
+ * Log an AUTOFILL_SESSION_COMMITTED event.
+ */
+ public void logAndEndEvent() {
+ if (!mEventInternal.isPresent()) {
+ Slog.w(TAG, "Shouldn't be logging AutofillSessionCommitted again for same session.");
+ return;
+ }
+ SessionCommittedEventInternal event = mEventInternal.get();
+ if (sVerbose) {
+ Slog.v(TAG, "Log AutofillSessionCommitted:"
+ + " sessionId=" + mSessionId
+ + " mComponentPackageUid=" + event.mComponentPackageUid
+ + " mRequestCount=" + event.mRequestCount
+ + " mCommitReason=" + event.mCommitReason
+ + " mSessionDurationMillis=" + event.mSessionDurationMillis);
+ }
+ FrameworkStatsLog.write(
+ AUTOFILL_SESSION_COMMITTED,
+ mSessionId,
+ event.mComponentPackageUid,
+ event.mRequestCount,
+ event.mCommitReason,
+ event.mSessionDurationMillis);
+ mEventInternal = Optional.empty();
+ }
+
+ private static final class SessionCommittedEventInternal {
+ int mComponentPackageUid = -1;
+ int mRequestCount = 0;
+ int mCommitReason = COMMIT_REASON_UNKNOWN;
+ long mSessionDurationMillis = 0;
+
+ SessionCommittedEventInternal() {
+ }
+ }
+}