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

Commit 695f6d6c authored by Kai Li's avatar Kai Li Committed by Android (Google) Code Review
Browse files

Merge "Add a new ContentCaptureSession#flush API." into main

parents abf5bd1e 25749335
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -57120,6 +57120,7 @@ package android.view.contentcapture {
    method public void close();
    method @NonNull public final android.view.contentcapture.ContentCaptureSession createContentCaptureSession(@NonNull android.view.contentcapture.ContentCaptureContext);
    method public final void destroy();
    method @FlaggedApi("android.view.contentcapture.flags.ccapi_baklava_enabled") public void flush();
    method @Nullable public final android.view.contentcapture.ContentCaptureContext getContentCaptureContext();
    method @NonNull public final android.view.contentcapture.ContentCaptureSessionId getContentCaptureSessionId();
    method @NonNull public android.view.autofill.AutofillId newAutofillId(@NonNull android.view.autofill.AutofillId, long);
+1 −0
Original line number Diff line number Diff line
@@ -19091,6 +19091,7 @@ package android.view.contentcapture {
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.view.contentcapture.ContentCaptureEvent> CREATOR;
    field public static final int TYPE_CONTEXT_UPDATED = 6; // 0x6
    field @FlaggedApi("android.view.contentcapture.flags.ccapi_baklava_enabled") public static final int TYPE_SESSION_FLUSH = 11; // 0xb
    field public static final int TYPE_SESSION_PAUSED = 8; // 0x8
    field public static final int TYPE_SESSION_RESUMED = 7; // 0x7
    field public static final int TYPE_VIEW_APPEARED = 1; // 0x1
+5 −0
Original line number Diff line number Diff line
@@ -141,6 +141,11 @@ final class ChildContentCaptureSession extends ContentCaptureSession {
        getMainCaptureSession().internalNotifySessionPaused();
    }

    @Override
    void internalNotifySessionFlushEvent(int sessionId) {
        getMainCaptureSession().internalNotifySessionFlushEvent(sessionId);
    }

    @Override
    boolean isContentCaptureEnabled() {
        return getMainCaptureSession().isContentCaptureEnabled();
+11 −0
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@ package android.view.contentcapture;
import static android.view.contentcapture.ContentCaptureHelper.getSanitizedString;
import static android.view.contentcapture.ContentCaptureManager.DEBUG;
import static android.view.contentcapture.ContentCaptureManager.NO_SESSION_ID;
import static android.view.contentcapture.flags.Flags.FLAG_CCAPI_BAKLAVA_ENABLED;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -137,6 +139,12 @@ public final class ContentCaptureEvent implements Parcelable {
     */
    public static final int TYPE_WINDOW_BOUNDS_CHANGED = 10;

    /**
     * Called to flush a semantics meaningful view changes status to Intelligence Service.
     */
    @FlaggedApi(FLAG_CCAPI_BAKLAVA_ENABLED)
    public static final int TYPE_SESSION_FLUSH = 11;

    /** @hide */
    @IntDef(prefix = { "TYPE_" }, value = {
            TYPE_VIEW_APPEARED,
@@ -149,6 +157,7 @@ public final class ContentCaptureEvent implements Parcelable {
            TYPE_SESSION_RESUMED,
            TYPE_VIEW_INSETS_CHANGED,
            TYPE_WINDOW_BOUNDS_CHANGED,
            TYPE_SESSION_FLUSH,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface EventType{}
@@ -697,6 +706,8 @@ public final class ContentCaptureEvent implements Parcelable {
                return "VIEW_INSETS_CHANGED";
            case TYPE_WINDOW_BOUNDS_CHANGED:
                return "TYPE_WINDOW_BOUNDS_CHANGED";
            case TYPE_SESSION_FLUSH:
                return "TYPE_SESSION_FLUSH";
            default:
                return "UKNOWN_TYPE: " + type;
        }
+31 −0
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@ import static android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE;
import static android.view.contentcapture.ContentCaptureHelper.sDebug;
import static android.view.contentcapture.ContentCaptureHelper.sVerbose;
import static android.view.contentcapture.ContentCaptureManager.NO_SESSION_ID;
import static android.view.contentcapture.flags.Flags.FLAG_CCAPI_BAKLAVA_ENABLED;

import android.annotation.CallSuper;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -548,6 +550,35 @@ public abstract class ContentCaptureSession implements AutoCloseable {

    abstract void internalNotifyViewInsetsChanged(int sessionId, @NonNull Insets viewInsets);

    /**
     * Flushes an internal buffer of UI events and signals System Intelligence (SI) that a
     * semantically meaningful state has been reached. SI uses this signal to potentially
     * rebuild the view hierarchy and understand the current state of the UI.
     *
     * <p>UI events are often batched together for performance reasons. A semantic batch
     * represents a series of events that, when applied sequentially, result in a
     * meaningful and complete UI state.
     *
     * <p>It is crucial to call {@code flush()} after completing a semantic batch to ensure
     * SI can accurately reconstruct the view hierarchy.
     *
     * <p><b>Premature Flushing:</b> Calling {@code flush()} within a semantic batch may
     * lead to SI failing to rebuild the view hierarchy correctly. This could manifest as
     * incorrect ordering of sibling nodes.
     *
     * <p><b>Delayed Flushing:</b> While not immediately flushing after a semantic batch is
     * generally safe, it's recommended to do so as soon as possible. In the worst-case
     * scenario where a {@code flush()} is never called, SI will attempt to process the
     * events after a short delay based on view appearance and disappearance events.
     */
    @FlaggedApi(FLAG_CCAPI_BAKLAVA_ENABLED)
    public void flush() {
        internalNotifySessionFlushEvent(mId);
    }

    /** @hide */
    abstract void internalNotifySessionFlushEvent(int sessionId);

    /** @hide */
    public void notifyViewTreeEvent(boolean started) {
        internalNotifyViewTreeEvent(mId, started);
Loading