1 /* 2 * Copyright 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.xr.runtime.internal 18 19 import androidx.annotation.RestrictTo 20 21 /** 22 * Defines a configuration state of all available features to be set at runtime. 23 * 24 * An instance of this class should be passed to [Session.configure()] to modify the current 25 * configuration. 26 */ 27 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) 28 public class Config( 29 public val planeTracking: PlaneTrackingMode = PlaneTrackingMode.Disabled, 30 public val handTracking: HandTrackingMode = HandTrackingMode.Disabled, 31 public val depthEstimation: DepthEstimationMode = DepthEstimationMode.Disabled, 32 public val anchorPersistence: AnchorPersistenceMode = AnchorPersistenceMode.Disabled, 33 public val headTracking: HeadTrackingMode = HeadTrackingMode.Disabled, 34 ) { equalsnull35 override fun equals(other: Any?): Boolean { 36 if (this === other) return true 37 if (other !is Config) return false 38 39 if (planeTracking != other.planeTracking) return false 40 if (handTracking != other.handTracking) return false 41 if (depthEstimation != other.depthEstimation) return false 42 if (anchorPersistence != other.anchorPersistence) return false 43 if (headTracking != other.headTracking) return false 44 45 return true 46 } 47 hashCodenull48 override fun hashCode(): Int { 49 var result = planeTracking.hashCode() 50 result = 31 * result + handTracking.hashCode() 51 result = 31 * result + depthEstimation.hashCode() 52 result = 31 * result + anchorPersistence.hashCode() 53 result = 31 * result + headTracking.hashCode() 54 return result 55 } 56 57 @JvmOverloads copynull58 public fun copy( 59 planeTracking: PlaneTrackingMode = this.planeTracking, 60 handTracking: HandTrackingMode = this.handTracking, 61 depthEstimation: DepthEstimationMode = this.depthEstimation, 62 anchorPersistence: AnchorPersistenceMode = this.anchorPersistence, 63 headTracking: HeadTrackingMode = this.headTracking, 64 ): Config { 65 return Config( 66 planeTracking = planeTracking, 67 handTracking = handTracking, 68 depthEstimation = depthEstimation, 69 anchorPersistence = anchorPersistence, 70 headTracking = headTracking, 71 ) 72 } 73 74 /** 75 * Feature that allows tracking of and provides information about scene planes. 76 * 77 * Setting this feature to [PlaneTrackingMode.Enabled] requires that the 78 * `SCENE_UNDERSTANDING_COARSE` Android permission is granted. 79 */ 80 public class PlaneTrackingMode private constructor(public val mode: Int) { 81 public companion object { 82 /** Planes will not be tracked. */ 83 @JvmField public val Disabled: PlaneTrackingMode = PlaneTrackingMode(0) 84 /** 85 * Horizontal and vertical planes will be tracked. Note that setting this mode will 86 * consume additional runtime resources. 87 */ 88 @JvmField public val HorizontalAndVertical: PlaneTrackingMode = PlaneTrackingMode(1) 89 } 90 toStringnull91 override fun toString(): String { 92 return "PlaneTracking_" + if (mode == 0) "Disabled" else "HorizontalAndVertical" 93 } 94 } 95 96 /** 97 * Feature that allows tracking of the user's hands and hand joints. 98 * 99 * Setting this feature to [HandTrackingMode.Enabled] requires that the `HAND_TRACKING` Android 100 * permission is granted by the calling application. 101 */ 102 public class HandTrackingMode private constructor(public val mode: Int) { 103 public companion object { 104 /** Hands will not be tracked. */ 105 @JvmField public val Disabled: HandTrackingMode = HandTrackingMode(0) 106 /** 107 * Hands will be tracked. Note that setting this mode will consume additional runtime 108 * resources. 109 */ 110 @JvmField public val Enabled: HandTrackingMode = HandTrackingMode(1) 111 } 112 toStringnull113 override fun toString(): String { 114 return "HandTracking_" + if (mode == 0) "Disabled" else "Enabled" 115 } 116 } 117 118 /** 119 * Feature that allows more accurate information about scene depth and meshes. 120 * 121 * Setting this feature to [DepthEstimationMode.Enabled] requires that the 122 * `SCENE_UNDERSTANDING_FINE` Android permission is granted by the calling application. 123 */ 124 public class DepthEstimationMode private constructor(public val mode: Int) { 125 public companion object { 126 /** No information about scene depth will be provided. */ 127 @JvmField public val Disabled: DepthEstimationMode = DepthEstimationMode(0) 128 /** 129 * Depth estimation will be enabled. Note that setting this mode will consume additional 130 * runtime resources. 131 */ 132 @JvmField public val Enabled: DepthEstimationMode = DepthEstimationMode(1) 133 } 134 toStringnull135 override fun toString(): String { 136 return "DepthEstimation_" + if (mode == 0) "Disabled" else "Enabled" 137 } 138 } 139 140 /** 141 * Feature that allows [Anchor]'s to be peristed through sessions. 142 * 143 * This feature does not require any additional application permissions. 144 */ 145 public class AnchorPersistenceMode private constructor(public val mode: Int) { 146 public companion object { 147 /** Anchors cannot be persisted. */ 148 @JvmField public val Disabled: AnchorPersistenceMode = AnchorPersistenceMode(0) 149 /** Anchors may be persisted. */ 150 @JvmField public val Enabled: AnchorPersistenceMode = AnchorPersistenceMode(1) 151 } 152 toStringnull153 override fun toString(): String { 154 return "AnchorPersistence_" + if (mode == 0) "Disabled" else "Enabled" 155 } 156 } 157 158 /** 159 * Feature that allows tracking of the user's head pose. 160 * 161 * Setting this feature to [HeadTracking.Enabled] requires that the `HEAD_TRACKING` Android 162 * permission is granted by the calling application. 163 */ 164 public class HeadTrackingMode private constructor(public val mode: Int) { 165 public companion object { 166 /** Head pose will not be tracked. */ 167 @JvmField public val Disabled: HeadTrackingMode = HeadTrackingMode(0) 168 /** Head pose will be tracked. */ 169 @JvmField public val Enabled: HeadTrackingMode = HeadTrackingMode(1) 170 } 171 } 172 } 173