Merge "Don't automatically autofill when manual request returned just 1 dataset." into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d8d9758363
@@ -16,6 +16,8 @@
|
||||
|
||||
package android.view.autofill;
|
||||
|
||||
import static android.view.autofill.Helper.sVerbose;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -186,6 +188,10 @@ public class AutofillPopupWindow extends PopupWindow {
|
||||
|
||||
@Override
|
||||
public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {
|
||||
if (sVerbose) {
|
||||
Log.v(TAG, "showAsDropDown(): anchor=" + anchor + ", xoff=" + xoff + ", yoff=" + yoff
|
||||
+ ", isShowing(): " + isShowing());
|
||||
}
|
||||
if (isShowing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
notifyUnavailableToClient();
|
||||
}
|
||||
synchronized (mLock) {
|
||||
processResponseLocked(response);
|
||||
processResponseLocked(response, requestFlags);
|
||||
}
|
||||
|
||||
final LogMaker log = (new LogMaker(MetricsEvent.AUTOFILL_REQUEST))
|
||||
@@ -1026,7 +1026,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
case ACTION_START_SESSION:
|
||||
// View is triggering autofill.
|
||||
mCurrentViewId = viewState.id;
|
||||
viewState.update(value, virtualBounds);
|
||||
viewState.update(value, virtualBounds, flags);
|
||||
viewState.setState(ViewState.STATE_STARTED_SESSION);
|
||||
requestNewFillResponseLocked(flags);
|
||||
break;
|
||||
@@ -1065,7 +1065,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
}
|
||||
|
||||
// If the ViewState is ready to be displayed, onReady() will be called.
|
||||
viewState.update(value, virtualBounds);
|
||||
viewState.update(value, virtualBounds, flags);
|
||||
break;
|
||||
case ACTION_VIEW_EXITED:
|
||||
if (mCurrentViewId == viewState.id) {
|
||||
@@ -1204,10 +1204,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
// Replace the old response
|
||||
mResponses.put(newResponse.getRequestId(), newResponse);
|
||||
// Now process the new response
|
||||
processResponseLocked(newResponse);
|
||||
processResponseLocked(newResponse, 0);
|
||||
}
|
||||
|
||||
private void processResponseLocked(@NonNull FillResponse newResponse) {
|
||||
private void processResponseLocked(@NonNull FillResponse newResponse, int flags) {
|
||||
// Make sure we are hiding the UI which will be shown
|
||||
// only if handling the current response requires it.
|
||||
hideAllUiIfOwnedByMe();
|
||||
@@ -1215,7 +1215,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
final int requestId = newResponse.getRequestId();
|
||||
if (sVerbose) {
|
||||
Slog.v(TAG, "processResponseLocked(): mCurrentViewId=" + mCurrentViewId
|
||||
+ ", reqId=" + requestId + ", resp=" + newResponse);
|
||||
+ ",flags=" + flags + ", reqId=" + requestId + ", resp=" + newResponse);
|
||||
}
|
||||
|
||||
if (mResponses == null) {
|
||||
@@ -1231,21 +1231,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
return;
|
||||
}
|
||||
|
||||
final ArrayList<Dataset> datasets = newResponse.getDatasets();
|
||||
|
||||
if (datasets != null && datasets.size() == 1) {
|
||||
// Check if it its a single response for a manual request, in which case it should
|
||||
// be automatically filled
|
||||
final FillContext context = getFillContextByRequestIdLocked(requestId);
|
||||
if (context != null && (context.getStructure().getFlags() & FLAG_MANUAL_REQUEST) != 0) {
|
||||
Slog.d(TAG, "autofilling manual request directly");
|
||||
autoFill(requestId, 0, datasets.get(0));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Updates the UI, if necessary.
|
||||
final ViewState currentView = mViewStates.get(mCurrentViewId);
|
||||
currentView.maybeCallOnFillReady();
|
||||
currentView.maybeCallOnFillReady(flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1331,20 +1319,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
return viewState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the given state from all existing views in the given dataset.
|
||||
*/
|
||||
private void resetViewStatesLocked(@NonNull Dataset dataset, int state) {
|
||||
final ArrayList<AutofillId> ids = dataset.getFieldIds();
|
||||
for (int j = 0; j < ids.size(); j++) {
|
||||
final AutofillId id = ids.get(j);
|
||||
final ViewState viewState = mViewStates.get(id);
|
||||
if (viewState != null) {
|
||||
viewState.resetState(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void autoFill(int requestId, int datasetIndex, Dataset dataset) {
|
||||
synchronized (mLock) {
|
||||
if (mDestroyed) {
|
||||
@@ -1452,8 +1426,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (sDebug) Slog.d(TAG, "autoFillApp(): the buck is on the app: " + dataset);
|
||||
|
||||
// Skip null values as a null values means no change
|
||||
final int entryCount = dataset.getFieldIds().size();
|
||||
final List<AutofillId> ids = new ArrayList<>(entryCount);
|
||||
@@ -1480,6 +1452,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
||||
if (waitingDatasetAuth) {
|
||||
hideFillUiIfOwnedByMe();
|
||||
}
|
||||
if (sDebug) Slog.d(TAG, "autoFillApp(): the buck is on the app: " + dataset);
|
||||
|
||||
mClient.autofill(id, ids, values);
|
||||
setViewStatesLocked(null, dataset, ViewState.STATE_AUTOFILLED, false);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.server.autofill;
|
||||
|
||||
import static android.service.autofill.FillRequest.FLAG_MANUAL_REQUEST;
|
||||
import static com.android.server.autofill.Helper.sDebug;
|
||||
import static com.android.server.autofill.Helper.sVerbose;
|
||||
|
||||
@@ -157,7 +158,7 @@ final class ViewState {
|
||||
// TODO: refactor / rename / document this method (and maybeCallOnFillReady) to make it clear
|
||||
// that it can change the value and update the UI; similarly, should replace code that
|
||||
// directly sets mAutofillValue to use encapsulation.
|
||||
void update(@Nullable AutofillValue autofillValue, @Nullable Rect virtualBounds) {
|
||||
void update(@Nullable AutofillValue autofillValue, @Nullable Rect virtualBounds, int flags) {
|
||||
if (autofillValue != null) {
|
||||
mCurrentValue = autofillValue;
|
||||
}
|
||||
@@ -165,7 +166,7 @@ final class ViewState {
|
||||
mVirtualBounds = virtualBounds;
|
||||
}
|
||||
|
||||
maybeCallOnFillReady();
|
||||
maybeCallOnFillReady(flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,8 +174,8 @@ final class ViewState {
|
||||
* Listener#onFillReady(FillResponse, AutofillId, AutofillValue)} if the
|
||||
* fill UI is ready to be displayed (i.e. when response and bounds are set).
|
||||
*/
|
||||
void maybeCallOnFillReady() {
|
||||
if ((mState & STATE_AUTOFILLED) != 0) {
|
||||
void maybeCallOnFillReady(int flags) {
|
||||
if ((mState & STATE_AUTOFILLED) != 0 && (flags & FLAG_MANUAL_REQUEST) == 0) {
|
||||
if (sDebug) Slog.d(TAG, "Ignoring UI for " + id + " on " + getStateAsString());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -158,6 +158,7 @@ final class FillUi {
|
||||
final RemoteViews presentation = dataset.getFieldPresentation(index);
|
||||
final View view;
|
||||
try {
|
||||
if (sVerbose) Slog.v(TAG, "setting remote view for " + focusedViewId);
|
||||
view = presentation.apply(context, null, interceptionHandler);
|
||||
} catch (RuntimeException e) {
|
||||
Slog.e(TAG, "Error inflating remote views", e);
|
||||
@@ -203,6 +204,7 @@ final class FillUi {
|
||||
return;
|
||||
}
|
||||
if (count <= 0) {
|
||||
if (sDebug) Slog.d(TAG, "No dataset matches filter: " + mFilterText);
|
||||
mCallback.requestHideFillUi();
|
||||
} else {
|
||||
if (updateContentSize()) {
|
||||
@@ -382,6 +384,7 @@ final class FillUi {
|
||||
* Shows the window.
|
||||
*/
|
||||
public void show(WindowManager.LayoutParams params) {
|
||||
if (sVerbose) Slog.v(TAG, "show(): showing=" + mShowing + ", params="+ params);
|
||||
try {
|
||||
if (!mShowing) {
|
||||
params.accessibilityTitle = mContentView.getContext()
|
||||
|
||||
Reference in New Issue
Block a user