Merge "Rollback dropdown or inline suggestions when cancel fill dialog" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-05-06 01:54:44 +00:00
committed by Android (Google) Code Review
3 changed files with 53 additions and 20 deletions

View File

@@ -1559,9 +1559,18 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
Slog.e(TAG, "Error sending input show up notification", e);
}
}
}
// AutoFillUiCallback
@Override
public void requestFallbackFromFillDialog() {
setFillDialogDisabled();
synchronized (mLock) {
// stop to show fill dialog
mSessionFlags.mFillDialogDisabled = true;
if (mCurrentViewId == null) {
return;
}
final ViewState currentView = mViewStates.get(mCurrentViewId);
currentView.maybeCallOnFillReady(mFlags);
}
}
@@ -3208,17 +3217,20 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
return;
}
if (requestShowFillDialog(response, filledId, filterText, flags)) {
synchronized (mLock) {
final ViewState currentView = mViewStates.get(mCurrentViewId);
currentView.setState(ViewState.STATE_FILL_DIALOG_SHOWN);
mService.logDatasetShown(id, mClientState, UI_TYPE_DIALOG);
final AutofillId[] ids = response.getFillDialogTriggerIds();
if (ids != null && ArrayUtils.contains(ids, filledId)) {
if (requestShowFillDialog(response, filledId, filterText, flags)) {
synchronized (mLock) {
final ViewState currentView = mViewStates.get(mCurrentViewId);
currentView.setState(ViewState.STATE_FILL_DIALOG_SHOWN);
mService.logDatasetShown(id, mClientState, UI_TYPE_DIALOG);
}
return;
} else {
setFillDialogDisabled();
}
return;
}
setFillDialogDisabled();
if (response.supportsInlineSuggestions()) {
synchronized (mLock) {
if (requestShowInlineSuggestionsLocked(response, filterText)) {
@@ -3324,15 +3336,11 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
return false;
}
final AutofillId[] ids = response.getFillDialogTriggerIds();
if (ids == null || !ArrayUtils.contains(ids, filledId)) {
return false;
}
final Drawable serviceIcon = getServiceIcon();
getUiForShowing().showFillDialog(filledId, response, filterText,
mService.getServicePackageName(), mComponentName, serviceIcon, this);
mService.getServicePackageName(), mComponentName, serviceIcon, this,
id, mCompatMode);
return true;
}

View File

@@ -97,6 +97,7 @@ public final class AutoFillUI {
void dispatchUnhandledKey(AutofillId id, KeyEvent keyEvent);
void cancelSession();
void requestShowSoftInput(AutofillId id);
void requestFallbackFromFillDialog();
}
public AutoFillUI(@NonNull Context context) {
@@ -388,13 +389,19 @@ public final class AutoFillUI {
public void showFillDialog(@NonNull AutofillId focusedId, @NonNull FillResponse response,
@Nullable String filterText, @Nullable String servicePackageName,
@NonNull ComponentName componentName, @Nullable Drawable serviceIcon,
@NonNull AutoFillUiCallback callback) {
@NonNull AutoFillUiCallback callback, int sessionId, boolean compatMode) {
if (sVerbose) {
Slog.v(TAG, "showFillDialog for "
+ componentName.toShortString() + ": " + response);
}
// TODO: enable LogMaker
final LogMaker log = Helper
.newLogMaker(MetricsEvent.AUTOFILL_FILL_UI, componentName, servicePackageName,
sessionId, compatMode)
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_FILTERTEXT_LEN,
filterText == null ? 0 : filterText.length())
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_DATASETS,
response.getDatasets() == null ? 0 : response.getDatasets().size());
mHandler.post(() -> {
if (callback != mCallback) {
@@ -406,6 +413,7 @@ public final class AutoFillUI {
mUiModeMgr.isNightMode(), new DialogFillUi.UiCallback() {
@Override
public void onResponsePicked(FillResponse response) {
log(MetricsEvent.TYPE_DETAIL);
hideFillDialogUiThread(callback);
if (mCallback != null) {
mCallback.authenticate(response.getRequestId(),
@@ -417,6 +425,7 @@ public final class AutoFillUI {
@Override
public void onDatasetPicked(Dataset dataset) {
log(MetricsEvent.TYPE_ACTION);
hideFillDialogUiThread(callback);
if (mCallback != null) {
final int datasetIndex = response.getDatasets().indexOf(dataset);
@@ -426,15 +435,29 @@ public final class AutoFillUI {
}
@Override
public void onCanceled() {
public void onDismissed() {
log(MetricsEvent.TYPE_DISMISS);
hideFillDialogUiThread(callback);
callback.requestShowSoftInput(focusedId);
}
@Override
public void onCanceled() {
log(MetricsEvent.TYPE_CLOSE);
hideFillDialogUiThread(callback);
callback.requestShowSoftInput(focusedId);
callback.requestFallbackFromFillDialog();
}
@Override
public void startIntentSender(IntentSender intentSender) {
mCallback.startIntentSenderAndFinishSession(intentSender);
}
private void log(int type) {
log.setType(type);
mMetricsLogger.write(log);
}
});
});
}

View File

@@ -81,6 +81,7 @@ final class DialogFillUi {
interface UiCallback {
void onResponsePicked(@NonNull FillResponse response);
void onDatasetPicked(@NonNull Dataset dataset);
void onDismissed();
void onCanceled();
void startIntentSender(IntentSender intentSender);
}
@@ -144,6 +145,7 @@ final class DialogFillUi {
mDialog = new Dialog(mContext, mThemeId);
mDialog.setContentView(decor);
setDialogParamsAsBottomSheet();
mDialog.setOnCancelListener((d) -> mCallback.onCanceled());
show();
}
@@ -220,7 +222,7 @@ final class DialogFillUi {
final TextView noButton = decor.findViewById(R.id.autofill_dialog_no);
// set "No thinks" by default
noButton.setText(R.string.autofill_save_no);
noButton.setOnClickListener((v) -> mCallback.onCanceled());
noButton.setOnClickListener((v) -> mCallback.onDismissed());
}
private void setContinueButton(View decor, View.OnClickListener listener) {