1 /* 2 * Copyright 2020 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 android.uwb; 18 19 import android.content.AttributionSource; 20 import android.os.PersistableBundle; 21 import android.uwb.IUwbAdapterStateCallbacks; 22 import android.uwb.IUwbAdfProvisionStateCallbacks; 23 import android.uwb.IUwbRangingCallbacks; 24 import android.uwb.SessionHandle; 25 import android.uwb.UwbAddress; 26 import android.uwb.IUwbVendorUciCallback; 27 import android.uwb.IUwbOemExtensionCallback; 28 import android.uwb.IOnUwbActivityEnergyInfoListener; 29 30 /** 31 * @hide 32 * TODO(b/211025367): Remove all the duplicate javadocs here. 33 */ 34 interface IUwbAdapter { 35 /* 36 * Register the callbacks used to notify the framework of events and data 37 * 38 * The provided callback's IUwbAdapterStateCallbacks#onAdapterStateChanged 39 * function must be called immediately following registration with the current 40 * state of the UWB adapter. 41 * 42 * @param callbacks callback to provide range and status updates to the framework 43 */ registerAdapterStateCallbacks(in IUwbAdapterStateCallbacks adapterStateCallbacks)44 void registerAdapterStateCallbacks(in IUwbAdapterStateCallbacks adapterStateCallbacks); 45 46 /* 47 * Register the callbacks used to notify the framework of events and data 48 * 49 * The provided callback's IUwbUciVendorCallback#onVendorNotificationReceived 50 * function must be called immediately following vendorNotification received 51 * 52 * @param callbacks callback to provide Notification data updates to the framework 53 */ registerVendorExtensionCallback(in IUwbVendorUciCallback callbacks)54 void registerVendorExtensionCallback(in IUwbVendorUciCallback callbacks); 55 56 /* 57 * Unregister the callbacks used to notify the framework of events and data 58 * 59 * Calling this function with an unregistered callback is a no-op 60 * 61 * @param callbacks callback to unregister 62 */ unregisterVendorExtensionCallback(in IUwbVendorUciCallback callbacks)63 void unregisterVendorExtensionCallback(in IUwbVendorUciCallback callbacks); 64 65 /* 66 * Unregister the callbacks used to notify the framework of events and data 67 * 68 * Calling this function with an unregistered callback is a no-op 69 * 70 * @param callbacks callback to unregister 71 */ unregisterAdapterStateCallbacks(in IUwbAdapterStateCallbacks callbacks)72 void unregisterAdapterStateCallbacks(in IUwbAdapterStateCallbacks callbacks); 73 registerOemExtensionCallback(in IUwbOemExtensionCallback callbacks)74 void registerOemExtensionCallback(in IUwbOemExtensionCallback callbacks); 75 unregisterOemExtensionCallback(in IUwbOemExtensionCallback callbacks)76 void unregisterOemExtensionCallback(in IUwbOemExtensionCallback callbacks); 77 78 /** 79 * Get the accuracy of the ranging timestamps 80 * 81 * @param chipId identifier of UWB chip for multi-HAL devices 82 * 83 * @return accuracy of the ranging timestamps in nanoseconds 84 */ getTimestampResolutionNanos(in String chipId)85 long getTimestampResolutionNanos(in String chipId); 86 87 /** 88 * Provides the capabilities and features of the device 89 * 90 * @param chipId identifier of UWB chip for multi-HAL devices 91 * 92 * @return specification specific capabilities and features of the device 93 */ getSpecificationInfo(in String chipId)94 PersistableBundle getSpecificationInfo(in String chipId); 95 96 /** 97 * Request to open a new ranging session 98 * 99 * This function does not start the ranging session, but all necessary 100 * components must be initialized and ready to start a new ranging 101 * session prior to calling IUwbAdapterCallback#onRangingOpened. 102 * 103 * IUwbAdapterCallbacks#onRangingOpened must be called within 104 * RANGING_SESSION_OPEN_THRESHOLD_MS milliseconds of #openRanging being 105 * called if the ranging session is opened successfully. 106 * 107 * IUwbAdapterCallbacks#onRangingOpenFailed must be called within 108 * RANGING_SESSION_OPEN_THRESHOLD_MS milliseconds of #openRanging being called 109 * if the ranging session fails to be opened. 110 * 111 * If the provided sessionHandle is already open for the calling client, then 112 * #onRangingOpenFailed must be called and the new session must not be opened. 113 * 114 * @param attributionSource AttributionSource to use for permission enforcement. 115 * @param sessionHandle the session handle to open ranging for 116 * @param rangingCallbacks the callbacks used to deliver ranging information 117 * @param parameters the configuration to use for ranging 118 * @param chipId identifier of UWB chip for multi-HAL devices 119 */ openRanging(in AttributionSource attributionSource, in SessionHandle sessionHandle, in IUwbRangingCallbacks rangingCallbacks, in PersistableBundle parameters, in String chipId)120 void openRanging(in AttributionSource attributionSource, 121 in SessionHandle sessionHandle, 122 in IUwbRangingCallbacks rangingCallbacks, 123 in PersistableBundle parameters, 124 in String chipId); 125 126 /** 127 * Request to start ranging 128 * 129 * IUwbAdapterCallbacks#onRangingStarted must be called within 130 * RANGING_SESSION_START_THRESHOLD_MS milliseconds of #startRanging being 131 * called if the ranging session starts successfully. 132 * 133 * IUwbAdapterCallbacks#onRangingStartFailed must be called within 134 * RANGING_SESSION_START_THRESHOLD_MS milliseconds of #startRanging being 135 * called if the ranging session fails to be started. 136 * 137 * @param sessionHandle the session handle to start ranging for 138 * @param parameters additional configuration required to start ranging 139 */ startRanging(in SessionHandle sessionHandle, in PersistableBundle parameters)140 void startRanging(in SessionHandle sessionHandle, 141 in PersistableBundle parameters); 142 143 /** 144 * Request to reconfigure ranging 145 * 146 * IUwbAdapterCallbacks#onRangingReconfigured must be called after 147 * successfully reconfiguring the session. 148 * 149 * IUwbAdapterCallbacks#onRangingReconfigureFailed must be called after 150 * failing to reconfigure the session. 151 * 152 * A session must not be modified by a failed call to #reconfigureRanging. 153 * 154 * @param sessionHandle the session handle to start ranging for 155 * @param parameters the parameters to reconfigure and their new values 156 */ reconfigureRanging(in SessionHandle sessionHandle, in PersistableBundle parameters)157 void reconfigureRanging(in SessionHandle sessionHandle, 158 in PersistableBundle parameters); 159 160 /** 161 * Request to stop ranging 162 * 163 * IUwbAdapterCallbacks#onRangingStopped must be called after 164 * successfully stopping the session. 165 * 166 * IUwbAdapterCallbacks#onRangingStopFailed must be called after failing 167 * to stop the session. 168 * 169 * @param sessionHandle the session handle to stop ranging for 170 */ stopRanging(in SessionHandle sessionHandle)171 void stopRanging(in SessionHandle sessionHandle); 172 173 /** 174 * Close ranging for the session associated with the given handle 175 * 176 * Calling with an invalid handle or a handle that has already been closed 177 * is a no-op. 178 * 179 * IUwbAdapterCallbacks#onRangingClosed must be called within 180 * RANGING_SESSION_CLOSE_THRESHOLD_MS of #closeRanging being called. 181 * 182 * @param sessionHandle the session handle to close ranging for 183 */ closeRanging(in SessionHandle sessionHandle)184 void closeRanging(in SessionHandle sessionHandle); 185 186 /** 187 * Add a new controlee to an ongoing session. 188 * <p>This call may be made when the session is open. 189 * 190 * <p>On successfully adding a new controlee to the session 191 * {@link RangingSession.Callback#onControleeAdded(PersistableBundle)} is invoked. 192 * 193 * <p>On failure to add a new controlee to the session, 194 * {@link RangingSession.Callback#onControleeAddFailed(int, PersistableBundle)}is invoked. 195 * 196 * @param sessionHandle the session handle to close ranging for 197 * @param params the parameters for the new controlee. 198 */ addControlee(in SessionHandle sessionHandle, in PersistableBundle params)199 void addControlee(in SessionHandle sessionHandle, in PersistableBundle params); 200 201 /** 202 * Remove an existing controlee from an ongoing session. 203 * <p>This call may be made when the session is open. 204 * 205 * <p>On successfully removing an existing controlee from the session 206 * {@link RangingSession.Callback#onControleeRemoved(PersistableBundle)} is invoked. 207 * 208 * <p>On failure to remove an existing controlee from the session, 209 * {@link RangingSession.Callback#onControleeRemoveFailed(int, PersistableBundle)}is invoked. 210 * 211 * @param sessionHandle the session handle to close ranging for 212 * @param params the parameters for the existing controlee. 213 */ removeControlee(in SessionHandle sessionHandle, in PersistableBundle params)214 void removeControlee(in SessionHandle sessionHandle, in PersistableBundle params); 215 216 /** 217 * Suspends an ongoing ranging session. 218 * 219 * <p>A session that has been pauseed may be resumed by calling 220 * {@link RangingSession#resume(PersistableBundle)} without the need to open a new session. 221 * 222 * <p>Suspending a {@link RangingSession} is useful when the lower layers should skip a few 223 * ranging rounds for a session without stopping it. 224 * 225 * <p>If the {@link RangingSession} is no longer needed, use {@link RangingSession#stop()} or 226 * {@link RangingSession#close()} to completely close the session. 227 * 228 * <p>On successfully pauseing the session, 229 * {@link RangingSession.Callback#onPaused(PersistableBundle)} is invoked. 230 * 231 * <p>On failure to pause the session, 232 * {@link RangingSession.Callback#onPauseFailed(int, PersistableBundle)} is invoked. 233 * 234 * @param sessionHandle the session handle to close ranging for 235 * @param params protocol specific parameters for pauseing the session. 236 */ pause(in SessionHandle sessionHandle, in PersistableBundle params)237 void pause(in SessionHandle sessionHandle, in PersistableBundle params); 238 239 /** 240 * Resumes a pauseed ranging session. 241 * 242 * <p>A session that has been previously pauseed using 243 * {@link RangingSession#pause(PersistableBundle)} can be resumed by calling 244 * {@link RangingSession#resume(PersistableBundle)}. 245 * 246 * <p>On successfully resuming the session, 247 * {@link RangingSession.Callback#onResumed(PersistableBundle)} is invoked. 248 * 249 * <p>On failure to pause the session, 250 * {@link RangingSession.Callback#onResumeFailed(int, PersistableBundle)} is invoked. 251 * 252 * @param sessionHandle the session handle to close ranging for 253 * @param params protocol specific parameters the resuming the session. 254 */ resume(in SessionHandle sessionHandle, in PersistableBundle params)255 void resume(in SessionHandle sessionHandle, in PersistableBundle params); 256 257 /** 258 * Send data to a remote device which is part of this ongoing session. 259 * The data is sent by piggybacking the provided data over RRM (initiator -> responder) or 260 * RIM (responder -> initiator). 261 * <p>This is only functional on a FIRA 2.0 compliant device. 262 * 263 * <p>On successfully sending the data, 264 * {@link RangingSession.Callback#onDataSent(UwbAddress, PersistableBundle)} is invoked. 265 * 266 * <p>On failure to send the data, 267 * {@link RangingSession.Callback#onDataSendFailed(UwbAddress, int, PersistableBundle)} is 268 * invoked. 269 * 270 * @param sessionHandle the session handle to close ranging for 271 * @param remoteDeviceAddress remote device's address. 272 * @param params protocol specific parameters the sending the data. 273 * @param data Raw data to be sent. 274 */ sendData(in SessionHandle sessionHandle, in UwbAddress remoteDeviceAddress, in PersistableBundle params, in byte[] data)275 void sendData(in SessionHandle sessionHandle, in UwbAddress remoteDeviceAddress, 276 in PersistableBundle params, in byte[] data); 277 278 /** 279 * Disables or enables UWB for a user 280 * 281 * The provided callback's IUwbAdapterStateCallbacks#onAdapterStateChanged 282 * function must be called immediately following state change. 283 * 284 * @param enabled value representing intent to disable or enable UWB. If 285 * true, any subsequent calls to #openRanging will be allowed. If false, 286 * all active ranging sessions will be closed and subsequent calls to 287 * #openRanging will be disallowed. 288 */ setEnabled(boolean enabled)289 void setEnabled(boolean enabled); 290 291 /** 292 * Returns the current enabled/disabled UWB state. 293 * 294 * Possible values are: 295 * IUwbAdapterState#STATE_DISABLED 296 * IUwbAdapterState#STATE_ENABLED_ACTIVE 297 * IUwbAdapterState#STATE_ENABLED_INACTIVE 298 * 299 * @return value representing enabled/disabled UWB state. 300 */ getAdapterState()301 int getAdapterState(); 302 303 /** 304 * Returns a list of UWB chip infos in a {@link PersistableBundle}. 305 * 306 * Callers can invoke methods on a specific UWB chip by passing its {@code chipId} to the 307 * method, which can be determined by calling: 308 * <pre> 309 * List<PersistableBundle> chipInfos = getChipInfos(); 310 * for (PersistableBundle chipInfo : chipInfos) { 311 * String chipId = ChipInfoParams.fromBundle(chipInfo).getChipId(); 312 * } 313 * </pre> 314 * 315 * @return list of {@link PersistableBundle} containing info about UWB chips for a multi-HAL 316 * system, or a list of info for a single chip for a single HAL system. 317 */ getChipInfos()318 List<PersistableBundle> getChipInfos(); 319 getChipIds()320 List<String> getChipIds(); 321 322 /** 323 * Returns the default UWB chip identifier. 324 * 325 * If callers do not pass a specific {@code chipId} to UWB methods, then the method will be 326 * invoked on the default chip, which is determined at system initialization from a configuration 327 * file. 328 * 329 * @return default UWB chip identifier for a multi-HAL system, or the identifier of the only UWB 330 * chip in a single HAL system. 331 */ getDefaultChipId()332 String getDefaultChipId(); 333 addServiceProfile(in PersistableBundle parameters)334 PersistableBundle addServiceProfile(in PersistableBundle parameters); 335 removeServiceProfile(in PersistableBundle parameters)336 int removeServiceProfile(in PersistableBundle parameters); 337 getAllServiceProfiles()338 PersistableBundle getAllServiceProfiles(); 339 getAdfProvisioningAuthorities(in PersistableBundle parameters)340 PersistableBundle getAdfProvisioningAuthorities(in PersistableBundle parameters); 341 getAdfCertificateAndInfo(in PersistableBundle parameters)342 PersistableBundle getAdfCertificateAndInfo(in PersistableBundle parameters); 343 provisionProfileAdfByScript(in PersistableBundle serviceProfileBundle, in IUwbAdfProvisionStateCallbacks callback)344 void provisionProfileAdfByScript(in PersistableBundle serviceProfileBundle, 345 in IUwbAdfProvisionStateCallbacks callback); 346 removeProfileAdf(in PersistableBundle serviceProfileBundle)347 int removeProfileAdf(in PersistableBundle serviceProfileBundle); 348 349 /** 350 * Updates the device pose. This helps the filter engine distinguish position noise from device 351 * motion. The device pose would typically come from ARCore. This requires that an application 352 * pose source was indicated in the call to openSession. 353 */ updatePose(in SessionHandle sessionHandle, in PersistableBundle params)354 void updatePose(in SessionHandle sessionHandle, in PersistableBundle params); 355 sendVendorUciMessage(int mt, int gid, int oid, in byte[] payload)356 int sendVendorUciMessage(int mt, int gid, int oid, in byte[] payload); 357 updateRangingRoundsDtTag(in SessionHandle sessionHandle, in PersistableBundle parameters)358 void updateRangingRoundsDtTag(in SessionHandle sessionHandle, in PersistableBundle parameters); 359 getUwbActivityEnergyInfoAsync(in IOnUwbActivityEnergyInfoListener listener)360 void getUwbActivityEnergyInfoAsync(in IOnUwbActivityEnergyInfoListener listener); 361 362 /** 363 * Returns the max Application Data payload size that can be sent by the UWBS in one ranging 364 * round. 365 */ queryMaxDataSizeBytes(in SessionHandle sessionHandle)366 int queryMaxDataSizeBytes(in SessionHandle sessionHandle); 367 368 /** 369 * The maximum allowed time to open a ranging session. 370 */ 371 const int RANGING_SESSION_OPEN_THRESHOLD_MS = 3000; // Value TBD 372 373 /** 374 * The maximum allowed time to start a ranging session. 375 */ 376 const int RANGING_SESSION_START_THRESHOLD_MS = 3000; // Value TBD 377 378 /** 379 * The maximum allowed time to notify the framework that a session has been 380 * closed. 381 */ 382 const int RANGING_SESSION_CLOSE_THRESHOLD_MS = 3000; // Value TBD 383 384 /** 385 * The maximum allowed time to configure ranging rounds update for DT Tag 386 */ 387 const int RANGING_ROUNDS_UPDATE_DT_TAG_THRESHOLD_MS = 3000; // Value TBD 388 } 389