diff options
Diffstat (limited to 'android/service/autofill/FillEventHistory.java')
-rw-r--r-- | android/service/autofill/FillEventHistory.java | 148 |
1 files changed, 69 insertions, 79 deletions
diff --git a/android/service/autofill/FillEventHistory.java b/android/service/autofill/FillEventHistory.java index 736d9ef4..df624464 100644 --- a/android/service/autofill/FillEventHistory.java +++ b/android/service/autofill/FillEventHistory.java @@ -16,16 +16,18 @@ package android.service.autofill; +import static android.view.autofill.Helper.sVerbose; + import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; -import android.annotation.TestApi; import android.content.IntentSender; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.util.ArrayMap; import android.util.ArraySet; +import android.util.Log; import android.view.autofill.AutofillId; import android.view.autofill.AutofillManager; @@ -35,6 +37,7 @@ import com.android.internal.util.Preconditions; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -57,10 +60,7 @@ import java.util.Set; * the history will clear out after some pre-defined time). */ public final class FillEventHistory implements Parcelable { - /** - * Not in parcel. The UID of the {@link AutofillService} that created the {@link FillResponse}. - */ - private final int mServiceUid; + private static final String TAG = "FillEventHistory"; /** * Not in parcel. The ID of the autofill session that created the {@link FillResponse}. @@ -70,17 +70,6 @@ public final class FillEventHistory implements Parcelable { @Nullable private final Bundle mClientState; @Nullable List<Event> mEvents; - /** - * Gets the UID of the {@link AutofillService} that created the {@link FillResponse}. - * - * @return The UID of the {@link AutofillService} - * - * @hide - */ - public int getServiceUid() { - return mServiceUid; - } - /** @hide */ public int getSessionId() { return mSessionId; @@ -123,9 +112,8 @@ public final class FillEventHistory implements Parcelable { /** * @hide */ - public FillEventHistory(int serviceUid, int sessionId, @Nullable Bundle clientState) { + public FillEventHistory(int sessionId, @Nullable Bundle clientState) { mClientState = clientState; - mServiceUid = serviceUid; mSessionId = sessionId; } @@ -140,34 +128,36 @@ public final class FillEventHistory implements Parcelable { } @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeBundle(mClientState); + public void writeToParcel(Parcel parcel, int flags) { + parcel.writeBundle(mClientState); if (mEvents == null) { - dest.writeInt(0); + parcel.writeInt(0); } else { - dest.writeInt(mEvents.size()); + parcel.writeInt(mEvents.size()); int numEvents = mEvents.size(); for (int i = 0; i < numEvents; i++) { Event event = mEvents.get(i); - dest.writeInt(event.mEventType); - dest.writeString(event.mDatasetId); - dest.writeBundle(event.mClientState); - dest.writeStringList(event.mSelectedDatasetIds); - dest.writeArraySet(event.mIgnoredDatasetIds); - dest.writeTypedList(event.mChangedFieldIds); - dest.writeStringList(event.mChangedDatasetIds); - - dest.writeTypedList(event.mManuallyFilledFieldIds); + parcel.writeInt(event.mEventType); + parcel.writeString(event.mDatasetId); + parcel.writeBundle(event.mClientState); + parcel.writeStringList(event.mSelectedDatasetIds); + parcel.writeArraySet(event.mIgnoredDatasetIds); + parcel.writeTypedList(event.mChangedFieldIds); + parcel.writeStringList(event.mChangedDatasetIds); + + parcel.writeTypedList(event.mManuallyFilledFieldIds); if (event.mManuallyFilledFieldIds != null) { final int size = event.mManuallyFilledFieldIds.size(); for (int j = 0; j < size; j++) { - dest.writeStringList(event.mManuallyFilledDatasetIds.get(j)); + parcel.writeStringList(event.mManuallyFilledDatasetIds.get(j)); } } - dest.writeString(event.mDetectedRemoteId); - if (event.mDetectedRemoteId != null) { - dest.writeInt(event.mDetectedFieldScore); + final AutofillId[] detectedFields = event.mDetectedFieldIds; + parcel.writeParcelableArray(detectedFields, flags); + if (detectedFields != null) { + FieldClassification.writeArrayToParcel(parcel, + event.mDetectedFieldClassifications); } } } @@ -217,6 +207,7 @@ public final class FillEventHistory implements Parcelable { * ({@link #getIgnoredDatasetIds()}). * <li>Which fields in the selected datasets were changed by the user after the dataset * was selected ({@link #getChangedFields()}. + * <li>Which fields match the {@link UserData} set by the service. * </ul> * * <p><b>Note: </b>This event is only generated when: @@ -231,16 +222,16 @@ public final class FillEventHistory implements Parcelable { * <p>See {@link android.view.autofill.AutofillManager} for more information about autofill * contexts. */ - // TODO(b/67867469): update with field detection behavior public static final int TYPE_CONTEXT_COMMITTED = 4; /** @hide */ - @IntDef( - value = {TYPE_DATASET_SELECTED, - TYPE_DATASET_AUTHENTICATION_SELECTED, - TYPE_AUTHENTICATION_SELECTED, - TYPE_SAVE_SHOWN, - TYPE_CONTEXT_COMMITTED}) + @IntDef(prefix = { "TYPE_" }, value = { + TYPE_DATASET_SELECTED, + TYPE_DATASET_AUTHENTICATION_SELECTED, + TYPE_AUTHENTICATION_SELECTED, + TYPE_SAVE_SHOWN, + TYPE_CONTEXT_COMMITTED + }) @Retention(RetentionPolicy.SOURCE) @interface EventIds{} @@ -259,8 +250,8 @@ public final class FillEventHistory implements Parcelable { @Nullable private final ArrayList<AutofillId> mManuallyFilledFieldIds; @Nullable private final ArrayList<ArrayList<String>> mManuallyFilledDatasetIds; - @Nullable private final String mDetectedRemoteId; - private final int mDetectedFieldScore; + @Nullable private final AutofillId[] mDetectedFieldIds; + @Nullable private final FieldClassification[] mDetectedFieldClassifications; /** * Returns the type of the event. @@ -364,35 +355,27 @@ public final class FillEventHistory implements Parcelable { } /** - * Gets the results of the last {@link FieldsDetection} request. - * - * @return map of edit-distance match ({@code 0} means full match, - * {@code 1} means 1 character different, etc...) by remote id (as set in the - * {@link FieldsDetection} constructor), or {@code null} if none of the user-input values - * matched the requested detection. + * Gets the <a href="AutofillService.html#FieldClassification">field classification</a> + * results. * * <p><b>Note: </b>Only set on events of type {@link #TYPE_CONTEXT_COMMITTED}, when the - * service requested {@link FillResponse.Builder#setFieldsDetection(FieldsDetection) fields - * detection}. - * - * TODO(b/67867469): - * - improve javadoc - * - refine score meaning (for example, should 1 be different of -1?) - * - mention when it's set - * - unhide - * - unhide / remove testApi - * - add @NonNull / check it / add unit tests - * - * @hide + * service requested {@link FillResponse.Builder#setFieldClassificationIds(AutofillId...) + * field classification}. */ - @TestApi - @NonNull public Map<String, Integer> getDetectedFields() { - if (mDetectedRemoteId == null || mDetectedFieldScore == -1) { + @NonNull public Map<AutofillId, FieldClassification> getFieldsClassification() { + if (mDetectedFieldIds == null) { return Collections.emptyMap(); } - - final ArrayMap<String, Integer> map = new ArrayMap<>(1); - map.put(mDetectedRemoteId, mDetectedFieldScore); + final int size = mDetectedFieldIds.length; + final ArrayMap<AutofillId, FieldClassification> map = new ArrayMap<>(size); + for (int i = 0; i < size; i++) { + final AutofillId id = mDetectedFieldIds[i]; + final FieldClassification fc = mDetectedFieldClassifications[i]; + if (sVerbose) { + Log.v(TAG, "getFieldsClassification[" + i + "]: id=" + id + ", fc=" + fc); + } + map.put(id, fc); + } return map; } @@ -472,6 +455,8 @@ public final class FillEventHistory implements Parcelable { * and belonged to datasets. * @param manuallyFilledDatasetIds The ids of datasets that had values matching the * respective entry on {@code manuallyFilledFieldIds}. + * @param detectedFieldClassifications the field classification matches. + * * @throws IllegalArgumentException If the length of {@code changedFieldIds} and * {@code changedDatasetIds} doesn't match. * @throws IllegalArgumentException If the length of {@code manuallyFilledFieldIds} and @@ -479,7 +464,6 @@ public final class FillEventHistory implements Parcelable { * * @hide */ - // TODO(b/67867469): document detection field parameters once stable public Event(int eventType, @Nullable String datasetId, @Nullable Bundle clientState, @Nullable List<String> selectedDatasetIds, @Nullable ArraySet<String> ignoredDatasetIds, @@ -487,7 +471,8 @@ public final class FillEventHistory implements Parcelable { @Nullable ArrayList<String> changedDatasetIds, @Nullable ArrayList<AutofillId> manuallyFilledFieldIds, @Nullable ArrayList<ArrayList<String>> manuallyFilledDatasetIds, - @Nullable String detectedRemoteId, int detectedFieldScore) { + @Nullable AutofillId[] detectedFieldIds, + @Nullable FieldClassification[] detectedFieldClassifications) { mEventType = Preconditions.checkArgumentInRange(eventType, 0, TYPE_CONTEXT_COMMITTED, "eventType"); mDatasetId = datasetId; @@ -510,8 +495,9 @@ public final class FillEventHistory implements Parcelable { } mManuallyFilledFieldIds = manuallyFilledFieldIds; mManuallyFilledDatasetIds = manuallyFilledDatasetIds; - mDetectedRemoteId = detectedRemoteId; - mDetectedFieldScore = detectedFieldScore; + + mDetectedFieldIds = detectedFieldIds; + mDetectedFieldClassifications = detectedFieldClassifications; } @Override @@ -524,8 +510,9 @@ public final class FillEventHistory implements Parcelable { + ", changedDatasetsIds=" + mChangedDatasetIds + ", manuallyFilledFieldIds=" + mManuallyFilledFieldIds + ", manuallyFilledDatasetIds=" + mManuallyFilledDatasetIds - + ", detectedRemoteId=" + mDetectedRemoteId - + ", detectedFieldScore=" + mDetectedFieldScore + + ", detectedFieldIds=" + Arrays.toString(mDetectedFieldIds) + + ", detectedFieldClassifications =" + + Arrays.toString(mDetectedFieldClassifications) + "]"; } } @@ -534,7 +521,7 @@ public final class FillEventHistory implements Parcelable { new Parcelable.Creator<FillEventHistory>() { @Override public FillEventHistory createFromParcel(Parcel parcel) { - FillEventHistory selection = new FillEventHistory(0, 0, parcel.readBundle()); + FillEventHistory selection = new FillEventHistory(0, parcel.readBundle()); final int numEvents = parcel.readInt(); for (int i = 0; i < numEvents; i++) { @@ -561,15 +548,18 @@ public final class FillEventHistory implements Parcelable { } else { manuallyFilledDatasetIds = null; } - final String detectedRemoteId = parcel.readString(); - final int detectedFieldScore = detectedRemoteId == null ? -1 - : parcel.readInt(); + final AutofillId[] detectedFieldIds = parcel.readParcelableArray(null, + AutofillId.class); + final FieldClassification[] detectedFieldClassifications = + (detectedFieldIds != null) + ? FieldClassification.readArrayFromParcel(parcel) + : null; selection.addEvent(new Event(eventType, datasetId, clientState, selectedDatasetIds, ignoredDatasets, changedFieldIds, changedDatasetIds, manuallyFilledFieldIds, manuallyFilledDatasetIds, - detectedRemoteId, detectedFieldScore)); + detectedFieldIds, detectedFieldClassifications)); } return selection; } |