ContentCaptureSession  |  API reference  |  Android Developers


public abstract class ContentCaptureSession
extends Object implements AutoCloseable



Session used when notifying the Android system about events associated with views.

Summary

Public methods

void close()

Closes this resource, relinquishing any underlying resources.

final ContentCaptureSession createContentCaptureSession(ContentCaptureContext context)

Creates a new ContentCaptureSession.

final void destroy()

Destroys this session, flushing out all pending notifications to the service.

void flush()

Flushes an internal buffer of UI events and signals System Intelligence (SI) that a semantically meaningful state has been reached.

final ContentCaptureContext getContentCaptureContext()

Gets the ContentCaptureContext associated with the session.

final ContentCaptureSessionId getContentCaptureSessionId()

Gets the id used to identify this session.

AutofillId newAutofillId(AutofillId hostId, long virtualChildId)

Creates a new AutofillId for a virtual child, so it can be used to uniquely identify the children in the session.

final ViewStructure newViewStructure(View view)

Creates a ViewStructure for a "standard" view.

final ViewStructure newVirtualViewStructure(AutofillId parentId, long virtualId)

Creates a ViewStructure for a "virtual" view, so it can be passed to notifyViewAppeared(ViewStructure) by the view managing the virtual view hierarchy.

final void notifySessionPaused()

Notifies the Content Capture Service that a session has paused.

final void notifySessionResumed()

Notifies the Content Capture Service that a session has resumed.

final void notifyViewAppeared(ViewStructure node)

Notifies the Content Capture Service that a node has been added to the view structure.

final void notifyViewDisappeared(AutofillId id)

Notifies the Content Capture Service that a node has been removed from the view structure.

final void notifyViewInsetsChanged(Insets viewInsets)

Notifies the Intelligence Service that the insets of a view have changed.

final void notifyViewTextChanged(AutofillId id, CharSequence text)

Notifies the Intelligence Service that the value of a text node has been changed.

final void notifyViewsAppeared(List<ViewStructure> appearedNodes)

Notifies the Content Capture Service that a list of nodes has appeared in the view structure.

final void notifyViewsDisappeared(AutofillId hostId, long[] virtualIds)

Notifies the Content Capture Service that many nodes has been removed from a virtual view structure.

final void setContentCaptureContext(ContentCaptureContext context)

Sets the ContentCaptureContext associated with the session.

String toString()

Returns a string representation of the object.

Inherited methods

From class java.lang.Object

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

From interface java.lang.AutoCloseable

abstract void close()

Closes this resource, relinquishing any underlying resources.

Public methods

close

public void close ()

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

destroy

public final void destroy ()

Destroys this session, flushing out all pending notifications to the service.

Once destroyed, any new notification will be dropped.

flush

public void flush ()

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.

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.

It is crucial to call flush() after completing a semantic batch to ensure SI can accurately reconstruct the view hierarchy.

Premature Flushing: Calling 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.

Delayed Flushing: 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 flush() is never called, SI will attempt to process the events after a short delay based on view appearance and disappearance events.

newAutofillId

public AutofillId newAutofillId (AutofillId hostId, 
                long virtualChildId)

Creates a new AutofillId for a virtual child, so it can be used to uniquely identify the children in the session.

Parameters
hostId AutofillId: id of the non-virtual view hosting the virtual view hierarchy (it can be obtained by calling ViewStructure.getAutofillId()).
This value cannot be null.
virtualChildId long: id of the virtual child, relative to the parent.
Returns
AutofillId if for the virtual child.
This value cannot be null.
Throws
IllegalArgumentException if the parentId is a virtual child id.

notifySessionPaused

public final void notifySessionPaused ()

Notifies the Content Capture Service that a session has paused.

notifySessionResumed

public final void notifySessionResumed ()

Notifies the Content Capture Service that a session has resumed.

notifyViewAppeared

public final void notifyViewAppeared (ViewStructure node)

Notifies the Content Capture Service that a node has been added to the view structure.

Typically called "manually" by views that handle their own virtual view hierarchy, or automatically by the Android System for views that return true on View.onProvideContentCaptureStructure(ViewStructure,int).

Consider use notifyViewsAppeared(List) which has a better performance when notifying a list of nodes has appeared.

Parameters
node ViewStructure: node that has been added.
This value cannot be null.

notifyViewDisappeared

public final void notifyViewDisappeared (AutofillId id)

Notifies the Content Capture Service that a node has been removed from the view structure.

Typically called "manually" by views that handle their own virtual view hierarchy, or automatically by the Android System for standard views.

Consider use notifyViewsDisappeared(AutofillId, long) which has a better performance when notifying a list of nodes has disappeared.

Parameters
id AutofillId: id of the node that has been removed.
This value cannot be null.

notifyViewInsetsChanged

public final void notifyViewInsetsChanged (Insets viewInsets)

Notifies the Intelligence Service that the insets of a view have changed.

Parameters
viewInsets Insets: This value cannot be null.

notifyViewTextChanged

public final void notifyViewTextChanged (AutofillId id, 
                CharSequence text)

Notifies the Intelligence Service that the value of a text node has been changed.

Parameters
id AutofillId: of the node.
This value cannot be null.
text CharSequence: new text.
This value may be null.

notifyViewsAppeared

public final void notifyViewsAppeared (List<ViewStructure> appearedNodes)

Notifies the Content Capture Service that a list of nodes has appeared in the view structure.

Typically called manually by views that handle their own virtual view hierarchy.

Parameters
appearedNodes List: nodes that have appeared. Each element represents a view node that has been added to the view structure. The order of the elements is important, which should be preserved as the attached order of when the node is attached to the virtual view hierarchy.
This value cannot be null.

notifyViewsDisappeared

public final void notifyViewsDisappeared (AutofillId hostId, 
                long[] virtualIds)

Notifies the Content Capture Service that many nodes has been removed from a virtual view structure.

Should only be called by views that handle their own virtual view hierarchy.

After UPSIDE_DOWN_CAKE, this method wraps the virtual children with a pair of view tree appearing and view tree appeared events.

Parameters
hostId AutofillId: id of the non-virtual view hosting the virtual view hierarchy (it can be obtained by calling ViewStructure.getAutofillId()).
This value cannot be null.
virtualIds long: ids of the virtual children.
This value cannot be null.
Throws
IllegalArgumentException if the hostId is an autofill id for a virtual view.
IllegalArgumentException if virtualIds is empty

setContentCaptureContext

public final void setContentCaptureContext (ContentCaptureContext context)

Sets the ContentCaptureContext associated with the session.

Typically used to change the context associated with the default session from an activity.

Parameters
context ContentCaptureContext: This value may be null.

toString

public String toString ()

Returns a string representation of the object.

Returns
String a string representation of the object.