@mentra/bluetooth-sdk 3.3.0 → 3.4.0-beta.1237

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.
Files changed (168) hide show
  1. package/MIGRATION.md +61 -0
  2. package/README.md +80 -11
  3. package/android/build.gradle +60 -51
  4. package/android/gradle.properties +3 -0
  5. package/android/settings.gradle +47 -3
  6. package/android/src/main/java/com/mentra/bluetoothsdk/BesCrashReportWaiters.kt +68 -0
  7. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +5 -2
  8. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +85 -6
  9. package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +35 -1
  10. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +154 -110
  11. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +21 -0
  12. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +1 -0
  13. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
  14. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +27 -2
  15. package/android/src/main/java/com/mentra/bluetoothsdk/connection/ConnectionModels.kt +5 -0
  16. package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
  17. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicy.kt +64 -0
  18. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +925 -155
  19. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +227 -0
  20. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +19 -0
  21. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicy.kt +94 -0
  22. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachine.kt +411 -0
  23. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateStore.kt +124 -0
  24. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +54 -59
  25. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +5 -32
  26. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasEncoder.kt +8 -1
  27. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +3 -10
  28. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
  29. package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +50 -0
  30. package/android/src/main/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueue.kt +92 -0
  31. package/android/src/main/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHost.kt +169 -0
  32. package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +74 -115
  33. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +348 -357
  34. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetector.kt +211 -0
  35. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngine.kt +137 -0
  36. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SttTextFormatter.kt +52 -0
  37. package/android/src/main/java/com/mentra/bluetoothsdk/stt/WakeWordDetector.kt +235 -0
  38. package/android/src/main/java/com/mentra/bluetoothsdk/utils/AvifExifStripper.java +2 -2
  39. package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +3 -3
  40. package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +11 -0
  41. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/AudioRouteWatcher.kt +120 -0
  42. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +181 -16
  43. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlayback.kt +177 -0
  44. package/android/src/test/java/com/mentra/bluetoothsdk/BesCrashReportWaitersTest.kt +112 -0
  45. package/android/src/test/java/com/mentra/bluetoothsdk/DeviceManagerOwnerLossTest.kt +146 -0
  46. package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusAudioSetupTest.kt +51 -0
  47. package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusClassicAudioTest.kt +2 -0
  48. package/android/src/test/java/com/mentra/bluetoothsdk/WifiAdbPeerIntentTest.kt +19 -0
  49. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicyTest.kt +65 -0
  50. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveAudioSetupReadinessTest.kt +231 -0
  51. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +5 -1
  52. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +183 -0
  53. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +368 -0
  54. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +20 -0
  55. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicyTest.kt +136 -0
  56. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachineTest.kt +346 -0
  57. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +1 -56
  58. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +0 -22
  59. package/android/src/test/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNamingTest.kt +23 -0
  60. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueueTest.kt +81 -0
  61. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHostTest.kt +216 -0
  62. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/STTToolsExtractionTest.kt +108 -0
  63. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetectorTest.kt +126 -0
  64. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngineTest.kt +245 -0
  65. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SttTextFormatterTest.kt +67 -0
  66. package/android/src/testDebug/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlaybackTest.kt +76 -0
  67. package/build/BluetoothSdk.types.d.ts +201 -1
  68. package/build/BluetoothSdk.types.d.ts.map +1 -1
  69. package/build/BluetoothSdk.types.js.map +1 -1
  70. package/build/_private/BluetoothSdkModule.d.ts +43 -5
  71. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  72. package/build/_private/BluetoothSdkModule.js +2 -0
  73. package/build/_private/BluetoothSdkModule.js.map +1 -1
  74. package/build/generated/changelogCatalog.d.ts +3 -0
  75. package/build/generated/changelogCatalog.d.ts.map +1 -1
  76. package/build/generated/changelogCatalog.js +4 -0
  77. package/build/generated/changelogCatalog.js.map +1 -1
  78. package/build/generated/releaseMetadata.js +6 -6
  79. package/build/generated/releaseMetadata.js.map +1 -1
  80. package/build/index.d.ts +1 -1
  81. package/build/index.d.ts.map +1 -1
  82. package/build/index.js +9 -0
  83. package/build/index.js.map +1 -1
  84. package/ios/BluetoothSdkModule.swift +76 -12
  85. package/ios/MentraBluetoothSDK.podspec +4 -0
  86. package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
  87. package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
  88. package/ios/Source/BesCrashReportWaiters.swift +64 -0
  89. package/ios/Source/BluetoothSdkDefaults.swift +2 -2
  90. package/ios/Source/Bridge.swift +11 -3
  91. package/ios/Source/DeviceManager.swift +131 -18
  92. package/ios/Source/DeviceStore.swift +27 -0
  93. package/ios/Source/GeneratedChangelogCatalog.swift +1 -0
  94. package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
  95. package/ios/Source/MentraBluetoothSDK.swift +40 -5
  96. package/ios/Source/audio/PcmStreamPlayer.swift +290 -57
  97. package/ios/Source/audio/PcmUrlPlayback.swift +231 -0
  98. package/ios/Source/audio/SpeechActivity.swift +277 -0
  99. package/ios/Source/errors/BluetoothSdkError.swift +5 -1
  100. package/ios/Source/events/BluetoothEvents.swift +41 -0
  101. package/ios/Source/internal/BleTraceLogger.swift +9 -6
  102. package/ios/Source/internal/BluetoothAvailability.swift +15 -5
  103. package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +186 -0
  104. package/ios/Source/sgcs/MentraLive.swift +1270 -189
  105. package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +260 -1
  106. package/ios/Source/sgcs/MentraLivePairingStateMachine.swift +385 -0
  107. package/ios/Source/sgcs/MentraLivePairingStateStore.swift +121 -0
  108. package/ios/Source/sgcs/Nimo.swift +10 -3
  109. package/ios/Source/sgcs/NimoCanvasCoordinator.swift +39 -9
  110. package/ios/Source/sgcs/SGCManager.swift +13 -0
  111. package/ios/Source/sgcs/Simulated.swift +2 -0
  112. package/ios/Source/status/DeviceStatus.swift +35 -0
  113. package/ios/Source/stt/STTTools.swift +13 -31
  114. package/ios/Source/stt/SherpaOnnxTranscriber.swift +204 -162
  115. package/ios/Source/stt/SileroSpeechActivity.swift +87 -0
  116. package/ios/Source/stt/WakeWordDetector.swift +145 -0
  117. package/ios/Source/types/DeviceModels.swift +8 -1
  118. package/ios/Source/utils/AudioSessionMonitor.swift +158 -5
  119. package/ios/Source/utils/BoundedWait.swift +44 -0
  120. package/ios/Source/utils/DemandDrivenAudioWorker.swift +79 -0
  121. package/ios/Source/utils/SttModelTraits.swift +62 -0
  122. package/ios/Tests/BesCrashReportTests.swift +142 -0
  123. package/ios/Tests/BluetoothAudioRouteTests.swift +82 -0
  124. package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
  125. package/ios/Tests/DeviceManagerReconnectTests.swift +4 -2
  126. package/ios/Tests/GlassesAudioSetupPolicyTests.swift +197 -0
  127. package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
  128. package/ios/Tests/MentraLiveAudioSetupTests.swift +209 -0
  129. package/ios/Tests/MentraLiveConnectionOptionsTests.swift +55 -0
  130. package/ios/Tests/MentraLivePairingAdvertisementTests.swift +327 -0
  131. package/ios/Tests/MentraLivePairingStateMachineTests.swift +402 -0
  132. package/ios/Tests/MentraLiveSessionReadinessTests.swift +368 -26
  133. package/ios/Tests/NimoCanvasTransportTests.swift +58 -0
  134. package/ios/Tests/PcmStreamTests.swift +299 -0
  135. package/ios/Tests/SpeechActivityTests.swift +238 -0
  136. package/ios/Tests/SttModelTraitsTests.swift +62 -0
  137. package/ios/Tests/WifiAdbDispatchTests.swift +118 -0
  138. package/package.json +3 -2
  139. package/plugin/build/withAndroid.js +9 -11
  140. package/plugin/build/withKotlinVersion.d.ts +2 -0
  141. package/plugin/build/withKotlinVersion.js +46 -0
  142. package/src/BluetoothSdk.types.ts +201 -1
  143. package/src/_private/BluetoothSdkModule.ts +47 -5
  144. package/src/generated/changelogCatalog.ts +4 -0
  145. package/src/generated/releaseMetadata.ts +6 -6
  146. package/src/index.ts +22 -0
  147. package/android/silero/LICENSE.md +0 -17
  148. package/android/silero/build.gradle +0 -50
  149. package/android/silero/proguard-rules.pro +0 -24
  150. package/android/silero/src/androidTest/assets/hello.wav +0 -0
  151. package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +0 -79
  152. package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +0 -160
  153. package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +0 -449
  154. package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +0 -15
  155. package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +0 -14
  156. package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +0 -12
  157. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +0 -47
  158. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +0 -41
  159. package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +0 -44
  160. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -368
  161. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +0 -156
  162. package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +0 -229
  163. package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -20
  164. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +0 -287
  165. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +0 -127
  166. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +0 -288
  167. /package/android/{silero/src/main/assets/LICENSE → src/main/assets/vad/LICENSE.silero_vad} +0 -0
  168. /package/android/{silero/src/main/assets → src/main/assets/vad}/silero_vad.onnx +0 -0
@@ -2,6 +2,7 @@ package com.mentra.bluetoothsdk
2
2
 
3
3
  import android.os.Handler
4
4
  import android.os.Looper
5
+ import com.mentra.bluetoothsdk.sgcs.GlassesAudioSetupPolicy
5
6
  import com.mentra.bluetoothsdk.utils.DeviceTypes
6
7
  import com.mentra.bluetoothsdk.utils.ConnTypes
7
8
  import com.mentra.bluetoothsdk.utils.MicMap
@@ -79,6 +80,8 @@ object DeviceStore {
79
80
  store.set("glasses", "micEnabled", false)
80
81
  store.set("glasses", "voiceActivityDetectionEnabled", BluetoothSdkDefaults.VOICE_ACTIVITY_DETECTION_ENABLED)
81
82
  store.set("glasses", "bluetoothClassicConnected", false)
83
+ store.set("glasses", "bluetoothClassicProfilesConnected", false)
84
+ store.set("glasses", "bluetoothAudioRouted", false)
82
85
  store.set("glasses", "caseRemoved", true)
83
86
  store.set("glasses", "caseOpen", true)
84
87
  store.set("glasses", "caseCharging", false)
@@ -167,6 +170,16 @@ object DeviceStore {
167
170
  return store.get(category, key)
168
171
  }
169
172
 
173
+ /**
174
+ * `GlassesStatus.audioSetup` follows readiness on every model ([GlassesAudioSetupPolicy]), so
175
+ * the snapshot that changed `fullyBooted` already carries the new state. Announce it like
176
+ * `pairing_state_changed`, only when it changed.
177
+ */
178
+ private fun publishAudioSetupChange(wasReady: Boolean, ready: Boolean) {
179
+ val state = GlassesAudioSetupPolicy.change(wasReady, ready) ?: return
180
+ Bridge.sendTypedMessage("audio_setup_changed", mapOf("state" to state.toMap()))
181
+ }
182
+
170
183
  fun set(category: String, key: String, value: Any) {
171
184
  store.set(category, key, value)
172
185
  }
@@ -175,12 +188,20 @@ object DeviceStore {
175
188
  fun apply(category: String, key: String, value: Any) {
176
189
  val oldValue = store.get(category, key)
177
190
  store.set(category, key, value)
191
+ if (category == "glasses" && key == "bluetoothClassicConnected") {
192
+ // Android has no separate profile/route signal; keep both equal to the Classic audio state.
193
+ store.set(category, "bluetoothClassicProfilesConnected", value)
194
+ store.set(category, "bluetoothAudioRouted", value)
195
+ }
178
196
  val skipped = observableStoreWouldHaveSkipped(oldValue, value)
179
197
  val forceMicReset =
180
198
  category == ObservableStore.BLUETOOTH_CATEGORY && key == "mic_tuning" && isMicTuningReset(value)
181
199
  if (skipped && !forceMicReset) {
182
200
  return
183
201
  }
202
+ if (category == "glasses" && key == "fullyBooted" && value is Boolean) {
203
+ publishAudioSetupChange(oldValue as? Boolean ?: false, value)
204
+ }
184
205
 
185
206
  // Trigger hardware updates based on setting changes
186
207
  when (category to key) {
@@ -3,6 +3,7 @@ package com.mentra.bluetoothsdk
3
3
  /** Generated from /changelogs. Do not edit directly. */
4
4
  internal val GENERATED_RELEASE_CHANGELOGS: List<ReleaseChangelog> =
5
5
  listOf(
6
+ ReleaseChangelog(version = "3.4.0", markdown = "This release is under active development. User-facing changes will be documented as they land."),
6
7
  ReleaseChangelog(version = "3.3.0", markdown = "- **Mentra Call:** Now available on iPhone, with a redesigned call screen and photo sharing during calls.\n- **Microphone:** Improved glasses microphone reliability, including after phone calls.\n- **Photos and gallery:** More reliable photo capture and gallery syncing.\n- **Glasses updates:** More reliable glasses updates, with clearer progress.\n- **Miniapps:** Miniapps now update automatically. Fixed miniapps getting stuck on loading screens.\n- **Mentra AI:** Reliability improvements and bug fixes.\n- **Notes:** Take photos with the glasses camera button, and add meeting and location details to your notes.\n- **Pairing and connections:** Improved glasses audio reconnection on Android.\n- **G1 and NIMO:** Improved text display, including accented letters.\n- **Android tablets:** The Mentra App now rotates to landscape."),
7
8
  ReleaseChangelog(version = "3.2.1", markdown = "- **Livestreamer:** \"Stream Here\" now works without a Wi-Fi network. Improved stream startup and connection reliability.\n- **Photos and gallery:** More reliable photo capture and gallery syncing.\n- **Mentra AI:** Reliability improvements and bug fixes.\n- **Miniapps:** Smoother transitions, with back buttons and gestures that take you to the previous screen inside a miniapp.\n- **Pairing and connections:** Improved G1 pairing and G2 background reconnection.\n- **Glasses updates:** Fixed repeated update checks and improved recovery after interrupted updates.\n- **Mentra Maps:** Bug fixes.\n- **NIMO:** Improved text and map layouts.\n- **Self-hosting:** Connect the Mentra App to your own self-hosted Mentra backend."),
8
9
  ReleaseChangelog(version = "3.2.0", markdown = "- Improved glasses connectivity and Wi-Fi setup.\n\n- Breaking Bluetooth SDK change: `forgetWifiNetwork(ssid)` now returns `WifiForgetResult` instead of `WifiStatusChangeEvent`. Migrate status-only consumers to the semantic `outcome`; the requested network remains `ssid`, while optional post-command connectivity is reported by `connected`, `currentSsid`, and `localIp`."),
@@ -2,10 +2,10 @@ package com.mentra.bluetoothsdk
2
2
 
3
3
  /** Generated by release CI. Do not edit in a release checkout. */
4
4
  internal object GeneratedReleaseMetadata {
5
- const val FAMILY_BASE_VERSION: String = "3.3.0"
6
- const val RELEASE_IDENTITY: String = "3.3.0"
7
- const val RELEASE_SET_ID: String = "mentra-3.3.0"
8
- const val SOURCE_COMMIT: String = "5bd50400b076b758691429755b6e1bd7b77268fb"
9
- const val OTA_MANIFEST_URL: String = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.3.0/mentra-live-ota-3.3.0-beta.1188.json"
10
- const val OTA_MANIFEST_SHA256: String = "66070872d18ee11303347e1be71b7385af96aab30adc3d226ceb4a82c2c4848f"
5
+ const val FAMILY_BASE_VERSION: String = "3.4.0"
6
+ const val RELEASE_IDENTITY: String = "3.4.0-beta.1237"
7
+ const val RELEASE_SET_ID: String = "mentra-3.4.0-beta.1237"
8
+ const val SOURCE_COMMIT: String = "ad9203eb7fe636f5a6a77510451d0a8da34b880c"
9
+ const val OTA_MANIFEST_URL: String = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-beta.1237.json"
10
+ const val OTA_MANIFEST_SHA256: String = "57f73cac781224161574b4a862c6fb76f98aafd384876ef1b06f998797d5e67f"
11
11
  }
@@ -9,6 +9,7 @@ import android.os.Bundle
9
9
  import android.os.Handler
10
10
  import android.os.Looper
11
11
  import android.util.Log
12
+ import com.mentra.bluetoothsdk.sgcs.MentraLive
12
13
  import com.mentra.bluetoothsdk.streaming.StreamSessionState
13
14
  import com.mentra.bluetoothsdk.utils.ControllerTypes
14
15
  import com.mentra.bluetoothsdk.utils.PhoneAudioMonitor
@@ -93,6 +94,7 @@ class MentraBluetoothSdk private constructor(
93
94
  private var pendingHotspotStatus: PendingHotspotStatusRequest? = null
94
95
  private val hotspotMutex = Mutex()
95
96
  private var pendingVersionInfo: PendingVersionInfoRequest? = null
97
+ private val besCrashReports = BesCrashReportWaiters()
96
98
  private val wifiSessionCapabilities = WifiSessionCapabilities()
97
99
  @Volatile private var configuredOtaVersionUrl: String? = null
98
100
 
@@ -147,6 +149,7 @@ class MentraBluetoothSdk private constructor(
147
149
  private const val VIDEO_UPLOAD_STOP_TIMEOUT_MS = 10 * 60 * 1000L
148
150
  private const val STREAM_START_TIMEOUT_MS = 30_000L
149
151
  private const val STREAM_STOP_TIMEOUT_MS = 15_000L
152
+ private const val BES_CRASH_REPORTED_TIMEOUT_MS = 10_000L
150
153
  private const val OTA_BES_VERSION_WAIT_MS = 5_000L
151
154
  private const val OTA_MTK_VERSION_WAIT_MS = 2_000L
152
155
  private const val OTA_VERSION_POLL_MS = 100L
@@ -1119,8 +1122,9 @@ class MentraBluetoothSdk private constructor(
1119
1122
  }
1120
1123
  }
1121
1124
 
1122
- fun setWifiAdbState(enabled: Boolean) {
1123
- deviceManager.setWifiAdbState(enabled)
1125
+ @JvmOverloads
1126
+ fun setWifiAdbState(enabled: Boolean, expectedBluetoothMac: String? = null) {
1127
+ deviceManager.setWifiAdbState(enabled, expectedBluetoothMac)
1124
1128
  }
1125
1129
 
1126
1130
  fun setSystemTime(timestampMs: Long) {
@@ -1675,6 +1679,14 @@ class MentraBluetoothSdk private constructor(
1675
1679
  deviceManager.sendIncidentId(incidentId, apiBaseUrl)
1676
1680
  }
1677
1681
 
1682
+ /** Resolves on the glasses' matching `ok:true` ack; throws on `ok:false`, disconnect or timeout. */
1683
+ internal suspend fun sendBesCrashReported(incidentKey: String, reportId: String) {
1684
+ requireGlassesConnected("report the BES crash")
1685
+ besCrashReports.await(incidentKey, reportId, BES_CRASH_REPORTED_TIMEOUT_MS) {
1686
+ deviceManager.sendBesCrashReported(incidentKey, reportId)
1687
+ }
1688
+ }
1689
+
1678
1690
  override fun close() {
1679
1691
  resetWifiProtocolSession("", "sdk_closed")
1680
1692
  if (activityLifecycleCallbacksRegistered) {
@@ -1695,6 +1707,12 @@ class MentraBluetoothSdk private constructor(
1695
1707
  "glasses" -> {
1696
1708
  if (changes["connected"] == false) {
1697
1709
  resetWifiProtocolSession("", "wifi_session_disconnected")
1710
+ besCrashReports.rejectAll(
1711
+ BluetoothSdkException(
1712
+ "glasses_not_connected",
1713
+ "Glasses disconnected before acknowledging bes_crash_reported.",
1714
+ )
1715
+ )
1698
1716
  }
1699
1717
  analytics.observeGlassesStatus(getRawGlassesStatus(), ::isPhoneBluetoothOff)
1700
1718
  val state = getState()
@@ -2056,6 +2074,12 @@ class MentraBluetoothSdk private constructor(
2056
2074
  }
2057
2075
  dispatchToListeners { it.onOtaStatus(event) }
2058
2076
  }
2077
+ "bes_crash_detected" -> {
2078
+ val event = BesCrashDetectedEvent(data + mapOf("type" to "bes_crash_detected"))
2079
+ dispatchToListeners { it.onBesCrashDetected(event) }
2080
+ }
2081
+ // Request-scoped: consumed by the waiting sendBesCrashReported call, never a listener event.
2082
+ "bes_crash_reported_ack" -> besCrashReports.onAck(data)
2059
2083
  "mic_health" -> {
2060
2084
  dispatchToListeners { it.onMicHealth(MicHealthEvent.fromMap(data)) }
2061
2085
  }
@@ -2102,6 +2126,7 @@ class MentraBluetoothSdk private constructor(
2102
2126
  BluetoothError(
2103
2127
  code = "pair_failure",
2104
2128
  message = data["error"] as? String ?: data.toString(),
2129
+ failureCode = data["code"] as? String,
2105
2130
  )
2106
2131
  )
2107
2132
  }
@@ -45,6 +45,11 @@ data class BluetoothError(
45
45
  val code: String,
46
46
  val message: String,
47
47
  val cause: Throwable? = null,
48
+ /**
49
+ * Stable machine-readable cause within [code], when the SDK can classify it. For
50
+ * `pair_failure`: `ios_forget_pairing` (iOS only).
51
+ */
52
+ val failureCode: String? = null,
48
53
  )
49
54
 
50
55
  enum class ScanStopReason {
@@ -106,6 +106,21 @@ data class OtaStatusEvent(
106
106
  }
107
107
  }
108
108
 
109
+ /** Mentra Live stored a BES crash incident; [values] is the glasses message with JSON nulls omitted. */
110
+ data class BesCrashDetectedEvent(
111
+ val values: Map<String, Any>,
112
+ ) {
113
+ val incidentKey: String get() = stringValue(values, "incidentKey").orEmpty()
114
+ val reason: String get() = stringValue(values, "reason").orEmpty()
115
+ val state: String get() = stringValue(values, "state").orEmpty()
116
+ val reportId: String? get() = stringValue(values, "reportId")?.takeIf { it.isNotEmpty() }
117
+ @Suppress("UNCHECKED_CAST")
118
+ val summary: Map<String, Any> get() = values["summary"] as? Map<String, Any> ?: emptyMap()
119
+
120
+ /** Event body for JavaScript; `reportId` is null rather than absent before a report exists. */
121
+ fun toEventMap(): Map<String, Any?> = values + ("reportId" to reportId)
122
+ }
123
+
109
124
  data class OtaQueryResult(
110
125
  val values: Map<String, Any>,
111
126
  ) {
@@ -170,6 +185,7 @@ interface MentraBluetoothSdkListener {
170
185
  fun onKeepAliveAck(event: KeepAliveAckEvent) {}
171
186
  fun onOtaStartAck(event: OtaStartAckEvent) {}
172
187
  fun onOtaStatus(event: OtaStatusEvent) {}
188
+ fun onBesCrashDetected(event: BesCrashDetectedEvent) {}
173
189
  fun onSettingsAck(event: SettingsAckEvent) {}
174
190
  fun onVersionInfo(event: VersionInfoResult) {}
175
191
  fun onMicPcm(event: MicPcmEvent) {}
@@ -0,0 +1,64 @@
1
+ package com.mentra.bluetoothsdk.sgcs
2
+
3
+ /**
4
+ * `GlassesStatus.audioSetup`: whether the user has to do anything to get glasses audio working.
5
+ * Native code encodes it as a map, `{"state": "idle"}` through
6
+ * `{"state": "needs_user", "action": "connect_in_settings"}`, the same shape as the TypeScript
7
+ * `GlassesAudioSetupState` and iOS.
8
+ */
9
+ internal enum class GlassesAudioSetupState(val state: String, val action: String? = null) {
10
+ /** No glasses session. */
11
+ IDLE("idle"),
12
+ /** No user step for audio on this platform and glasses. */
13
+ NOT_APPLICABLE("not_applicable"),
14
+ /** The link is up, audio is not, and the SDK still expects audio to come up on its own. */
15
+ CONNECTING("connecting"),
16
+ /** Classic audio to these glasses is up. */
17
+ CONNECTED("connected"),
18
+ /** Audio did not come up on its own. The user connects it in system Bluetooth settings. */
19
+ NEEDS_USER("needs_user", "connect_in_settings");
20
+
21
+ fun toMap(): Map<String, Any> =
22
+ if (action == null) mapOf("state" to state) else mapOf("state" to state, "action" to action)
23
+
24
+ companion object {
25
+ fun fromMap(raw: Any?): GlassesAudioSetupState? {
26
+ val state = (raw as? Map<*, *>)?.get("state") as? String ?: return null
27
+ return values().firstOrNull { it.state == state }
28
+ }
29
+ }
30
+ }
31
+
32
+ /**
33
+ * The Android audio setup rule, for every glasses model including Mentra Live. Android attaches
34
+ * Classic audio from the BLE bond (CTKD on secure Mentra Live firmware, `createBond` on older
35
+ * firmware), and glasses without Classic audio have nothing to set up, so there is never a user
36
+ * step to offer: `not_applicable` while the glasses are ready, `idle` without a session. The
37
+ * shared status layer applies it, so the update that marks the glasses ready carries
38
+ * `not_applicable` with it. iOS keeps its timed Mentra Live rules in `GlassesAudioSetupPolicy.swift`.
39
+ */
40
+ internal object GlassesAudioSetupPolicy {
41
+ fun state(ready: Boolean): GlassesAudioSetupState =
42
+ if (ready) GlassesAudioSetupState.NOT_APPLICABLE else GlassesAudioSetupState.IDLE
43
+
44
+ /** The state `audio_setup_changed` announces when readiness moves, or null when it is unchanged. */
45
+ fun change(wasReady: Boolean, ready: Boolean): GlassesAudioSetupState? {
46
+ val after = state(ready)
47
+ return if (state(wasReady) == after) null else after
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Mentra Live firmware `{"type":"classic_link","a2dp":<bool>,"hfp":<bool>}`: whether the phone's
53
+ * A2DP and HFP (service-level) links to the glasses are up. iOS feeds it into its audio setup
54
+ * rules; Android's `audioSetup` does not depend on it. A missing or malformed field reads false.
55
+ */
56
+ internal data class MentraLiveClassicLink(val a2dp: Boolean, val hfp: Boolean) {
57
+ companion object {
58
+ fun parse(json: org.json.JSONObject): MentraLiveClassicLink =
59
+ MentraLiveClassicLink(
60
+ a2dp = json.optBoolean("a2dp", false),
61
+ hfp = json.optBoolean("hfp", false),
62
+ )
63
+ }
64
+ }