Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01ca2d04 authored by Tim Yu's avatar Tim Yu
Browse files

Fix Autofill's DATASETS_SHOWN event to be triggered when the UI shows,

instead of before.

Note: this also fixes cases in which DATASET_SHOWN events were logged
multiple times but only shown once.

Test: atest
* android.autofillservice.cts.inline.InlineFillEventHistoryTest
* android.autofillservice.cts.dropdown.FillEventHistoryTest
* manually test filldialog history

Bug: 230363706
Change-Id: I7076621490a64ef52b11180970494d4313936f69
parent 0eb9f586
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -849,7 +849,6 @@ final class AutofillManagerServiceImpl
        }
    }


    /**
     * Updates the last fill response when a view was entered.
     */
+5 −0
Original line number Diff line number Diff line
@@ -356,6 +356,11 @@ final class RemoteAugmentedAutofillService
                            public void onError() {
                                onErrorCallback.run();
                            }

                            @Override
                            public void onInflate() {
                                /* nothing */
                            }
                        });

        if (inlineSuggestionsCallback.apply(inlineFillUi)) {
+30 −7
Original line number Diff line number Diff line
@@ -276,6 +276,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    @GuardedBy("mLock")
    private DeathRecipient mClientVulture;

    @GuardedBy("mLock")
    private boolean mLoggedInlineDatasetShown;

    /**
     * Reference to the remote service.
     *
@@ -1981,6 +1984,22 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                Session::removeFromService, this));
    }

    // AutofillUiCallback
    @Override
    public void onShown(int uiType) {
        synchronized (mLock) {
            if (uiType == UI_TYPE_INLINE) {
                if (mLoggedInlineDatasetShown) {
                    // Chip inflation already logged, do not log again.
                    // This is needed because every chip inflation will call this.
                    return;
                }
                mLoggedInlineDatasetShown = true;
            }
            mService.logDatasetShown(this.id, mClientState, uiType);
        }
    }

    // AutoFillUiCallback
    @Override
    public void requestShowFillUi(AutofillId id, int width, int height,
@@ -3861,8 +3880,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                synchronized (mLock) {
                    final ViewState currentView = mViewStates.get(mCurrentViewId);
                    currentView.setState(ViewState.STATE_FILL_DIALOG_SHOWN);
                    mService.logDatasetShown(id, mClientState, UI_TYPE_DIALOG);

                    mPresentationStatsEventLogger.maybeSetCountShown(
                            response.getDatasets(), mCurrentViewId);
                    mPresentationStatsEventLogger.maybeSetDisplayPresentationType(UI_TYPE_DIALOG);
@@ -3892,10 +3909,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                    // back a response via callback.
                    final ViewState currentView = mViewStates.get(mCurrentViewId);
                    currentView.setState(ViewState.STATE_INLINE_SHOWN);
                    // TODO(b/248378401): Fix it to log showed only when IME asks for inflation,
                    // rather than here where framework sends back the response.
                    mService.logDatasetShown(id, mClientState, UI_TYPE_INLINE);

                    // TODO(b/234475358): Log more accurate value of number of inline suggestions
                    // shown, inflated, and filtered.
                    mPresentationStatsEventLogger.maybeSetCountShown(
@@ -3912,7 +3925,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                targetLabel, targetIcon, this, id, mCompatMode);

        synchronized (mLock) {
            mService.logDatasetShown(id, mClientState, UI_TYPE_MENU);
            mPresentationStatsEventLogger.maybeSetCountShown(
                    response.getDatasets(), mCurrentViewId);
            mPresentationStatsEventLogger.maybeSetDisplayPresentationType(UI_TYPE_MENU);
@@ -4124,6 +4136,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            return false;
        }

        // Set this to false - we are requesting a new inline request and haven't shown
        // anything yet
        synchronized (mLock) {
            mLoggedInlineDatasetShown = false;
        }

        final InlineFillUi.InlineFillUiInfo inlineFillUiInfo =
                new InlineFillUi.InlineFillUiInfo(request, focusedId,
                        filterText, remoteRenderService, userId, id);
@@ -4153,6 +4171,11 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                                    InlineFillUi.emptyUi(focusedId));
                        }
                    }

                    @Override
                    public void onInflate() {
                        Session.this.onShown(UI_TYPE_INLINE);
                    }
                });
        return mInlineSessionController.setInlineFillUiLocked(inlineFillUi);
    }
+13 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ public final class AutoFillUI {
        void cancelSession();
        void requestShowSoftInput(AutofillId id);
        void requestFallbackFromFillDialog();
        void onShown(int uiType);
    }

    public AutoFillUI(@NonNull Context context) {
@@ -236,6 +237,13 @@ public final class AutoFillUI {
                    }
                }

                @Override
                public void onShown() {
                    if (mCallback != null) {
                        mCallback.onShown(UI_TYPE_MENU);
                    }
                }

                @Override
                public void onDatasetPicked(Dataset dataset) {
                    log.setType(MetricsEvent.TYPE_ACTION);
@@ -423,6 +431,11 @@ public final class AutoFillUI {
                            }
                        }

                        @Override
                        public void onShown() {
                            callback.onShown(UI_TYPE_DIALOG);
                        }

                        @Override
                        public void onDatasetPicked(Dataset dataset) {
                            log(MetricsEvent.TYPE_ACTION);
+2 −1
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ final class DialogFillUi {
        void onDatasetPicked(@NonNull Dataset dataset);
        void onDismissed();
        void onCanceled();
        void onShown();
        void startIntentSender(IntentSender intentSender);
    }

@@ -148,7 +149,7 @@ final class DialogFillUi {
        mDialog.setContentView(decor);
        setDialogParamsAsBottomSheet();
        mDialog.setOnCancelListener((d) -> mCallback.onCanceled());

        mDialog.setOnShowListener((d) -> mCallback.onShown());
        show();
    }

Loading