Merge "Don't automatically autofill when manual request returned just 1 dataset." into oc-dev

This commit is contained in:
TreeHugger Robot
2017-05-31 20:43:14 +00:00
committed by Android (Google) Code Review
4 changed files with 23 additions and 39 deletions

View File

@@ -16,6 +16,8 @@
package android.view.autofill; package android.view.autofill;
import static android.view.autofill.Helper.sVerbose;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@@ -186,6 +188,10 @@ public class AutofillPopupWindow extends PopupWindow {
@Override @Override
public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) { 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()) { if (isShowing()) {
return; return;
} }

View File

@@ -419,7 +419,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
notifyUnavailableToClient(); notifyUnavailableToClient();
} }
synchronized (mLock) { synchronized (mLock) {
processResponseLocked(response); processResponseLocked(response, requestFlags);
} }
final LogMaker log = (new LogMaker(MetricsEvent.AUTOFILL_REQUEST)) final LogMaker log = (new LogMaker(MetricsEvent.AUTOFILL_REQUEST))
@@ -1026,7 +1026,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
case ACTION_START_SESSION: case ACTION_START_SESSION:
// View is triggering autofill. // View is triggering autofill.
mCurrentViewId = viewState.id; mCurrentViewId = viewState.id;
viewState.update(value, virtualBounds); viewState.update(value, virtualBounds, flags);
viewState.setState(ViewState.STATE_STARTED_SESSION); viewState.setState(ViewState.STATE_STARTED_SESSION);
requestNewFillResponseLocked(flags); requestNewFillResponseLocked(flags);
break; break;
@@ -1065,7 +1065,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
} }
// If the ViewState is ready to be displayed, onReady() will be called. // If the ViewState is ready to be displayed, onReady() will be called.
viewState.update(value, virtualBounds); viewState.update(value, virtualBounds, flags);
break; break;
case ACTION_VIEW_EXITED: case ACTION_VIEW_EXITED:
if (mCurrentViewId == viewState.id) { if (mCurrentViewId == viewState.id) {
@@ -1204,10 +1204,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
// Replace the old response // Replace the old response
mResponses.put(newResponse.getRequestId(), newResponse); mResponses.put(newResponse.getRequestId(), newResponse);
// Now process the new response // 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 // Make sure we are hiding the UI which will be shown
// only if handling the current response requires it. // only if handling the current response requires it.
hideAllUiIfOwnedByMe(); hideAllUiIfOwnedByMe();
@@ -1215,7 +1215,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
final int requestId = newResponse.getRequestId(); final int requestId = newResponse.getRequestId();
if (sVerbose) { if (sVerbose) {
Slog.v(TAG, "processResponseLocked(): mCurrentViewId=" + mCurrentViewId Slog.v(TAG, "processResponseLocked(): mCurrentViewId=" + mCurrentViewId
+ ", reqId=" + requestId + ", resp=" + newResponse); + ",flags=" + flags + ", reqId=" + requestId + ", resp=" + newResponse);
} }
if (mResponses == null) { if (mResponses == null) {
@@ -1231,21 +1231,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
return; 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. // Updates the UI, if necessary.
final ViewState currentView = mViewStates.get(mCurrentViewId); final ViewState currentView = mViewStates.get(mCurrentViewId);
currentView.maybeCallOnFillReady(); currentView.maybeCallOnFillReady(flags);
} }
/** /**
@@ -1331,20 +1319,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
return 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) { void autoFill(int requestId, int datasetIndex, Dataset dataset) {
synchronized (mLock) { synchronized (mLock) {
if (mDestroyed) { if (mDestroyed) {
@@ -1452,8 +1426,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
return; return;
} }
try { try {
if (sDebug) Slog.d(TAG, "autoFillApp(): the buck is on the app: " + dataset);
// Skip null values as a null values means no change // Skip null values as a null values means no change
final int entryCount = dataset.getFieldIds().size(); final int entryCount = dataset.getFieldIds().size();
final List<AutofillId> ids = new ArrayList<>(entryCount); final List<AutofillId> ids = new ArrayList<>(entryCount);
@@ -1480,6 +1452,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
if (waitingDatasetAuth) { if (waitingDatasetAuth) {
hideFillUiIfOwnedByMe(); hideFillUiIfOwnedByMe();
} }
if (sDebug) Slog.d(TAG, "autoFillApp(): the buck is on the app: " + dataset);
mClient.autofill(id, ids, values); mClient.autofill(id, ids, values);
setViewStatesLocked(null, dataset, ViewState.STATE_AUTOFILLED, false); setViewStatesLocked(null, dataset, ViewState.STATE_AUTOFILLED, false);
} }

View File

@@ -16,6 +16,7 @@
package com.android.server.autofill; 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.sDebug;
import static com.android.server.autofill.Helper.sVerbose; 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 // 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 // that it can change the value and update the UI; similarly, should replace code that
// directly sets mAutofillValue to use encapsulation. // 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) { if (autofillValue != null) {
mCurrentValue = autofillValue; mCurrentValue = autofillValue;
} }
@@ -165,7 +166,7 @@ final class ViewState {
mVirtualBounds = virtualBounds; mVirtualBounds = virtualBounds;
} }
maybeCallOnFillReady(); maybeCallOnFillReady(flags);
} }
/** /**
@@ -173,8 +174,8 @@ final class ViewState {
* Listener#onFillReady(FillResponse, AutofillId, AutofillValue)} if the * Listener#onFillReady(FillResponse, AutofillId, AutofillValue)} if the
* fill UI is ready to be displayed (i.e. when response and bounds are set). * fill UI is ready to be displayed (i.e. when response and bounds are set).
*/ */
void maybeCallOnFillReady() { void maybeCallOnFillReady(int flags) {
if ((mState & STATE_AUTOFILLED) != 0) { if ((mState & STATE_AUTOFILLED) != 0 && (flags & FLAG_MANUAL_REQUEST) == 0) {
if (sDebug) Slog.d(TAG, "Ignoring UI for " + id + " on " + getStateAsString()); if (sDebug) Slog.d(TAG, "Ignoring UI for " + id + " on " + getStateAsString());
return; return;
} }

View File

@@ -158,6 +158,7 @@ final class FillUi {
final RemoteViews presentation = dataset.getFieldPresentation(index); final RemoteViews presentation = dataset.getFieldPresentation(index);
final View view; final View view;
try { try {
if (sVerbose) Slog.v(TAG, "setting remote view for " + focusedViewId);
view = presentation.apply(context, null, interceptionHandler); view = presentation.apply(context, null, interceptionHandler);
} catch (RuntimeException e) { } catch (RuntimeException e) {
Slog.e(TAG, "Error inflating remote views", e); Slog.e(TAG, "Error inflating remote views", e);
@@ -203,6 +204,7 @@ final class FillUi {
return; return;
} }
if (count <= 0) { if (count <= 0) {
if (sDebug) Slog.d(TAG, "No dataset matches filter: " + mFilterText);
mCallback.requestHideFillUi(); mCallback.requestHideFillUi();
} else { } else {
if (updateContentSize()) { if (updateContentSize()) {
@@ -382,6 +384,7 @@ final class FillUi {
* Shows the window. * Shows the window.
*/ */
public void show(WindowManager.LayoutParams params) { public void show(WindowManager.LayoutParams params) {
if (sVerbose) Slog.v(TAG, "show(): showing=" + mShowing + ", params="+ params);
try { try {
if (!mShowing) { if (!mShowing) {
params.accessibilityTitle = mContentView.getContext() params.accessibilityTitle = mContentView.getContext()