New Autofill field: FIELD_AUTOFILL_SESSION_ID

This field contains the autofill session id (Thank You, Captain Obvious!), which
is useful to correlate autofill metrics that are not logged on
AUTOFILL_REQUEST.

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'. Example:
     [757,913,758,4,806,android.autofillservice.cts,871,android.autofillservice.cts.LoginActivity,914,2,915,2,1456,-2045861404

Fixes: 80093094

Change-Id: If4b1c9ab616b2ba580745096894997eb7edb3e34
(cherry picked from commit 064c562c23edcb2c220be45450274869b529a8ee)
This commit is contained in:
Felipe Leme
2018-05-24 10:41:48 -07:00
parent 3c2956e0bc
commit 833c99b9d1
8 changed files with 83 additions and 39 deletions

View File

@@ -1900,8 +1900,11 @@ public final class AutofillManager {
private LogMaker newLog(int category) {
final LogMaker log = new LogMaker(category)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_COMPAT_MODE,
isCompatibilityModeEnabledLocked() ? 1 : 0);
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_SESSION_ID, mSessionId);
if (isCompatibilityModeEnabledLocked()) {
log.addTaggedData(MetricsEvent.FIELD_AUTOFILL_COMPAT_MODE, 1);
}
final AutofillClient client = getClient();
if (client == null) {
// Client should never be null here, but it doesn't hurt to check...

View File

@@ -3993,8 +3993,9 @@ message MetricsEvent {
// 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.
// Tag FIELD_AUTOFIL_FLAGS: flags used to start the session.
// Tag FIELD_AUTOFILL_SESSION_ID: id of the autofill session started.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SESSION_STARTED = 906;
// An autofill request was processed by a service
@@ -4015,6 +4016,7 @@ message MetricsEvent {
// Tag FIELD_AUTOFILL_AUTHENTICATION_STATUS: status of authenticated datasets or responses.
// Tag FIELD_AUTOFILL_NUM_FIELD_CLASSIFICATION_IDS: if service requested field classification,
// number of entries field ids in the request.
// Tag FIELD_AUTOFILL_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
// NOTE: Prior to P, some of the fields above were logged by 5 different metrics:
// - AUTOFILL_UI_LATENCY
@@ -4041,6 +4043,7 @@ message MetricsEvent {
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_FILL_UI = 910;
@@ -4059,6 +4062,7 @@ message MetricsEvent {
// Tag FIELD_AUTOFILL_NUM_VIEWS_FILLED: Number of views that could be filled
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_DATASET_APPLIED = 913;
@@ -4077,6 +4081,7 @@ message MetricsEvent {
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_UI = 916;
@@ -4091,6 +4096,7 @@ message MetricsEvent {
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_DATA_SAVE_REQUEST = 918;
@@ -4099,6 +4105,7 @@ message MetricsEvent {
// Package: Package of app that was autofilled
// NOTE: starting on OS P, it also added the following fields:
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_AUTOFILL_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
// Tag FIELD_AUTOFILL_NUMBER_REQUESTS: number of requests made to the service (each request
// is logged by a separate AUTOFILL_REQUEST metric)
@@ -4688,6 +4695,7 @@ message MetricsEvent {
// Tag FIELD_AUTOFILL_PREVIOUS_LENGTH: the previous length of the value
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_VALUE_RESET = 1124;
@@ -4722,6 +4730,7 @@ message MetricsEvent {
// Tag FIELD_AUTOFILL_SAVE_TYPE: Type of save object passed by the service
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_CUSTOM_DESCRIPTION = 1129;
@@ -4736,6 +4745,7 @@ message MetricsEvent {
// Tag FIELD_AUTOFILL_SAVE_TYPE: Type of save object passed by the service
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_CUSTOM_SUBTITLE = 1131;
@@ -4749,6 +4759,7 @@ message MetricsEvent {
// Tag FIELD_AUTOFILL_SAVE_TYPE: Type of save object passed by the service
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_LINK_TAPPED = 1132;
@@ -4762,6 +4773,7 @@ message MetricsEvent {
// Tag FIELD_AUTOFILL_SAVE_TYPE: Type of save object passed by the service
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_VALIDATION = 1133;
@@ -4774,6 +4786,7 @@ message MetricsEvent {
// Type TYPE_FAILURE: An invalid opperation was reported by the app's AutofillManager
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_PENDING_SAVE_UI_OPERATION = 1134;
@@ -4956,6 +4969,7 @@ message MetricsEvent {
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_EXPLICIT_SAVE_TRIGGER_DEFINITION = 1228;
@@ -4964,6 +4978,7 @@ message MetricsEvent {
// Package: Package of app that is autofilled
// OS: P
// Tag FIELD_CLASS_NAME: Class name of the activity that is autofilled.
// Tag FIELD_AUTOFILL_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SAVE_EXPLICITLY_TRIGGERED = 1229;
@@ -4977,6 +4992,7 @@ message MetricsEvent {
// OS: P
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_AUTOFILL_DURATION: duration (in ms) that autofill will be disabled
// Tag FIELD_AUTOFILL_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SERVICE_DISABLED_APP = 1231;
@@ -4986,6 +5002,7 @@ message MetricsEvent {
// Tag FIELD_AUTOFILL_SERVICE: Package of service that processed the request
// Tag FIELD_CLASS_NAME: Class name of the activity that is being disabled for autofill
// Tag FIELD_AUTOFILL_DURATION: duration (in ms) that autofill will be disabled
// Tag FIELD_AUTOFILL_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_SERVICE_DISABLED_ACTIVITY = 1232;
@@ -5199,6 +5216,7 @@ message MetricsEvent {
// 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_SESSION_ID: id of the autofill session associated with this metric.
// Tag FIELD_AUTOFILL_COMPAT_MODE: package is being autofilled on compatibility mode.
AUTOFILL_FIELD_CLASSIFICATION_MATCHES = 1273;
@@ -6094,6 +6112,10 @@ message MetricsEvent {
// OS: P
FIELD_AUTOFILL_NUMBER_REQUESTS = 1455;
// FIELD: Id of the autofill session associated with this metric.
// OS: P
FIELD_AUTOFILL_SESSION_ID = 1456;
// ---- End P Constants, all P constants go above this line ----
// First Q constant in master goes here:

View File

@@ -537,11 +537,17 @@ final class AutofillManagerServiceImpl {
final String callingPackage = packages != null ? packages[0] : "uid-" + callingUid;
Slog.w(TAG, "App (package=" + callingPackage + ", UID=" + callingUid
+ ") passed component (" + componentName + ") owned by UID " + packageUid);
mMetricsLogger.write(
Helper.newLogMaker(MetricsEvent.AUTOFILL_FORGED_COMPONENT_ATTEMPT,
callingPackage, getServicePackageName(), compatMode)
// NOTE: not using Helper.newLogMaker() because we don't have the session id
final LogMaker log = new LogMaker(MetricsEvent.AUTOFILL_FORGED_COMPONENT_ATTEMPT)
.setPackageName(callingPackage)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_SERVICE, getServicePackageName())
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_FORGED_COMPONENT_NAME,
componentName == null ? "null" : componentName.flattenToShortString()));
componentName == null ? "null" : componentName.flattenToShortString());
if (compatMode) {
log.addTaggedData(MetricsEvent.FIELD_AUTOFILL_COMPAT_MODE, 1);
}
mMetricsLogger.write(log);
throw new SecurityException("Invalid component: " + componentName);
}
@@ -835,7 +841,7 @@ final class AutofillManagerServiceImpl {
final int averageScore = (int) ((totalScore * 100) / totalSize);
mMetricsLogger.write(Helper
.newLogMaker(MetricsEvent.AUTOFILL_FIELD_CLASSIFICATION_MATCHES,
appComponentName, getServicePackageName(), compatMode)
appComponentName, getServicePackageName(), sessionId, compatMode)
.setCounterValue(numberFields)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_MATCH_SCORE,
averageScore));
@@ -1133,7 +1139,8 @@ final class AutofillManagerServiceImpl {
/**
* Called by {@link Session} when service asked to disable autofill for an app.
*/
void disableAutofillForApp(@NonNull String packageName, long duration, boolean compatMode) {
void disableAutofillForApp(@NonNull String packageName, long duration, int sessionId,
boolean compatMode) {
synchronized (mLock) {
if (mDisabledApps == null) {
mDisabledApps = new ArrayMap<>(1);
@@ -1146,7 +1153,7 @@ final class AutofillManagerServiceImpl {
mDisabledApps.put(packageName, expiration);
int intDuration = duration > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) duration;
mMetricsLogger.write(Helper.newLogMaker(MetricsEvent.AUTOFILL_SERVICE_DISABLED_APP,
packageName, getServicePackageName(), compatMode)
packageName, getServicePackageName(), sessionId, compatMode)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_DURATION, intDuration));
}
}
@@ -1155,7 +1162,7 @@ final class AutofillManagerServiceImpl {
* Called by {@link Session} when service asked to disable autofill an app.
*/
void disableAutofillForActivity(@NonNull ComponentName componentName, long duration,
boolean compatMode) {
int sessionId, boolean compatMode) {
synchronized (mLock) {
if (mDisabledActivities == null) {
mDisabledActivities = new ArrayMap<>(1);
@@ -1166,14 +1173,20 @@ final class AutofillManagerServiceImpl {
expiration = Long.MAX_VALUE;
}
mDisabledActivities.put(componentName, expiration);
final int intDuration = duration > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) duration;
final int intDuration = duration > Integer.MAX_VALUE
? Integer.MAX_VALUE
: (int) duration;
// NOTE: not using Helper.newLogMaker() because we're setting the componentName instead
// of package name
mMetricsLogger.write(new LogMaker(MetricsEvent.AUTOFILL_SERVICE_DISABLED_ACTIVITY)
final LogMaker log = new LogMaker(MetricsEvent.AUTOFILL_SERVICE_DISABLED_ACTIVITY)
.setComponentName(componentName)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_SERVICE, getServicePackageName())
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_DURATION, intDuration)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_COMPAT_MODE, compatMode ? 1 : 0));
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_SESSION_ID, sessionId);
if (compatMode) {
log.addTaggedData(MetricsEvent.FIELD_AUTOFILL_COMPAT_MODE, 1);
}
mMetricsLogger.write(log);
}
}

View File

@@ -111,9 +111,10 @@ public final class Helper {
@NonNull
private static LogMaker newLogMaker(int category, @NonNull String servicePackageName,
boolean compatMode) {
int sessionId, boolean compatMode) {
final LogMaker log = new LogMaker(category)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_SERVICE, servicePackageName);
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_SERVICE, servicePackageName)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_SESSION_ID, sessionId);
if (compatMode) {
log.addTaggedData(MetricsEvent.FIELD_AUTOFILL_COMPAT_MODE, 1);
}
@@ -122,14 +123,15 @@ public final class Helper {
@NonNull
public static LogMaker newLogMaker(int category, @NonNull String packageName,
@NonNull String servicePackageName, boolean compatMode) {
return newLogMaker(category, servicePackageName, compatMode).setPackageName(packageName);
@NonNull String servicePackageName, int sessionId, boolean compatMode) {
return newLogMaker(category, servicePackageName, sessionId, compatMode)
.setPackageName(packageName);
}
@NonNull
public static LogMaker newLogMaker(int category, @NonNull ComponentName componentName,
@NonNull String servicePackageName, boolean compatMode) {
return newLogMaker(category, servicePackageName, compatMode)
@NonNull String servicePackageName, int sessionId, boolean compatMode) {
return newLogMaker(category, servicePackageName, sessionId, compatMode)
.setComponentName(componentName);
}

View File

@@ -672,10 +672,11 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
Slog.d(TAG, message.toString());
}
if ((flags & FillResponse.FLAG_DISABLE_ACTIVITY_ONLY) != 0) {
mService.disableAutofillForActivity(mComponentName, disableDuration, mCompatMode);
mService.disableAutofillForActivity(mComponentName, disableDuration,
id, mCompatMode);
} else {
mService.disableAutofillForApp(mComponentName.getPackageName(), disableDuration,
mCompatMode);
id, mCompatMode);
}
sessionFinishedState = AutofillManager.STATE_DISABLED_BY_SERVICE;
}
@@ -1649,8 +1650,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
mPendingSaveUi = new PendingUi(mActivityToken, id, client);
getUiForShowing().showSaveUi(mService.getServiceLabel(), mService.getServiceIcon(),
mService.getServicePackageName(), saveInfo, this,
mComponentName, this,
mPendingSaveUi, mCompatMode);
mComponentName, this, mPendingSaveUi, mCompatMode);
if (client != null) {
try {
client.setSaveUiState(id, true);
@@ -2128,7 +2128,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
getUiForShowing().showFillUi(filledId, response, filterText,
mService.getServicePackageName(), mComponentName,
mService.getServiceLabel(), mService.getServiceIcon(), this, mCompatMode);
mService.getServiceLabel(), mService.getServiceIcon(), this, id, mCompatMode);
synchronized (mLock) {
if (mUiShownTime == 0) {
@@ -2834,7 +2834,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
}
private LogMaker newLogMaker(int category, String servicePackageName) {
return Helper.newLogMaker(category, mComponentName, servicePackageName, mCompatMode);
return Helper.newLogMaker(category, mComponentName, servicePackageName, id, mCompatMode);
}
private void writeLog(int category) {

View File

@@ -166,19 +166,22 @@ public final class AutoFillUI {
* @param componentName component name of the activity that is filled
* @param serviceLabel label of autofill service
* @param serviceIcon icon of autofill service
* @param callback Identifier for the caller
* @param callback identifier for the caller
* @param sessionId id of the autofill session
* @param compatMode whether the app is being autofilled in compatibility mode.
*/
public void showFillUi(@NonNull AutofillId focusedId, @NonNull FillResponse response,
@Nullable String filterText, @Nullable String servicePackageName,
@NonNull ComponentName componentName, @NonNull CharSequence serviceLabel,
@NonNull Drawable serviceIcon, @NonNull AutoFillUiCallback callback, boolean compatMode) {
@NonNull Drawable serviceIcon, @NonNull AutoFillUiCallback callback, int sessionId,
boolean compatMode) {
if (sDebug) {
final int size = filterText == null ? 0 : filterText.length();
Slog.d(TAG, "showFillUi(): id=" + focusedId + ", filter=" + size + " chars");
}
final LogMaker log = Helper
.newLogMaker(MetricsEvent.AUTOFILL_FILL_UI, componentName, servicePackageName,
compatMode)
sessionId, compatMode)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_FILTERTEXT_LEN,
filterText == null ? 0 : filterText.length())
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_DATASETS,
@@ -275,7 +278,7 @@ public final class AutoFillUI {
final LogMaker log = Helper
.newLogMaker(MetricsEvent.AUTOFILL_SAVE_UI, componentName, servicePackageName,
compatMode)
pendingSaveUi.sessionId, compatMode)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_IDS, numIds);
mHandler.post(() -> {
@@ -412,7 +415,7 @@ public final class AutoFillUI {
if (pendingSaveUi != null && notifyClient) {
try {
if (sDebug) Slog.d(TAG, "destroySaveUiUiThread(): notifying client");
pendingSaveUi.client.setSaveUiState(pendingSaveUi.id, false);
pendingSaveUi.client.setSaveUiState(pendingSaveUi.sessionId, false);
} catch (RemoteException e) {
Slog.e(TAG, "Error notifying client to set save UI state to hidden: " + e);
}

View File

@@ -35,7 +35,7 @@ public final class PendingUi {
private final IBinder mToken;
private int mState;
public final int id;
public final int sessionId;
public final IAutoFillManagerClient client;
/**
@@ -43,10 +43,11 @@ public final class PendingUi {
*
* @param token token used to identify this pending UI.
*/
public PendingUi(@NonNull IBinder token, int id, @NonNull IAutoFillManagerClient client) {
public PendingUi(@NonNull IBinder token, int sessionId,
@NonNull IAutoFillManagerClient client) {
mToken = token;
mState = STATE_CREATED;
this.id = id;
this.sessionId = sessionId;
this.client = client;
}
@@ -81,7 +82,7 @@ public final class PendingUi {
@Override
public String toString() {
return "PendingUi: [token=" + mToken + ", id=" + id + ", state="
return "PendingUi: [token=" + mToken + ", sessionId=" + sessionId + ", state="
+ DebugUtils.flagsToString(PendingUi.class, "STATE_", mState) + "]";
}
}

View File

@@ -413,12 +413,12 @@ final class SaveUi {
}
private LogMaker newLogMaker(int category, int saveType) {
return Helper.newLogMaker(category, mComponentName, mServicePackageName, mCompatMode)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_SAVE_TYPE, saveType);
return newLogMaker(category).addTaggedData(MetricsEvent.FIELD_AUTOFILL_SAVE_TYPE, saveType);
}
private LogMaker newLogMaker(int category) {
return Helper.newLogMaker(category, mComponentName, mServicePackageName, mCompatMode);
return Helper.newLogMaker(category, mComponentName, mServicePackageName,
mPendingUi.sessionId, mCompatMode);
}
private void writeLog(int category, int saveType) {