@mentra/bluetooth-sdk 3.3.0 → 3.4.0-beta.1241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION.md +61 -0
- package/README.md +80 -11
- package/android/build.gradle +60 -51
- package/android/gradle.properties +3 -0
- package/android/settings.gradle +47 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/BesCrashReportWaiters.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +5 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +85 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +35 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +154 -110
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +21 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +1 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +27 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/connection/ConnectionModels.kt +5 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicy.kt +64 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +925 -155
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +227 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +19 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicy.kt +94 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachine.kt +411 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateStore.kt +124 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +54 -59
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +5 -32
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasEncoder.kt +8 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +3 -10
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +50 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueue.kt +92 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHost.kt +169 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +74 -115
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +348 -357
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetector.kt +211 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngine.kt +137 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SttTextFormatter.kt +52 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/WakeWordDetector.kt +235 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AvifExifStripper.java +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +3 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +11 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/AudioRouteWatcher.kt +120 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +181 -16
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlayback.kt +177 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/BesCrashReportWaitersTest.kt +112 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/DeviceManagerOwnerLossTest.kt +146 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusAudioSetupTest.kt +51 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusClassicAudioTest.kt +2 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/WifiAdbPeerIntentTest.kt +19 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicyTest.kt +65 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveAudioSetupReadinessTest.kt +231 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +5 -1
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +183 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +368 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +20 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicyTest.kt +136 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachineTest.kt +346 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +1 -56
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +0 -22
- package/android/src/test/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNamingTest.kt +23 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueueTest.kt +81 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHostTest.kt +216 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/STTToolsExtractionTest.kt +108 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetectorTest.kt +126 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngineTest.kt +245 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SttTextFormatterTest.kt +67 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlaybackTest.kt +76 -0
- package/build/BluetoothSdk.types.d.ts +201 -1
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +43 -5
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +2 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/generated/changelogCatalog.d.ts +3 -0
- package/build/generated/changelogCatalog.d.ts.map +1 -1
- package/build/generated/changelogCatalog.js +4 -0
- package/build/generated/changelogCatalog.js.map +1 -1
- package/build/generated/releaseMetadata.js +6 -6
- package/build/generated/releaseMetadata.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +9 -0
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +76 -12
- package/ios/MentraBluetoothSDK.podspec +4 -0
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
- package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
- package/ios/Source/BesCrashReportWaiters.swift +64 -0
- package/ios/Source/BluetoothSdkDefaults.swift +2 -2
- package/ios/Source/Bridge.swift +11 -3
- package/ios/Source/DeviceManager.swift +131 -18
- package/ios/Source/DeviceStore.swift +27 -0
- package/ios/Source/GeneratedChangelogCatalog.swift +1 -0
- package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
- package/ios/Source/MentraBluetoothSDK.swift +40 -5
- package/ios/Source/audio/PcmStreamPlayer.swift +290 -57
- package/ios/Source/audio/PcmUrlPlayback.swift +231 -0
- package/ios/Source/audio/SpeechActivity.swift +277 -0
- package/ios/Source/errors/BluetoothSdkError.swift +5 -1
- package/ios/Source/events/BluetoothEvents.swift +41 -0
- package/ios/Source/internal/BleTraceLogger.swift +9 -6
- package/ios/Source/internal/BluetoothAvailability.swift +15 -5
- package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +186 -0
- package/ios/Source/sgcs/MentraLive.swift +1270 -189
- package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +260 -1
- package/ios/Source/sgcs/MentraLivePairingStateMachine.swift +385 -0
- package/ios/Source/sgcs/MentraLivePairingStateStore.swift +121 -0
- package/ios/Source/sgcs/Nimo.swift +10 -3
- package/ios/Source/sgcs/NimoCanvasCoordinator.swift +39 -9
- package/ios/Source/sgcs/SGCManager.swift +13 -0
- package/ios/Source/sgcs/Simulated.swift +2 -0
- package/ios/Source/status/DeviceStatus.swift +35 -0
- package/ios/Source/stt/STTTools.swift +13 -31
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +204 -162
- package/ios/Source/stt/SileroSpeechActivity.swift +87 -0
- package/ios/Source/stt/WakeWordDetector.swift +145 -0
- package/ios/Source/types/DeviceModels.swift +8 -1
- package/ios/Source/utils/AudioSessionMonitor.swift +158 -5
- package/ios/Source/utils/BoundedWait.swift +44 -0
- package/ios/Source/utils/DemandDrivenAudioWorker.swift +79 -0
- package/ios/Source/utils/SttModelTraits.swift +62 -0
- package/ios/Tests/BesCrashReportTests.swift +142 -0
- package/ios/Tests/BluetoothAudioRouteTests.swift +82 -0
- package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
- package/ios/Tests/DeviceManagerReconnectTests.swift +4 -2
- package/ios/Tests/GlassesAudioSetupPolicyTests.swift +197 -0
- package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
- package/ios/Tests/MentraLiveAudioSetupTests.swift +209 -0
- package/ios/Tests/MentraLiveConnectionOptionsTests.swift +55 -0
- package/ios/Tests/MentraLivePairingAdvertisementTests.swift +327 -0
- package/ios/Tests/MentraLivePairingStateMachineTests.swift +402 -0
- package/ios/Tests/MentraLiveSessionReadinessTests.swift +368 -26
- package/ios/Tests/NimoCanvasTransportTests.swift +58 -0
- package/ios/Tests/PcmStreamTests.swift +299 -0
- package/ios/Tests/SpeechActivityTests.swift +238 -0
- package/ios/Tests/SttModelTraitsTests.swift +62 -0
- package/ios/Tests/WifiAdbDispatchTests.swift +118 -0
- package/package.json +3 -2
- package/plugin/build/withAndroid.js +9 -11
- package/plugin/build/withKotlinVersion.d.ts +2 -0
- package/plugin/build/withKotlinVersion.js +46 -0
- package/src/BluetoothSdk.types.ts +201 -1
- package/src/_private/BluetoothSdkModule.ts +47 -5
- package/src/generated/changelogCatalog.ts +4 -0
- package/src/generated/releaseMetadata.ts +6 -6
- package/src/index.ts +22 -0
- package/android/silero/LICENSE.md +0 -17
- package/android/silero/build.gradle +0 -50
- package/android/silero/proguard-rules.pro +0 -24
- package/android/silero/src/androidTest/assets/hello.wav +0 -0
- package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +0 -79
- package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +0 -160
- package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +0 -449
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +0 -15
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +0 -14
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +0 -12
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +0 -47
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +0 -41
- package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +0 -44
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -368
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +0 -156
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +0 -229
- package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -20
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +0 -287
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +0 -127
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +0 -288
- /package/android/{silero/src/main/assets/LICENSE → src/main/assets/vad/LICENSE.silero_vad} +0 -0
- /package/android/{silero/src/main/assets → src/main/assets/vad}/silero_vad.onnx +0 -0
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Bluetooth SDK migration: Mentra Live pairing state
|
|
2
|
+
|
|
3
|
+
This note covers the public pairing API in `@mentra/bluetooth-sdk` `3.3.0` relative to the published `3.2.1` package. `3.3.0` is the current release family in `package.json` and is not on npm yet.
|
|
4
|
+
|
|
5
|
+
## Version
|
|
6
|
+
|
|
7
|
+
The SDK version is `package.json` `"version"`. The iOS podspec (`ios/MentraBluetoothSDK.podspec`) and the Android Gradle module (`android/build.gradle`) read that same value. Swift package metadata is injected from it at pack time.
|
|
8
|
+
|
|
9
|
+
This repository keeps the Bluetooth SDK version aligned with the matching Mentra Live software release. It does not cut an independent major for a breaking SDK change. The break below ships in the unpublished `3.3.0` family. No further version bump was applied in this change. Integrators on `3.2.1` pick it up by moving to `3.3.0` when that release is published.
|
|
10
|
+
|
|
11
|
+
## Removed
|
|
12
|
+
|
|
13
|
+
- `confirmReplaceOwner()` is removed.
|
|
14
|
+
- The `confirm_replace_owner_result` event and its types are removed.
|
|
15
|
+
- `owner_replaced` is deprecated and is never emitted. Remove listeners. Use `pairing_state_changed` or `GlassesStatus.pairingState`.
|
|
16
|
+
- `pairing_info` no longer includes `awaiting_confirm` or `retained_owner_link`.
|
|
17
|
+
|
|
18
|
+
## Added
|
|
19
|
+
|
|
20
|
+
`GlassesStatus.pairingState` (absent on models other than Mentra Live):
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
type MentraLivePairingState =
|
|
24
|
+
| {state: "normal"}
|
|
25
|
+
| {state: "pairing_mode"; windowId: number; endsAtMs: number}
|
|
26
|
+
| {state: "pairing_rejected"}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
| State | What to do |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| `normal` | Automatic reconnect is allowed. |
|
|
32
|
+
| `pairing_mode` | A pairing window is open. Leave reconnect paused until `endsAtMs`. That timestamp is the window plus a 30-second margin. `windowId` identifies the window and survives a cold start. |
|
|
33
|
+
| `pairing_rejected` | The glasses no longer accept this phone (another phone paired, or repeated authentication rejections on secure-pairing firmware). Reconnect has stopped. Show **Pair Again**. This clears only after a successful explicit `connect()` / `connectDefault()`, or after `forget()`. |
|
|
34
|
+
|
|
35
|
+
`useMentraBluetooth().glasses` does not include `pairingState`. Read `getGlassesStatus()`, `subscribeGlassesStatus()`, or the `pairing_state_changed` event (`{state: MentraLivePairingState}`).
|
|
36
|
+
|
|
37
|
+
`GlassesStatus.audioSetup` (every model) says whether the user has to do anything for glasses audio:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
type GlassesAudioSetupState =
|
|
41
|
+
| {state: "idle"}
|
|
42
|
+
| {state: "not_applicable"}
|
|
43
|
+
| {state: "connecting"}
|
|
44
|
+
| {state: "connected"}
|
|
45
|
+
| {state: "needs_user"; action: "connect_in_settings"}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Render `needs_user` as a step that sends the user to Settings > Bluetooth, and treat `connected` and `not_applicable` as done. The SDK owns the waits (on iPhone: up to 8 seconds after a pair on firmware with `auto_audio`, none on older firmware, 10 seconds after a reconnect). Remove any app-side audio timers or `pairing_info.auto_audio` checks. Changes also arrive as `audio_setup_changed` (`{state: GlassesAudioSetupState}`).
|
|
49
|
+
|
|
50
|
+
Other additions:
|
|
51
|
+
|
|
52
|
+
- `entering_pairing_mode` includes `window_id` (same window as `pairingState.windowId`).
|
|
53
|
+
- `pairing_mode_ended` fires when the glasses close the window and this phone is still accepted. `reason` is `"paired"`, `"cancelled"`, or `"timeout"`. Optional `window_id`. The previous phone does not get this event when another phone pairs; it moves to `pairing_rejected`.
|
|
54
|
+
- `pairing_info.auto_audio` is true when the glasses derive Classic audio from the LE pair (CTKD). The SDK already uses it for `audioSetup`.
|
|
55
|
+
- `pair_failure.code` may be `"ios_forget_pairing"`: iOS holds a stale Bluetooth pairing for these glasses during an explicit attempt. The user must open Settings > Bluetooth, choose Forget This Device, then pair again. On Android and iOS native apps this arrives as the pairing-failure error's `failureCode`.
|
|
56
|
+
|
|
57
|
+
## Behavior
|
|
58
|
+
|
|
59
|
+
On supported Mentra Live firmware, three presses of the power button open one 120-second pairing window. The glasses speak a 4-character code. Three presses again cancel the window. After a timeout or a cancel, the phone that was already paired reconnects automatically. If another phone pairs, that previous phone gets `pairing_rejected`. Pairing readiness needs no app-side `pairing_info` wait: the SDK reports the glasses ready only after secure firmware commits the bond, and treats glasses that send no `pairing_info` within 5 seconds as older firmware.
|
|
60
|
+
|
|
61
|
+
User-facing sample copy should say "Pair Again". Do not say "owner" in that copy. API fields such as `owner_retained`, `owner_committed`, and `ownership_transfer` are unchanged identifiers on `entering_pairing_mode` and `pairing_info`.
|
package/README.md
CHANGED
|
@@ -46,6 +46,8 @@ changes. Adding this JS package alone cannot reroute logs in an older binary.
|
|
|
46
46
|
- React Native `0.72+`.
|
|
47
47
|
- Expo `49+` when using Expo.
|
|
48
48
|
- Android min SDK `28+`.
|
|
49
|
+
- Android source builds use Kotlin `2.3.0+`; the Expo config plugin selects it
|
|
50
|
+
automatically. The public Maven SDK still targets Kotlin 2.1 consumers.
|
|
49
51
|
- iOS deployment target `15.1+`.
|
|
50
52
|
- Native macOS deployment target `13+`. The Starter Kit's separate
|
|
51
53
|
`react-native-macos` host requires macOS `14+` and a matching React Native / Expo
|
|
@@ -448,6 +450,51 @@ await BluetoothSdk.clearDefaultDevice()
|
|
|
448
450
|
await saveDeviceToYourAppStorage(null)
|
|
449
451
|
```
|
|
450
452
|
|
|
453
|
+
## Mentra Live pairing
|
|
454
|
+
|
|
455
|
+
`confirmReplaceOwner()` and `confirm_replace_owner_result` are removed. `owner_replaced` is deprecated and is never emitted. The replacement is `GlassesStatus.pairingState`, also delivered as `pairing_state_changed`. Full steps are in [MIGRATION.md](./MIGRATION.md). The version stays `3.3.0` in `package.json` (podspec and Gradle read it). npm still publishes `3.2.1`.
|
|
456
|
+
|
|
457
|
+
On supported Mentra Live firmware, three power-button presses open one 120-second window and the glasses speak a 4-character code. Three presses again cancel it. The phone that was already paired pauses automatic reconnect for that window plus a 30-second margin (`pairingState.endsAtMs`), then reconnects after `pairing_mode_ended` with `reason` `"timeout"` or `"cancelled"`. If the glasses stop accepting this phone (another phone paired, or repeated authentication rejections on secure-pairing firmware), this phone's state becomes `pairing_rejected`: reconnect stops, and the UI should show Pair Again. That state clears only after a successful explicit pair or `forget()`.
|
|
458
|
+
|
|
459
|
+
`useMentraBluetooth().glasses` does not include `pairingState`. Read `getGlassesStatus()`, `subscribeGlassesStatus()`, or:
|
|
460
|
+
|
|
461
|
+
```ts
|
|
462
|
+
BluetoothSdk.addListener("pairing_state_changed", (event) => {
|
|
463
|
+
if (event.state.state === "pairing_rejected") showPairAgain()
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
BluetoothSdk.addListener("pair_failure", (event) => {
|
|
467
|
+
if (event.code === "ios_forget_pairing") {
|
|
468
|
+
// iOS still has a Bluetooth pairing for these glasses.
|
|
469
|
+
// Settings > Bluetooth > Forget This Device, then pair again.
|
|
470
|
+
}
|
|
471
|
+
})
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
`entering_pairing_mode` includes `window_id`. `pairing_info` includes `auto_audio` and no longer includes `awaiting_confirm` or `retained_owner_link`. Do not use the word "owner" in user-facing sample copy.
|
|
475
|
+
|
|
476
|
+
## Glasses audio setup
|
|
477
|
+
|
|
478
|
+
`GlassesStatus.audioSetup`, also delivered as `audio_setup_changed` (`{state}`), says whether the user has to do anything to get glasses audio working. The SDK decides it for every glasses model. Render it; do not add your own audio timers or platform checks.
|
|
479
|
+
|
|
480
|
+
| `audioSetup.state` | Meaning | What to show |
|
|
481
|
+
| --- | --- | --- |
|
|
482
|
+
| `idle` | No glasses session | Nothing |
|
|
483
|
+
| `not_applicable` | No audio step (Android attaches audio from the BLE bond; glasses without Classic audio) | Nothing |
|
|
484
|
+
| `connecting` | Glasses connected, audio expected to come up on its own | A "connecting" state |
|
|
485
|
+
| `connected` | Classic audio (A2DP or HFP) is up | Nothing |
|
|
486
|
+
| `needs_user` | Audio did not come up on its own (`action: "connect_in_settings"`) | Ask the user to connect the glasses in Settings > Bluetooth |
|
|
487
|
+
|
|
488
|
+
On iPhone, after a pair the SDK waits up to 8 seconds on firmware that brings audio up from the BLE pair and reports `needs_user` at once on older firmware. After a reconnect it waits 10 seconds. The state moves to `connected` as soon as audio comes up. Mentra Live firmware that reports its own audio link (`classic_link`) is preferred over the phone's audio route, which is wrong while another Bluetooth audio device holds it.
|
|
489
|
+
|
|
490
|
+
```ts
|
|
491
|
+
BluetoothSdk.addListener("audio_setup_changed", (event) => {
|
|
492
|
+
if (event.state.state === "needs_user") showConnectAudioInSettings()
|
|
493
|
+
})
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
`useMentraBluetooth().glasses` does not include `audioSetup`. Read `getGlassesStatus()`, `subscribeGlassesStatus()`, or the event.
|
|
497
|
+
|
|
451
498
|
## Native notification controls
|
|
452
499
|
|
|
453
500
|
G2 exposes firmware-owned notification history and popups. `getNativeNotificationStatus()` reports support, source (`phone` on Android or `ancs` on iOS), authorization, the desired controls, and submission/failure state. `submitted` means the controls were queued for the glasses, not that firmware acknowledged them. Unsupported drivers reject configuration instead of silently succeeding.
|
|
@@ -619,7 +666,7 @@ Engine coordinator:
|
|
|
619
666
|
|
|
620
667
|
Release CI embeds an immutable manifest URL and checksum into every published
|
|
621
668
|
SDK distribution. The completed coordinated release record correlates the SDK
|
|
622
|
-
package with its exact manifest and OTA bundle. A completed release is available at
|
|
669
|
+
package with its exact manifest and, for beta and stable releases, its OTA bundle. A completed release is available at
|
|
623
670
|
`https://github.com/Mentra-Community/MentraOS/releases/tag/mentra-v<releaseIdentity>`
|
|
624
671
|
and contains `mentra-release-<releaseIdentity>.json`, which records the exact
|
|
625
672
|
package coordinates, asset URLs, sizes, checksums, and build provenance.
|
|
@@ -634,10 +681,11 @@ Android/iOS OTA contract or infrastructure beneath a coordinator. React Native
|
|
|
634
681
|
application pages should render Mentra Engine's semantic controller state
|
|
635
682
|
instead of sequencing raw events.
|
|
636
683
|
|
|
637
|
-
Each
|
|
638
|
-
|
|
639
|
-
and
|
|
640
|
-
|
|
684
|
+
Each beta release publishes a portable OTA bundle; development releases do not.
|
|
685
|
+
A stable release publishes byte-identical copies of the promoted beta's OTA
|
|
686
|
+
manifest and bundle under its own names, so always resolve the bundle
|
|
687
|
+
coordinate and URL from `mentra-release-<releaseIdentity>.json` rather than
|
|
688
|
+
constructing a filename. The selected archive contains
|
|
641
689
|
`version.template.json`, every referenced ASG/MTK/BES artifact, `SHA256SUMS`,
|
|
642
690
|
and a dependency-free configuration script. After unpacking it, generate the
|
|
643
691
|
final manifest for its exact hosting URL:
|
|
@@ -751,6 +799,8 @@ export function HardwareEventLogger() {
|
|
|
751
799
|
|
|
752
800
|
For non-React modules, `BluetoothSdk.addListener(...)` is the low-level subscription API. Keep the returned subscription and call `remove()` when the listener is no longer needed.
|
|
753
801
|
|
|
802
|
+
Common event names include `button_press`, `touch_event`, `head_up`, `battery_status`, `wifi_status_change`, `wifi_scan_result`, `hotspot_status_change`, `photo_status`, `photo_response`, `gallery_status`, `settings_ack`, `version_info`, `stream_status`, `ota_start_ack`, `ota_status`, `mic_pcm`, `mic_lc3`, `mic_health`, `local_transcription`, `rgb_led_control_response`, `pair_failure`, `pairing_info`, `entering_pairing_mode`, `pairing_mode_ended`, `pairing_state_changed`, `audio_connected`, `audio_disconnected`, and `log`. `owner_replaced` remains in the type map and is never emitted.
|
|
803
|
+
|
|
754
804
|
### Claiming touchpad gestures
|
|
755
805
|
|
|
756
806
|
On Mentra Live, disable a gesture's stock action before using it in your app:
|
|
@@ -818,10 +868,28 @@ MentraOS repo root:
|
|
|
818
868
|
./scripts/check-android-compile.sh bluetooth-sdk
|
|
819
869
|
```
|
|
820
870
|
|
|
821
|
-
The
|
|
822
|
-
|
|
823
|
-
`
|
|
824
|
-
|
|
871
|
+
The check script prepares `mobile/android` and uses its Gradle wrapper with
|
|
872
|
+
`-PmentraPublicSdk=true`, matching the CI release workflow's public SDK
|
|
873
|
+
dependency mode. Inside an Expo app, the `android/` folder in this package is
|
|
874
|
+
included by autolinking as `:mentra-bluetooth-sdk`.
|
|
875
|
+
|
|
876
|
+
A plain Android app can also build the native SDK from a MentraOS checkout,
|
|
877
|
+
without publishing it to Maven local, through a Gradle composite build. In the
|
|
878
|
+
app's `settings.gradle.kts`:
|
|
879
|
+
|
|
880
|
+
```kotlin
|
|
881
|
+
includeBuild("/path/to/MentraOS/mobile/modules/bluetooth-sdk/android") {
|
|
882
|
+
dependencySubstitution {
|
|
883
|
+
substitute(module("com.mentraglass:bluetooth-sdk")).using(project(":"))
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
```
|
|
887
|
+
|
|
888
|
+
The app keeps its `com.mentraglass:bluetooth-sdk` dependency; Gradle replaces it
|
|
889
|
+
with the source build. This standalone build has the same dependencies as the
|
|
890
|
+
Maven Central artifact (`-PmentraPublicSdk=true` is its default) and leaves out
|
|
891
|
+
the Expo adapter classes, which need an Expo host. It needs the Android NDK for
|
|
892
|
+
`lc3Lib`.
|
|
825
893
|
|
|
826
894
|
For bare native iOS or macOS apps, use the public SwiftPM repository:
|
|
827
895
|
|
|
@@ -831,7 +899,7 @@ https://github.com/Mentra-Community/mentra-bluetooth-sdk-ios.git
|
|
|
831
899
|
|
|
832
900
|
Select a coordinated SDK version that includes your target platform, then add
|
|
833
901
|
the `MentraBluetoothSDK` product to your app target. Native macOS support is new
|
|
834
|
-
on `dev`; use the local
|
|
902
|
+
on `dev`; use the local package below until a supporting release is published.
|
|
835
903
|
|
|
836
904
|
For local SDK development, add this package folder directly in Xcode:
|
|
837
905
|
|
|
@@ -847,7 +915,8 @@ permission/audio-input capability for host microphone capture and network-server
|
|
|
847
915
|
capability for local SDK servers. macOS uses CoreAudio instead of
|
|
848
916
|
`AVAudioSession`; it does not provide iOS background modes or ANCS relay. See
|
|
849
917
|
[the macOS integration guide](../../../mintlify-docs/bluetooth-sdk/macos.mdx)
|
|
850
|
-
and the
|
|
918
|
+
and the [`examples/bluetooth/macos`](../../../examples/bluetooth/macos/README.md) and
|
|
919
|
+
[`examples/bluetooth/react-native-macos`](../../../examples/bluetooth/react-native-macos/README.md) hosts.
|
|
851
920
|
|
|
852
921
|
Maintainers publishing the public SwiftPM mirror should follow
|
|
853
922
|
[RELEASING_IOS_SPM.md](./RELEASING_IOS_SPM.md).
|
package/android/build.gradle
CHANGED
|
@@ -8,7 +8,14 @@ apply plugin: 'signing'
|
|
|
8
8
|
def packageJson = new JsonSlurper().parse(file("../package.json"))
|
|
9
9
|
def mavenGroupId = 'com.mentraglass'
|
|
10
10
|
def mavenPublishVersion = (findProperty('mentraMavenVersion') ?: System.getenv('MENTRA_MAVEN_VERSION') ?: packageJson.version).toString()
|
|
11
|
-
|
|
11
|
+
// Inside an Expo host such as the MentraOS app, autolinking provides
|
|
12
|
+
// :expo-modules-core. Without it, this directory is the root of a standalone
|
|
13
|
+
// build (settings.gradle), for example a composite build in a plain Android app.
|
|
14
|
+
// expo-modules-core has no prebuilt Android artifact to resolve instead, so a
|
|
15
|
+
// standalone build leaves out the Expo adapter classes and defaults to the
|
|
16
|
+
// public Maven artifact's dependency shape.
|
|
17
|
+
def standaloneBuild = findProject(':expo-modules-core') == null
|
|
18
|
+
def publicMavenSdk = (findProperty('mentraPublicSdk') ?: System.getenv('MENTRA_PUBLIC_SDK') ?: standaloneBuild.toString()).toString().toBoolean()
|
|
12
19
|
|
|
13
20
|
// Download Sherpa-ONNX Android AAR from the upstream GitHub release and stage
|
|
14
21
|
// it as a Maven artifact in a tiny on-disk repository under libs/maven/.
|
|
@@ -88,7 +95,7 @@ if (!sherpaOnnxAar.exists()) {
|
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
// Minimal POM so the Maven resolver is happy. No transitive deps — the AAR
|
|
91
|
-
// ships its own native libs
|
|
98
|
+
// ships its own native libs, including its own libonnxruntime.so.
|
|
92
99
|
if (!sherpaOnnxPom.exists()) {
|
|
93
100
|
sherpaOnnxPom.text = """<?xml version="1.0" encoding="UTF-8"?>
|
|
94
101
|
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
|
@@ -181,13 +188,38 @@ gradle.taskGraph.whenReady {
|
|
|
181
188
|
}
|
|
182
189
|
}
|
|
183
190
|
|
|
184
|
-
|
|
185
|
-
apply
|
|
186
|
-
|
|
187
|
-
|
|
191
|
+
if (standaloneBuild) {
|
|
192
|
+
apply plugin: 'kotlin-android'
|
|
193
|
+
// Java 17 bytecode, as in the MentraOS app build.
|
|
194
|
+
android {
|
|
195
|
+
compileOptions {
|
|
196
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
197
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
kotlin {
|
|
201
|
+
compilerOptions {
|
|
202
|
+
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Expo adapters, compiled only inside an Expo host (see expo-module.config.json).
|
|
206
|
+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
|
|
207
|
+
exclude(
|
|
208
|
+
'**/com/mentra/bluetoothsdk/BluetoothSdkModule.kt',
|
|
209
|
+
'**/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt',
|
|
210
|
+
'**/com/mentra/bluetoothsdk/otaserver/MentraOtaServerModule.kt',
|
|
211
|
+
'**/com/mentra/bluetoothsdk/photoreceiver/MentraPhotoReceiverModule.kt'
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
216
|
+
apply from: expoModulesCorePlugin
|
|
217
|
+
applyKotlinExpoModulesCorePlugin()
|
|
218
|
+
useExpoPublishing()
|
|
219
|
+
}
|
|
188
220
|
|
|
189
|
-
//
|
|
190
|
-
//
|
|
221
|
+
// Source builds use Kotlin 2.3 for avif-coder (and Crust's QuickJS when present).
|
|
222
|
+
// Keep the public Maven artifact usable from Kotlin 2.1 builds:
|
|
191
223
|
// 2.2 metadata (a 2.1 compiler reads one version ahead; 2.2 is also the lowest
|
|
192
224
|
// language version that reads the 2.3 expo-modules-core classes compiled here),
|
|
193
225
|
// 2.1 stdlib APIs, and a kotlin-stdlib 2.1.20 dependency in the POM.
|
|
@@ -225,6 +257,9 @@ if (useManagedAndroidSdkVersions) {
|
|
|
225
257
|
|
|
226
258
|
android {
|
|
227
259
|
namespace "com.mentra.bluetoothsdk"
|
|
260
|
+
buildFeatures {
|
|
261
|
+
buildConfig true
|
|
262
|
+
}
|
|
228
263
|
defaultConfig {
|
|
229
264
|
versionCode 1
|
|
230
265
|
versionName project.version
|
|
@@ -255,7 +290,9 @@ android {
|
|
|
255
290
|
dependencies {
|
|
256
291
|
// Expo adapter class is compiled into the MentraOS module, but the bare SDK
|
|
257
292
|
// artifact should not expose Expo as a runtime dependency.
|
|
258
|
-
|
|
293
|
+
if (!standaloneBuild) {
|
|
294
|
+
compileOnly project(':expo-modules-core')
|
|
295
|
+
}
|
|
259
296
|
|
|
260
297
|
// Kotlin standard library (explicitly added for IDE support)
|
|
261
298
|
// Version is managed by Expo modules, but explicit dependency helps IDE indexing
|
|
@@ -278,13 +315,15 @@ dependencies {
|
|
|
278
315
|
implementation 'androidx.exifinterface:exifinterface:1.3.7'
|
|
279
316
|
|
|
280
317
|
// AVIF decode for BLE photo fallback. Public Maven artifacts omit this
|
|
281
|
-
//
|
|
282
|
-
//
|
|
283
|
-
//
|
|
284
|
-
//
|
|
285
|
-
// 2.
|
|
286
|
-
//
|
|
287
|
-
dependencies.add(publicMavenSdk ? 'compileOnly' : 'implementation', '
|
|
318
|
+
// decoder from runtime metadata; Android 12+ can still use the platform
|
|
319
|
+
// decoder, while MentraOS app builds keep Coder for broader fallback.
|
|
320
|
+
// 3.0.0 ships 16 KB-aligned libcoder.so (1.7.3 was 4 KB). Its POM depends
|
|
321
|
+
// on kotlin-stdlib 2.3.0. Exclude it to keep the public SDK's runtime
|
|
322
|
+
// dependencies on 2.1; the Expo plugin selects a 2.3 source compiler to
|
|
323
|
+
// read the decoder's metadata, independently of this stdlib exclusion.
|
|
324
|
+
dependencies.add(publicMavenSdk ? 'compileOnly' : 'implementation', 'io.github.awxkee:avif-coder:3.0.0') {
|
|
325
|
+
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib'
|
|
326
|
+
}
|
|
288
327
|
|
|
289
328
|
testImplementation 'junit:junit:4.13.2'
|
|
290
329
|
testImplementation 'org.robolectric:robolectric:4.11.1'
|
|
@@ -308,28 +347,18 @@ dependencies {
|
|
|
308
347
|
// Maven Central/Google repositories for normal SDK use.
|
|
309
348
|
def optionalMentraOsIntegrationDependency = publicMavenSdk ? 'compileOnly' : 'implementation'
|
|
310
349
|
|
|
311
|
-
// Sherpa-ONNX for
|
|
312
|
-
//
|
|
313
|
-
//
|
|
314
|
-
//
|
|
350
|
+
// Sherpa-ONNX for on-device transcription, the wake word and Silero speech
|
|
351
|
+
// activity (com.k2fsa.sherpa.onnx.Vad, model in src/main/assets/vad/).
|
|
352
|
+
// Jitpack's v1.13.2 build failed upstream, so we stage the prebuilt AAR into
|
|
353
|
+
// libs/maven/ (see top of file) and consume it as a Maven coord — AGP rejects
|
|
354
|
+
// raw files() .aar deps in library modules.
|
|
315
355
|
dependencies.add(optionalMentraOsIntegrationDependency, "${sherpaOnnxGroup}:${sherpaOnnxArtifact}:${sherpaOnnxVersion}@aar")
|
|
316
356
|
|
|
317
357
|
if (!publicMavenSdk) {
|
|
318
|
-
// Silero VAD — vendored source under silero/, wired as :silero
|
|
319
|
-
// sub-project (see settings.gradle). This replaces the previous Jitpack AAR
|
|
320
|
-
// (com.github.gkonovalov:android-vad:2.0.9) whose prebuilt JNI was bound to
|
|
321
|
-
// an ORT version incompatible with the one bundled by sherpa-onnx, causing a
|
|
322
|
-
// dlopen UnsatisfiedLinkError for OrtGetApiBase at VAD startup. By owning the
|
|
323
|
-
// source we control both the Java API surface and the ORT version it links
|
|
324
|
-
// against; today both consumers (Silero VAD and sherpa-onnx) load their own
|
|
325
|
-
// libonnxruntime.so — see packagingOptions pickFirst above.
|
|
326
|
-
implementation project(':silero')
|
|
327
|
-
|
|
328
358
|
// Vuzix Z100
|
|
329
359
|
implementation 'com.vuzix:ultralite-sdk-android:1.8'
|
|
330
360
|
implementation 'com.squareup.picasso:picasso:2.8'
|
|
331
361
|
} else {
|
|
332
|
-
compileOnly project(':silero')
|
|
333
362
|
compileOnly 'com.vuzix:ultralite-sdk-android:1.8'
|
|
334
363
|
compileOnly 'com.squareup.picasso:picasso:2.8'
|
|
335
364
|
}
|
|
@@ -338,26 +367,6 @@ dependencies {
|
|
|
338
367
|
implementation 'com.google.protobuf:protobuf-java-util:4.32.0'
|
|
339
368
|
}
|
|
340
369
|
|
|
341
|
-
// Pin onnxruntime-android to 1.24.3 — the version sherpa-onnx 1.13.2 was built
|
|
342
|
-
// against (its libonnxruntime.so exports OrtGetApiBase@@VERS_1.24.3). Matching
|
|
343
|
-
// this lets the :silero VAD module share a single libonnxruntime.so with
|
|
344
|
-
// sherpa-onnx, resolving the ELF symbol-versioning conflict that crashed VAD
|
|
345
|
-
// startup on previous mismatched versions.
|
|
346
|
-
configurations.all {
|
|
347
|
-
resolutionStrategy {
|
|
348
|
-
eachDependency { DependencyResolveDetails details ->
|
|
349
|
-
if (details.requested.group == 'com.microsoft.onnxruntime') {
|
|
350
|
-
details.useVersion '1.24.3'
|
|
351
|
-
details.because('Match sherpa-onnx 1.13.2 ORT 1.24.3')
|
|
352
|
-
}
|
|
353
|
-
if (details.requested.name == 'onnxruntime-android') {
|
|
354
|
-
details.useVersion '1.24.3'
|
|
355
|
-
details.because('Match sherpa-onnx 1.13.2 ORT 1.24.3')
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
370
|
afterEvaluate {
|
|
362
371
|
publishing {
|
|
363
372
|
publications {
|
package/android/settings.gradle
CHANGED
|
@@ -1,4 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
// Standalone build of the Bluetooth SDK's Android library, used when this
|
|
2
|
+
// directory is the root of a Gradle build: for example a plain Android app that
|
|
3
|
+
// consumes the SDK from source through a composite build,
|
|
4
|
+
// includeBuild("<MentraOS>/mobile/modules/bluetooth-sdk/android")
|
|
5
|
+
// with com.mentraglass:bluetooth-sdk substituted by project(":").
|
|
6
|
+
// The MentraOS app (an Expo host) ignores this file: Expo autolinking adds this
|
|
7
|
+
// directory as :mentra-bluetooth-sdk, and the SDK's config plugin adds :lc3Lib
|
|
8
|
+
// to the host's own settings.gradle.
|
|
9
|
+
|
|
10
|
+
gradle.rootProject { project ->
|
|
11
|
+
// Same versions as the MentraOS app's generated Android project. AGP refuses
|
|
12
|
+
// two versions in one composite build, so when this build is included in an
|
|
13
|
+
// app, use the AGP version on that app's root build classpath.
|
|
14
|
+
def androidGradlePluginVersion = '8.12.0'
|
|
15
|
+
def appGradle = gradle.parent
|
|
16
|
+
if (appGradle != null) {
|
|
17
|
+
try {
|
|
18
|
+
androidGradlePluginVersion = appGradle.rootProject.buildscript.classLoader
|
|
19
|
+
.loadClass('com.android.Version')
|
|
20
|
+
.getField('ANDROID_GRADLE_PLUGIN_VERSION')
|
|
21
|
+
.get(null)
|
|
22
|
+
} catch (ClassNotFoundException ignored) {
|
|
23
|
+
// The app does not load AGP in its root build; keep the default.
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
project.buildscript {
|
|
28
|
+
repositories {
|
|
29
|
+
google()
|
|
30
|
+
mavenCentral()
|
|
31
|
+
}
|
|
32
|
+
dependencies {
|
|
33
|
+
classpath "com.android.tools.build:gradle:${androidGradlePluginVersion}"
|
|
34
|
+
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.3.0'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
2
38
|
|
|
3
|
-
|
|
4
|
-
project
|
|
39
|
+
gradle.beforeProject { project ->
|
|
40
|
+
project.repositories {
|
|
41
|
+
google()
|
|
42
|
+
mavenCentral()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
rootProject.name = 'mentra-bluetooth-sdk'
|
|
47
|
+
|
|
48
|
+
include ':lc3Lib'
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk
|
|
2
|
+
|
|
3
|
+
import kotlinx.coroutines.CompletableDeferred
|
|
4
|
+
import kotlinx.coroutines.withTimeoutOrNull
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Correlates `bes_crash_reported` commands with the glasses' `bes_crash_reported_ack`.
|
|
8
|
+
*
|
|
9
|
+
* Each call owns one waiter keyed by (incidentKey, reportId), so concurrent reports for
|
|
10
|
+
* different incidents, or a stale ack for an earlier reportId, never settle each other.
|
|
11
|
+
*/
|
|
12
|
+
internal class BesCrashReportWaiters {
|
|
13
|
+
private class Waiter(val incidentKey: String, val reportId: String) {
|
|
14
|
+
val result = CompletableDeferred<Unit>()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private val waiters = mutableListOf<Waiter>()
|
|
18
|
+
|
|
19
|
+
/** Registers before [send] so an immediate ack cannot be missed. */
|
|
20
|
+
suspend fun await(incidentKey: String, reportId: String, timeoutMs: Long, send: () -> Unit) {
|
|
21
|
+
val waiter = Waiter(incidentKey, reportId)
|
|
22
|
+
synchronized(waiters) { waiters.add(waiter) }
|
|
23
|
+
try {
|
|
24
|
+
send()
|
|
25
|
+
withTimeoutOrNull(timeoutMs) { waiter.result.await() }
|
|
26
|
+
?: throw BluetoothSdkException(
|
|
27
|
+
"request_timeout",
|
|
28
|
+
"bes_crash_reported for $incidentKey timed out waiting for the glasses ack.",
|
|
29
|
+
)
|
|
30
|
+
} finally {
|
|
31
|
+
synchronized(waiters) { waiters.remove(waiter) }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Settles the waiters this ack answers. `ok:true` must echo the reportId; an `ok:false`
|
|
37
|
+
* without a reportId rejects every waiter for that incidentKey. Returns the number settled.
|
|
38
|
+
*/
|
|
39
|
+
fun onAck(values: Map<String, Any>): Int {
|
|
40
|
+
val incidentKey = values["incidentKey"] as? String ?: return 0
|
|
41
|
+
val reportId = (values["reportId"] as? String)?.takeIf { it.isNotEmpty() }
|
|
42
|
+
val ok = values["ok"] == true
|
|
43
|
+
val matched = synchronized(waiters) {
|
|
44
|
+
waiters.filter {
|
|
45
|
+
it.incidentKey == incidentKey && (it.reportId == reportId || (!ok && reportId == null))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (ok) {
|
|
49
|
+
matched.forEach { it.result.complete(Unit) }
|
|
50
|
+
} else {
|
|
51
|
+
val error = (values["error"] as? String)?.takeIf { it.isNotEmpty() } ?: "unknown_error"
|
|
52
|
+
matched.forEach {
|
|
53
|
+
it.result.completeExceptionally(
|
|
54
|
+
BluetoothSdkException(
|
|
55
|
+
"bes_crash_report_rejected",
|
|
56
|
+
"Glasses rejected bes_crash_reported for $incidentKey: $error",
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return matched.size
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fun rejectAll(error: Throwable) {
|
|
65
|
+
val snapshot = synchronized(waiters) { waiters.toList() }
|
|
66
|
+
snapshot.forEach { it.result.completeExceptionally(error) }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -5,6 +5,9 @@ object BluetoothSdkDefaults {
|
|
|
5
5
|
const val VOICE_ACTIVITY_DETECTION_ENABLED = false
|
|
6
6
|
const val LOUDNESS_GATE_ENABLED = true
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Must match the firmware default (on). Re-pushed on connect, so a false
|
|
10
|
+
* value here would silently turn it off on every pair the app touches.
|
|
11
|
+
*/
|
|
12
|
+
const val AUTO_POWER_OFF_ENABLED = true
|
|
10
13
|
}
|