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

Commit 0d50b26f authored by Felipe Leme's avatar Felipe Leme Committed by android-build-merger
Browse files

Fixed how FillEventHistory is reset and clarified javadoc. am: 2e30c6f3

am: 9cd1c528

Change-Id: Ida68112cd418e241b95ce3c65b37169b9098c053
parents 70a5df72 9cd1c528
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -208,12 +208,22 @@ public abstract class AutofillService extends Service {
    }

    /**
     * Returns the {@link FillEventHistory.Event events} since the last {@link FillResponse} was
     * returned.
     * Gets the events that happened after the last
     * {@link AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback)}
     * call.
     *
     * <p>The history is not persisted over reboots.
     * <p>This method is typically used to keep track of previous user actions to optimize further
     * requests. For example, the service might return email addresses in alphabetical order by
     * default, but change that order based on the address the user picked on previous requests.
     *
     * @return The history or {@code null} if there are not events.
     * <p>The history is not persisted over reboots, and it's cleared every time the service
     * replies to a {@link #onFillRequest(FillRequest, CancellationSignal, FillCallback)} by calling
     * {@link FillCallback#onSuccess(FillResponse)} or {@link FillCallback#onFailure(CharSequence)}
     * (if the service doesn't call any of these methods, the history will clear out after some
     * pre-defined time). Hence, the service should call {@link #getFillEventHistory()} before
     * finishing the {@link FillCallback}.
     *
     * @return The history or {@code null} if there are no events.
     */
    @Nullable public final FillEventHistory getFillEventHistory() {
        AutofillManager afm = getSystemService(AutofillManager.class);
+18 −3
Original line number Diff line number Diff line
@@ -33,7 +33,20 @@ import java.util.ArrayList;
import java.util.List;

/**
 * Describes what happened after the latest call to {@link FillCallback#onSuccess(FillResponse)}.
 * Describes what happened after the last
 * {@link AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback)}
 * call.
 *
 * <p>This history is typically used to keep track of previous user actions to optimize further
 * requests. For example, the service might return email addresses in alphabetical order by
 * default, but change that order based on the address the user picked on previous requests.
 *
 * <p>The history is not persisted over reboots, and it's cleared every time the service
 * replies to a
 * {@link AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback)}
 * by calling {@link FillCallback#onSuccess(FillResponse)} or
 * {@link FillCallback#onFailure(CharSequence)} (if the service doesn't call any of these methods,
 * the history will clear out after some pre-defined time).
 */
public final class FillEventHistory implements Parcelable {
    /**
@@ -56,9 +69,11 @@ public final class FillEventHistory implements Parcelable {
    }

    /**
     * Returns the client state of the {@link FillResponse}.
     * Returns the client state set in the previous {@link FillResponse}.
     *
     * @return The client state set by the last {@link FillResponse}
     * <p><b>NOTE: </b>the state is associated with the app that was autofilled in the previous
     * {@link AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback)}
     * , which is not necessary the same app being autofilled now.
     */
    @Nullable public Bundle getClientState() {
        return mClientState;
+25 −0
Original line number Diff line number Diff line
@@ -495,11 +495,24 @@ final class AutofillManagerServiceImpl {
        }
    }

    /**
     * Resets the last fill selection.
     */
    void resetLastResponse() {
        synchronized (mLock) {
            mEventHistory = null;
        }
    }

    /**
     * Updates the last fill selection when an authentication was selected.
     */
    void setAuthenticationSelected() {
        synchronized (mLock) {
            if (mEventHistory == null) {
                Slog.w(TAG, "setAuthenticationSelected(): ignored when history is null");
                return;
            }
            mEventHistory.addEvent(new Event(Event.TYPE_AUTHENTICATION_SELECTED, null));
        }
    }
@@ -509,6 +522,10 @@ final class AutofillManagerServiceImpl {
     */
    void setDatasetAuthenticationSelected(@Nullable String selectedDataset) {
        synchronized (mLock) {
            if (mEventHistory == null) {
                Slog.w(TAG, "setDatasetAuthenticationSelected(): ignored when history is null");
                return;
            }
            mEventHistory.addEvent(
                    new Event(Event.TYPE_DATASET_AUTHENTICATION_SELECTED, selectedDataset));
        }
@@ -519,6 +536,10 @@ final class AutofillManagerServiceImpl {
     */
    void setSaveShown() {
        synchronized (mLock) {
            if (mEventHistory == null) {
                Slog.w(TAG, "setSaveShown(): ignored when history is null");
                return;
            }
            mEventHistory.addEvent(new Event(Event.TYPE_SAVE_SHOWN, null));
        }
    }
@@ -528,6 +549,10 @@ final class AutofillManagerServiceImpl {
     */
    void setDatasetSelected(@Nullable String selectedDataset) {
        synchronized (mLock) {
            if (mEventHistory == null) {
                Slog.w(TAG, "setDatasetSelected(): ignored when history is null");
                return;
            }
            mEventHistory.addEvent(new Event(Event.TYPE_DATASET_SELECTED, selectedDataset));
        }
    }
+1 −0
Original line number Diff line number Diff line
@@ -427,6 +427,7 @@ final class RemoteFillService implements DeathRecipient {
                    mCompleted = true;
                }

                Slog.w(LOG_TAG, getClass().getSimpleName() + " timed out");
                final RemoteFillService remoteService = mWeakService.get();
                if (remoteService != null) {
                    fail(remoteService);
+2 −0
Original line number Diff line number Diff line
@@ -407,6 +407,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            if ((requestFlags & FLAG_MANUAL_REQUEST) != 0) {
                getUiForShowing().showError(R.string.autofill_error_cannot_autofill, this);
            }
            mService.resetLastResponse();
            // Nothing to be done, but need to notify client.
            notifyUnavailableToClient();
            removeSelf();
@@ -444,6 +445,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                        + id + " destroyed");
                return;
            }
            mService.resetLastResponse();
        }
        LogMaker log = (new LogMaker(MetricsEvent.AUTOFILL_REQUEST))
                .setType(MetricsEvent.TYPE_FAILURE)