From 8fd057532783fda6f5187431ed2afac72d3bb0e8 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Fri, 5 May 2017 14:02:21 -0700 Subject: [PATCH] Fixed scenario where an authentication response has no dataset. Also use getUiForShowing() on all relevant places, and added missing SaveDataType value. Test: LoginActivityTest.testFillResponseAuthServiceHasNoData() Test: manual verification Fixes: 37711385 Fixes: 38009452 Change-Id: Id69c831f96fb9ac35d1f2d86cfd41e76428c776e --- .../android/service/autofill/SaveInfo.java | 1 + .../com/android/server/autofill/Helper.java | 6 ---- .../com/android/server/autofill/Session.java | 33 +++++++++++-------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/core/java/android/service/autofill/SaveInfo.java b/core/java/android/service/autofill/SaveInfo.java index 277c6223985b5..9487760780e3d 100644 --- a/core/java/android/service/autofill/SaveInfo.java +++ b/core/java/android/service/autofill/SaveInfo.java @@ -174,6 +174,7 @@ public final class SaveInfo implements Parcelable { SAVE_DATA_TYPE_PASSWORD, SAVE_DATA_TYPE_ADDRESS, SAVE_DATA_TYPE_CREDIT_CARD, + SAVE_DATA_TYPE_USERNAME, SAVE_DATA_TYPE_EMAIL_ADDRESS}) @Retention(RetentionPolicy.SOURCE) @interface SaveDataType{} diff --git a/services/autofill/java/com/android/server/autofill/Helper.java b/services/autofill/java/com/android/server/autofill/Helper.java index cbf97ddc8abb4..8d947b92159c7 100644 --- a/services/autofill/java/com/android/server/autofill/Helper.java +++ b/services/autofill/java/com/android/server/autofill/Helper.java @@ -20,9 +20,7 @@ import android.annotation.NonNull; import android.app.assist.AssistStructure; import android.app.assist.AssistStructure.ViewNode; import android.os.Bundle; -import android.util.DebugUtils; import android.view.autofill.AutofillId; -import android.view.autofill.AutofillManager; import java.util.Arrays; import java.util.Objects; @@ -68,10 +66,6 @@ public final class Helper { return builder.toString(); } - static String getUpdateActionAsString(int action) { - return DebugUtils.flagsToString(AutofillManager.class, "ACTION_", action); - } - static ViewNode findViewNodeById(@NonNull AssistStructure structure, @NonNull AutofillId id) { final int size = structure.getWindowNodeCount(); for (int i = 0; i < size; i++) { diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index 23b734adaa9af..25bb7cc094186 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -26,7 +26,6 @@ import static android.view.autofill.AutofillManager.ACTION_VIEW_ENTERED; import static android.view.autofill.AutofillManager.ACTION_VIEW_EXITED; import static com.android.server.autofill.Helper.findViewNodeById; -import static com.android.server.autofill.Helper.getUpdateActionAsString; import static com.android.server.autofill.Helper.sDebug; import static com.android.server.autofill.Helper.sVerbose; import static com.android.server.autofill.ViewState.STATE_AUTOFILLED; @@ -679,6 +678,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } else { final Parcelable result = data.getParcelable( AutofillManager.EXTRA_AUTHENTICATION_RESULT); + if (sVerbose) Slog.d(TAG, "setAuthenticationResultLocked() for " + result); + if (result instanceof FillResponse) { FillResponse response = (FillResponse) result; @@ -687,6 +688,16 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState mResponseWaitingAuth = null; if (requestIndex >= 0) { response.setRequestId(mResponses.keyAt(requestIndex)); + if (response.getDatasets() == null || response.getDatasets().isEmpty()) { + // TODO(b/37424539): there is a race condition that causes the authentication + // dialog to be shown again after the service authreplied with a no-datasets + // response. We're fixing it by hiding the UI when that happens, but that + // sounds like a hack - hopefully the real problem will go away when we + // refactor auth to support partitions; if it doesn't, we need to + // investigate it further (it can be reproduced by running + // LoginActivityTest.testFillResponseAuthServiceHasNoData()) + mUi.hideAll(); + } processResponseLocked(response); } else { Slog.e(TAG, "Error cannot find id for auth response"); @@ -986,18 +997,14 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return; } if (sVerbose) { - Slog.v(TAG, "updateLocked(): id=" + id + ", action=" + getUpdateActionAsString(action) - + ", flags=" + flags); + Slog.v(TAG, "updateLocked(): id=" + id + ", action=" + action + ", flags=" + flags); } ViewState viewState = mViewStates.get(id); if (viewState == null) { if (action == ACTION_START_SESSION || action == ACTION_VALUE_CHANGED || action == ACTION_VIEW_ENTERED) { - if (sVerbose) { - Slog.v(TAG, - "Creating viewState for " + id + " on " + getActionAsString(action)); - } + if (sVerbose) Slog.v(TAG, "Creating viewState for " + id + " on " + action); boolean isIgnored = isIgnoredLocked(id); viewState = new ViewState(this, id, value, this, isIgnored ? ViewState.STATE_IGNORED : ViewState.STATE_INITIAL); @@ -1007,7 +1014,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return; } } else { - if (sVerbose) Slog.v(TAG, "Ignored " + getActionAsString(action) + " for " + id); + if (sVerbose) Slog.v(TAG, "Ignored action " + action + " for " + id); return; } } @@ -1056,6 +1063,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState break; case ACTION_VIEW_EXITED: if (mCurrentViewId == viewState.id) { + if (sVerbose) Slog.d(TAG, "Exiting view " + id); mUi.hideFillUi(viewState.id); mCurrentViewId = null; } @@ -1096,10 +1104,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState getUiForShowing().showFillUi(filledId, response, filterText, mPackageName); } - String getActionAsString(int flag) { - return DebugUtils.flagsToString(AutofillManager.class, "ACTION_", flag); - } - boolean isDestroyed() { synchronized (mLock) { return mDestroyed; @@ -1158,14 +1162,15 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } private void processResponseLocked(@NonNull FillResponse response) { + final int requestId = response.getRequestId(); if (sVerbose) { - Slog.v(TAG, "processResponseLocked(mCurrentViewId=" + mCurrentViewId + "):" + response); + Slog.v(TAG, "processResponseLocked(): mCurrentViewId=" + mCurrentViewId + + ", reqId=" + requestId + ", resp=" + response); } if (mResponses == null) { mResponses = new SparseArray<>(4); } - final int requestId = response.getRequestId(); mResponses.put(requestId, response); mClientState = response.getClientState();