New Autofill API: SaveRequest.getDatasetIds()
Test: modified some existing CTS tests to use it Test: cts-tradefed run commandAndExit cts-dev -m CtsAutoFillServiceTestCases Fixes: 64843801 Change-Id: I95fe7766f19e5a9eea9d7138636a15cc832c704c
This commit is contained in:
@@ -37193,6 +37193,7 @@ package android.service.autofill {
|
||||
public final class SaveRequest implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method public android.os.Bundle getClientState();
|
||||
method public java.util.List<java.lang.String> getDatasetIds();
|
||||
method public java.util.List<android.service.autofill.FillContext> getFillContexts();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator<android.service.autofill.SaveRequest> CREATOR;
|
||||
|
||||
@@ -40284,6 +40284,7 @@ package android.service.autofill {
|
||||
public final class SaveRequest implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method public android.os.Bundle getClientState();
|
||||
method public java.util.List<java.lang.String> getDatasetIds();
|
||||
method public java.util.List<android.service.autofill.FillContext> getFillContexts();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator<android.service.autofill.SaveRequest> CREATOR;
|
||||
|
||||
@@ -37395,6 +37395,7 @@ package android.service.autofill {
|
||||
public final class SaveRequest implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method public android.os.Bundle getClientState();
|
||||
method public java.util.List<java.lang.String> getDatasetIds();
|
||||
method public java.util.List<android.service.autofill.FillContext> getFillContexts();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator<android.service.autofill.SaveRequest> CREATOR;
|
||||
|
||||
@@ -2555,9 +2555,6 @@ public final class Parcel {
|
||||
* Read into the given List items String objects that were written with
|
||||
* {@link #writeStringList} at the current dataPosition().
|
||||
*
|
||||
* @return A newly created ArrayList containing strings with the same data
|
||||
* as those that were previously written.
|
||||
*
|
||||
* @see #writeStringList
|
||||
*/
|
||||
public final void readStringList(List<String> list) {
|
||||
|
||||
@@ -198,15 +198,22 @@ public final class Dataset implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the id for the dataset so its usage history can be retrieved later.
|
||||
* Sets the id for the dataset so its usage can be tracked.
|
||||
*
|
||||
* <p>The id of the last selected dataset can be read from
|
||||
* {@link AutofillService#getFillEventHistory()}. If the id is not set it will not be clear
|
||||
* if a dataset was selected as {@link AutofillService#getFillEventHistory()} uses
|
||||
* {@code null} to indicate that no dataset was selected.
|
||||
* <p>Dataset usage can be tracked for 2 purposes:
|
||||
*
|
||||
* <ul>
|
||||
* <li>For statistical purposes, the service can call
|
||||
* {@link AutofillService#getFillEventHistory()} when handling {@link
|
||||
* AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback)}
|
||||
* calls.
|
||||
* <li>For normal autofill workflow, the service can call
|
||||
* {@link SaveRequest#getDatasetIds()} when handling
|
||||
* {@link AutofillService#onSaveRequest(SaveRequest, SaveCallback)} calls.
|
||||
* </ul>
|
||||
*
|
||||
* @param id id for this dataset or {@code null} to unset.
|
||||
|
||||
*
|
||||
* @return This builder.
|
||||
*/
|
||||
public @NonNull Builder setId(@Nullable String id) {
|
||||
|
||||
@@ -228,6 +228,11 @@ public final class FillEventHistory implements Parcelable {
|
||||
mDatasetId = datasetId;
|
||||
mClientState = clientState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FillEvent [datasetId=" + mDatasetId + ", type=" + mEventType + "]";
|
||||
}
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<FillEventHistory> CREATOR =
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -36,16 +37,18 @@ import java.util.List;
|
||||
public final class SaveRequest implements Parcelable {
|
||||
private final @NonNull ArrayList<FillContext> mFillContexts;
|
||||
private final @Nullable Bundle mClientState;
|
||||
private final @Nullable ArrayList<String> mDatasetIds;
|
||||
|
||||
/** @hide */
|
||||
public SaveRequest(@NonNull ArrayList<FillContext> fillContexts,
|
||||
@Nullable Bundle clientState) {
|
||||
@Nullable Bundle clientState, @Nullable ArrayList<String> datasetIds) {
|
||||
mFillContexts = Preconditions.checkNotNull(fillContexts, "fillContexts");
|
||||
mClientState = clientState;
|
||||
mDatasetIds = datasetIds;
|
||||
}
|
||||
|
||||
private SaveRequest(@NonNull Parcel parcel) {
|
||||
this(parcel.readTypedArrayList(null), parcel.readBundle());
|
||||
this(parcel.readTypedArrayList(null), parcel.readBundle(), parcel.createStringArrayList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,6 +69,14 @@ public final class SaveRequest implements Parcelable {
|
||||
return mClientState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ids of the datasets selected by the user, in the order in which they were selected.
|
||||
*/
|
||||
@Nullable
|
||||
public List<String> getDatasetIds() {
|
||||
return mDatasetIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
@@ -75,6 +86,7 @@ public final class SaveRequest implements Parcelable {
|
||||
public void writeToParcel(Parcel parcel, int flags) {
|
||||
parcel.writeTypedArrayList(mFillContexts, flags);
|
||||
parcel.writeBundle(mClientState);
|
||||
parcel.writeStringList(mDatasetIds);
|
||||
}
|
||||
|
||||
public static final Creator<SaveRequest> CREATOR =
|
||||
|
||||
@@ -176,6 +176,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
@GuardedBy("mLock")
|
||||
private PendingUi mPendingSaveUi;
|
||||
|
||||
/**
|
||||
* List of dataset ids selected by the user.
|
||||
*/
|
||||
@GuardedBy("mLock")
|
||||
private ArrayList<String> mSelectedDatasetIds;
|
||||
|
||||
/**
|
||||
* Receiver of assist data from the app's {@link Activity}.
|
||||
*/
|
||||
@@ -1098,7 +1104,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
// until the dispatch happens. The items in the list don't need to be cloned
|
||||
// since we don't hold on them anywhere else. The client state is not touched
|
||||
// by us, so no need to copy.
|
||||
final SaveRequest saveRequest = new SaveRequest(new ArrayList<>(mContexts), mClientState);
|
||||
final SaveRequest saveRequest = new SaveRequest(new ArrayList<>(mContexts), mClientState,
|
||||
mSelectedDatasetIds);
|
||||
mRemoteFillService.onSaveRequest(saveRequest);
|
||||
}
|
||||
|
||||
@@ -1626,6 +1633,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
pw.print(prefix); pw.print("mHasCallback: "); pw.println(mHasCallback);
|
||||
pw.print(prefix); pw.print("mClientState: "); pw.println(
|
||||
Helper.bundleToString(mClientState));
|
||||
pw.print(prefix); pw.print("mSelectedDatasetIds: "); pw.println(mSelectedDatasetIds);
|
||||
mRemoteFillService.dump(prefix, pw);
|
||||
}
|
||||
|
||||
@@ -1666,6 +1674,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
if (sDebug) Slog.d(TAG, "autoFillApp(): the buck is on the app: " + dataset);
|
||||
|
||||
mClient.autofill(id, ids, values);
|
||||
if (dataset.getId() != null) {
|
||||
if (mSelectedDatasetIds == null) {
|
||||
mSelectedDatasetIds = new ArrayList<>();
|
||||
}
|
||||
mSelectedDatasetIds.add(dataset.getId());
|
||||
}
|
||||
setViewStatesLocked(null, dataset, ViewState.STATE_AUTOFILLED, false);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
|
||||
Reference in New Issue
Block a user