@mentra/bluetooth-sdk 3.2.1-dev.314 → 3.3.0-beta.1000

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 (199) hide show
  1. package/README.md +103 -10
  2. package/android/build.gradle +15 -0
  3. package/android/lc3Lib/build.gradle +6 -1
  4. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +368 -0
  5. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +156 -0
  6. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkAnalytics.kt +63 -14
  7. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkAnalyticsTracker.kt +55 -1
  8. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +4 -1
  9. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkInstallId.kt +23 -0
  10. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +12 -2
  11. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkUpdateCheck.kt +184 -0
  12. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkUsageTracker.kt +388 -0
  13. package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +2 -1
  14. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +138 -26
  15. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +37 -13
  16. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +3 -2
  17. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
  18. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +235 -36
  19. package/android/src/main/java/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt +24 -0
  20. package/android/src/main/java/com/mentra/bluetoothsdk/NetworkDiagnostics.kt +25 -0
  21. package/android/src/main/java/com/mentra/bluetoothsdk/TouchGesture.kt +19 -0
  22. package/android/src/main/java/com/mentra/bluetoothsdk/VersionInfoResponseAccumulator.kt +13 -2
  23. package/android/src/main/java/com/mentra/bluetoothsdk/debug/BleTraceLogger.kt +3 -0
  24. package/android/src/main/java/com/mentra/bluetoothsdk/requests/DisplayRequests.kt +1 -1
  25. package/android/src/main/java/com/mentra/bluetoothsdk/services/Foreground.kt +33 -0
  26. package/android/src/main/java/com/mentra/bluetoothsdk/services/G2ConnectionRecovery.kt +47 -0
  27. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTracker.kt +4 -0
  28. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioServiceDiscovery.kt +70 -0
  29. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1.kt +2 -2
  30. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1TextSanitizer.kt +11 -32
  31. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G2.kt +72 -21
  32. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/LatinTextSanitizer.kt +39 -0
  33. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +261 -42
  34. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraNex.kt +12 -8
  35. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +314 -395
  36. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCodec.kt +247 -0
  37. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +238 -0
  38. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasEncoder.kt +58 -0
  39. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +180 -0
  40. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +11 -0
  41. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SelectedDeviceAddress.kt +17 -0
  42. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SerializedGattCallback.kt +5 -0
  43. package/android/src/main/java/com/mentra/bluetoothsdk/utils/G2Text.kt +7 -0
  44. package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +20 -0
  45. package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkAnalyticsTrackerTest.kt +58 -3
  46. package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkUpdateCheckTest.kt +124 -0
  47. package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkUsageTrackerTest.kt +263 -0
  48. package/android/src/test/java/com/mentra/bluetoothsdk/DashboardContentFormatterTest.kt +2 -2
  49. package/android/src/test/java/com/mentra/bluetoothsdk/DeviceIdentityPairingTest.kt +59 -0
  50. package/android/src/test/java/com/mentra/bluetoothsdk/DeviceManagerSceneHandoffTest.kt +666 -0
  51. package/android/src/test/java/com/mentra/bluetoothsdk/G2TextTest.kt +13 -0
  52. package/android/src/test/java/com/mentra/bluetoothsdk/NetworkDiagnosticsTest.kt +55 -0
  53. package/android/src/test/java/com/mentra/bluetoothsdk/ScanCompletionTest.kt +5 -1
  54. package/android/src/test/java/com/mentra/bluetoothsdk/TouchGestureCommandTest.kt +112 -0
  55. package/android/src/test/java/com/mentra/bluetoothsdk/VersionInfoResponseAccumulatorTest.kt +71 -0
  56. package/android/src/test/java/com/mentra/bluetoothsdk/debug/BleTraceLoggerTest.kt +69 -0
  57. package/android/src/test/java/com/mentra/bluetoothsdk/services/G2ConnectionRecoveryTest.kt +51 -0
  58. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioServiceDiscoveryTest.kt +124 -0
  59. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G1PairingTest.kt +105 -0
  60. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G1TextSanitizerTest.kt +29 -4
  61. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G2DisplayThreadTest.kt +120 -0
  62. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G2PairingTargetTest.kt +90 -0
  63. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveClassicDisconnectTest.kt +133 -0
  64. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveFileTransferSessionTest.kt +55 -0
  65. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGattCallbackTest.kt +33 -0
  66. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +137 -0
  67. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +126 -0
  68. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingTargetTest.kt +65 -0
  69. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveWifiCredentialLogTest.kt +55 -0
  70. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraNexPairingTest.kt +151 -0
  71. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoBitmapAcceptanceTest.kt +105 -0
  72. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCodecTest.kt +233 -0
  73. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +348 -0
  74. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +339 -0
  75. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoMicReconnectTest.kt +93 -0
  76. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoProtocolTest.kt +11 -0
  77. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/SelectedDeviceAddressTest.kt +27 -0
  78. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +287 -0
  79. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +127 -0
  80. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +288 -0
  81. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoReadinessDriverTest.kt +205 -0
  82. package/build/BluetoothSdk.types.d.ts +22 -1
  83. package/build/BluetoothSdk.types.d.ts.map +1 -1
  84. package/build/BluetoothSdk.types.js +1 -0
  85. package/build/BluetoothSdk.types.js.map +1 -1
  86. package/build/_private/BluetoothSdkModule.d.ts +6 -1
  87. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  88. package/build/_private/BluetoothSdkModule.js +5 -1
  89. package/build/_private/BluetoothSdkModule.js.map +1 -1
  90. package/build/_private/MentraLocalNetworkModule.d.ts +23 -0
  91. package/build/_private/MentraLocalNetworkModule.d.ts.map +1 -1
  92. package/build/_private/MentraLocalNetworkModule.js.map +1 -1
  93. package/build/_private/nativeLogConsole.d.ts +19 -0
  94. package/build/_private/nativeLogConsole.d.ts.map +1 -1
  95. package/build/_private/nativeLogConsole.js +12 -0
  96. package/build/_private/nativeLogConsole.js.map +1 -1
  97. package/build/generated/changelogCatalog.d.ts +5 -2
  98. package/build/generated/changelogCatalog.d.ts.map +1 -1
  99. package/build/generated/changelogCatalog.js +6 -2
  100. package/build/generated/changelogCatalog.js.map +1 -1
  101. package/build/generated/releaseMetadata.js +6 -6
  102. package/build/generated/releaseMetadata.js.map +1 -1
  103. package/build/index.d.ts +1 -1
  104. package/build/index.d.ts.map +1 -1
  105. package/build/index.js +2 -0
  106. package/build/index.js.map +1 -1
  107. package/build/ota-transport/index.d.ts +4 -0
  108. package/build/ota-transport/index.d.ts.map +1 -1
  109. package/build/ota-transport/index.js +2 -0
  110. package/build/ota-transport/index.js.map +1 -1
  111. package/ios/BluetoothSdkModule.swift +25 -4
  112. package/ios/MentraBluetoothSDK.podspec +3 -2
  113. package/ios/Source/BluetoothBackgroundMode.swift +32 -0
  114. package/ios/Source/BluetoothSdkDefaults.swift +7 -2
  115. package/ios/Source/Bridge.swift +15 -2
  116. package/ios/Source/DeviceManager.swift +106 -66
  117. package/ios/Source/DeviceStore.swift +26 -7
  118. package/ios/Source/GeneratedChangelogCatalog.swift +3 -2
  119. package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
  120. package/ios/Source/MentraBluetoothSDK.swift +324 -54
  121. package/ios/Source/TouchGesture.swift +13 -0
  122. package/ios/Source/audio/GlassesMicWatchdog.swift +33 -0
  123. package/ios/Source/events/BluetoothEvents.swift +4 -0
  124. package/ios/Source/internal/BluetoothAvailability.swift +6 -0
  125. package/ios/Source/internal/BluetoothSdkAnalytics.swift +87 -13
  126. package/ios/Source/internal/BluetoothSdkAnalyticsTracker.swift +54 -1
  127. package/ios/Source/internal/BluetoothSdkInstallId.swift +21 -0
  128. package/ios/Source/internal/BluetoothSdkUpdateCheck.swift +223 -0
  129. package/ios/Source/internal/BluetoothSdkUsageTracker.swift +428 -0
  130. package/ios/Source/requests/DisplayRequests.swift +1 -1
  131. package/ios/Source/requests/VersionInfoResponseAccumulator.swift +11 -1
  132. package/ios/Source/sgcs/Ar99.swift +1 -2
  133. package/ios/Source/sgcs/G1.swift +68 -38
  134. package/ios/Source/sgcs/G1ConnectionTarget.swift +13 -0
  135. package/ios/Source/sgcs/G2.swift +261 -247
  136. package/ios/Source/sgcs/G2ConnectionSession.swift +101 -0
  137. package/ios/Source/sgcs/Mach1.swift +19 -7
  138. package/ios/Source/sgcs/MentraLive.swift +368 -220
  139. package/ios/Source/sgcs/MentraLiveFileTransferSession.swift +137 -0
  140. package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +47 -0
  141. package/ios/Source/sgcs/MentraNex.swift +8 -31
  142. package/ios/Source/sgcs/NexConnectionTarget.swift +15 -0
  143. package/ios/Source/sgcs/Nimo.swift +280 -408
  144. package/ios/Source/sgcs/NimoCanvasCodec.swift +272 -0
  145. package/ios/Source/sgcs/NimoCanvasCoordinator.swift +233 -0
  146. package/ios/Source/sgcs/NimoCanvasImage.swift +53 -0
  147. package/ios/Source/sgcs/NimoCanvasSession.swift +166 -0
  148. package/ios/Source/sgcs/NimoDiscovery.swift +49 -0
  149. package/ios/Source/sgcs/SGCManager.swift +25 -1
  150. package/ios/Source/sgcs/VuzixConnectionTarget.swift +15 -0
  151. package/ios/Source/status/DeviceStatus.swift +1 -0
  152. package/ios/Source/stt/SherpaOnnxTranscriber.swift +49 -189
  153. package/ios/Source/utils/AudioSessionMonitor.swift +44 -8
  154. package/ios/Source/utils/DemandDrivenAudioWorker.swift +150 -0
  155. package/ios/Source/utils/G1Text.swift +2 -24
  156. package/ios/Source/utils/G1TextSanitizer.swift +27 -0
  157. package/ios/Source/utils/G2Text.swift +11 -0
  158. package/ios/Source/utils/LatinTextSanitizer.swift +48 -0
  159. package/ios/Tests/BluetoothAudioRouteTests.swift +26 -0
  160. package/ios/Tests/BluetoothBackgroundModeTests.swift +32 -0
  161. package/ios/Tests/BluetoothSdkAnalyticsTrackerTests.swift +54 -3
  162. package/ios/Tests/BluetoothSdkUpdateCheckTests.swift +153 -0
  163. package/ios/Tests/BluetoothSdkUsageTrackerTests.swift +296 -0
  164. package/ios/Tests/DashboardContentFormatterTests.swift +2 -2
  165. package/ios/Tests/DashboardRenderingTests.swift +31 -0
  166. package/ios/Tests/DemandDrivenAudioWorkerTests.swift +157 -0
  167. package/ios/Tests/DeviceIdentityPairingTests.swift +49 -0
  168. package/ios/Tests/DeviceManagerReconnectTests.swift +362 -0
  169. package/ios/Tests/G1PairingTests.swift +162 -0
  170. package/ios/Tests/G1TextSanitizerTests.swift +32 -0
  171. package/ios/Tests/G2ConnectionSessionTests.swift +172 -0
  172. package/ios/Tests/G2TextTests.swift +10 -0
  173. package/ios/Tests/IncidentLogDispatchTests.swift +111 -0
  174. package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
  175. package/ios/Tests/MentraLiveFileTransferSessionTests.swift +47 -0
  176. package/ios/Tests/MentraLiveReconnectPolicyTests.swift +58 -0
  177. package/ios/Tests/MentraLiveSessionReadinessTests.swift +292 -0
  178. package/ios/Tests/NimoCanvasCodecTests.swift +217 -0
  179. package/ios/Tests/NimoCanvasSessionTests.swift +181 -0
  180. package/ios/Tests/NimoCanvasTransportTests.swift +186 -0
  181. package/ios/Tests/NimoDeviceCommandsTests.swift +16 -0
  182. package/ios/Tests/NimoDiscoveryTests.swift +79 -0
  183. package/ios/Tests/SGCConnectionTargetTests.swift +48 -0
  184. package/ios/Tests/TouchGestureCommandTests.swift +87 -0
  185. package/ios/Tests/VersionInfoCommandTests.swift +194 -0
  186. package/ios/Tests/VersionInfoResponseAccumulatorTests.swift +65 -0
  187. package/ios/Tests/VideoRecordingCommandTests.swift +81 -0
  188. package/ios/Tests/WifiCredentialLoggingTests.swift +42 -0
  189. package/package.json +2 -2
  190. package/plugin/build/withIos.d.ts +2 -0
  191. package/plugin/build/withIos.js +12 -1
  192. package/src/BluetoothSdk.types.ts +30 -0
  193. package/src/_private/BluetoothSdkModule.ts +12 -1
  194. package/src/_private/MentraLocalNetworkModule.ts +28 -0
  195. package/src/_private/nativeLogConsole.ts +19 -0
  196. package/src/generated/changelogCatalog.ts +6 -2
  197. package/src/generated/releaseMetadata.ts +6 -6
  198. package/src/index.ts +3 -0
  199. package/src/ota-transport/index.ts +10 -1
@@ -318,9 +318,9 @@ struct ViewState {
318
318
  var lc3Converter: PcmConverter?
319
319
  /// Audio output format - defaults to LC3 for bandwidth savings
320
320
  private var audioOutputFormat: AudioOutputFormat = .lc3
321
- /// Last time we received an LC3 frame from the glasses (used by the mic
322
- /// inactivity watchdog).
323
- private var lastLc3Event: Date?
321
+ private var micWatchdog = GlassesMicWatchdog()
322
+ // Injectable monotonic clock so recovery deadlines can be tested without sleeping.
323
+ var micWatchdogNow: () -> TimeInterval = { ProcessInfo.processInfo.systemUptime }
324
324
  private var sequenceGapEvents: Int64 = 0
325
325
  private var decodeFailures: Int64 = 0
326
326
  private var lastLc3ReceivedAt: Int64?
@@ -330,7 +330,7 @@ struct ViewState {
330
330
 
331
331
  /// STT:
332
332
  #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
333
- private var transcriber: SherpaOnnxTranscriber?
333
+ private let transcriber = SherpaOnnxTranscriber()
334
334
  #endif
335
335
 
336
336
  var viewStates: [ViewState] = [
@@ -383,24 +383,6 @@ struct ViewState {
383
383
  // Start memory monitoring (logs every 30s to help detect leaks)
384
384
  // MemoryMonitor.start()
385
385
 
386
- // Initialize SherpaOnnx Transcriber
387
- #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
388
- if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
389
- let window = windowScene.windows.first,
390
- let rootViewController = window.rootViewController
391
- {
392
- transcriber = SherpaOnnxTranscriber(context: rootViewController)
393
- } else {
394
- Bridge.log("Failed to create SherpaOnnxTranscriber - no root view controller found")
395
- }
396
-
397
- // Initialize the transcriber
398
- if let transcriber = transcriber {
399
- transcriber.initialize()
400
- Bridge.log("SherpaOnnxTranscriber fully initialized")
401
- }
402
- #endif
403
-
404
386
  // Initialize persistent LC3 converter for unified audio encoding
405
387
  lc3Converter = PcmConverter()
406
388
  Bridge.log("LC3 converter initialized for unified audio encoding")
@@ -472,10 +454,17 @@ struct ViewState {
472
454
  }
473
455
 
474
456
  func reportGlassesAudioActivity() {
475
- lastLc3Event = Date()
457
+ micWatchdog.receivedAudio(at: micWatchdogNow())
476
458
  lastPcmProducedAt = nowMs()
477
459
  }
478
460
 
461
+ /// Decoded glasses audio must update recovery health; phone PCM must not.
462
+ func handleGlassesPcm(_ pcmData: Data) {
463
+ guard !pcmData.isEmpty else { return }
464
+ reportGlassesAudioActivity()
465
+ handlePcm(pcmData)
466
+ }
467
+
479
468
  private func micHealth() -> MicHealth {
480
469
  MicHealth(
481
470
  sequenceGapEvents: sequenceGapEvents,
@@ -499,13 +488,13 @@ struct ViewState {
499
488
  lastLc3ReceivedAt = nil
500
489
  lastPcmProducedAt = nil
501
490
  lastLc3Sequence = nil
502
- lastLc3Event = nil
491
+ micWatchdog = GlassesMicWatchdog()
503
492
  }
504
493
 
505
494
  private func recordLc3Packet(sequenceNumber: Int?) {
506
495
  let receivedAt = nowMs()
507
496
  lastLc3ReceivedAt = receivedAt
508
- lastLc3Event = Date()
497
+ micWatchdog.receivedAudio(at: micWatchdogNow())
509
498
  var hasGap = false
510
499
  if let sequenceNumber {
511
500
  let normalized = sequenceNumber & 0xFF
@@ -535,7 +524,7 @@ struct ViewState {
535
524
  // Send PCM to local transcriber.
536
525
  #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
537
526
  if shouldSendTranscript || localSttFallbackActive {
538
- transcriber?.acceptAudio(pcm16le: pcmData)
527
+ transcriber.acceptAudio(pcm16le: pcmData)
539
528
  }
540
529
  #endif
541
530
  }
@@ -605,6 +594,7 @@ struct ViewState {
605
594
  }
606
595
 
607
596
  currentMic = micUsed
597
+ updateGlassesMicExpectation()
608
598
 
609
599
  // log if no mic was found:
610
600
  if micUsed == "" && micEnabled {
@@ -723,6 +713,7 @@ struct ViewState {
723
713
  Bridge.log("MAN: Manager already initialized, cleaning up previous sgc")
724
714
  sgc?.cleanup()
725
715
  sgc = nil
716
+ DeviceStore.shared.apply("glasses", "micEnabled", false)
726
717
  resetSystemTimeSync()
727
718
  }
728
719
 
@@ -902,27 +893,20 @@ struct ViewState {
902
893
  return result
903
894
  }
904
895
 
905
- private func checkAndReinitGlassesMic() {
906
- // if the glasses mic is marked as enabled (and the glasses are connected), but our last known lc3 event is from > 5 seconds ago, reinitialize the mic:
907
- let glassesMicEnabled = DeviceStore.shared.get("glasses", "micEnabled") as? Bool ?? false
908
- let glassesConnected = DeviceStore.shared.get("glasses", "connected") as? Bool ?? false
909
- if !glassesMicEnabled || !glassesConnected {
910
- return
911
- }
912
-
913
- if sgc?.isMicSuspendedForAudio == true {
914
- Bridge.log("MAN: Glasses mic intentionally suspended for phone audio; skipping mic recovery")
915
- return
916
- }
917
-
918
- if PhoneAudioMonitor.getInstance().isOwnAppAudioPlaying() {
919
- Bridge.log("MAN: Mentra audio is playing; skipping glasses mic recovery")
920
- return
921
- }
896
+ private func updateGlassesMicExpectation() {
897
+ // Demand/route and device readiness decide whether audio is expected. The
898
+ // shared micEnabled flag alone is not evidence of a running hardware stream.
899
+ let expected = micEnabled && currentMic == MicTypes.GLASSES_CUSTOM
900
+ && sgc?.fullyBooted == true && sgc?.hasMic == true
901
+ && sgc?.isMicSuspendedForAudio != true
902
+ && !PhoneAudioMonitor.getInstance().isOwnAppAudioPlaying()
903
+ micWatchdog.expectAudio(expected, at: micWatchdogNow())
904
+ }
922
905
 
923
- let timeSinceLastLc3Event = Date().timeIntervalSince(lastLc3Event ?? Date())
924
- if timeSinceLastLc3Event > 5 {
925
- Bridge.log("MAN: No audio activity in the last 5 seconds from glasses, reinitializing glasses mic")
906
+ func checkAndReinitGlassesMic() {
907
+ updateGlassesMicExpectation()
908
+ if micWatchdog.shouldRetry(at: micWatchdogNow()) {
909
+ Bridge.log("MAN: Expected glasses audio missing for 5 seconds; retrying mic start")
926
910
  sgc?.setMicEnabled(true)
927
911
  }
928
912
  }
@@ -982,7 +966,7 @@ struct ViewState {
982
966
  func restartTranscriber() {
983
967
  #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
984
968
  Bridge.log("MAN: Restarting SherpaOnnxTranscriber via command")
985
- transcriber?.restart()
969
+ transcriber.restart()
986
970
  #else
987
971
  Bridge.log("MAN: Local STT is not included in this SwiftPM build")
988
972
  #endif
@@ -998,12 +982,16 @@ struct ViewState {
998
982
  Bridge.log("MAN: handleDeviceReady(): \(sgc.type)")
999
983
  resetMicHealth()
1000
984
 
985
+ // A new identity must never inherit the previous glasses' address when
986
+ // pairing supplied only a name. Same-device reconnects retain their cache.
987
+ let identityChanged = !pendingDeviceName.isEmpty &&
988
+ (pendingDeviceName != deviceName || sgc.type != defaultWearable)
989
+ if identityChanged || !pendingDeviceAddress.isEmpty {
990
+ deviceAddress = pendingDeviceAddress
991
+ }
1001
992
  if !pendingDeviceName.isEmpty {
1002
993
  deviceName = pendingDeviceName
1003
994
  }
1004
- if !pendingDeviceAddress.isEmpty {
1005
- deviceAddress = pendingDeviceAddress
1006
- }
1007
995
  clearPendingConnection()
1008
996
  defaultWearable = sgc.type
1009
997
  searching = false
@@ -1020,18 +1008,22 @@ struct ViewState {
1020
1008
  let h = DeviceStore.shared.get("bluetooth", "dashboard_height") as? Int ?? 4
1021
1009
  // Fall back to the canonical default (2), matching DeviceStore, not 1.
1022
1010
  let rawDepth = DeviceStore.shared.get("bluetooth", "dashboard_depth") as? Int ?? 2
1023
- let d = min(max(rawDepth, 1), 4)
1011
+ let d = sgc.type == DeviceTypes.NIMO ? min(max(rawDepth, 0), 10) : min(max(rawDepth, 1), 4)
1024
1012
  sgc.setDashboardPosition(h, d)
1025
1013
  }
1026
1014
 
1027
- // Show welcome message on first connect for all display glasses
1015
+ // Preserve the connected-edge scene replay on full-frame adapters.
1028
1016
  if shouldSendBootingMessage {
1029
- Task {
1030
- await sgc.sendTextWall("// MentraOS Connected")
1031
- try? await Task.sleep(nanoseconds: 3_000_000_000) // 1 second
1032
- sgc.clearDisplay()
1033
- }
1034
1017
  shouldSendBootingMessage = false
1018
+ if sgc.showConnectionConfirmation {
1019
+ Task {
1020
+ guard (self.sgc as AnyObject?) === (sgc as AnyObject) else { return }
1021
+ await sgc.sendTextWall("// MentraOS Connected")
1022
+ try? await Task.sleep(nanoseconds: 3_000_000_000)
1023
+ guard (self.sgc as AnyObject?) === (sgc as AnyObject) else { return }
1024
+ sgc.clearDisplay()
1025
+ }
1026
+ }
1035
1027
  }
1036
1028
 
1037
1029
  // Call device-specific setup handlers
@@ -1058,6 +1050,11 @@ struct ViewState {
1058
1050
  #endif
1059
1051
  checkCurrentAudioDevice()
1060
1052
 
1053
+ // Disconnect clears micEnabled but preserves the consumers' audio requests.
1054
+ // Recompute demand before selecting a microphone; unchanged requests are
1055
+ // deduplicated by DeviceStore.apply().
1056
+ setMicState()
1057
+
1061
1058
  // save the default_wearable now that we're connected:
1062
1059
  Bridge.saveSetting("default_wearable", defaultWearable)
1063
1060
  Bridge.saveSetting("device_name", deviceName)
@@ -1214,7 +1211,9 @@ struct ViewState {
1214
1211
  self.dashboardSceneCleanupPending = false
1215
1212
  let elementIds = Array(self.pendingDashboardSceneElementIds)
1216
1213
  self.pendingDashboardSceneElementIds.removeAll()
1217
- await self.sgc?.clearSceneElements(elementIds)
1214
+ if self.sgc?.sceneHandoffRequiresClear == true {
1215
+ await self.sgc?.clearSceneElements(elementIds)
1216
+ }
1218
1217
  }
1219
1218
  self.dashboardSceneCleanupTask = nil
1220
1219
  }
@@ -1261,7 +1260,7 @@ struct ViewState {
1261
1260
  if stateIndex == 1, dashboardSceneCleanupDeferred {
1262
1261
  dashboardSceneCleanupPending = true
1263
1262
  pendingDashboardSceneElementIds.formUnion(prevFrame.elements.map(\.id))
1264
- } else if layoutType != "clear_view" {
1263
+ } else if layoutType != "clear_view", shouldClearSceneHandoff(stateIndex) {
1265
1264
  let ids = prevFrame.elements.map(\.id)
1266
1265
  Task { [weak self] in
1267
1266
  await self?.sgc?.clearSceneElements(ids)
@@ -1355,7 +1354,7 @@ struct ViewState {
1355
1354
  // on G2 - no page rebuild).
1356
1355
  let prevLegacyType = viewStates[stateIndex].layoutType
1357
1356
  let cleanupDeferred = stateIndex == 1 && dashboardSceneCleanupDeferred
1358
- if !cleanupDeferred,
1357
+ if !cleanupDeferred, shouldClearSceneHandoff(stateIndex),
1359
1358
  !prevLegacyType.isEmpty,
1360
1359
  prevLegacyType != "clear_view",
1361
1360
  prevLegacyType != "scene"
@@ -1371,7 +1370,7 @@ struct ViewState {
1371
1370
  if stateIndex == 1, dashboardSceneCleanupDeferred {
1372
1371
  dashboardSceneCleanupPending = true
1373
1372
  pendingDashboardSceneElementIds.formUnion(prevFrame.elements.map(\.id))
1374
- } else {
1373
+ } else if shouldClearSceneHandoff(stateIndex) {
1375
1374
  let ids = prevFrame.elements.map(\.id)
1376
1375
  Task { [weak self] in
1377
1376
  await self?.sgc?.clearSceneElements(ids)
@@ -1395,6 +1394,13 @@ struct ViewState {
1395
1394
  }
1396
1395
  }
1397
1396
 
1397
+ private func shouldClearSceneHandoff(_ stateIndex: Int) -> Bool {
1398
+ let visibleIndex = headUp && contextualDashboard ? 1 : 0
1399
+ guard let sgc else { return false }
1400
+ return stateIndex == visibleIndex && !screenDisabled && sgc.fullyBooted
1401
+ && !sgc.type.contains(DeviceTypes.SIMULATED) && sgc.sceneHandoffRequiresClear
1402
+ }
1403
+
1398
1404
  /// Guarded scene dispatch - mirrors sendCurrentState's send conditions.
1399
1405
  private func dispatchSceneFrame(_ frame: SceneFrame, stateIndex: Int) {
1400
1406
  if screenDisabled { return }
@@ -1512,13 +1518,16 @@ struct ViewState {
1512
1518
  sgc?.requestSavedWifiNetworks(requestId: requestId, sid: sid) ?? false
1513
1519
  }
1514
1520
 
1515
- func sendIncidentId(_ incidentId: String, apiBaseUrl: String? = nil) {
1521
+ func sendIncidentId(_ incidentId: String, apiBaseUrl: String? = nil) throws {
1522
+ guard let driver = sgc else {
1523
+ throw BluetoothSdkError(code: "glasses_not_connected", message: "Cannot request incident logs because glasses are not connected.")
1524
+ }
1516
1525
  Bridge.log("MAN: Sending incidentId to glasses for log upload: \(incidentId)")
1517
- sgc?.sendIncidentId(incidentId, apiBaseUrl: apiBaseUrl)
1526
+ try driver.sendIncidentId(incidentId, apiBaseUrl: apiBaseUrl)
1518
1527
  }
1519
1528
 
1520
1529
  func sendWifiCredentials(_ ssid: String, _ password: String) {
1521
- Bridge.log("MAN: Sending wifi credentials: \(ssid) \(password)")
1530
+ Bridge.log("MAN: Sending wifi credentials: \(ssid)")
1522
1531
  sgc?.sendWifiCredentials(ssid, password)
1523
1532
  }
1524
1533
 
@@ -1588,6 +1597,10 @@ struct ViewState {
1588
1597
  try liveSgc().sendGalleryServerEnabled(requestId: requestId, enabled: enabled)
1589
1598
  }
1590
1599
 
1600
+ func sendTouchGestureDefaultBehaviorEnabled(requestId: String, gesture: TouchGesture, enabled: Bool) throws {
1601
+ try liveSgc().sendTouchGestureDefaultBehaviorEnabled(requestId: requestId, gesture: gesture, enabled: enabled)
1602
+ }
1603
+
1591
1604
  func sendGalleryMode(requestId: String, enabled: Bool) throws {
1592
1605
  try liveSgc().sendGalleryMode(requestId: requestId, active: enabled)
1593
1606
  }
@@ -1738,6 +1751,9 @@ struct ViewState {
1738
1751
  func setMicState() {
1739
1752
  let willSendPcm = shouldSendPcm || shouldSendLc3
1740
1753
  let willSendTranscript = shouldSendTranscript || localSttFallbackActive
1754
+ #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
1755
+ transcriber.setActive(willSendTranscript)
1756
+ #endif
1741
1757
  micEnabled = willSendPcm || willSendTranscript
1742
1758
  updateMicState()
1743
1759
  }
@@ -1943,6 +1959,9 @@ struct ViewState {
1943
1959
  sgc?.clearDisplay() // clear the screen
1944
1960
  sgc?.disconnect()
1945
1961
  sgc = nil // Clear the SGC reference after disconnect
1962
+ // This cache belongs to the discarded connection. Keep consumer demand,
1963
+ // but require a new mic-enable command when replacement glasses are ready.
1964
+ DeviceStore.shared.apply("glasses", "micEnabled", false)
1946
1965
  resetSystemTimeSync()
1947
1966
  resetMicHealth()
1948
1967
  searching = false
@@ -1987,6 +2006,28 @@ struct ViewState {
1987
2006
  controller = nil // Clear the controller reference after disconnect
1988
2007
  }
1989
2008
 
2009
+ private var unpairInProgress = false
2010
+
2011
+ /// Explicit user Unpair, separate from passive pairing cleanup and logout.
2012
+ func unpair() async throws {
2013
+ guard !unpairInProgress else {
2014
+ throw NSError(domain: "NimoUnpair", code: 1,
2015
+ userInfo: [NSLocalizedDescriptionKey: "Unpair already in progress"])
2016
+ }
2017
+ unpairInProgress = true
2018
+ defer { unpairInProgress = false }
2019
+ if let nimo = sgc as? Nimo {
2020
+ _ = await withCheckedContinuation { (continuation: CheckedContinuation<Bool, Never>) in
2021
+ nimo.resetForUnpair { continuation.resume(returning: $0) }
2022
+ }
2023
+ guard (sgc as? Nimo) === nimo else {
2024
+ throw NSError(domain: "NimoUnpair", code: 2,
2025
+ userInfo: [NSLocalizedDescriptionKey: "Glasses changed during Unpair"])
2026
+ }
2027
+ }
2028
+ forget()
2029
+ }
2030
+
1990
2031
  func forget() {
1991
2032
  Bridge.log("MAN: Forgetting smart glasses")
1992
2033
  // Call forget first to stop timers/handlers/reconnect logic
@@ -2053,8 +2094,7 @@ struct ViewState {
2053
2094
  #endif
2054
2095
  // Clean up transcriber resources
2055
2096
  #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
2056
- transcriber?.shutdown()
2057
- transcriber = nil
2097
+ transcriber.shutdown()
2058
2098
  #endif
2059
2099
 
2060
2100
  // Clean up LC3 converter
@@ -94,6 +94,7 @@ class DeviceStore {
94
94
  store.set("bluetooth", "gallery_mode", true)
95
95
  store.set("bluetooth", "voice_activity_detection_enabled", BluetoothSdkDefaults.voiceActivityDetectionEnabled)
96
96
  store.set("bluetooth", "loudness_gate_enabled", BluetoothSdkDefaults.loudnessGateEnabled)
97
+ store.set("bluetooth", "auto_power_off_enabled", BluetoothSdkDefaults.autoPowerOffEnabled)
97
98
  // Mentra Nex feature flag (off by default; toggled from Nex Developer Settings):
98
99
  store.set("bluetooth", "nex_chinese_captions", false)
99
100
  store.set("bluetooth", "screen_disabled", false)
@@ -191,14 +192,25 @@ class DeviceStore {
191
192
 
192
193
  // BLUETOOTH:
193
194
 
195
+ case ("bluetooth", "contextual_dashboard"):
196
+ if value is Bool {
197
+ Task { @MainActor in
198
+ if self.store.get("glasses", "headUp") as? Bool == true {
199
+ DeviceManager.shared.sendCurrentState()
200
+ }
201
+ }
202
+ }
203
+
194
204
  case ("bluetooth", "brightness"):
195
205
  let b = value as? Int ?? 50
196
206
  let auto = store.get("bluetooth", "auto_brightness") as? Bool ?? true
197
207
  Task {
198
- DeviceManager.shared.sgc?.setBrightness(b, autoMode: auto)
199
- await DeviceManager.shared.sgc?.sendTextWall("Set brightness to \(b)%")
208
+ guard let device = DeviceManager.shared.sgc else { return }
209
+ device.setBrightness(b, autoMode: auto)
210
+ guard device.showBrightnessConfirmation else { return }
211
+ await device.sendTextWall("Set brightness to \(b)%")
200
212
  try? await Task.sleep(nanoseconds: 800_000_000) // 0.8 seconds
201
- DeviceManager.shared.sgc?.clearDisplay()
213
+ if (DeviceManager.shared.sgc as AnyObject?) === (device as AnyObject) { device.clearDisplay() }
202
214
  }
203
215
 
204
216
  case ("bluetooth", "auto_brightness"):
@@ -206,13 +218,14 @@ class DeviceStore {
206
218
  let auto = value as? Bool ?? true
207
219
  let autoBrightnessChanged = (oldValue as? Bool) != auto
208
220
  Task {
209
- DeviceManager.shared.sgc?.setBrightness(b, autoMode: auto)
210
- if autoBrightnessChanged {
211
- await DeviceManager.shared.sgc?.sendTextWall(
221
+ guard let device = DeviceManager.shared.sgc else { return }
222
+ device.setBrightness(b, autoMode: auto)
223
+ if autoBrightnessChanged, device.showBrightnessConfirmation {
224
+ await device.sendTextWall(
212
225
  auto ? "Enabled auto brightness" : "Disabled auto brightness"
213
226
  )
214
227
  try? await Task.sleep(nanoseconds: 800_000_000) // 0.8 seconds
215
- DeviceManager.shared.sgc?.clearDisplay()
228
+ if (DeviceManager.shared.sgc as AnyObject?) === (device as AnyObject) { device.clearDisplay() }
216
229
  }
217
230
  }
218
231
 
@@ -254,6 +267,12 @@ class DeviceStore {
254
267
  case ("bluetooth", "loudness_gate_enabled"):
255
268
  DeviceManager.shared.sgc?.sendLoudnessGateSetting()
256
269
 
270
+ case ("bluetooth", "auto_power_off_enabled"):
271
+ Bridge.log(
272
+ "DeviceStore: auto_power_off_enabled changed to \(String(describing: value)) — sending cs_swit type 11"
273
+ )
274
+ DeviceManager.shared.sgc?.sendAutoPowerOffSetting()
275
+
257
276
  // Deliberately has no seeded default: the key starts absent so that a
258
277
  // session where the engine has not authorized tuning can only ever
259
278
  // send a reset.
@@ -2,8 +2,9 @@ import Foundation
2
2
 
3
3
  /// Generated from /changelogs. Do not edit directly.
4
4
  let generatedReleaseChangelogs: [ReleaseChangelog] = [
5
- ReleaseChangelog(version: "3.2.1", markdown: "This release is under active development. User-facing changes will be documented as they land."),
6
- ReleaseChangelog(version: "3.2.0", markdown: "This release is under active development. User-facing changes will be documented as they land.\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`."),
5
+ 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."),
6
+ 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."),
7
+ 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`."),
7
8
  ReleaseChangelog(version: "3.1.1", markdown: "- Improved Google login on iOS.\n- Pairing no longer requires phone microphone access."),
8
9
  ReleaseChangelog(version: "3.1.0", markdown: "**Mentra App and glasses**\n\n- Improved glasses pairing and reconnection, including on iPad.\n- Improved Android background reliability for captions and miniapps.\n- Added Xingyi AR99 support.\n- More reliable photo and video capture, with improved shutter sounds and privacy-light timing. Taking photos no longer interrupts your running miniapp.\n- Added video thumbnails and smoother gallery browsing.\n- Easier Mentra Live updates through your phone, with clearer progress and better recovery from interruptions.\n\n**Miniapp updates**\n\n- **Mentra AI:** Control whether photos are included with questions. Improved visual answers and connected-app follow-ups.\n- **Captions:** Added offline transcription settings and top/bottom positioning on supported displays.\n- **Translation:** Restored all 60 languages.\n- **Mentra Maps:** Clearer directions on G1/G2, less display flickering, and improved Android offline routing.\n- **Livestreamer:** More video-quality controls and custom streaming options, plus improved startup and sharing.\n- **Merge:** Tap to expand an insight; swipe down or back to dismiss it.\n- **Mentra Notes:** Smoother back navigation.\n- **Recorder:** Fixed audio sharing."),
9
10
  ]
@@ -2,10 +2,10 @@ import Foundation
2
2
 
3
3
  /// Generated by release CI. Do not edit in a release checkout.
4
4
  enum GeneratedReleaseMetadata {
5
- static let familyBaseVersion = "3.2.1"
6
- static let releaseIdentity = "3.2.1-dev.314"
7
- static let releaseSetId = "mentra-3.2.1-dev.314"
8
- static let sourceCommit = "00ab17c37df5902fbdb1a5824a41288b6850acc5"
9
- static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.2.1/mentra-live-ota-3.2.1-dev.314.json"
10
- static let otaManifestSha256 = "1062c560fcced026e5b43245e84cdd5febfd603f3ad19fbebef8fac455ba21d6"
5
+ static let familyBaseVersion = "3.3.0"
6
+ static let releaseIdentity = "3.3.0-beta.1000"
7
+ static let releaseSetId = "mentra-3.3.0-beta.1000"
8
+ static let sourceCommit = "422e5a0839ce00b23c423af481845e9ea66c4253"
9
+ static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.3.0/mentra-live-ota-3.3.0-beta.1000.json"
10
+ static let otaManifestSha256 = "5be623fd0627084dc3b2ffe54c58b3a44940b91f66860980995ac99c4d6f36dc"
11
11
  }