public final class Session


The Session provides the primary interface to SceneCore functionality for the application. Each spatialized Activity must create and hold an instance of Session.

Once created, the application can use the Session interfaces to create spatialized entities, such as Widget panels and geometric models, set the background environment, and anchor content to the real world.

Summary

Public constructors

Session(
    @NonNull Activity activity,
    @NonNull JxrPlatformAdapter runtime,
    @NonNull SpatialEnvironment spatialEnvironment
)

Public methods

final void

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change.

final void

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change.

final boolean

This method is deprecated. Use getSpatialCapabilities.hasCapabilility(SPATIAL_CAPABILITY_EMBED_ACTIVITY)

static final @NonNull Session
create(@NonNull Activity activity, JxrPlatformAdapter runtime)

Creates a session and pairs it with an Activity and its lifecycle.

final @NonNull ActivityPanelEntity
createActivityPanelEntity(
    @NonNull Rect windowBoundsPx,
    @NonNull String name,
    @NonNull Pose pose
)

Public factory function for a spatial ActivityPanelEntity.

final @NonNull AnchorEntity

Public factory function for an AnchorEntity which uses an Anchor from ARCore for XR.

final @NonNull AnchorEntity
createAnchorEntity(
    @NonNull Dimensions bounds,
    int planeType,
    int planeSemantic,
    @NonNull Duration timeout
)

Public factory function for an AnchorEntity which searches for a location to create an Anchor among the tracked planes available to the perception system.

final @NonNull Entity

Public factory function for creating a content-less entity.

final @NonNull ExrImage

Public factory function for an EXRImage, where the EXR is loaded from a local file.

final @NonNull GltfModelEntity

Public factory function for a GltfModelEntity.

final @NonNull ListenableFuture<@NonNull GltfModel>

Public factory function for a GltfModel, where the glTF is asynchronously loaded.

final @NonNull InteractableComponent
createInteractableComponent(
    @NonNull Executor executor,
    @NonNull InputEventListener inputEventListener
)

Public factory for creating an InteractableComponent.

final @NonNull MovableComponent
createMovableComponent(
    boolean systemMovable,
    boolean scaleInZ,
    @NonNull Set<@NonNull AnchorPlacement> anchorPlacement,
    boolean shouldDisposeParentAnchor
)

Public factory function for creating a MovableComponent.

final @NonNull PanelEntity
createPanelEntity(
    @NonNull View view,
    @NonNull Dimensions surfaceDimensionsPx,
    @NonNull Dimensions dimensions,
    @NonNull String name,
    @NonNull Pose pose
)

Public factory function for a spatialized PanelEntity.

final @NonNull AnchorEntity

Public factory function for a persisted AnchorEntity using UUID.

final @NonNull ResizableComponent
createResizableComponent(
    @NonNull Dimensions minimumSize,
    @NonNull Dimensions maximumSize
)

Public factory function for creating a ResizableComponent.

final @NonNull StereoSurfaceEntity
@MainThread
createStereoSurfaceEntity(
    int stereoMode,
    @NonNull Dimensions dimensions,
    @NonNull Pose pose
)

Public factory function for a StereoSurfaceEntity.

final @NonNull Activity
final @NonNull ActivitySpace

The ActivitySpace is a special entity that represents the space in which the application is launched.

final @NonNull Entity
final @NonNull List<@NonNull T>
<T extends Entity> getEntitiesOfType(@NonNull Class<@NonNull T> type)

Returns all Entitys of the given type or its subtypes.

final @NonNull PanelEntity

A spatialized PanelEntity associated with the "main window" for the Activity.

final @NonNull PerceptionSpace

The PerceptionSpace represents the origin of the space in which the ARCore for XR API provides tracking info.

final @NonNull JxrPlatformAdapter
final @NonNull SpatialCapabilities

Returns the current SpatialCapabilities of the Session.

final @NonNull SpatialEnvironment
final @NonNull SpatialUser

The SpatialUser contains information about the user.

final boolean
hasSpatialCapability(int capability)

This method is deprecated. Removing in favor of getSpatialCapabilities().hasCapability()

final void

Releases the given Consumer from receiving updates when the Session's SpatialCapabilities change.

final void

If the primary Activity for this Session has focus, causes it to be placed in FullSpace Mode.

final void

If the primary Activity for this Session has focus, causes it to be placed in HomeSpace Mode.

final @NonNull Bundle

Sets the full space mode flag to the given android.os.Bundle.

final @NonNull Bundle

Sets the inherit full space mode environvment flag to the given android.os.Bundle.

final void
setPreferredAspectRatio(@NonNull Activity activity, float preferredRatio)

Sets a preferred main panel aspect ratio for home space mode.

final boolean

Unpersists an anchor.

Public constructors

Session

Added in 1.0.0-alpha01
public Session(
    @NonNull Activity activity,
    @NonNull JxrPlatformAdapter runtime,
    @NonNull SpatialEnvironment spatialEnvironment
)

Public methods

addSpatialCapabilitiesChangedListener

Added in 1.0.0-alpha01
public final void addSpatialCapabilitiesChangedListener(
    @NonNull Consumer<@NonNull SpatialCapabilities> listener
)

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change. Consumer#accept(SpatialCapabilities) will be invoked on the main thread.

addSpatialCapabilitiesChangedListener

Added in 1.0.0-alpha01
public final void addSpatialCapabilitiesChangedListener(
    @NonNull Executor callbackExecutor,
    @NonNull Consumer<@NonNull SpatialCapabilities> listener
)

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change. Consumer#accept(SpatialCapabilities) will be invoked on the given callbackExecutor, or the main thread if the callbackExecutor is null (default).

canEmbedActivityPanel

Added in 1.0.0-alpha01
Deprecated in 1.0.0-alpha01
public final boolean canEmbedActivityPanel(@NonNull Activity activity)

Helper function to query if given activity can be a host to ActivityPanel.

create

Added in 1.0.0-alpha01
public static final @NonNull Session create(@NonNull Activity activity, JxrPlatformAdapter runtime)

Creates a session and pairs it with an Activity and its lifecycle. If a session is already paired with an Activity, return that Session instead of creating a new one.

For our Alpha release, we just directly instantiate the Android XR PlatformAdapter.

createActivityPanelEntity

Added in 1.0.0-alpha01
public final @NonNull ActivityPanelEntity createActivityPanelEntity(
    @NonNull Rect windowBoundsPx,
    @NonNull String name,
    @NonNull Pose pose
)

Public factory function for a spatial ActivityPanelEntity.

Parameters
@NonNull Rect windowBoundsPx

Bounds for the panel window in pixels.

@NonNull String name

Name of the panel.

@NonNull Pose pose

Pose of this entity relative to its parent, default value is Identity.

Returns
@NonNull ActivityPanelEntity

an ActivityPanelEntity instance.

createAnchorEntity

Added in 1.0.0-alpha01
public final @NonNull AnchorEntity createAnchorEntity(@NonNull Anchor anchor)

Public factory function for an AnchorEntity which uses an Anchor from ARCore for XR.

Parameters
@NonNull Anchor anchor

The PerceptionAnchor to use for this AnchorEntity.

createAnchorEntity

Added in 1.0.0-alpha01
public final @NonNull AnchorEntity createAnchorEntity(
    @NonNull Dimensions bounds,
    int planeType,
    int planeSemantic,
    @NonNull Duration timeout
)

Public factory function for an AnchorEntity which searches for a location to create an Anchor among the tracked planes available to the perception system.

Note that this function will fail if the application has not been granted the "android.permission.SCENE_UNDERSTANDING" permission. Consider using PermissionHelper to help request permission from the User.

Parameters
@NonNull Dimensions bounds

Bounds for this AnchorEntity.

int planeType

Orientation of plane to which this Anchor should attach.

int planeSemantic

Semantics of the plane to which this Anchor should attach.

@NonNull Duration timeout

The amount of time as a Duration to search for the a suitable plane to attach to. If a plane is not found within the timeout, the returned AnchorEntity state will be set to AnchorEntity.State.TIMEDOUT. It may take longer than the timeout period before the anchor state is updated. If the timeout duration is zero it will search for the anchor indefinitely.

createEntity

Added in 1.0.0-alpha01
public final @NonNull Entity createEntity(@NonNull String name, @NonNull Pose pose)

Public factory function for creating a content-less entity. This entity is used as a connection point for attaching children entities and managing them (i.e. setPose()) as a group.

Parameters
@NonNull String name

Name of the entity.

@NonNull Pose pose

Initial pose of the entity.

createExrImageResource

Added in 1.0.0-alpha01
public final @NonNull ExrImage createExrImageResource(@NonNull String name)

Public factory function for an EXRImage, where the EXR is loaded from a local file.

Parameters
@NonNull String name

The path for an EXR image to be loaded

Returns
@NonNull ExrImage

an EXRImage instance.

createGltfEntity

Added in 1.0.0-alpha01
@MainThread
public final @NonNull GltfModelEntity createGltfEntity(@NonNull GltfModel model, @NonNull Pose pose)

Public factory function for a GltfModelEntity.

This method must be called from the main thread. https://developer.android.com/guide/components/processes-and-threads

Parameters
@NonNull GltfModel model

The GltfModel this Entity is referencing.

@NonNull Pose pose

The initial pose of the entity.

Returns
@NonNull GltfModelEntity

a GltfModelEntity instance

createGltfResourceAsync

Added in 1.0.0-alpha01
@MainThread
public final @NonNull ListenableFuture<@NonNull GltfModelcreateGltfResourceAsync(@NonNull String name)

Public factory function for a GltfModel, where the glTF is asynchronously loaded.

This method must be called from the main thread. https://developer.android.com/guide/components/processes-and-threads

Currently, only URLs and relative paths from the android_assets/ directory are supported. Currently, only binary glTF (.glb) files are supported.

Parameters
@NonNull String name

The URL or asset-relative path of a binary glTF (.glb) model to be loaded

Returns
@NonNull ListenableFuture<@NonNull GltfModel>

a ListenableFuture. Listeners will be called on the main thread if Runnable::run is supplied.

createInteractableComponent

Added in 1.0.0-alpha01
public final @NonNull InteractableComponent createInteractableComponent(
    @NonNull Executor executor,
    @NonNull InputEventListener inputEventListener
)

Public factory for creating an InteractableComponent. It enables access to raw input events.

Parameters
@NonNull Executor executor

Executor for invoking InputEventListener.

@NonNull InputEventListener inputEventListener

InputEventListener that accepts InputEvents.

createMovableComponent

Added in 1.0.0-alpha01
public final @NonNull MovableComponent createMovableComponent(
    boolean systemMovable,
    boolean scaleInZ,
    @NonNull Set<@NonNull AnchorPlacement> anchorPlacement,
    boolean shouldDisposeParentAnchor
)

Public factory function for creating a MovableComponent. This component can be attached to a single instance of any non-Anchor Entity.

When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

Parameters
boolean systemMovable

A Boolean which causes the system to automatically apply transform updates to the entity in response to user interaction.

boolean scaleInZ

A Boolean which tells the system to update the scale of the Entity as the user moves it closer and further away. This is mostly useful for Panel auto-rescaling with Distance

@NonNull Set<@NonNull AnchorPlacement> anchorPlacement

A Set containing different AnchorPlacement for how to anchor the Entity movable component. If this is not empty the movement semantics will be slightly different from the system as it will add the ability to anchor to nearby planes.

boolean shouldDisposeParentAnchor

A Boolean, which if set to true, when an entity is moved off of an AnchorEntity that was created by the underlying MovableComponent, and the AnchorEntity has no other children, the AnchorEntity will be disposed, and the underlying Anchor will be detached.

createPanelEntity

Added in 1.0.0-alpha01
public final @NonNull PanelEntity createPanelEntity(
    @NonNull View view,
    @NonNull Dimensions surfaceDimensionsPx,
    @NonNull Dimensions dimensions,
    @NonNull String name,
    @NonNull Pose pose
)

Public factory function for a spatialized PanelEntity.

Parameters
@NonNull View view

View to embed in this panel entity.

@NonNull Dimensions surfaceDimensionsPx

Dimensions for the underlying surface for the given view.

@NonNull Dimensions dimensions

Dimensions for the panel in meters.

@NonNull String name

Name of the panel.

@NonNull Pose pose

Pose of this entity relative to its parent, default value is Identity.

Returns
@NonNull PanelEntity

a PanelEntity instance.

createPersistedAnchorEntity

Added in 1.0.0-alpha01
public final @NonNull AnchorEntity createPersistedAnchorEntity(@NonNull UUID uuid)

Public factory function for a persisted AnchorEntity using UUID. Note that the system keeps a limited number of scenes and anchors. If the anchor is pruned due to the system limitation, the creation will fail. It will return null if there is a failure.

Parameters
@NonNull UUID uuid

The UUID of the persisted anchor to recreate.

Returns
@NonNull AnchorEntity

a persisted AnchorEntity instance.

createResizableComponent

Added in 1.0.0-alpha01
public final @NonNull ResizableComponent createResizableComponent(
    @NonNull Dimensions minimumSize,
    @NonNull Dimensions maximumSize
)

Public factory function for creating a ResizableComponent. This component can be attached to a single instance of any non-Anchor Entity.

When attached, this Component will enable the user to resize the Entity by dragging along the boundaries of the interaction highlight.

Parameters
@NonNull Dimensions minimumSize

A lower bound for the User's resize actions, in meters. This value is used to set constraints on how small the user can resize the bounding box of the entity down to. The size of the content inside that bounding box is fully controlled by the application. The default value for this param is 0 meters.

@NonNull Dimensions maximumSize

An upper bound for the User's resize actions, in meters. This value is used to set constraints on how large the user can resize the bounding box of the entity up to. The size of the content inside that bounding box is fully controlled by the application. The default value for this param is 10 meters.

createStereoSurfaceEntity

Added in 1.0.0-alpha01
@MainThread
public final @NonNull StereoSurfaceEntity createStereoSurfaceEntity(
    int stereoMode,
    @NonNull Dimensions dimensions,
    @NonNull Pose pose
)

Public factory function for a StereoSurfaceEntity.

This method must be called from the main thread. https://developer.android.com/guide/components/processes-and-threads

Parameters
int stereoMode

Stereo mode for the surface.

@NonNull Dimensions dimensions

Dimensions for the surface.

@NonNull Pose pose

Pose of this entity relative to its parent, default value is Identity.

Returns
@NonNull StereoSurfaceEntity

a StereoSurfaceEntity instance

getActivity

Added in 1.0.0-alpha01
public final @NonNull Activity getActivity()

getActivitySpace

Added in 1.0.0-alpha01
public final @NonNull ActivitySpace getActivitySpace()

The ActivitySpace is a special entity that represents the space in which the application is launched. It is the default parent of all entities in the scene.

The ActivitySpace is created automatically when the Session is created.

getActivitySpaceRoot

Added in 1.0.0-alpha01
public final @NonNull Entity getActivitySpaceRoot()

getEntitiesOfType

Added in 1.0.0-alpha01
public final @NonNull List<@NonNull T> <T extends Entity> getEntitiesOfType(@NonNull Class<@NonNull T> type)

Returns all Entitys of the given type or its subtypes.

Parameters
@NonNull Class<@NonNull T> type

the type of Entity to return.

Returns
@NonNull List<@NonNull T>

a list of all Entitys of the given type.

getMainPanelEntity

Added in 1.0.0-alpha01
public final @NonNull PanelEntity getMainPanelEntity()

A spatialized PanelEntity associated with the "main window" for the Activity. When in HomeSpace mode, this is the application's "main window".

If called multiple times, this will return the same PanelEntity.

getPerceptionSpace

Added in 1.0.0-alpha01
public final @NonNull PerceptionSpace getPerceptionSpace()

The PerceptionSpace represents the origin of the space in which the ARCore for XR API provides tracking info. The transformations provided by the PerceptionSpace are only valid for the call frame, as the transformation can be changed by the system at any time.

getRuntime

Added in 1.0.0-alpha01
public final @NonNull JxrPlatformAdapter getRuntime()

getSpatialCapabilities

Added in 1.0.0-alpha01
public final @NonNull SpatialCapabilities getSpatialCapabilities()

Returns the current SpatialCapabilities of the Session. The set of capabilities can change within a session. The returned object will not update if the capabilities change; this method should be called again to get the latest set of capabilities.

getSpatialEnvironment

Added in 1.0.0-alpha01
public final @NonNull SpatialEnvironment getSpatialEnvironment()

getSpatialUser

Added in 1.0.0-alpha01
public final @NonNull SpatialUser getSpatialUser()

The SpatialUser contains information about the user.

hasSpatialCapability

Added in 1.0.0-alpha01
Deprecated in 1.0.0-alpha01
public final boolean hasSpatialCapability(int capability)

Returns true if the Session is currently capable of the given SpatialCapability, false otherwise. The available set of capabilities can change within a session.

removeSpatialCapabilitiesChangedListener

Added in 1.0.0-alpha01
public final void removeSpatialCapabilitiesChangedListener(
    @NonNull Consumer<@NonNull SpatialCapabilities> listener
)

Releases the given Consumer from receiving updates when the Session's SpatialCapabilities change.

requestFullSpaceMode

Added in 1.0.0-alpha01
public final void requestFullSpaceMode()

If the primary Activity for this Session has focus, causes it to be placed in FullSpace Mode. Otherwise, this call does nothing.

requestHomeSpaceMode

Added in 1.0.0-alpha01
public final void requestHomeSpaceMode()

If the primary Activity for this Session has focus, causes it to be placed in HomeSpace Mode. Otherwise, this call does nothing.

setFullSpaceMode

Added in 1.0.0-alpha01
public final @NonNull Bundle setFullSpaceMode(@NonNull Bundle bundle)

Sets the full space mode flag to the given android.os.Bundle.

The android.os.Bundle then could be used to launch an android.app.Activity with requesting to enter full space mode through android.app.Activity.startActivity. If there's a bundle used for customizing how the android.app.Activity should be started by android.app.ActivityOptions.toBundle or androidx.core.app.ActivityOptionsCompat.toBundle, it's suggested to use the bundle to call this method.

The flag will be ignored when no android.content.Intent.FLAG_ACTIVITY_NEW_TASK is set in the bundle, or it is not started from a focused Activity context.

This flag is also ignored when the android.window.PROPERTY_XR_ACTIVITY_START_MODE property is set to a value other than XR_ACTIVITY_START_MODE_UNDEFINED in the AndroidManifest.xml file for the activity being launched.

Parameters
@NonNull Bundle bundle

the input bundle to set with the full space mode flag.

Returns
@NonNull Bundle

the input bundle with the full space mode flag set.

setFullSpaceModeWithEnvironmentInherited

Added in 1.0.0-alpha01
public final @NonNull Bundle setFullSpaceModeWithEnvironmentInherited(@NonNull Bundle bundle)

Sets the inherit full space mode environvment flag to the given android.os.Bundle.

The android.os.Bundle then could be used to launch an android.app.Activity with requesting to enter full space mode while inherit the existing environment through android.app.Activity.startActivity. If there's a bundle used for customizing how the android.app.Activity should be started by android.app.ActivityOptions.toBundle or androidx.core.app.ActivityOptionsCompat.toBundle, it's suggested to use the bundle to call this method.

When launched, the activity will be in full space mode and also inherits the environment from the launching activity. If the inherited environment needs to be animated, the launching activity has to continue updating the environment even after the activity is put into the stopped state.

The flag will be ignored when no android.content.Intent.FLAG_ACTIVITY_NEW_TASK is set in the intent, or it is not started from a focused Activity context.

The flag will also be ignored when there is no environment to inherit or the activity has its own environment set already.

This flag is ignored too when the android.window.PROPERTY_XR_ACTIVITY_START_MODE property is set to a value other than XR_ACTIVITY_START_MODE_UNDEFINED in the AndroidManifest.xml file for the activity being launched.

For security reasons, Z testing for the new activity is disabled, and the activity is always drawn on top of the inherited environment. Because Z testing is disabled, the activity should not spatialize itself, and should not curve its panel too much either.

Parameters
@NonNull Bundle bundle

the input bundle to set with the inherit full space mode environment flag.

Returns
@NonNull Bundle

the input bundle with the inherit full space mode flag set.

setPreferredAspectRatio

Added in 1.0.0-alpha01
public final void setPreferredAspectRatio(@NonNull Activity activity, float preferredRatio)

Sets a preferred main panel aspect ratio for home space mode.

The ratio is only applied to the activity. If the activity launches another activity in the same task, the ratio is not applied to the new activity. Also, while the activity is in full space mode, the preference is temporarily removed.

Parameters
@NonNull Activity activity

the activity to set the preference.

float preferredRatio

the aspect ratio determined by taking the panel's width over its height. A value <= 0.0f means there are no preferences.

unpersistAnchor

Added in 1.0.0-alpha01
public final boolean unpersistAnchor(@NonNull UUID uuid)

Unpersists an anchor. It will clean up the data in the storage that is required to retrieve the anchor.

Parameters
@NonNull UUID uuid

UUID of the anchor to unpersist.