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

Commit 2e785fed authored by Tim Yu's avatar Tim Yu Committed by Android (Google) Code Review
Browse files

Merge "[Autofill] Add new API for getting FillEventHistory" into main

parents 5043fb74 7726696e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -40810,13 +40810,14 @@ package android.service.autofill {
  public abstract class AutofillService extends android.app.Service {
    ctor public AutofillService();
    method @Nullable public final android.service.autofill.FillEventHistory getFillEventHistory();
    method @Deprecated @FlaggedApi("android.service.autofill.autofill_session_destroyed") @Nullable public final android.service.autofill.FillEventHistory getFillEventHistory();
    method public final android.os.IBinder onBind(android.content.Intent);
    method public void onConnected();
    method public void onDisconnected();
    method public abstract void onFillRequest(@NonNull android.service.autofill.FillRequest, @NonNull android.os.CancellationSignal, @NonNull android.service.autofill.FillCallback);
    method public abstract void onSaveRequest(@NonNull android.service.autofill.SaveRequest, @NonNull android.service.autofill.SaveCallback);
    method public void onSavedDatasetsInfoRequest(@NonNull android.service.autofill.SavedDatasetsInfoCallback);
    method @FlaggedApi("android.service.autofill.autofill_session_destroyed") public void onSessionDestroyed(@Nullable android.service.autofill.FillEventHistory);
    field public static final String EXTRA_FILL_RESPONSE = "android.service.autofill.extra.FILL_RESPONSE";
    field public static final String SERVICE_INTERFACE = "android.service.autofill.AutofillService";
    field public static final String SERVICE_META_DATA = "android.autofill";
+37 −10
Original line number Diff line number Diff line
@@ -15,9 +15,12 @@
 */
package android.service.autofill;

import static android.service.autofill.Flags.FLAG_AUTOFILL_SESSION_DESTROYED;

import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;

import android.annotation.CallSuper;
import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
@@ -669,6 +672,14 @@ public abstract class AutofillService extends Service {
                    AutofillService.this,
                    new SavedDatasetsInfoCallbackImpl(receiver, SavedDatasetsInfo.TYPE_PASSWORDS)));
        }

        @Override
        public void onSessionDestroyed(@Nullable FillEventHistory history) {
            mHandler.sendMessage(obtainMessage(
                    AutofillService::onSessionDestroyed,
                    AutofillService.this,
                    history));
        }
    };

    private Handler mHandler;
@@ -783,26 +794,42 @@ public abstract class AutofillService extends Service {
    }

    /**
     * Gets the events that happened after the last
     * {@link AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback)}
     * Called when an Autofill context has ended and the Autofill session is finished. This will be
     * called as the last step of the Autofill lifecycle described in {@link AutofillManager}.
     *
     * <p>This will also contain the finished Session's FillEventHistory, so providers do not need
     * to explicitly call {@link #getFillEventHistory()}
     *
     * <p>This will usually happens whenever {@link AutofillManager#commit()} or {@link
     * AutofillManager#cancel()} is called.
     */
    @FlaggedApi(FLAG_AUTOFILL_SESSION_DESTROYED)
    public void onSessionDestroyed(@Nullable FillEventHistory history) {}

    /**
     * Gets the events that happened after the last {@link
     * AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback)}
     * call.
     *
     * <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.
     *
     * <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}.
     * <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.
     *
     * @throws RuntimeException if the event history could not be retrieved.
     * @deprecated Use {@link #onSessionDestroyed(FillEventHistory) instead}
     */
    @Nullable public final FillEventHistory getFillEventHistory() {
    @FlaggedApi(FLAG_AUTOFILL_SESSION_DESTROYED)
    @Deprecated
    @Nullable
    public final FillEventHistory getFillEventHistory() {
        final AutofillManager afm = getSystemService(AutofillManager.class);

        if (afm == null) {
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.service.autofill.ISaveCallback;
import android.service.autofill.SaveRequest;
import com.android.internal.os.IResultReceiver;

parcelable FillEventHistory;

/**
 * Interface from the system to an auto fill service.
 *
@@ -38,4 +40,5 @@ oneway interface IAutoFillService {
    void onSaveRequest(in SaveRequest request, in ISaveCallback callback);
    void onSavedPasswordCountRequest(in IResultReceiver receiver);
    void onConvertCredentialRequest(in ConvertCredentialRequest convertCredentialRequest, in IConvertCredentialCallback convertCredentialCallback);
    void onSessionDestroyed(in FillEventHistory history);
}
+7 −0
Original line number Diff line number Diff line
package: "android.service.autofill"
container: "system"

flag {
  name: "autofill_session_destroyed"
  namespace: "autofill"
  description: "Guards against new metrics definitions introduced in W"
  bug: "342676602"
}

flag {
  name: "autofill_w_metrics"
  namespace: "autofill"
+18 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import android.service.autofill.FillEventHistory;
import android.service.autofill.FillEventHistory.Event;
import android.service.autofill.FillEventHistory.Event.NoSaveReason;
import android.service.autofill.FillResponse;
import android.service.autofill.Flags;
import android.service.autofill.IAutoFillService;
import android.service.autofill.InlineSuggestionRenderService;
import android.service.autofill.SaveInfo;
@@ -100,6 +101,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;

/**
 * Bridge between the {@code system_server}'s {@link AutofillManagerService} and the
 * app's {@link IAutoFillService} implementation.
@@ -748,6 +750,22 @@ final class AutofillManagerServiceImpl
    @GuardedBy("mLock")
    void removeSessionLocked(int sessionId) {
        mSessions.remove(sessionId);
        if (Flags.autofillSessionDestroyed()) {
            if (sVerbose) {
                Slog.v(
                        TAG,
                        "removeSessionLocked(): removed " + sessionId);
            }
            RemoteFillService remoteService =
                    new RemoteFillService(
                            getContext(),
                            mInfo.getServiceInfo().getComponentName(),
                            mUserId,
                            /* callbacks= */ null,
                            mMaster.isInstantServiceAllowed(),
                            /* credentialAutofillService= */ null);
            remoteService.onSessionDestroyed(null);
        }
    }

    /**
Loading