@mentra/bluetooth-sdk 3.3.0-dev.944 → 3.4.0-dev.1004

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 (100) hide show
  1. package/MIGRATION.md +61 -0
  2. package/README.md +78 -0
  3. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +274 -0
  4. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +13 -3
  5. package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +8 -1
  6. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +79 -8
  7. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +21 -0
  8. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +1 -0
  9. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
  10. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +22 -4
  11. package/android/src/main/java/com/mentra/bluetoothsdk/TouchGesture.kt +19 -0
  12. package/android/src/main/java/com/mentra/bluetoothsdk/connection/ConnectionModels.kt +5 -0
  13. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicy.kt +64 -0
  14. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +832 -134
  15. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +227 -0
  16. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +19 -0
  17. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicy.kt +94 -0
  18. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachine.kt +411 -0
  19. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateStore.kt +124 -0
  20. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +337 -39
  21. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +8 -0
  22. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasEncoder.kt +8 -1
  23. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +1 -0
  24. package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +50 -0
  25. package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +16 -0
  26. package/android/src/test/java/com/mentra/bluetoothsdk/DeviceManagerOwnerLossTest.kt +146 -0
  27. package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusAudioSetupTest.kt +51 -0
  28. package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusClassicAudioTest.kt +2 -0
  29. package/android/src/test/java/com/mentra/bluetoothsdk/TouchGestureCommandTest.kt +112 -0
  30. package/android/src/test/java/com/mentra/bluetoothsdk/WifiAdbPeerIntentTest.kt +19 -0
  31. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicyTest.kt +65 -0
  32. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveAudioSetupReadinessTest.kt +231 -0
  33. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +368 -0
  34. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +20 -0
  35. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicyTest.kt +136 -0
  36. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachineTest.kt +346 -0
  37. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +564 -1
  38. package/build/BluetoothSdk.types.d.ts +110 -2
  39. package/build/BluetoothSdk.types.d.ts.map +1 -1
  40. package/build/BluetoothSdk.types.js.map +1 -1
  41. package/build/_private/BluetoothSdkModule.d.ts +6 -2
  42. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  43. package/build/_private/BluetoothSdkModule.js +1 -0
  44. package/build/_private/BluetoothSdkModule.js.map +1 -1
  45. package/build/generated/changelogCatalog.d.ts +3 -0
  46. package/build/generated/changelogCatalog.d.ts.map +1 -1
  47. package/build/generated/changelogCatalog.js +4 -0
  48. package/build/generated/changelogCatalog.js.map +1 -1
  49. package/build/generated/releaseMetadata.js +6 -6
  50. package/build/generated/releaseMetadata.js.map +1 -1
  51. package/build/index.d.ts +1 -1
  52. package/build/index.d.ts.map +1 -1
  53. package/build/index.js +4 -0
  54. package/build/index.js.map +1 -1
  55. package/ios/BluetoothSdkModule.swift +24 -4
  56. package/ios/Source/BluetoothSdkDefaults.swift +1 -1
  57. package/ios/Source/Bridge.swift +11 -3
  58. package/ios/Source/DeviceManager.swift +103 -7
  59. package/ios/Source/DeviceStore.swift +27 -0
  60. package/ios/Source/GeneratedChangelogCatalog.swift +1 -0
  61. package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
  62. package/ios/Source/MentraBluetoothSDK.swift +41 -7
  63. package/ios/Source/TouchGesture.swift +13 -0
  64. package/ios/Source/errors/BluetoothSdkError.swift +5 -1
  65. package/ios/Source/events/BluetoothEvents.swift +4 -0
  66. package/ios/Source/internal/BleTraceLogger.swift +9 -6
  67. package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +181 -0
  68. package/ios/Source/sgcs/MentraLive.swift +1196 -173
  69. package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +260 -1
  70. package/ios/Source/sgcs/MentraLivePairingStateMachine.swift +385 -0
  71. package/ios/Source/sgcs/MentraLivePairingStateStore.swift +121 -0
  72. package/ios/Source/sgcs/Nimo.swift +278 -38
  73. package/ios/Source/sgcs/NimoCanvasCoordinator.swift +77 -18
  74. package/ios/Source/sgcs/NimoCanvasSession.swift +1 -0
  75. package/ios/Source/sgcs/NimoMacResourceTransport.swift +217 -0
  76. package/ios/Source/sgcs/NimoResourceFixture.swift +384 -0
  77. package/ios/Source/sgcs/NimoResourceSession.swift +406 -0
  78. package/ios/Source/sgcs/SGCManager.swift +7 -0
  79. package/ios/Source/sgcs/Simulated.swift +2 -0
  80. package/ios/Source/status/DeviceStatus.swift +35 -0
  81. package/ios/Source/types/DeviceModels.swift +8 -1
  82. package/ios/Source/utils/AudioSessionMonitor.swift +158 -5
  83. package/ios/Tests/BluetoothAudioRouteTests.swift +82 -0
  84. package/ios/Tests/DeviceManagerReconnectTests.swift +75 -2
  85. package/ios/Tests/GlassesAudioSetupPolicyTests.swift +191 -0
  86. package/ios/Tests/MentraLiveAudioSetupTests.swift +215 -0
  87. package/ios/Tests/MentraLiveConnectionOptionsTests.swift +55 -0
  88. package/ios/Tests/MentraLivePairingAdvertisementTests.swift +327 -0
  89. package/ios/Tests/MentraLivePairingStateMachineTests.swift +402 -0
  90. package/ios/Tests/MentraLiveSessionReadinessTests.swift +328 -26
  91. package/ios/Tests/NimoCanvasTransportTests.swift +147 -0
  92. package/ios/Tests/NimoResourceSessionTests.swift +476 -0
  93. package/ios/Tests/TouchGestureCommandTests.swift +87 -0
  94. package/ios/Tests/WifiAdbDispatchTests.swift +118 -0
  95. package/package.json +3 -2
  96. package/src/BluetoothSdk.types.ts +115 -1
  97. package/src/_private/BluetoothSdkModule.ts +7 -1
  98. package/src/generated/changelogCatalog.ts +4 -0
  99. package/src/generated/releaseMetadata.ts +6 -6
  100. package/src/index.ts +12 -0
@@ -23,8 +23,10 @@ import com.mentra.bluetoothsdk.sgcs.SceneElement
23
23
  import com.mentra.bluetoothsdk.sgcs.SceneFrame
24
24
  import com.mentra.bluetoothsdk.sgcs.Mach1
25
25
  import com.mentra.bluetoothsdk.sgcs.MentraLive
26
+ import com.mentra.bluetoothsdk.sgcs.MentraLivePairingStateStore
26
27
  import com.mentra.bluetoothsdk.sgcs.MentraNex
27
28
  import com.mentra.bluetoothsdk.sgcs.Nimo
29
+ import com.mentra.bluetoothsdk.sgcs.NimoResourceDiagnostics
28
30
  import com.mentra.bluetoothsdk.sgcs.SGCManager
29
31
  import com.mentra.bluetoothsdk.sgcs.Simulated
30
32
  import com.mentra.bluetoothsdk.utils.ControllerTypes
@@ -305,7 +307,10 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
305
307
  }
306
308
  }
307
309
  initializeViewStates()
308
- if (initializeHardware) initializeHardwareServices()
310
+ if (initializeHardware) {
311
+ initializeHardwareServices()
312
+ NimoResourceDiagnostics.start(Bridge.getContext())
313
+ }
309
314
  }
310
315
 
311
316
  // Keep host routing usable without starting audio codecs, receivers or services.
@@ -567,8 +572,10 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
567
572
 
568
573
  BluetoothAdapter.STATE_ON -> {
569
574
  Bridge.log("MAN: Bluetooth turned ON")
570
- // Auto-reconnect to last known device if we have one
571
- if (defaultWearable.isNotEmpty() && deviceName.isNotEmpty()) {
575
+ // Auto-reconnect to last known device if we have one.
576
+ // After owner loss, connectById watches for the next pairing
577
+ // mode instead of opening GATT.
578
+ if (shouldReconnectAfterBluetoothOn()) {
572
579
  Bridge.log(
573
580
  "MAN: Bluetooth restored, attempting reconnect to: $deviceName"
574
581
  )
@@ -1375,6 +1382,7 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
1375
1382
  // MARK: - Auxiliary Commands
1376
1383
 
1377
1384
  fun initSGC(wearable: String) {
1385
+ if (!NimoResourceDiagnostics.allowManagerConnect(wearable)) return
1378
1386
  Bridge.log("Initializing manager for wearable: $wearable")
1379
1387
  if (sgc != null && sgc?.type != wearable) {
1380
1388
  Bridge.log("MAN: Manager already initialized, cleaning up previous sgc")
@@ -1504,6 +1512,8 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
1504
1512
  Bridge.log("MAN: SGC is null, returning")
1505
1513
  return
1506
1514
  }
1515
+ // Before clearPendingConnection(): the pending target is what marks an explicit pair.
1516
+ notePairingSessionReady()
1507
1517
 
1508
1518
  // A new identity must never inherit the previous glasses' address when
1509
1519
  // pairing supplied only a name. Same-device reconnects retain their cache.
@@ -2017,7 +2027,13 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2017
2027
  sgc?.sendHotspotState(enabled)
2018
2028
  }
2019
2029
 
2020
- fun setWifiAdbState(enabled: Boolean) {
2030
+ fun setWifiAdbState(enabled: Boolean, expectedBluetoothMac: String? = null) {
2031
+ if (expectedBluetoothMac != null) {
2032
+ val current = sgc as? MentraLive ?: throw BluetoothSdkException(
2033
+ "glasses_not_connected", "Mentra Live glasses are not connected.")
2034
+ current.sendWifiAdbStateToPeer(enabled, expectedBluetoothMac)
2035
+ return
2036
+ }
2021
2037
  Bridge.log("MAN: Setting glasses Wi-Fi ADB state: $enabled")
2022
2038
  sgc?.sendWifiAdbState(enabled)
2023
2039
  }
@@ -2065,6 +2081,11 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2065
2081
  live.sendGalleryServerEnabled(requestId, enabled)
2066
2082
  }
2067
2083
 
2084
+ fun sendTouchGestureDefaultBehaviorEnabled(requestId: String, gesture: TouchGesture, enabled: Boolean) {
2085
+ val live = sgc as? MentraLive ?: throw BluetoothSdkException("unsupported_device", "This command requires Mentra Live glasses.")
2086
+ live.sendTouchGestureDefaultBehaviorEnabled(requestId, gesture, enabled)
2087
+ }
2088
+
2068
2089
  fun sendGalleryMode(requestId: String, enabled: Boolean) {
2069
2090
  val live = sgc as? MentraLive ?: throw IllegalStateException("unsupported_device")
2070
2091
  live.sendGalleryMode(requestId, enabled)
@@ -2334,7 +2355,39 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2334
2355
  sgc?.sendRgbLedControl(requestId, packageName, action, color, onDurationMs, offDurationMs, count)
2335
2356
  }
2336
2357
 
2358
+ internal fun shouldReconnectAfterBluetoothOn(): Boolean =
2359
+ defaultWearable.isNotEmpty() && deviceName.isNotEmpty()
2360
+
2361
+ /**
2362
+ * A ready Mentra Live session. Only an explicit pair (a pending target) clears
2363
+ * `pairing_rejected`; an automatic session only ends a pause and resets the streak.
2364
+ */
2365
+ internal fun notePairingSessionReady() {
2366
+ if (sgc !is MentraLive) return
2367
+ val explicitAttempt = pendingDeviceName.isNotEmpty() || pendingDeviceAddress.isNotEmpty()
2368
+ MentraLivePairingStateStore.update("device_ready") { it.onSessionReady(explicitAttempt) }
2369
+ }
2370
+
2371
+ /** Forget ends the pairing record. Also drops the pre-v4 owner-lost setting. */
2372
+ internal fun clearPairingStateOnForget() {
2373
+ MentraLivePairingStateStore.update("forget") { it.onForget() }
2374
+ if (DeviceStore.store.get("bluetooth", "mentra_live_owner_lost") as? Boolean != true) return
2375
+ DeviceStore.apply("bluetooth", "mentra_live_owner_lost", false)
2376
+ Bridge.saveSetting("mentra_live_owner_lost", false)
2377
+ }
2378
+
2379
+ /**
2380
+ * The saved glasses' firmware is no longer known once they are forgotten. The next glasses
2381
+ * report it again with their first `pairing_info`.
2382
+ */
2383
+ internal fun clearSecureFirmware() {
2384
+ if (DeviceStore.store.get("bluetooth", "mentra_live_secure_firmware") as? Boolean != true) return
2385
+ DeviceStore.apply("bluetooth", "mentra_live_secure_firmware", false)
2386
+ Bridge.saveSetting("mentra_live_secure_firmware", false)
2387
+ }
2388
+
2337
2389
  fun connectDefault() {
2390
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { connectDefault() }) return
2338
2391
  if (defaultWearable.isEmpty()) {
2339
2392
  Bridge.log("MAN: No default wearable, returning")
2340
2393
  return
@@ -2356,10 +2409,17 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2356
2409
  Bridge.log("MAN: connectDefault skipped — bluetooth runtime permissions not granted")
2357
2410
  return
2358
2411
  }
2412
+ if (!NimoResourceDiagnostics.allowManagerConnect(defaultWearable, reconnectTarget)) return
2359
2413
  initSGC(defaultWearable)
2360
2414
  val live = sgc as? MentraLive
2361
- if (live?.isPairingYieldActive() == true) {
2362
- Bridge.log("MAN: connectDefault skipped — Mentra Live pairing yield active")
2415
+ if (live != null && MentraLivePairingStateStore.isRejected) {
2416
+ Bridge.log("MAN: connectDefault skipped — Mentra Live pairing_rejected (Pair Again or forget)")
2417
+ return
2418
+ }
2419
+ if (live != null && MentraLivePairingStateStore.isPaused) {
2420
+ // connectById only records the target and watches for the window to end.
2421
+ Bridge.log("MAN: connectDefault deferred — Mentra Live pairing_mode")
2422
+ live.connectById(reconnectTarget)
2363
2423
  return
2364
2424
  }
2365
2425
  searching = true
@@ -2386,6 +2446,7 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2386
2446
  }
2387
2447
 
2388
2448
  fun connectByName(dName: String) {
2449
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { connectByName(dName) }) return
2389
2450
  Bridge.log("MAN: Connecting to wearable: $dName")
2390
2451
 
2391
2452
  var name = dName
@@ -2400,6 +2461,7 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2400
2461
  return
2401
2462
  }
2402
2463
 
2464
+ if (!NimoResourceDiagnostics.allowManagerConnect(pendingWearable.ifEmpty { defaultWearable }, name)) return
2403
2465
  if (pendingWearable.isEmpty() && !defaultWearable.isEmpty()) {
2404
2466
  Bridge.log("MAN: No pending wearable, using default wearable")
2405
2467
  pendingWearable = defaultWearable
@@ -2414,8 +2476,11 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2414
2476
  return
2415
2477
  }
2416
2478
 
2417
- disconnect(clearPendingIdentity = false)
2418
- Thread.sleep(100)
2479
+ if (!NimoResourceDiagnostics.allowManagerConnect(pendingWearable, name)) return
2480
+ if (!NimoResourceDiagnostics.preserveCapturedScan(pendingWearable, name)) {
2481
+ disconnect(clearPendingIdentity = false)
2482
+ Thread.sleep(100)
2483
+ }
2419
2484
  searching = true
2420
2485
  pendingDeviceName = name
2421
2486
 
@@ -2424,8 +2489,10 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2424
2489
  }
2425
2490
 
2426
2491
  fun connectDevice(deviceModel: String, deviceName: String) {
2492
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { connectDevice(deviceModel, deviceName) }) return
2427
2493
  Bridge.log("MAN: Connecting to device: $deviceModel $deviceName")
2428
2494
  if (DeviceTypes.ALL.contains(deviceModel)) {
2495
+ if (!NimoResourceDiagnostics.allowManagerConnect(deviceModel, deviceName)) return
2429
2496
  pendingWearable = deviceModel
2430
2497
  initSGC(pendingWearable)
2431
2498
  sgc?.connectById(deviceName)
@@ -2545,6 +2612,8 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2545
2612
  connectionRecovery.clear()
2546
2613
  }
2547
2614
  Bridge.log("MAN: Forgetting smart glasses")
2615
+ clearPairingStateOnForget()
2616
+ clearSecureFirmware()
2548
2617
 
2549
2618
  val live = sgc as? MentraLive
2550
2619
  if (live != null) {
@@ -2629,6 +2698,8 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2629
2698
  }
2630
2699
 
2631
2700
  fun findCompatibleDevices(deviceModel: String) {
2701
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { findCompatibleDevices(deviceModel) }) return
2702
+ if (!NimoResourceDiagnostics.allowManagerConnect(deviceModel)) return
2632
2703
  Bridge.log("MAN: Searching for compatible device names for: $deviceModel")
2633
2704
 
2634
2705
  // reset the search results:
@@ -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 = "This release is under active development. User-facing changes will be documented as they land."),
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-dev.944"
7
- const val RELEASE_SET_ID: String = "mentra-3.3.0-dev.944"
8
- const val SOURCE_COMMIT: String = "77b4e08cc991d8d88db9401a5a0157ed647c5c7f"
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-dev.944.json"
10
- const val OTA_MANIFEST_SHA256: String = "faa9e0d6e501772a9ca0e8fd6cdd03d795b5e40c6a1b103b0f0bb4b6d970dd07"
5
+ const val FAMILY_BASE_VERSION: String = "3.4.0"
6
+ const val RELEASE_IDENTITY: String = "3.4.0-dev.1004"
7
+ const val RELEASE_SET_ID: String = "mentra-3.4.0-dev.1004"
8
+ const val SOURCE_COMMIT: String = "c90a1bab4cd14b0c01338dd3bfc521a619ec795f"
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-dev.1004.json"
10
+ const val OTA_MANIFEST_SHA256: String = "a1d512d3b583f84667edb7fdc2e83667c70deb53315b7abd29c2207e7a4027a3"
11
11
  }
@@ -9,6 +9,8 @@ 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
13
+ import com.mentra.bluetoothsdk.sgcs.NimoResourceDiagnostics
12
14
  import com.mentra.bluetoothsdk.streaming.StreamSessionState
13
15
  import com.mentra.bluetoothsdk.utils.ControllerTypes
14
16
  import com.mentra.bluetoothsdk.utils.PhoneAudioMonitor
@@ -364,6 +366,8 @@ class MentraBluetoothSdk private constructor(
364
366
  }
365
367
 
366
368
  fun startScan(model: DeviceModel) {
369
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { startScan(model) }) return
370
+ if (!NimoResourceDiagnostics.allowManagerConnect(model.deviceType)) return
367
371
  if (model != DeviceModel.SIMULATED) {
368
372
  requireBluetoothReady("scan for glasses")
369
373
  }
@@ -470,11 +474,13 @@ class MentraBluetoothSdk private constructor(
470
474
 
471
475
  @JvmOverloads
472
476
  fun connect(device: Device, options: ConnectOptions = ConnectOptions()) {
477
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { connect(device, options) }) return
478
+ if (!NimoResourceDiagnostics.allowManagerConnect(device.model.deviceType, device.name)) return
473
479
  if (device.model != DeviceModel.SIMULATED) {
474
480
  requireBluetoothReady("connect to glasses")
475
481
  }
476
482
  val isController = ControllerTypes.ALL.contains(device.model.deviceType)
477
- if (options.cancelExistingConnectionAttempt) {
483
+ if (options.cancelExistingConnectionAttempt && !NimoResourceDiagnostics.preserveCapturedScan(device.model.deviceType, device.name)) {
478
484
  if (isController) {
479
485
  deviceManager.disconnectController()
480
486
  } else {
@@ -511,16 +517,18 @@ class MentraBluetoothSdk private constructor(
511
517
 
512
518
  @JvmOverloads
513
519
  fun connectDefault(options: ConnectOptions = ConnectOptions()) {
520
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { connectDefault(options) }) return
514
521
  val defaultDevice =
515
522
  currentDefaultDevice()
516
523
  ?: throw BluetoothSdkException(
517
524
  "default_device_missing",
518
525
  "Set a default glasses device before calling connectDefault.",
519
526
  )
527
+ if (!NimoResourceDiagnostics.allowManagerConnect(defaultDevice.model.deviceType, defaultDevice.name)) return
520
528
  if (defaultDevice.model != DeviceModel.SIMULATED) {
521
529
  requireBluetoothReady("connect to glasses")
522
530
  }
523
- if (options.cancelExistingConnectionAttempt) {
531
+ if (options.cancelExistingConnectionAttempt && !NimoResourceDiagnostics.preserveCapturedScan(defaultDevice.model.deviceType, defaultDevice.name)) {
524
532
  cancelConnectionAttempt()
525
533
  }
526
534
  deviceManager.connectDefault()
@@ -640,6 +648,14 @@ class MentraBluetoothSdk private constructor(
640
648
  send = { requestId -> deviceManager.sendGalleryServerEnabled(requestId, enabled) },
641
649
  )
642
650
 
651
+ /** Disable a stock action while retaining touch events. Reset by BES on BLE disconnect. */
652
+ suspend fun setTouchGestureDefaultBehaviorEnabled(gesture: TouchGesture, enabled: Boolean): SettingsAckEvent =
653
+ performSettingsCommand(
654
+ setting = "touch_gesture_default",
655
+ updateStore = {},
656
+ send = { requestId -> deviceManager.sendTouchGestureDefaultBehaviorEnabled(requestId, gesture, enabled) },
657
+ )
658
+
643
659
  suspend fun setGalleryModeEnabled(enabled: Boolean): SettingsAckEvent =
644
660
  performSettingsCommand(
645
661
  setting = "gallery_mode",
@@ -1111,8 +1127,9 @@ class MentraBluetoothSdk private constructor(
1111
1127
  }
1112
1128
  }
1113
1129
 
1114
- fun setWifiAdbState(enabled: Boolean) {
1115
- deviceManager.setWifiAdbState(enabled)
1130
+ @JvmOverloads
1131
+ fun setWifiAdbState(enabled: Boolean, expectedBluetoothMac: String? = null) {
1132
+ deviceManager.setWifiAdbState(enabled, expectedBluetoothMac)
1116
1133
  }
1117
1134
 
1118
1135
  fun setSystemTime(timestampMs: Long) {
@@ -2094,6 +2111,7 @@ class MentraBluetoothSdk private constructor(
2094
2111
  BluetoothError(
2095
2112
  code = "pair_failure",
2096
2113
  message = data["error"] as? String ?: data.toString(),
2114
+ failureCode = data["code"] as? String,
2097
2115
  )
2098
2116
  )
2099
2117
  }
@@ -0,0 +1,19 @@
1
+ package com.mentra.bluetoothsdk
2
+
3
+ /** Mentra Live touchpad gestures, using the public touch_event names. */
4
+ enum class TouchGesture(val wireName: String) {
5
+ SINGLE_TAP("single_tap"),
6
+ DOUBLE_TAP("double_tap"),
7
+ TRIPLE_TAP("triple_tap"),
8
+ LONG_PRESS("long_press"),
9
+ FORWARD_SWIPE("forward_swipe"),
10
+ BACKWARD_SWIPE("backward_swipe"),
11
+ UP_SWIPE("up_swipe"),
12
+ DOWN_SWIPE("down_swipe");
13
+
14
+ companion object {
15
+ fun fromWireName(value: String): TouchGesture =
16
+ entries.firstOrNull { it.wireName == value }
17
+ ?: throw BluetoothSdkException("invalid_touch_gesture", "Unknown touch gesture: $value")
18
+ }
19
+ }
@@ -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 {
@@ -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
+ }