Merge "Merge "[PCC]: Fixes for PCC Create session only once. Previously, multiple sessions could be created, and can result in multiple requsets to PCC. Add local logs for debugging. Fix to show datasets from PCC. Seems like it stopped working from a previous change. Upcoming PccFieldClassificationTest should prevent such regressions." into udc-dev am: bdeb39fec4 am: c3f096ad9b am: e148a0230d" into udc-qpr-dev-plus-aosp
This commit is contained in:
committed by
Android (Google) Code Review
commit
dd974fec54
@@ -1477,15 +1477,23 @@ public final class AutofillManager {
|
|||||||
// to PCC classification service.
|
// to PCC classification service.
|
||||||
if (AutofillFeatureFlags.isAutofillPccClassificationEnabled()) {
|
if (AutofillFeatureFlags.isAutofillPccClassificationEnabled()) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
|
// If session has already been created, that'd mean we already have issued the
|
||||||
|
// detection request previously. It is possible in cases like autofocus that this
|
||||||
|
// method isn't invoked, so the server should still handle such cases where fill
|
||||||
|
// request comes in but PCC Detection hasn't been triggered. There is no benefit to
|
||||||
|
// trigger PCC Detection separately in those cases.
|
||||||
|
if (!isActiveLocked()) {
|
||||||
final boolean clientAdded = tryAddServiceClientIfNeededLocked();
|
final boolean clientAdded = tryAddServiceClientIfNeededLocked();
|
||||||
if (clientAdded){
|
if (clientAdded) {
|
||||||
startSessionLocked(/* id= */ AutofillId.NO_AUTOFILL_ID,
|
startSessionLocked(/* id= */ AutofillId.NO_AUTOFILL_ID, /* bounds= */ null,
|
||||||
/* bounds= */ null, /* value= */ null, /* flags= */ FLAG_PCC_DETECTION);
|
/* value= */ null, /* flags= */ FLAG_PCC_DETECTION);
|
||||||
} else {
|
} else {
|
||||||
if (sVerbose) {
|
if (sVerbose) {
|
||||||
Log.v(TAG, "not starting session: no service client");
|
Log.v(TAG, "not starting session: no service client");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,6 +157,8 @@ final class RemoteFieldClassificationService
|
|||||||
if (sDebug) {
|
if (sDebug) {
|
||||||
Log.d(TAG, "onSuccess Response: " + response);
|
Log.d(TAG, "onSuccess Response: " + response);
|
||||||
}
|
}
|
||||||
|
fieldClassificationServiceCallbacks
|
||||||
|
.onClassificationRequestSuccess(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -165,6 +167,8 @@ final class RemoteFieldClassificationService
|
|||||||
if (sDebug) {
|
if (sDebug) {
|
||||||
Log.d(TAG, "onFailure");
|
Log.d(TAG, "onFailure");
|
||||||
}
|
}
|
||||||
|
fieldClassificationServiceCallbacks
|
||||||
|
.onClassificationRequestFailure(0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -204,6 +204,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
RemoteFieldClassificationService.FieldClassificationServiceCallbacks {
|
RemoteFieldClassificationService.FieldClassificationServiceCallbacks {
|
||||||
private static final String TAG = "AutofillSession";
|
private static final String TAG = "AutofillSession";
|
||||||
|
|
||||||
|
// This should never be true in production. This is only for local debugging.
|
||||||
|
// Otherwise it will spam logcat.
|
||||||
|
private static final boolean DBG = false;
|
||||||
|
|
||||||
private static final String ACTION_DELAYED_FILL =
|
private static final String ACTION_DELAYED_FILL =
|
||||||
"android.service.autofill.action.DELAYED_FILL";
|
"android.service.autofill.action.DELAYED_FILL";
|
||||||
private static final String EXTRA_REQUEST_ID = "android.service.autofill.extra.REQUEST_ID";
|
private static final String EXTRA_REQUEST_ID = "android.service.autofill.extra.REQUEST_ID";
|
||||||
@@ -1240,6 +1244,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
|
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private void requestAssistStructureForPccLocked(int flags) {
|
private void requestAssistStructureForPccLocked(int flags) {
|
||||||
|
if (!mClassificationState.shouldTriggerRequest()) return;
|
||||||
|
mClassificationState.updatePendingRequest();
|
||||||
// Get request id
|
// Get request id
|
||||||
int requestId;
|
int requestId;
|
||||||
// TODO(b/158623971): Update this to prevent possible overflow
|
// TODO(b/158623971): Update this to prevent possible overflow
|
||||||
@@ -1571,12 +1577,18 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
// TODO(b/266379948): Ideally wait for PCC request to finish for a while more
|
// TODO(b/266379948): Ideally wait for PCC request to finish for a while more
|
||||||
// (say 100ms) before proceeding further on.
|
// (say 100ms) before proceeding further on.
|
||||||
|
|
||||||
|
if (DBG) {
|
||||||
|
Slog.d(TAG, "DBG: Initial response: " + response);
|
||||||
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
response = getEffectiveFillResponse(response);
|
response = getEffectiveFillResponse(response);
|
||||||
if (isEmptyResponse(response)) {
|
if (isEmptyResponse(response)) {
|
||||||
// Treat it as a null response.
|
// Treat it as a null response.
|
||||||
processNullResponseLocked(requestId, requestFlags);
|
processNullResponseLocked(requestId, requestFlags);
|
||||||
}
|
}
|
||||||
|
if (DBG) {
|
||||||
|
Slog.d(TAG, "DBG: Processed response: " + response);
|
||||||
|
}
|
||||||
processResponseLocked(response, null, requestFlags);
|
processResponseLocked(response, null, requestFlags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1601,12 +1613,25 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
DatasetComputationContainer autofillProviderContainer = new DatasetComputationContainer();
|
DatasetComputationContainer autofillProviderContainer = new DatasetComputationContainer();
|
||||||
computeDatasetsForProviderAndUpdateContainer(response, autofillProviderContainer);
|
computeDatasetsForProviderAndUpdateContainer(response, autofillProviderContainer);
|
||||||
|
|
||||||
|
if (DBG) {
|
||||||
|
Slog.d(TAG, "DBG: computeDatasetsForProviderAndUpdateContainer: "
|
||||||
|
+ autofillProviderContainer);
|
||||||
|
}
|
||||||
if (!mService.getMaster().isPccClassificationEnabled()) {
|
if (!mService.getMaster().isPccClassificationEnabled()) {
|
||||||
|
if (sVerbose) {
|
||||||
|
Slog.v(TAG, "PCC classification is disabled");
|
||||||
|
}
|
||||||
return createShallowCopy(response, autofillProviderContainer);
|
return createShallowCopy(response, autofillProviderContainer);
|
||||||
}
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mClassificationState.mState != ClassificationState.STATE_RESPONSE
|
if (mClassificationState.mState != ClassificationState.STATE_RESPONSE
|
||||||
|| mClassificationState.mLastFieldClassificationResponse == null) {
|
|| mClassificationState.mLastFieldClassificationResponse == null) {
|
||||||
|
if (sVerbose) {
|
||||||
|
Slog.v(TAG, "PCC classification no last response:"
|
||||||
|
+ (mClassificationState.mLastFieldClassificationResponse == null)
|
||||||
|
+ " ,ineligible state="
|
||||||
|
+ (mClassificationState.mState != ClassificationState.STATE_RESPONSE));
|
||||||
|
}
|
||||||
return createShallowCopy(response, autofillProviderContainer);
|
return createShallowCopy(response, autofillProviderContainer);
|
||||||
}
|
}
|
||||||
if (!mClassificationState.processResponse()) return response;
|
if (!mClassificationState.processResponse()) return response;
|
||||||
@@ -1614,11 +1639,22 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
boolean preferAutofillProvider = mService.getMaster().preferProviderOverPcc();
|
boolean preferAutofillProvider = mService.getMaster().preferProviderOverPcc();
|
||||||
boolean shouldUseFallback = mService.getMaster().shouldUsePccFallback();
|
boolean shouldUseFallback = mService.getMaster().shouldUsePccFallback();
|
||||||
if (preferAutofillProvider && !shouldUseFallback) {
|
if (preferAutofillProvider && !shouldUseFallback) {
|
||||||
|
if (sVerbose) {
|
||||||
|
Slog.v(TAG, "preferAutofillProvider but no fallback");
|
||||||
|
}
|
||||||
return createShallowCopy(response, autofillProviderContainer);
|
return createShallowCopy(response, autofillProviderContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DBG) {
|
||||||
|
synchronized (mLock) {
|
||||||
|
Slog.d(TAG, "DBG: ClassificationState: " + mClassificationState);
|
||||||
|
}
|
||||||
|
}
|
||||||
DatasetComputationContainer detectionPccContainer = new DatasetComputationContainer();
|
DatasetComputationContainer detectionPccContainer = new DatasetComputationContainer();
|
||||||
computeDatasetsForPccAndUpdateContainer(response, detectionPccContainer);
|
computeDatasetsForPccAndUpdateContainer(response, detectionPccContainer);
|
||||||
|
if (DBG) {
|
||||||
|
Slog.d(TAG, "DBG: computeDatasetsForPccAndUpdateContainer: " + detectionPccContainer);
|
||||||
|
}
|
||||||
|
|
||||||
DatasetComputationContainer resultContainer;
|
DatasetComputationContainer resultContainer;
|
||||||
if (preferAutofillProvider) {
|
if (preferAutofillProvider) {
|
||||||
@@ -1692,6 +1728,20 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
// FillResponse.
|
// FillResponse.
|
||||||
Set<Dataset> mDatasets = new LinkedHashSet<>();
|
Set<Dataset> mDatasets = new LinkedHashSet<>();
|
||||||
ArrayMap<AutofillId, Set<Dataset>> mAutofillIdToDatasetMap = new ArrayMap<>();
|
ArrayMap<AutofillId, Set<Dataset>> mAutofillIdToDatasetMap = new ArrayMap<>();
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder builder = new StringBuilder("DatasetComputationContainer[");
|
||||||
|
if (mAutofillIds != null) {
|
||||||
|
builder.append(", autofillIds=").append(mAutofillIds);
|
||||||
|
}
|
||||||
|
if (mDatasets != null) {
|
||||||
|
builder.append(", mDatasets=").append(mDatasets);
|
||||||
|
}
|
||||||
|
if (mAutofillIdToDatasetMap != null) {
|
||||||
|
builder.append(", mAutofillIdToDatasetMap=").append(mAutofillIdToDatasetMap);
|
||||||
|
}
|
||||||
|
return builder.append(']').toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds fallback datasets to the first container.
|
// Adds fallback datasets to the first container.
|
||||||
@@ -1843,7 +1893,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
Dataset dataset = datasets.get(i);
|
Dataset dataset = datasets.get(i);
|
||||||
if (dataset.getAutofillDatatypes() == null
|
if (dataset.getAutofillDatatypes() == null
|
||||||
|| dataset.getAutofillDatatypes().isEmpty()) continue;
|
|| dataset.getAutofillDatatypes().isEmpty()) continue;
|
||||||
if (dataset.getFieldIds() != null && dataset.getFieldIds().size() > 0) continue;
|
|
||||||
|
|
||||||
ArrayList<AutofillId> fieldIds = new ArrayList<>();
|
ArrayList<AutofillId> fieldIds = new ArrayList<>();
|
||||||
ArrayList<AutofillValue> fieldValues = new ArrayList<>();
|
ArrayList<AutofillValue> fieldValues = new ArrayList<>();
|
||||||
@@ -1852,9 +1901,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
ArrayList<InlinePresentation> fieldInlinePresentations = new ArrayList<>();
|
ArrayList<InlinePresentation> fieldInlinePresentations = new ArrayList<>();
|
||||||
ArrayList<InlinePresentation> fieldInlineTooltipPresentations = new ArrayList<>();
|
ArrayList<InlinePresentation> fieldInlineTooltipPresentations = new ArrayList<>();
|
||||||
ArrayList<Dataset.DatasetFieldFilter> fieldFilters = new ArrayList<>();
|
ArrayList<Dataset.DatasetFieldFilter> fieldFilters = new ArrayList<>();
|
||||||
|
Set<AutofillId> datasetAutofillIds = new ArraySet<>();
|
||||||
|
|
||||||
for (int j = 0; j < dataset.getAutofillDatatypes().size(); j++) {
|
for (int j = 0; j < dataset.getAutofillDatatypes().size(); j++) {
|
||||||
if (dataset.getAutofillDatatypes().get(0) == null) continue;
|
if (dataset.getAutofillDatatypes().get(j) == null) continue;
|
||||||
String hint = dataset.getAutofillDatatypes().get(j);
|
String hint = dataset.getAutofillDatatypes().get(j);
|
||||||
|
|
||||||
if (hintsToAutofillIdMap.containsKey(hint)) {
|
if (hintsToAutofillIdMap.containsKey(hint)) {
|
||||||
@@ -1863,6 +1913,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
|
|
||||||
for (AutofillId autofillId : tempIds) {
|
for (AutofillId autofillId : tempIds) {
|
||||||
eligibleAutofillIds.add(autofillId);
|
eligibleAutofillIds.add(autofillId);
|
||||||
|
datasetAutofillIds.add(autofillId);
|
||||||
// For each of the field, copy over values.
|
// For each of the field, copy over values.
|
||||||
fieldIds.add(autofillId);
|
fieldIds.add(autofillId);
|
||||||
fieldValues.add(dataset.getFieldValues().get(j));
|
fieldValues.add(dataset.getFieldValues().get(j));
|
||||||
@@ -1876,7 +1927,13 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
dataset.getFieldInlineTooltipPresentation(j));
|
dataset.getFieldInlineTooltipPresentation(j));
|
||||||
fieldFilters.add(dataset.getFilter(j));
|
fieldFilters.add(dataset.getFilter(j));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// TODO(b/266379948): handle the case:
|
||||||
|
// groupHintsToAutofillIdMap.containsKey(hint))
|
||||||
|
// but the autofill id not being applicable to other hints.
|
||||||
|
// TODO(b/266379948): also handle the case where there could be more types in
|
||||||
|
// the dataset, provided by the provider, however, they aren't applicable.
|
||||||
|
}
|
||||||
Dataset newDataset =
|
Dataset newDataset =
|
||||||
new Dataset(
|
new Dataset(
|
||||||
fieldIds,
|
fieldIds,
|
||||||
@@ -1895,10 +1952,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
dataset.getId(),
|
dataset.getId(),
|
||||||
dataset.getAuthentication());
|
dataset.getAuthentication());
|
||||||
eligibleDatasets.add(newDataset);
|
eligibleDatasets.add(newDataset);
|
||||||
|
|
||||||
// Associate this dataset with all the ids that are represented with it.
|
|
||||||
Set<Dataset> newDatasets;
|
Set<Dataset> newDatasets;
|
||||||
for (AutofillId autofillId : tempIds) {
|
for (AutofillId autofillId : datasetAutofillIds) {
|
||||||
if (map.containsKey(autofillId)) {
|
if (map.containsKey(autofillId)) {
|
||||||
newDatasets = map.get(autofillId);
|
newDatasets = map.get(autofillId);
|
||||||
} else {
|
} else {
|
||||||
@@ -1908,13 +1963,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
map.put(autofillId, newDatasets);
|
map.put(autofillId, newDatasets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO(b/266379948): handle the case:
|
|
||||||
// groupHintsToAutofillIdMap.containsKey(hint))
|
|
||||||
// but the autofill id not being applicable to other hints.
|
|
||||||
// TODO(b/266379948): also handle the case where there could be more types in
|
|
||||||
// the dataset, provided by the provider, however, they aren't applicable.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
container.mAutofillIds = eligibleAutofillIds;
|
container.mAutofillIds = eligibleAutofillIds;
|
||||||
container.mDatasets = eligibleDatasets;
|
container.mDatasets = eligibleDatasets;
|
||||||
container.mAutofillIdToDatasetMap = map;
|
container.mAutofillIdToDatasetMap = map;
|
||||||
@@ -5319,6 +5367,26 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
mState = STATE_PENDING_REQUEST;
|
mState = STATE_PENDING_REQUEST;
|
||||||
mPendingFieldClassificationRequest = null;
|
mPendingFieldClassificationRequest = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GuardedBy("mLock")
|
||||||
|
private boolean shouldTriggerRequest() {
|
||||||
|
return mState == STATE_INITIAL || mState == STATE_INVALIDATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GuardedBy("mLock")
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ClassificationState: ["
|
||||||
|
+ "state=" + stateToString()
|
||||||
|
+ ", mPendingFieldClassificationRequest=" + mPendingFieldClassificationRequest
|
||||||
|
+ ", mLastFieldClassificationResponse=" + mLastFieldClassificationResponse
|
||||||
|
+ ", mClassificationHintsMap=" + mClassificationHintsMap
|
||||||
|
+ ", mClassificationGroupHintsMap=" + mClassificationGroupHintsMap
|
||||||
|
+ ", mHintsToAutofillIdMap=" + mHintsToAutofillIdMap
|
||||||
|
+ ", mGroupHintsToAutofillIdMap=" + mGroupHintsToAutofillIdMap
|
||||||
|
+ "]";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -5843,7 +5911,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
return serviceInfo == null ? Process.INVALID_UID : serviceInfo.applicationInfo.uid;
|
return serviceInfo == null ? Process.INVALID_UID : serviceInfo.applicationInfo.uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DetectionServiceCallbacks
|
// FieldClassificationServiceCallbacks
|
||||||
public void onClassificationRequestSuccess(@Nullable FieldClassificationResponse response) {
|
public void onClassificationRequestSuccess(@Nullable FieldClassificationResponse response) {
|
||||||
mClassificationState.updateResponseReceived(response);
|
mClassificationState.updateResponseReceived(response);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user