@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
@@ -0,0 +1,339 @@
1
+ package com.mentra.bluetoothsdk.sgcs
2
+
3
+ import org.junit.Assert.*
4
+ import org.junit.Test
5
+
6
+ class NimoCanvasSessionTest {
7
+ private val frameA = byteArrayOf(0, 0, 1)
8
+ private val frameB = byteArrayOf(1, 0, 1, 1)
9
+ private val frameC = byteArrayOf(2, 0, 1, 2)
10
+ private fun send(actions: List<NimoCanvasSession.Action>): NimoCanvasSession.Action.Send =
11
+ actions.single() as NimoCanvasSession.Action.Send
12
+ private fun success(session: NimoCanvasSession, key: Int) = session.response(key,
13
+ if (key == 4) byteArrayOf(0, 0xFD.toByte(), 0, 0, 0) else byteArrayOf(0, 0xFD.toByte()))
14
+ private fun launched(session: NimoCanvasSession): NimoCanvasSession.Action.Send {
15
+ assertTrue(session.offer(frameA, "one:1").isEmpty())
16
+ assertEquals(1, send(session.readiness(true)).key)
17
+ return send(success(session, 1))
18
+ }
19
+
20
+ @Test fun launchAckPrecedesUpdateAndLatestOfferWins() {
21
+ val session = NimoCanvasSession()
22
+ session.readiness(true)
23
+ assertEquals(1, send(session.offer(frameA, "one:1")).key)
24
+ assertTrue(session.offer(frameB, "one:1").isEmpty())
25
+ assertTrue(session.offer(frameC, "one:1").isEmpty())
26
+ val update = send(success(session, 1))
27
+ assertEquals(4, update.key)
28
+ assertArrayEquals(frameC, update.frame)
29
+ }
30
+
31
+ @Test fun inflightUpdatesCoalesceAndDedupUsesActualBytes() {
32
+ val session = NimoCanvasSession()
33
+ launched(session)
34
+ session.offer(frameB, "one:1")
35
+ session.offer(frameC, "one:1")
36
+ assertArrayEquals(frameC, send(success(session, 4)).frame)
37
+ assertTrue(success(session, 4).isEmpty())
38
+ assertTrue(session.offer(frameC.copyOf(), "one:1").isEmpty())
39
+ assertArrayEquals(frameB, send(session.offer(frameB, "one:1")).frame)
40
+ }
41
+
42
+ @Test fun dedupDoesNotOverrideReversionWhileUpdateIsInFlight() {
43
+ val session = NimoCanvasSession()
44
+ launched(session); success(session, 4)
45
+ session.offer(frameB, "one:1")
46
+ session.offer(frameA, "one:1")
47
+ assertArrayEquals(frameA, send(success(session, 4)).frame)
48
+ }
49
+
50
+ @Test fun replayEpochAndReconnectForceAcceptedFrameAgain() {
51
+ val session = NimoCanvasSession()
52
+ launched(session); success(session, 4)
53
+ assertEquals(4, send(session.offer(frameA, "one:1", force = true)).key)
54
+ success(session, 4)
55
+ assertEquals(4, send(session.offer(frameA, "one:2")).key)
56
+ success(session, 4)
57
+ session.disconnected()
58
+ assertEquals(1, send(session.readiness(true)).key)
59
+ assertEquals(4, send(success(session, 1)).key)
60
+ }
61
+
62
+ @Test fun malformedSuccessAndWrongCommandCannotAcknowledgeLaunch() {
63
+ val session = NimoCanvasSession()
64
+ session.offer(frameA, "one:1"); val launch = send(session.readiness(true))
65
+ assertTrue(session.response(1, byteArrayOf(0)).isEmpty())
66
+ assertTrue(session.response(1, byteArrayOf(0, 0x04)).isEmpty())
67
+ assertTrue(session.response(4, byteArrayOf(0, 0xFD.toByte(), 0, 0, 0)).isEmpty())
68
+ assertTrue(session.timeout(launch.ticket).single() is NimoCanvasSession.Action.Reconnect)
69
+ }
70
+
71
+ @Test fun timeoutRequiresFreshTransportBeforeLateAckCanDoAnything() {
72
+ val session = NimoCanvasSession()
73
+ val update = launched(session)
74
+ assertTrue(session.timeout(update.ticket).single() is NimoCanvasSession.Action.Reconnect)
75
+ assertTrue(success(session, 4).isEmpty())
76
+ assertTrue(session.offer(frameB, "one:1").isEmpty())
77
+ session.disconnected()
78
+ assertEquals(1, send(session.readiness(true)).key)
79
+ assertTrue(session.timeout(update.ticket).isEmpty())
80
+ assertArrayEquals(frameB, send(success(session, 1)).frame)
81
+ }
82
+
83
+ @Test fun unsupportedAndInvalidDoNotRetryUnchangedFrame() {
84
+ for (status in listOf(1, 5, 6)) {
85
+ val session = NimoCanvasSession()
86
+ launched(session)
87
+ assertTrue(session.response(4, byteArrayOf(status.toByte())).single() is NimoCanvasSession.Action.Rejected)
88
+ assertTrue(session.offer(frameA, "one:1").isEmpty())
89
+ assertTrue(session.offer(frameA, "one:2", force = true).isEmpty())
90
+ assertArrayEquals(frameB, send(session.offer(frameB, "one:1")).frame)
91
+ }
92
+ }
93
+
94
+ @Test fun failedLaunchDoesNotRetryIdenticalLaunchForChangingCaptions() {
95
+ for (status in listOf(1, 5, 6)) {
96
+ val session = NimoCanvasSession()
97
+ session.offer(frameA, "one:1"); session.readiness(true)
98
+ assertTrue(session.response(1, byteArrayOf(status.toByte())).single() is NimoCanvasSession.Action.Rejected)
99
+ assertTrue(session.offer(frameB, "one:1").isEmpty())
100
+ assertTrue(session.offer(frameC, "one:2", true).isEmpty())
101
+ session.disconnected()
102
+ assertEquals(1, send(session.readiness(true)).key)
103
+ }
104
+ }
105
+
106
+ @Test fun readinessErrorWaitsForExplicitReadySignal() {
107
+ val session = NimoCanvasSession()
108
+ launched(session)
109
+ assertTrue(session.response(4, byteArrayOf(7)).single() is NimoCanvasSession.Action.Rejected)
110
+ assertTrue(session.offer(frameB, "one:1").isEmpty())
111
+ assertTrue(session.readiness(true).isEmpty())
112
+ assertTrue(session.readiness(false).isEmpty())
113
+ assertEquals(1, send(session.readiness(true)).key)
114
+ assertArrayEquals(frameB, send(success(session, 1)).frame)
115
+ }
116
+
117
+ @Test fun freshConfirmedReadinessReleasesNotReadyWithoutFalseEdge() {
118
+ for (key in listOf(1, 4)) {
119
+ val session = NimoCanvasSession()
120
+ session.offer(frameA, "one:1"); session.readiness(true)
121
+ if (key == 4) success(session, 1)
122
+ assertTrue(session.response(key, byteArrayOf(7)).single() is NimoCanvasSession.Action.Rejected)
123
+ assertTrue(session.offer(frameB, "one:1").isEmpty())
124
+ assertTrue("cached true must not release status 7", session.readiness(true).isEmpty())
125
+ assertEquals(1, send(session.confirmedReadiness(true)).key)
126
+ assertArrayEquals(frameB, send(success(session, 1)).frame)
127
+ }
128
+ }
129
+
130
+ @Test fun confirmedNotReadyStaysBlockedUntilConfirmedReady() {
131
+ val session = NimoCanvasSession()
132
+ launched(session)
133
+ session.response(4, byteArrayOf(7))
134
+ assertTrue(session.confirmedReadiness(false).isEmpty())
135
+ assertTrue(session.offer(frameB, "one:1").isEmpty())
136
+ assertEquals(1, send(session.confirmedReadiness(true)).key)
137
+ assertArrayEquals(frameB, send(success(session, 1)).frame)
138
+ }
139
+
140
+ @Test fun repeatedReadyButRejectedLaunchHasBoundedRecovery() {
141
+ val session = NimoCanvasSession()
142
+ session.offer(frameA, "one:1"); session.readiness(true)
143
+ repeat(3) {
144
+ session.response(1, byteArrayOf(7))
145
+ assertEquals(1, send(session.confirmedReadiness(true)).key)
146
+ assertTrue("duplicate heartbeat cannot overlap Launch", session.confirmedReadiness(true).isEmpty())
147
+ }
148
+ session.response(1, byteArrayOf(7))
149
+ repeat(5) { assertTrue("ready-only recovery must stop after three retries", session.confirmedReadiness(true).isEmpty()) }
150
+ session.offer(frameB, "one:2", true)
151
+ assertTrue(session.confirmedReadiness(true).isEmpty())
152
+ session.readiness(false)
153
+ assertEquals(1, send(session.confirmedReadiness(true)).key)
154
+ assertArrayEquals(frameB, send(success(session, 1)).frame)
155
+ success(session, 4)
156
+ session.offer(frameC, "one:2")
157
+ session.response(4, byteArrayOf(7))
158
+ assertEquals(1, send(session.confirmedReadiness(true)).key)
159
+ }
160
+
161
+ @Test fun confirmedReadyDoesNotUnlockRejectedLaunchOrDeviceLock() {
162
+ for (status in listOf(1, 5, 6, 8)) {
163
+ val session = NimoCanvasSession()
164
+ session.offer(frameA, "one:1"); session.readiness(true)
165
+ session.response(1, byteArrayOf(status.toByte()))
166
+ assertTrue(session.offer(frameB, "one:2", true).isEmpty())
167
+ assertTrue(session.confirmedReadiness(false).isEmpty())
168
+ assertTrue(session.confirmedReadiness(true).isEmpty())
169
+ }
170
+ }
171
+
172
+ @Test fun deviceLockedStopsAllCanvasUntilNewTransport() {
173
+ val session = NimoCanvasSession()
174
+ launched(session)
175
+ session.response(4, byteArrayOf(8))
176
+ assertTrue(session.readiness(true).isEmpty())
177
+ assertTrue(session.confirmedReadiness(true).isEmpty())
178
+ assertTrue(session.offer(frameB, "one:2", true).isEmpty())
179
+ session.disconnected()
180
+ assertEquals(1, send(session.readiness(true)).key)
181
+ }
182
+
183
+ @Test fun statusTwoResetsTransportInsteadOfBlindRetry() {
184
+ val session = NimoCanvasSession()
185
+ launched(session)
186
+ val actions = session.response(4, byteArrayOf(2))
187
+ assertEquals(2, actions.size)
188
+ assertTrue(actions.last() is NimoCanvasSession.Action.Reconnect)
189
+ assertTrue(session.offer(frameB, "one:1").isEmpty())
190
+ }
191
+
192
+ @Test fun explicitExitWaitsForCurrentCommandAndDoesNotReplayOldFrame() {
193
+ val session = NimoCanvasSession()
194
+ launched(session)
195
+ assertTrue(session.exit().isEmpty())
196
+ assertEquals(3, send(success(session, 4)).key)
197
+ assertTrue(session.nativeApp(0xFD, false).isEmpty())
198
+ assertTrue(success(session, 3).isEmpty())
199
+ session.disconnected()
200
+ assertTrue(session.readiness(true).isEmpty())
201
+ }
202
+
203
+ @Test fun newSceneDuringExitLaunchesOnlyAfterExitAck() {
204
+ val session = NimoCanvasSession()
205
+ launched(session); success(session, 4)
206
+ assertEquals(3, send(session.exit()).key)
207
+ assertTrue(session.offer(frameB, "two:1").isEmpty())
208
+ assertTrue(session.nativeApp(0xFD, false).isEmpty())
209
+ assertEquals(1, send(success(session, 3)).key)
210
+ assertArrayEquals(frameB, send(success(session, 1)).frame)
211
+ }
212
+
213
+ @Test fun nativeReportDuringExitPreservesNewerHostScene() {
214
+ val session = NimoCanvasSession()
215
+ launched(session); success(session, 4)
216
+ assertEquals(3, send(session.exit()).key)
217
+ session.offer(frameB, "two:1")
218
+ assertTrue(session.nativeApp(0, true).isEmpty())
219
+ assertEquals(1, send(success(session, 3)).key)
220
+ assertArrayEquals(frameB, send(success(session, 1)).frame)
221
+ }
222
+
223
+ @Test fun nativeTakeoverRestoresLatestSceneWithoutAnotherHostOffer() {
224
+ for (app in listOf(0, 0xFD)) {
225
+ val session = NimoCanvasSession()
226
+ launched(session); success(session, 4)
227
+ assertEquals(1, send(session.nativeApp(app, app != 0xFD)).key)
228
+ assertArrayEquals(frameA, send(success(session, 1)).frame)
229
+ }
230
+ }
231
+
232
+ @Test fun nativeTakeoverWaitsForCurrentAckInsteadOfOverlappingCommands() {
233
+ val session = NimoCanvasSession(); launched(session)
234
+ assertTrue(session.nativeApp(0, true).isEmpty())
235
+ session.offer(frameB, "one:1")
236
+ assertEquals(1, send(success(session, 4)).key)
237
+ assertTrue(session.nativeApp(0, true).isEmpty()) // Startup report during Launch.
238
+ assertArrayEquals(frameB, send(success(session, 1)).frame)
239
+ }
240
+
241
+ @Test fun takeoverDuringUpdateReplaysIdenticalFrameAfterRelaunch() {
242
+ val session = NimoCanvasSession(); launched(session)
243
+ assertTrue(session.nativeApp(0, true).isEmpty())
244
+ // The old Update ACK must not deduplicate the same scene on a new canvas.
245
+ assertEquals(1, send(success(session, 4)).key)
246
+ assertArrayEquals(frameA, send(success(session, 1)).frame)
247
+ assertTrue(success(session, 4).isEmpty())
248
+ assertTrue(session.offer(frameA, "one:1").isEmpty())
249
+ }
250
+
251
+ @Test fun startupStockUiDoesNotDiscardRetainedSceneBeforeReadiness() {
252
+ val session = NimoCanvasSession(); launched(session); success(session, 4)
253
+ session.disconnected()
254
+ assertTrue(session.nativeApp(0, true).isEmpty())
255
+ session.activate()
256
+ assertEquals(1, send(session.readiness(true)).key)
257
+ assertArrayEquals(frameA, send(success(session, 1)).frame)
258
+ }
259
+
260
+ @Test fun explicitExitStillReturnsControlToStockUiUntilNextConnection() {
261
+ val session = NimoCanvasSession(); launched(session); success(session, 4)
262
+ assertEquals(3, send(session.exit()).key)
263
+ assertTrue(session.nativeApp(0, true).isEmpty())
264
+ assertTrue(success(session, 3).isEmpty())
265
+ assertTrue(session.nativeApp(0, true).isEmpty())
266
+ session.disconnected(); session.activate()
267
+ assertEquals(1, send(session.readiness(true)).key)
268
+ assertArrayEquals(byteArrayOf(0, 0, 1), send(success(session, 1)).frame)
269
+ }
270
+
271
+ @Test fun activationLaunchesBlankCanvasWithoutAnyMiniapp() {
272
+ val session = NimoCanvasSession()
273
+ assertTrue(session.activate().isEmpty())
274
+ assertEquals(1, send(session.readiness(true)).key)
275
+ assertArrayEquals(byteArrayOf(0, 0, 1), send(success(session, 1)).frame)
276
+ }
277
+
278
+ @Test fun successfulUpdateRestoresProbeBudgetForNextRecovery() {
279
+ val session = NimoCanvasSession(); session.activate(); session.readiness(true)
280
+ repeat(2) { episode ->
281
+ if (episode > 0) assertEquals(1, send(session.nativeApp(0, true)).key)
282
+ repeat(3) {
283
+ session.response(1, byteArrayOf(7))
284
+ assertEquals(1, send(session.retryNotReady()).key)
285
+ }
286
+ assertEquals(4, send(success(session, 1)).key)
287
+ assertTrue(success(session, 4).isEmpty())
288
+ }
289
+ }
290
+
291
+ @Test fun notReadyProbesAreBoundedAndFreshHeartbeatStillRecovers() {
292
+ val session = NimoCanvasSession(); session.activate(); session.readiness(true)
293
+ repeat(3) {
294
+ session.response(1, byteArrayOf(7))
295
+ assertEquals(1, send(session.retryNotReady()).key)
296
+ }
297
+ session.response(1, byteArrayOf(7))
298
+ repeat(5) { assertTrue(session.retryNotReady().isEmpty()) }
299
+ assertEquals(1, send(session.confirmedReadiness(true)).key)
300
+ assertEquals(4, send(success(session, 1)).key)
301
+ }
302
+
303
+ @Test fun lostReadinessDuringCommandStillResets() {
304
+ val session = NimoCanvasSession(); launched(session)
305
+ assertTrue(session.readiness(false).single() is NimoCanvasSession.Action.Reconnect)
306
+ assertTrue(session.retryNotReady().isEmpty())
307
+ }
308
+
309
+ @Test fun offersCopyMutableInputAndRejectOversizedFrame() {
310
+ val session = NimoCanvasSession()
311
+ val input = frameA.copyOf(); session.offer(input, "one:1"); input[0] = 99
312
+ session.readiness(true)
313
+ assertArrayEquals(frameA, send(success(session, 1)).frame)
314
+ assertThrows(IllegalArgumentException::class.java) { session.offer(ByteArray(12281), "one:1") }
315
+ }
316
+
317
+ @Test fun diagnosticHoldRetainsOnlyLatestSceneUntilReleased() {
318
+ val session = NimoCanvasSession()
319
+ launched(session); success(session, 4)
320
+
321
+ assertTrue(session.hold(true).isEmpty())
322
+ assertTrue(session.offer(frameB, "two:1").isEmpty())
323
+ assertTrue(session.offer(frameC, "two:2", force = true).isEmpty())
324
+
325
+ val update = send(session.hold(false))
326
+ assertEquals(4, update.key)
327
+ assertArrayEquals(frameC, update.frame)
328
+ }
329
+
330
+ @Test fun preemptedHoldDoesNotFlushStaleSceneBeforeExit() {
331
+ val session = NimoCanvasSession()
332
+ launched(session); success(session, 4)
333
+ session.hold(true)
334
+ session.offer(frameB, "two:1")
335
+
336
+ assertTrue(session.hold(false, resume = false).isEmpty())
337
+ assertEquals(3, send(session.exit()).key)
338
+ }
339
+ }
@@ -0,0 +1,93 @@
1
+ package com.mentra.bluetoothsdk.sgcs
2
+
3
+ import android.bluetooth.BluetoothGattCharacteristic
4
+ import androidx.test.core.app.ApplicationProvider
5
+ import com.mentra.bluetoothsdk.Bridge
6
+ import com.mentra.bluetoothsdk.DeviceManager
7
+ import com.mentra.bluetoothsdk.DeviceStore
8
+ import org.junit.Assert.*
9
+ import org.junit.Test
10
+ import org.junit.runner.RunWith
11
+ import org.robolectric.RobolectricTestRunner
12
+ import org.robolectric.annotation.Config
13
+ import org.robolectric.annotation.LooperMode
14
+ import java.util.UUID
15
+
16
+ @RunWith(RobolectricTestRunner::class)
17
+ @Config(sdk = [33])
18
+ @LooperMode(LooperMode.Mode.PAUSED)
19
+ class NimoMicReconnectTest {
20
+ private val requests = listOf("should_send_lc3", "should_send_pcm", "should_send_transcript", "local_stt_fallback_active")
21
+
22
+ @Test fun sameAdapterReconnectRestartsTheStoppedAudioClientForRetainedConsumers() {
23
+ for (request in requests) withNimo { manager, device ->
24
+ DeviceStore.apply("bluetooth", request, true)
25
+ assertTrue(audioStarted(device))
26
+ repeat(3) {
27
+ resetLink(device)
28
+ assertFalse(audioStarted(device))
29
+ assertEquals(true, DeviceStore.get("bluetooth", request))
30
+ // This is the same adapter, not the replacement fake used by the manager tests.
31
+ DeviceStore.apply("glasses", "fullyBooted", true)
32
+ assertSame(device, manager.sgc)
33
+ assertTrue("Readiness must restart Nimo decoding without waiting for the watchdog", audioStarted(device))
34
+ }
35
+ }
36
+ }
37
+
38
+ @Test fun consumerStoppingDuringLinkLossDoesNotRestartAudio() = withNimo { _, device ->
39
+ DeviceStore.apply("bluetooth", "should_send_pcm", true)
40
+ assertTrue(audioStarted(device))
41
+ resetLink(device)
42
+ DeviceStore.apply("bluetooth", "should_send_pcm", false)
43
+ DeviceStore.apply("glasses", "fullyBooted", true)
44
+ assertFalse(audioStarted(device))
45
+ assertEquals(false, DeviceStore.get("glasses", "micEnabled"))
46
+ }
47
+
48
+ private fun resetLink(device: Nimo) {
49
+ // Exercise the production reset called by the GATT disconnect callback.
50
+ Nimo::class.java.getDeclaredMethod("resetSessionState").apply { isAccessible = true }.invoke(device)
51
+ DeviceStore.apply("glasses", "fullyBooted", false)
52
+ }
53
+
54
+ private fun audioStarted(device: Nimo): Boolean {
55
+ val audio = Nimo::class.java.getDeclaredField("audioClient").apply { isAccessible = true }.get(device)
56
+ return audio.javaClass.getDeclaredField("started").apply { isAccessible = true }.getBoolean(audio)
57
+ }
58
+
59
+ private fun withNimo(block: (DeviceManager, Nimo) -> Unit) {
60
+ Bridge.initialize(ApplicationProvider.getApplicationContext())
61
+ val singleton = DeviceManager::class.java.getDeclaredField("_instance").apply { isAccessible = true }
62
+ val previous = singleton.get(null)
63
+ val saved = listOf("bluetooth", "glasses").associateWith { DeviceStore.store.getCategory(it) }
64
+ val manager = DeviceManager(initializeHardware = false)
65
+ singleton.set(null, manager)
66
+ val device = Nimo()
67
+ manager.sgc = device
68
+ // No radio/firmware: supply the discovered mic characteristic and inspect the real
69
+ // audio-client lifecycle. Codec output and BLE delivery still require a device test.
70
+ Nimo::class.java.getDeclaredField("micChar").apply { isAccessible = true }.set(
71
+ device, BluetoothGattCharacteristic(UUID.randomUUID(), BluetoothGattCharacteristic.PROPERTY_WRITE, 0)
72
+ )
73
+ requests.forEach { DeviceStore.set("bluetooth", it, false) }
74
+ DeviceStore.set("bluetooth", "micEnabled", false)
75
+ DeviceStore.set("bluetooth", "micRanking", listOf("glasses"))
76
+ DeviceStore.set("glasses", "micEnabled", false)
77
+ DeviceStore.set("glasses", "fullyBooted", false)
78
+ try {
79
+ block(manager, device)
80
+ } finally {
81
+ device.cleanup()
82
+ manager.sgc = null
83
+ manager.cleanup()
84
+ singleton.set(null, previous)
85
+ saved.forEach { (category, values) ->
86
+ DeviceStore.store.getCategory(category).keys.filter { it !in values }.forEach {
87
+ DeviceStore.store.remove(category, it)
88
+ }
89
+ values.forEach { (key, value) -> DeviceStore.set(category, key, value) }
90
+ }
91
+ }
92
+ }
93
+ }
@@ -19,6 +19,17 @@ class NimoCrc16Test {
19
19
  }
20
20
 
21
21
  class NimoFrameCodecTest {
22
+ @Test
23
+ fun `system English and factory reset match firmware wire commands`() {
24
+ fun hex(bytes: ByteArray) = bytes.joinToString("") { "%02X".format(it.toInt() and 255) }
25
+ assertThat(hex(NimoFrameCodec.encodeFrame(NimoProtocol.CMD_SET_PARAMETER,
26
+ NimoProtocol.SET_SYSTEM_LANGUAGE, byteArrayOf(NimoProtocol.LANGUAGE_ENGLISH.toByte()))))
27
+ .isEqualTo("BF020500702500000324010001")
28
+ assertThat(hex(NimoFrameCodec.encodeFrame(NimoProtocol.CMD_CONTROL_FACTORY,
29
+ NimoProtocol.FACTORY_RECOVER, byteArrayOf())))
30
+ .isEqualTo("BF0204005358000008030000")
31
+ }
32
+
22
33
 
23
34
  @Test
24
35
  fun `transport header layout`() {
@@ -0,0 +1,27 @@
1
+ package com.mentra.bluetoothsdk.sgcs
2
+
3
+ import org.junit.Assert.assertEquals
4
+ import org.junit.Assert.assertNull
5
+ import org.junit.Test
6
+
7
+ class SelectedDeviceAddressTest {
8
+ @Test fun `selected pending address wins over saved address`() {
9
+ assertEquals("new", SelectedDeviceAddress.resolve("LIVE_2", "LIVE_2", "new", "LIVE_1", "old"))
10
+ }
11
+
12
+ @Test fun `a name-only selection cannot use another device's saved address`() {
13
+ assertNull(SelectedDeviceAddress.resolve("LIVE_2", "LIVE_2", "", "LIVE_1", "old"))
14
+ assertNull(SelectedDeviceAddress.resolve("Nex1-2", "Nex1-2", null, "Nex1-1", "old"))
15
+ assertNull(SelectedDeviceAddress.resolve("Nex1-2", null, null, "Simulated Glasses", ""))
16
+ }
17
+
18
+ @Test fun `saved reconnect keeps its address even with an unrelated pending selection`() {
19
+ assertEquals("old", SelectedDeviceAddress.resolve("LIVE_1", "LIVE_2", "new", "LIVE_1", "old"))
20
+ assertEquals("old", SelectedDeviceAddress.resolve("Nex1-1", null, null, "Nex1-1", "old"))
21
+ }
22
+
23
+ @Test fun `empty or mismatched identities never supply an address`() {
24
+ assertNull(SelectedDeviceAddress.resolve("", "", "new", "", "old"))
25
+ assertNull(SelectedDeviceAddress.resolve("LIVE_2", "LIVE_1", "new", "LIVE_1", "old"))
26
+ }
27
+ }