Skip to content

Commit

Permalink
Added the class name of activity being autofilled on (most) autofill …
Browse files Browse the repository at this point in the history
…metrics.

Test: atest CtsAutoFillServiceTestCases # to make sure it didn't break anything
Test: manually run some test and watched
      'adb shell logcat -b events | grep sysui'

Fixes: 80151641

Change-Id: I5b83e6ceb549a641d10c39bbfd4f24d0a43d1a23
  • Loading branch information
the-felipeal committed May 24, 2018
1 parent f61ba5c commit 212b161
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 51 deletions.
11 changes: 9 additions & 2 deletions core/java/android/view/autofill/AutofillManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1899,10 +1899,17 @@ private void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> v
}

private LogMaker newLog(int category) {
return new LogMaker(category)
.setPackageName(mContext.getPackageName())
final LogMaker log = new LogMaker(category)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_COMPAT_MODE,
isCompatibilityModeEnabledLocked() ? 1 : 0);
final AutofillClient client = getClient();
if (client == null) {
// Client should never be null here, but it doesn't hurt to check...
log.setPackageName(mContext.getPackageName());
} else {
log.setComponentName(client.autofillClientGetComponentName());
}
return log;
}

/**
Expand Down
35 changes: 25 additions & 10 deletions proto/src/metrics_constants.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3992,6 +3992,7 @@ message MetricsEvent {
// NOTE: starting on OS MR1, it also added the following field:
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// NOTE: starting on OS P, it also added the following field:
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFIL_FLAGS - Flags used to start the session
// Type FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SESSION_STARTED = 906;
Expand All @@ -4005,6 +4006,7 @@ message MetricsEvent {
// the service returned a null response
// NOTE: starting on OS P, it also added the following fields:
// TYPE_CLOSE: request timed out before service called a FillCallback method
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_REQUEST_ORDINAL: sequence number of the request inside a session; starts
// with 1.
// Tag FIELD_AUTOFILL_FLAGS: flags used to request autofill
Expand Down Expand Up @@ -4036,7 +4038,8 @@ message MetricsEvent {
// Package: Package of app that was autofilled
// Tag FIELD_AUTOFILL_FILTERTEXT_LEN: The length of the filter text
// Tag FIELD_AUTOFILL_NUM_DATASETS: The number of datasets shown
// NOTE: starting on OS P, it also added the following field:
// NOTE: starting on OS P, it also added the following fields:
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_FILL_UI = 910;
Expand All @@ -4054,7 +4057,8 @@ message MetricsEvent {
// Package: Package of app that is autofilled
// Tag FIELD_AUTOFILL_NUM_VALUES: Number of values that were suggested to be autofilled
// Tag FIELD_AUTOFILL_NUM_VIEWS_FILLED: Number of views that could be filled
// NOTE: starting on OS P, it also added the following field:
// NOTE: starting on OS P, it also added the following fields:
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_DATASET_APPLIED = 913;

Expand All @@ -4070,7 +4074,8 @@ message MetricsEvent {
// Type TYPE_ACTION: data was saved
// Package: Package of app that was autofilled
// Tag FIELD_AUTOFILL_NUM_IDS: The number of ids that are saved
// NOTE: starting on OS P, it also added the following field:
// NOTE: starting on OS P, it also added the following fields:
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_UI = 916;
Expand All @@ -4084,7 +4089,8 @@ message MetricsEvent {
// Type TYPE_FAILURE: The request failed
// Package: Package of app that was autofilled
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// NOTE: starting on OS P, it also added the following field:
// NOTE: starting on OS P, it also added the following fields:
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_DATA_SAVE_REQUEST = 918;

Expand Down Expand Up @@ -4680,7 +4686,8 @@ message MetricsEvent {
// OS: O MR
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_AUTOFILL_PREVIOUS_LENGTH: the previous length of the value
// NOTE: starting on OS P, it also added the following field:
// NOTE: starting on OS P, it also added the following fields:
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_VALUE_RESET = 1124;

Expand Down Expand Up @@ -4713,7 +4720,8 @@ message MetricsEvent {
// OS: O MR
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_AUTOFILL_SAVE_TYPE: Type of save object passed by the service
// NOTE: starting on OS P, it also added the following field:
// NOTE: starting on OS P, it also added the following fields:
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_CUSTOM_DESCRIPTION = 1129;

Expand All @@ -4726,7 +4734,8 @@ message MetricsEvent {
// OS: O MR
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_AUTOFILL_SAVE_TYPE: Type of save object passed by the service
// NOTE: starting on OS P, it also added the following field:
// NOTE: starting on OS P, it also added the following fields:
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_CUSTOM_SUBTITLE = 1131;

Expand All @@ -4738,7 +4747,8 @@ message MetricsEvent {
// Type TYPE_FAILURE: The link could not launc an activity
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_AUTOFILL_SAVE_TYPE: Type of save object passed by the service
// NOTE: starting on OS P, it also added the following field:
// NOTE: starting on OS P, it also added the following fields:
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_LINK_TAPPED = 1132;

Expand All @@ -4750,7 +4760,8 @@ message MetricsEvent {
// Type TYPE_DISMISS: The validation failed
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_AUTOFILL_SAVE_TYPE: Type of save object passed by the service
// NOTE: starting on OS P, it also added the following field:
// NOTE: starting on OS P, it also added the following fields:
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_VALIDATION = 1133;

Expand All @@ -4761,7 +4772,8 @@ message MetricsEvent {
// Type TYPE_OPEN: The autofill save UI was restored
// Type TYPE_DISMISS: The autofill save UI was destroyed
// Type TYPE_FAILURE: An invalid opperation was reported by the app's AutofillManager
// NOTE: starting on OS P, it also added the following field:
// NOTE: starting on OS P, it also added the following fields:
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_PENDING_SAVE_UI_OPERATION = 1134;

Expand Down Expand Up @@ -4942,6 +4954,7 @@ message MetricsEvent {
// An autofill service explicitly defined which view should commit the autofill context
// Package: Package of app that is autofilled
// OS: P
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_EXPLICIT_SAVE_TRIGGER_DEFINITION = 1228;
Expand All @@ -4950,6 +4963,7 @@ message MetricsEvent {
// service as committing it
// Package: Package of app that is autofilled
// OS: P
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_EXPLICITLY_TRIGGERED = 1229;

Expand Down Expand Up @@ -5182,6 +5196,7 @@ message MetricsEvent {
// Package: Package of app that is autofilled
// Counter: number of matches found
// OS: P
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_AUTOFILL_MATCH_SCORE: Average score of the matches, in the range of 0 to 100
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,10 +780,10 @@ void logContextCommittedLocked(int sessionId, @Nullable Bundle clientState,
@Nullable ArrayList<String> changedDatasetIds,
@Nullable ArrayList<AutofillId> manuallyFilledFieldIds,
@Nullable ArrayList<ArrayList<String>> manuallyFilledDatasetIds,
@NonNull String appPackageName, boolean compatMode) {
@NonNull ComponentName appComponentName, boolean compatMode) {
logContextCommittedLocked(sessionId, clientState, selectedDatasets, ignoredDatasets,
changedFieldIds, changedDatasetIds, manuallyFilledFieldIds,
manuallyFilledDatasetIds, null, null, appPackageName, compatMode);
manuallyFilledDatasetIds, null, null, appComponentName, compatMode);
}

@GuardedBy("mLock")
Expand All @@ -796,7 +796,7 @@ void logContextCommittedLocked(int sessionId, @Nullable Bundle clientState,
@Nullable ArrayList<ArrayList<String>> manuallyFilledDatasetIds,
@Nullable ArrayList<AutofillId> detectedFieldIdsList,
@Nullable ArrayList<FieldClassification> detectedFieldClassificationsList,
@NonNull String appPackageName, boolean compatMode) {
@NonNull ComponentName appComponentName, boolean compatMode) {
if (isValidEventLocked("logDatasetNotSelected()", sessionId)) {
if (sVerbose) {
Slog.v(TAG, "logContextCommitted() with FieldClassification: id=" + sessionId
Expand All @@ -807,6 +807,7 @@ void logContextCommittedLocked(int sessionId, @Nullable Bundle clientState,
+ ", manuallyFilledFieldIds=" + manuallyFilledFieldIds
+ ", detectedFieldIds=" + detectedFieldIdsList
+ ", detectedFieldClassifications=" + detectedFieldClassificationsList
+ ", appComponentName=" + appComponentName.toShortString()
+ ", compatMode=" + compatMode);
}
AutofillId[] detectedFieldsIds = null;
Expand Down Expand Up @@ -834,7 +835,7 @@ void logContextCommittedLocked(int sessionId, @Nullable Bundle clientState,
final int averageScore = (int) ((totalScore * 100) / totalSize);
mMetricsLogger.write(Helper
.newLogMaker(MetricsEvent.AUTOFILL_FIELD_CLASSIFICATION_MATCHES,
appPackageName, getServicePackageName(), compatMode)
appComponentName, getServicePackageName(), compatMode)
.setCounterValue(numberFields)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_MATCH_SCORE,
averageScore));
Expand Down Expand Up @@ -889,9 +890,11 @@ void setUserData(int callingUid, UserData userData) {
}
mUserData = userData;
// Log it
int numberFields = mUserData == null ? 0: mUserData.getCategoryIds().length;
mMetricsLogger.write(Helper.newLogMaker(MetricsEvent.AUTOFILL_USERDATA_UPDATED,
getServicePackageName(), null)
final int numberFields = mUserData == null ? 0: mUserData.getCategoryIds().length;
// NOTE: contrary to most metrics, the service name is logged as the main package name
// here, not as MetricsEvent.FIELD_AUTOFILL_SERVICE
mMetricsLogger.write(new LogMaker(MetricsEvent.AUTOFILL_USERDATA_UPDATED)
.setPackageName(getServicePackageName())
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_VALUES, numberFields));
}
}
Expand Down
29 changes: 17 additions & 12 deletions services/autofill/java/com/android/server/autofill/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.annotation.Nullable;
import android.app.assist.AssistStructure;
import android.app.assist.AssistStructure.ViewNode;
import android.content.ComponentName;
import android.metrics.LogMaker;
import android.service.autofill.Dataset;
import android.util.ArrayMap;
Expand Down Expand Up @@ -109,23 +110,27 @@ static ArrayMap<AutofillId, AutofillValue> getFields(@NonNull Dataset dataset) {
}

@NonNull
public static LogMaker newLogMaker(int category, String packageName,
String servicePackageName) {
final LogMaker log = new LogMaker(category).setPackageName(packageName);
if (servicePackageName != null) {
log.addTaggedData(MetricsEvent.FIELD_AUTOFILL_SERVICE, servicePackageName);
private static LogMaker newLogMaker(int category, @NonNull String servicePackageName,
boolean compatMode) {
final LogMaker log = new LogMaker(category)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_SERVICE, servicePackageName);
if (compatMode) {
log.addTaggedData(MetricsEvent.FIELD_AUTOFILL_COMPAT_MODE, 1);
}
return log;
}

@NonNull
public static LogMaker newLogMaker(int category, String packageName,
String servicePackageName, boolean compatMode) {
final LogMaker log = newLogMaker(category, packageName, servicePackageName);
if (compatMode) {
log.addTaggedData(MetricsEvent.FIELD_AUTOFILL_COMPAT_MODE, 1);
}
return log;
public static LogMaker newLogMaker(int category, @NonNull String packageName,
@NonNull String servicePackageName, boolean compatMode) {
return newLogMaker(category, servicePackageName, compatMode).setPackageName(packageName);
}

@NonNull
public static LogMaker newLogMaker(int category, @NonNull ComponentName componentName,
@NonNull String servicePackageName, boolean compatMode) {
return newLogMaker(category, servicePackageName, compatMode)
.setComponentName(componentName);
}

public static void printlnRedactedText(@NonNull PrintWriter pw, @Nullable CharSequence text) {
Expand Down
13 changes: 6 additions & 7 deletions services/autofill/java/com/android/server/autofill/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ private void logContextCommittedLocked() {
mService.logContextCommittedLocked(id, mClientState, mSelectedDatasetIds,
ignoredDatasets, changedFieldIds, changedDatasetIds,
manuallyFilledFieldIds, manuallyFilledDatasetIds,
mComponentName.getPackageName(), mCompatMode);
mComponentName, mCompatMode);
}
}

Expand Down Expand Up @@ -1354,7 +1354,7 @@ private void logFieldClassificationScoreLocked(
mService.logContextCommittedLocked(id, mClientState, mSelectedDatasetIds,
ignoredDatasets, changedFieldIds, changedDatasetIds,
manuallyFilledFieldIds, manuallyFilledDatasetIds,
mComponentName.getPackageName(), mCompatMode);
mComponentName, mCompatMode);
return;
}
final Scores scores = result.getParcelable(EXTRA_SCORES);
Expand Down Expand Up @@ -1419,7 +1419,7 @@ else if (sVerbose) {
mService.logContextCommittedLocked(id, mClientState, mSelectedDatasetIds,
ignoredDatasets, changedFieldIds, changedDatasetIds, manuallyFilledFieldIds,
manuallyFilledDatasetIds, detectedFieldIds, detectedFieldClassifications,
mComponentName.getPackageName(), mCompatMode);
mComponentName, mCompatMode);
});

fcStrategy.getScores(callback, algorithm, algorithmArgs, currentValues, userValues);
Expand Down Expand Up @@ -1649,7 +1649,7 @@ public boolean showSaveLocked() {
mPendingSaveUi = new PendingUi(mActivityToken, id, client);
getUiForShowing().showSaveUi(mService.getServiceLabel(), mService.getServiceIcon(),
mService.getServicePackageName(), saveInfo, this,
mComponentName.getPackageName(), this,
mComponentName, this,
mPendingSaveUi, mCompatMode);
if (client != null) {
try {
Expand Down Expand Up @@ -2127,7 +2127,7 @@ public void onFillReady(@NonNull FillResponse response, @NonNull AutofillId fill
}

getUiForShowing().showFillUi(filledId, response, filterText,
mService.getServicePackageName(), mComponentName.getPackageName(),
mService.getServicePackageName(), mComponentName,
mService.getServiceLabel(), mService.getServiceIcon(), this, mCompatMode);

synchronized (mLock) {
Expand Down Expand Up @@ -2834,8 +2834,7 @@ private LogMaker newLogMaker(int category) {
}

private LogMaker newLogMaker(int category, String servicePackageName) {
return Helper.newLogMaker(category, mComponentName.getPackageName(), servicePackageName,
mCompatMode);
return Helper.newLogMaker(category, mComponentName, servicePackageName, mCompatMode);
}

private void writeLog(int category) {
Expand Down
Loading

0 comments on commit 212b161

Please sign in to comment.