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

Commit 25749335 authored by Kai Li's avatar Kai Li
Browse files

Add a new ContentCaptureSession#flush API.

Design: go/ccapi-b

Bug: 380381249
Flag: android.view.contentcapture.flags.ccapi_baklava_enabled
Test: atest CtsContentCaptureServiceTestCases
Change-Id: I66611e834f7cf62ce3fad31f2d24013818f21a29
parent 49413be1
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -57123,6 +57123,7 @@ package android.view.contentcapture {
    method public void close();
    method public void close();
    method @NonNull public final android.view.contentcapture.ContentCaptureSession createContentCaptureSession(@NonNull android.view.contentcapture.ContentCaptureContext);
    method @NonNull public final android.view.contentcapture.ContentCaptureSession createContentCaptureSession(@NonNull android.view.contentcapture.ContentCaptureContext);
    method public final void destroy();
    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 @Nullable public final android.view.contentcapture.ContentCaptureContext getContentCaptureContext();
    method @NonNull public final android.view.contentcapture.ContentCaptureSessionId getContentCaptureSessionId();
    method @NonNull public final android.view.contentcapture.ContentCaptureSessionId getContentCaptureSessionId();
    method @NonNull public android.view.autofill.AutofillId newAutofillId(@NonNull android.view.autofill.AutofillId, long);
    method @NonNull public android.view.autofill.AutofillId newAutofillId(@NonNull android.view.autofill.AutofillId, long);
+1 −0
Original line number Original line Diff line number Diff line
@@ -19249,6 +19249,7 @@ package android.view.contentcapture {
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.view.contentcapture.ContentCaptureEvent> CREATOR;
    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 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_PAUSED = 8; // 0x8
    field public static final int TYPE_SESSION_RESUMED = 7; // 0x7
    field public static final int TYPE_SESSION_RESUMED = 7; // 0x7
    field public static final int TYPE_VIEW_APPEARED = 1; // 0x1
    field public static final int TYPE_VIEW_APPEARED = 1; // 0x1
+5 −0
Original line number Original line Diff line number Diff line
@@ -141,6 +141,11 @@ final class ChildContentCaptureSession extends ContentCaptureSession {
        getMainCaptureSession().internalNotifySessionPaused();
        getMainCaptureSession().internalNotifySessionPaused();
    }
    }


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

    @Override
    @Override
    boolean isContentCaptureEnabled() {
    boolean isContentCaptureEnabled() {
        return getMainCaptureSession().isContentCaptureEnabled();
        return getMainCaptureSession().isContentCaptureEnabled();
+11 −0
Original line number Original line 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.ContentCaptureHelper.getSanitizedString;
import static android.view.contentcapture.ContentCaptureManager.DEBUG;
import static android.view.contentcapture.ContentCaptureManager.DEBUG;
import static android.view.contentcapture.ContentCaptureManager.NO_SESSION_ID;
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.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -137,6 +139,12 @@ public final class ContentCaptureEvent implements Parcelable {
     */
     */
    public static final int TYPE_WINDOW_BOUNDS_CHANGED = 10;
    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 */
    /** @hide */
    @IntDef(prefix = { "TYPE_" }, value = {
    @IntDef(prefix = { "TYPE_" }, value = {
            TYPE_VIEW_APPEARED,
            TYPE_VIEW_APPEARED,
@@ -149,6 +157,7 @@ public final class ContentCaptureEvent implements Parcelable {
            TYPE_SESSION_RESUMED,
            TYPE_SESSION_RESUMED,
            TYPE_VIEW_INSETS_CHANGED,
            TYPE_VIEW_INSETS_CHANGED,
            TYPE_WINDOW_BOUNDS_CHANGED,
            TYPE_WINDOW_BOUNDS_CHANGED,
            TYPE_SESSION_FLUSH,
    })
    })
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    public @interface EventType{}
    public @interface EventType{}
@@ -697,6 +706,8 @@ public final class ContentCaptureEvent implements Parcelable {
                return "VIEW_INSETS_CHANGED";
                return "VIEW_INSETS_CHANGED";
            case TYPE_WINDOW_BOUNDS_CHANGED:
            case TYPE_WINDOW_BOUNDS_CHANGED:
                return "TYPE_WINDOW_BOUNDS_CHANGED";
                return "TYPE_WINDOW_BOUNDS_CHANGED";
            case TYPE_SESSION_FLUSH:
                return "TYPE_SESSION_FLUSH";
            default:
            default:
                return "UKNOWN_TYPE: " + type;
                return "UKNOWN_TYPE: " + type;
        }
        }
+31 −0
Original line number Original line 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.sDebug;
import static android.view.contentcapture.ContentCaptureHelper.sVerbose;
import static android.view.contentcapture.ContentCaptureHelper.sVerbose;
import static android.view.contentcapture.ContentCaptureManager.NO_SESSION_ID;
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.CallSuper;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -548,6 +550,35 @@ public abstract class ContentCaptureSession implements AutoCloseable {


    abstract void internalNotifyViewInsetsChanged(int sessionId, @NonNull Insets viewInsets);
    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 */
    /** @hide */
    public void notifyViewTreeEvent(boolean started) {
    public void notifyViewTreeEvent(boolean started) {
        internalNotifyViewTreeEvent(mId, started);
        internalNotifyViewTreeEvent(mId, started);
Loading