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 companion functions

Session
create(activity: Activity, runtime: JxrPlatformAdapter?)

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

Public constructors

Session(
    activity: Activity,
    runtime: JxrPlatformAdapter,
    spatialEnvironment: SpatialEnvironment
)

Public functions

Unit

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

Unit
addSpatialCapabilitiesChangedListener(
    callbackExecutor: Executor,
    listener: Consumer<SpatialCapabilities>
)

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

Boolean

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

ActivityPanelEntity
createActivityPanelEntity(windowBoundsPx: Rect, name: String, pose: Pose)

Public factory function for a spatial ActivityPanelEntity.

AnchorEntity

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

AnchorEntity
createAnchorEntity(
    bounds: Dimensions,
    planeType: Int,
    planeSemantic: Int,
    timeout: Duration
)

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

Entity
createEntity(name: String, pose: Pose)

Public factory function for creating a content-less entity.

ExrImage

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

GltfModelEntity

Public factory function for a GltfModelEntity.

ListenableFuture<GltfModel>

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

InteractableComponent
createInteractableComponent(
    executor: Executor,
    inputEventListener: InputEventListener
)

Public factory for creating an InteractableComponent.

MovableComponent
createMovableComponent(
    systemMovable: Boolean,
    scaleInZ: Boolean,
    anchorPlacement: Set<AnchorPlacement>,
    shouldDisposeParentAnchor: Boolean
)

Public factory function for creating a MovableComponent.

PanelEntity
createPanelEntity(
    view: View,
    surfaceDimensionsPx: Dimensions,
    dimensions: Dimensions,
    name: String,
    pose: Pose
)

Public factory function for a spatialized PanelEntity.

AnchorEntity

Public factory function for a persisted AnchorEntity using UUID.

ResizableComponent
createResizableComponent(
    minimumSize: Dimensions,
    maximumSize: Dimensions
)

Public factory function for creating a ResizableComponent.

StereoSurfaceEntity
@MainThread
createStereoSurfaceEntity(
    stereoMode: Int,
    dimensions: Dimensions,
    pose: Pose
)

Public factory function for a StereoSurfaceEntity.

List<T>
<T : Entity> getEntitiesOfType(type: Class<T>)

Returns all Entitys of the given type or its subtypes.

SpatialCapabilities

Returns the current SpatialCapabilities of the Session.

Boolean

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

Unit

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

Unit

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

Unit

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

Bundle

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

Bundle

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

Unit
setPreferredAspectRatio(activity: Activity, preferredRatio: Float)

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

Boolean

Unpersists an anchor.

Public properties

Activity
ActivitySpace

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

Entity
PanelEntity

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

PerceptionSpace

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

JxrPlatformAdapter
SpatialEnvironment
SpatialUser

The SpatialUser contains information about the user.

Public companion functions

create

Added in 1.0.0-alpha01
fun create(activity: Activity, runtime: JxrPlatformAdapter? = null): Session

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.

Public constructors

Session

Added in 1.0.0-alpha01
Session(
    activity: Activity,
    runtime: JxrPlatformAdapter,
    spatialEnvironment: SpatialEnvironment
)

Public functions

addSpatialCapabilitiesChangedListener

Added in 1.0.0-alpha01
fun addSpatialCapabilitiesChangedListener(
    listener: Consumer<SpatialCapabilities>
): Unit

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
fun addSpatialCapabilitiesChangedListener(
    callbackExecutor: Executor,
    listener: Consumer<SpatialCapabilities>
): Unit

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
fun canEmbedActivityPanel(activity: Activity): Boolean

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

createActivityPanelEntity

Added in 1.0.0-alpha01
fun createActivityPanelEntity(
    windowBoundsPx: Rect,
    name: String,
    pose: Pose = Pose.Identity
): ActivityPanelEntity

Public factory function for a spatial ActivityPanelEntity.

Parameters
windowBoundsPx: Rect

Bounds for the panel window in pixels.

name: String

Name of the panel.

pose: Pose = Pose.Identity

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

Returns
ActivityPanelEntity

an ActivityPanelEntity instance.

createAnchorEntity

Added in 1.0.0-alpha01
fun createAnchorEntity(anchor: Anchor): AnchorEntity

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

Parameters
anchor: Anchor

The PerceptionAnchor to use for this AnchorEntity.

createAnchorEntity

Added in 1.0.0-alpha01
fun createAnchorEntity(
    bounds: Dimensions,
    planeType: Int,
    planeSemantic: Int,
    timeout: Duration = Duration.ZERO
): AnchorEntity

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
bounds: Dimensions

Bounds for this AnchorEntity.

planeType: Int

Orientation of plane to which this Anchor should attach.

planeSemantic: Int

Semantics of the plane to which this Anchor should attach.

timeout: Duration = Duration.ZERO

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
fun createEntity(name: String, pose: Pose = Pose.Identity): Entity

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
name: String

Name of the entity.

pose: Pose = Pose.Identity

Initial pose of the entity.

createExrImageResource

Added in 1.0.0-alpha01
fun createExrImageResource(name: String): ExrImage

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

Parameters
name: String

The path for an EXR image to be loaded

Returns
ExrImage

an EXRImage instance.

createGltfEntity

Added in 1.0.0-alpha01
@MainThread
fun createGltfEntity(model: GltfModel, pose: Pose = Pose.Identity): GltfModelEntity

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
model: GltfModel

The GltfModel this Entity is referencing.

pose: Pose = Pose.Identity

The initial pose of the entity.

Returns
GltfModelEntity

a GltfModelEntity instance

createGltfResourceAsync

Added in 1.0.0-alpha01
@MainThread
fun createGltfResourceAsync(name: String): ListenableFuture<GltfModel>

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
name: String

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

Returns
ListenableFuture<GltfModel>

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

createInteractableComponent

Added in 1.0.0-alpha01
fun createInteractableComponent(
    executor: Executor,
    inputEventListener: InputEventListener
): InteractableComponent

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

Parameters
executor: Executor

Executor for invoking InputEventListener.

inputEventListener: InputEventListener

InputEventListener that accepts InputEvents.

createMovableComponent

Added in 1.0.0-alpha01
fun createMovableComponent(
    systemMovable: Boolean = true,
    scaleInZ: Boolean = true,
    anchorPlacement: Set<AnchorPlacement> = emptySet(),
    shouldDisposeParentAnchor: Boolean = true
): MovableComponent

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
systemMovable: Boolean = true

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

scaleInZ: Boolean = true

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

anchorPlacement: Set<AnchorPlacement> = emptySet()

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.

shouldDisposeParentAnchor: Boolean = true

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
fun createPanelEntity(
    view: View,
    surfaceDimensionsPx: Dimensions,
    dimensions: Dimensions,
    name: String,
    pose: Pose = Pose.Identity
): PanelEntity

Public factory function for a spatialized PanelEntity.

Parameters
view: View

View to embed in this panel entity.

surfaceDimensionsPx: Dimensions

Dimensions for the underlying surface for the given view.

dimensions: Dimensions

Dimensions for the panel in meters.

name: String

Name of the panel.

pose: Pose = Pose.Identity

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

Returns
PanelEntity

a PanelEntity instance.

createPersistedAnchorEntity

Added in 1.0.0-alpha01
fun createPersistedAnchorEntity(uuid: UUID): AnchorEntity

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
uuid: UUID

The UUID of the persisted anchor to recreate.

Returns
AnchorEntity

a persisted AnchorEntity instance.

createResizableComponent

Added in 1.0.0-alpha01
fun createResizableComponent(
    minimumSize: Dimensions = ResizableComponent.kMinimumSize,
    maximumSize: Dimensions = ResizableComponent.kMaximumSize
): ResizableComponent

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
minimumSize: Dimensions = ResizableComponent.kMinimumSize

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.

maximumSize: Dimensions = ResizableComponent.kMaximumSize

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
fun createStereoSurfaceEntity(
    stereoMode: Int = StereoSurfaceEntity.StereoMode.SIDE_BY_SIDE,
    dimensions: Dimensions = Dimensions(1.0f, 1.0f, 1.0f),
    pose: Pose = Pose.Identity
): StereoSurfaceEntity

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
stereoMode: Int = StereoSurfaceEntity.StereoMode.SIDE_BY_SIDE

Stereo mode for the surface.

dimensions: Dimensions = Dimensions(1.0f, 1.0f, 1.0f)

Dimensions for the surface.

pose: Pose = Pose.Identity

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

Returns
StereoSurfaceEntity

a StereoSurfaceEntity instance

getEntitiesOfType

Added in 1.0.0-alpha01
fun <T : Entity> getEntitiesOfType(type: Class<T>): List<T>

Returns all Entitys of the given type or its subtypes.

Parameters
type: Class<T>

the type of Entity to return.

Returns
List<T>

a list of all Entitys of the given type.

getSpatialCapabilities

Added in 1.0.0-alpha01
fun getSpatialCapabilities(): SpatialCapabilities

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.

hasSpatialCapability

Added in 1.0.0-alpha01
Deprecated in 1.0.0-alpha01
fun hasSpatialCapability(capability: Int): Boolean

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
fun removeSpatialCapabilitiesChangedListener(
    listener: Consumer<SpatialCapabilities>
): Unit

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

requestFullSpaceMode

Added in 1.0.0-alpha01
fun requestFullSpaceMode(): Unit

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
fun requestHomeSpaceMode(): Unit

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
fun setFullSpaceMode(bundle: 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
bundle: Bundle

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

Returns
Bundle

the input bundle with the full space mode flag set.

setFullSpaceModeWithEnvironmentInherited

Added in 1.0.0-alpha01
fun setFullSpaceModeWithEnvironmentInherited(bundle: 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
bundle: Bundle

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

Returns
Bundle

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

setPreferredAspectRatio

Added in 1.0.0-alpha01
fun setPreferredAspectRatio(activity: Activity, preferredRatio: Float): Unit

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
activity: Activity

the activity to set the preference.

preferredRatio: Float

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
fun unpersistAnchor(uuid: UUID): Boolean

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

Parameters
uuid: UUID

UUID of the anchor to unpersist.

Public properties

activity

Added in 1.0.0-alpha01
val activityActivity

activitySpace

Added in 1.0.0-alpha01
val activitySpaceActivitySpace

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.

activitySpaceRoot

Added in 1.0.0-alpha01
val activitySpaceRootEntity

mainPanelEntity

Added in 1.0.0-alpha01
val mainPanelEntityPanelEntity

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.

perceptionSpace

Added in 1.0.0-alpha01
val perceptionSpacePerceptionSpace

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.

runtime

Added in 1.0.0-alpha01
val runtimeJxrPlatformAdapter

spatialEnvironment

Added in 1.0.0-alpha01
val spatialEnvironmentSpatialEnvironment

spatialUser

Added in 1.0.0-alpha01
val spatialUserSpatialUser

The SpatialUser contains information about the user.