@mentra/bluetooth-sdk 3.4.0-dev.998 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION.md +16 -7
- package/README.md +40 -13
- package/android/build.gradle +60 -51
- package/android/gradle.properties +3 -0
- package/android/settings.gradle +47 -3
- package/android/src/main/assets/nimo/nimo-firmware-0.1.1.1-537cf1.bin +0 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BesCrashReportWaiters.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +5 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +77 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +41 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +114 -122
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +31 -10
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt +57 -196
- package/android/src/main/java/com/mentra/bluetoothsdk/OtaManifest.kt +1 -16
- package/android/src/main/java/com/mentra/bluetoothsdk/debug/BleTraceLogger.kt +10 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/Ipv4Prefix.kt +51 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/NetworkFacts.kt +81 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkError.kt +108 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkReadiness.kt +103 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkRequestSpec.kt +44 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkState.kt +117 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedSoftApNetwork.kt +598 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/SoftApTrace.kt +143 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/otaserver/MentraOtaServerModule.kt +0 -7
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTracker.kt +15 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +274 -56
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +5 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +210 -325
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +0 -35
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +2 -10
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareUpdater.kt +213 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoOtaProtocol.kt +112 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/streaming/StreamModels.kt +17 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueue.kt +92 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHost.kt +169 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +74 -115
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +348 -357
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetector.kt +211 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngine.kt +137 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SttTextFormatter.kt +52 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/WakeWordDetector.kt +235 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AvifExifStripper.java +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +3 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +11 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/AudioRouteWatcher.kt +120 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +181 -16
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlayback.kt +177 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/BesCrashReportWaitersTest.kt +112 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/StreamRequestCaptureAudioTest.kt +23 -4
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/Ipv4PrefixTest.kt +59 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/NetworkFactsTest.kt +59 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedLocalNetworkPermissionTest.kt +35 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkErrorTest.kt +85 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkLifecycleTest.kt +164 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkReadinessTest.kt +141 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkRequestSpecTest.kt +56 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/SoftApTraceTest.kt +97 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/UnavailableRetryTest.kt +47 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTrackerTest.kt +26 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +141 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +183 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +3 -3
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveRgbLedResponseTest.kt +76 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +1 -56
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +0 -22
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareTargetTest.kt +15 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareUpdaterTest.kt +76 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoOtaProtocolTest.kt +77 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNamingTest.kt +23 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoReadinessDriverTest.kt +31 -1
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueueTest.kt +81 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHostTest.kt +216 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/STTToolsExtractionTest.kt +108 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetectorTest.kt +126 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngineTest.kt +245 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SttTextFormatterTest.kt +67 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlaybackTest.kt +76 -0
- package/build/BluetoothSdk.types.d.ts +103 -5
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +42 -8
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +1 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/_private/MentraLocalNetworkModule.d.ts +1 -1
- package/build/_private/MentraLocalNetworkModule.d.ts.map +1 -1
- package/build/_private/MentraLocalNetworkModule.js.map +1 -1
- package/build/generated/changelogCatalog.d.ts +2 -2
- package/build/generated/changelogCatalog.js +2 -2
- package/build/generated/changelogCatalog.js.map +1 -1
- package/build/generated/releaseMetadata.js +5 -5
- package/build/generated/releaseMetadata.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -1
- package/build/index.js.map +1 -1
- package/build/ota-server/MentraOtaServerModule.d.ts +0 -2
- package/build/ota-server/MentraOtaServerModule.d.ts.map +1 -1
- package/build/ota-server/MentraOtaServerModule.js.map +1 -1
- package/build/ota-server/MentraOtaServerModule.web.d.ts +0 -1
- package/build/ota-server/MentraOtaServerModule.web.d.ts.map +1 -1
- package/build/ota-server/MentraOtaServerModule.web.js +0 -3
- package/build/ota-server/MentraOtaServerModule.web.js.map +1 -1
- package/build/ota-transport/index.d.ts +3 -3
- package/build/ota-transport/index.d.ts.map +1 -1
- package/build/ota-transport/index.js +4 -4
- package/build/ota-transport/index.js.map +1 -1
- package/build/react/useGlassesConnection.d.ts +1 -1
- package/build/react/useGlassesConnection.d.ts.map +1 -1
- package/build/react/useGlassesConnection.js +3 -3
- package/build/react/useGlassesConnection.js.map +1 -1
- package/build/react/useMentraBluetooth.d.ts +1 -1
- package/build/react/useMentraBluetooth.d.ts.map +1 -1
- package/build/react/useMentraBluetooth.js +1 -1
- package/build/react/useMentraBluetooth.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +73 -22
- package/ios/LocalIPv4.swift +0 -61
- package/ios/MentraBluetoothSDK.podspec +7 -1
- package/ios/MentraOtaServerModule.swift +0 -16
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
- package/ios/Resources/NimoFirmware/nimo-firmware-0.1.1.1-537cf1.bin +0 -0
- package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
- package/ios/Source/BesCrashReportWaiters.swift +64 -0
- package/ios/Source/BluetoothSdkDefaults.swift +4 -4
- package/ios/Source/Bridge.swift +14 -0
- package/ios/Source/DeviceManager.swift +43 -22
- package/ios/Source/GeneratedChangelogCatalog.swift +2 -2
- package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
- package/ios/Source/MentraBluetoothSDK.swift +35 -16
- package/ios/Source/OtaManifest.swift +1 -17
- package/ios/Source/audio/PcmStreamPlayer.swift +290 -57
- package/ios/Source/audio/PcmUrlPlayback.swift +231 -0
- package/ios/Source/audio/SpeechActivity.swift +277 -0
- package/ios/Source/events/BluetoothEvents.swift +41 -0
- package/ios/Source/internal/BleTraceLogger.swift +14 -1
- package/ios/Source/internal/BluetoothAvailability.swift +15 -5
- package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +5 -0
- package/ios/Source/sgcs/MentraLive.swift +195 -66
- package/ios/Source/sgcs/Nimo.swift +249 -276
- package/ios/Source/sgcs/NimoCanvasCoordinator.swift +9 -38
- package/ios/Source/sgcs/NimoCanvasSession.swift +0 -1
- package/ios/Source/sgcs/NimoFirmwareUpdater.swift +260 -0
- package/ios/Source/sgcs/NimoOtaProtocol.swift +159 -0
- package/ios/Source/sgcs/SGCManager.swift +6 -0
- package/ios/Source/streaming/StreamModels.swift +15 -6
- package/ios/Source/stt/STTTools.swift +13 -31
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +204 -162
- package/ios/Source/stt/SileroSpeechActivity.swift +87 -0
- package/ios/Source/stt/WakeWordDetector.swift +145 -0
- package/ios/Source/utils/BoundedWait.swift +44 -0
- package/ios/Source/utils/DemandDrivenAudioWorker.swift +79 -0
- package/ios/Source/utils/SttModelTraits.swift +62 -0
- package/ios/Tests/BesCrashReportTests.swift +142 -0
- package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
- package/ios/Tests/DeviceManagerReconnectTests.swift +0 -71
- package/ios/Tests/GlassesAudioSetupPolicyTests.swift +9 -3
- package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
- package/ios/Tests/MentraLiveAudioSetupTests.swift +6 -12
- package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
- package/ios/Tests/MentraLiveSessionReadinessTests.swift +179 -10
- package/ios/Tests/NimoCanvasTransportTests.swift +0 -89
- package/ios/Tests/NimoOtaProtocolTests.swift +78 -0
- package/ios/Tests/PcmStreamTests.swift +299 -0
- package/ios/Tests/SpeechActivityTests.swift +238 -0
- package/ios/Tests/StreamRequestTests.swift +18 -0
- package/ios/Tests/SttModelTraitsTests.swift +62 -0
- package/package.json +2 -2
- package/plugin/build/withAndroid.js +9 -11
- package/plugin/build/withKotlinVersion.d.ts +2 -0
- package/plugin/build/withKotlinVersion.js +46 -0
- package/src/BluetoothSdk.types.ts +107 -5
- package/src/_private/BluetoothSdkModule.ts +45 -8
- package/src/_private/MentraLocalNetworkModule.ts +5 -1
- package/src/generated/changelogCatalog.ts +2 -2
- package/src/generated/releaseMetadata.ts +5 -5
- package/src/index.ts +13 -1
- package/src/ota-server/MentraOtaServerModule.ts +0 -2
- package/src/ota-server/MentraOtaServerModule.web.ts +0 -4
- package/src/ota-transport/index.ts +4 -5
- package/src/react/useGlassesConnection.ts +4 -4
- package/src/react/useMentraBluetooth.ts +2 -2
- package/android/silero/LICENSE.md +0 -17
- package/android/silero/build.gradle +0 -50
- package/android/silero/proguard-rules.pro +0 -24
- package/android/silero/src/androidTest/assets/hello.wav +0 -0
- package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +0 -79
- package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +0 -160
- package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +0 -449
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +0 -15
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +0 -14
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +0 -12
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +0 -47
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +0 -41
- package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +0 -44
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -368
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +0 -156
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -274
- package/android/src/main/java/com/mentra/bluetoothsdk/ScopedNetworkReadiness.kt +0 -17
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +0 -229
- package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -20
- package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -16
- package/android/src/test/java/com/mentra/bluetoothsdk/ScopedNetworkReadinessTest.kt +0 -39
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +0 -287
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +0 -127
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +0 -851
- package/ios/Source/sgcs/NimoMacResourceTransport.swift +0 -217
- package/ios/Source/sgcs/NimoResourceFixture.swift +0 -384
- package/ios/Source/sgcs/NimoResourceSession.swift +0 -406
- package/ios/Tests/NimoResourceSessionTests.swift +0 -476
- /package/android/{silero/src/main/assets/LICENSE → src/main/assets/vad/LICENSE.silero_vad} +0 -0
- /package/android/{silero/src/main/assets → src/main/assets/vad}/silero_vad.onnx +0 -0
package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt
CHANGED
|
@@ -8,9 +8,14 @@ import androidx.test.core.app.ApplicationProvider
|
|
|
8
8
|
import com.mentra.bluetoothsdk.BluetoothSdkException
|
|
9
9
|
import com.mentra.bluetoothsdk.Bridge
|
|
10
10
|
import com.mentra.bluetoothsdk.DeviceStore
|
|
11
|
+
import com.mentra.bluetoothsdk.utils.IncidentLogBleRelayNaming
|
|
12
|
+
import java.net.ServerSocket
|
|
13
|
+
import java.net.SocketException
|
|
11
14
|
import java.nio.charset.StandardCharsets
|
|
12
15
|
import java.time.Duration
|
|
13
16
|
import java.util.UUID
|
|
17
|
+
import java.util.concurrent.LinkedBlockingQueue
|
|
18
|
+
import java.util.concurrent.TimeUnit
|
|
14
19
|
import java.util.concurrent.atomic.AtomicLong
|
|
15
20
|
import org.junit.Assert.*
|
|
16
21
|
import org.junit.Test
|
|
@@ -20,12 +25,14 @@ import org.robolectric.Shadows.shadowOf
|
|
|
20
25
|
import org.robolectric.annotation.Config
|
|
21
26
|
import org.robolectric.annotation.LooperMode
|
|
22
27
|
import org.robolectric.shadows.ShadowLog
|
|
28
|
+
import org.robolectric.shadows.ShadowSystemClock
|
|
23
29
|
|
|
24
30
|
@RunWith(RobolectricTestRunner::class)
|
|
25
31
|
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
26
32
|
@LooperMode(LooperMode.Mode.PAUSED)
|
|
27
33
|
class MentraLiveIncidentDispatchTest {
|
|
28
34
|
private val incident = "rep_01M4HBVT88DFSN8TYNZ1WTV4PB"
|
|
35
|
+
private val collidingIncident = "rep_01M4HBVT88DZZZZZZZZZZZZZZZ"
|
|
29
36
|
private val apiBase = "https://core.dev.us-west-2.mentraglass.com"
|
|
30
37
|
|
|
31
38
|
@Test fun `missing native BLE link rejects even when cached status is connected`() = withLive { live ->
|
|
@@ -45,6 +52,14 @@ class MentraLiveIncidentDispatchTest {
|
|
|
45
52
|
prefs.edit().remove("core_token").commit()
|
|
46
53
|
}
|
|
47
54
|
|
|
55
|
+
@Test fun `deletes the Core token older builds left in plain storage`() {
|
|
56
|
+
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
|
|
57
|
+
val prefs = context.getSharedPreferences("augmentos_auth_prefs", android.content.Context.MODE_PRIVATE)
|
|
58
|
+
prefs.edit().putString("core_token", "stale-synthetic-token").commit()
|
|
59
|
+
withLive { }
|
|
60
|
+
assertFalse(prefs.contains("core_token"))
|
|
61
|
+
}
|
|
62
|
+
|
|
48
63
|
@Test fun `current token is queued before upload and never logged`() = withLive { live ->
|
|
49
64
|
ready(live)
|
|
50
65
|
val token = "synthetic-${UUID.randomUUID()}"
|
|
@@ -87,6 +102,174 @@ class MentraLiveIncidentDispatchTest {
|
|
|
87
102
|
} finally { Bridge.removeEventSink(sink) }
|
|
88
103
|
}
|
|
89
104
|
|
|
105
|
+
@Test fun `colliding report waits for the owner's Cloud confirmation and never receives its evidence`() = withLive { live ->
|
|
106
|
+
ready(live)
|
|
107
|
+
DeviceStore.set("bluetooth", "core_token", "synthetic")
|
|
108
|
+
withCloud { cloud ->
|
|
109
|
+
val name = IncidentLogBleRelayNaming.bleFileBaseName(incident, 'B')
|
|
110
|
+
assertEquals(name, IncidentLogBleRelayNaming.bleFileBaseName(collidingIncident, 'B'))
|
|
111
|
+
|
|
112
|
+
live.sendIncidentId(incident, cloud.base)
|
|
113
|
+
expectCode("incident_relay_busy") { live.sendIncidentId(collidingIncident, cloud.base) }
|
|
114
|
+
assertFalse(wire(live).contains(collidingIncident))
|
|
115
|
+
assertEquals(incident, relayOwner(live, name))
|
|
116
|
+
assertEquals(incident, relayOwner(live, IncidentLogBleRelayNaming.bleFileBaseName(incident, 'L')))
|
|
117
|
+
|
|
118
|
+
receiveRelayFile(live, name, "owner-evidence")
|
|
119
|
+
assertEquals("/api/client/reports/$incident/artifacts owner-evidence", cloud.requests.poll(5, TimeUnit.SECONDS))
|
|
120
|
+
awaitMain { relayOwner(live, name) == null }
|
|
121
|
+
val confirmation = wire(live).substringAfterLast("transfer_complete")
|
|
122
|
+
assertTrue(confirmation.contains(name) && confirmation.contains("\"success\":true"))
|
|
123
|
+
|
|
124
|
+
// The owner's logcat name is still in flight, so the colliding report is still refused.
|
|
125
|
+
val logName = IncidentLogBleRelayNaming.bleFileBaseName(incident, 'L')
|
|
126
|
+
expectCode("incident_relay_busy") { live.sendIncidentId(collidingIncident, cloud.base) }
|
|
127
|
+
receiveRelayFile(live, logName, "owner-logcat")
|
|
128
|
+
assertEquals("/api/client/reports/$incident/artifacts owner-logcat", cloud.requests.poll(5, TimeUnit.SECONDS))
|
|
129
|
+
awaitMain { relayOwner(live, logName) == null }
|
|
130
|
+
|
|
131
|
+
live.sendIncidentId(collidingIncident, cloud.base)
|
|
132
|
+
receiveRelayFile(live, name, "second-evidence")
|
|
133
|
+
assertEquals(
|
|
134
|
+
"/api/client/reports/$collidingIncident/artifacts second-evidence",
|
|
135
|
+
cloud.requests.poll(5, TimeUnit.SECONDS),
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@Test fun `stale callback of a finished owner cannot confirm the colliding report's file`() = withLive { live ->
|
|
141
|
+
ready(live)
|
|
142
|
+
DeviceStore.set("bluetooth", "core_token", "synthetic")
|
|
143
|
+
withCloud { cloud ->
|
|
144
|
+
val name = IncidentLogBleRelayNaming.bleFileBaseName(incident, 'B')
|
|
145
|
+
val logName = IncidentLogBleRelayNaming.bleFileBaseName(incident, 'L')
|
|
146
|
+
live.sendIncidentId(incident, cloud.base)
|
|
147
|
+
val staleRelay = (get(live, "bleIncidentLogRelays") as Map<*, *>)[name]!!
|
|
148
|
+
receiveRelayFile(live, name, "owner")
|
|
149
|
+
assertNotNull(cloud.requests.poll(5, TimeUnit.SECONDS))
|
|
150
|
+
awaitMain { relayOwner(live, name) == null }
|
|
151
|
+
receiveRelayFile(live, logName, "owner-logcat")
|
|
152
|
+
assertNotNull(cloud.requests.poll(5, TimeUnit.SECONDS))
|
|
153
|
+
awaitMain { relayOwner(live, logName) == null }
|
|
154
|
+
|
|
155
|
+
live.sendIncidentId(collidingIncident, cloud.base)
|
|
156
|
+
val confirmationsBefore = wire(live).split("transfer_complete").size
|
|
157
|
+
|
|
158
|
+
// A late callback of the first report's request arrives while the colliding report owns the name.
|
|
159
|
+
uploadWith(live, staleRelay, name, "late-owner-evidence")
|
|
160
|
+
assertNotNull(cloud.requests.poll(5, TimeUnit.SECONDS))
|
|
161
|
+
repeat(50) { shadowOf(Looper.getMainLooper()).idle(); Thread.sleep(10) }
|
|
162
|
+
|
|
163
|
+
assertEquals(confirmationsBefore, wire(live).split("transfer_complete").size)
|
|
164
|
+
assertEquals(collidingIncident, relayOwner(live, name))
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@Test fun `failed Cloud POST keeps the owner until its ownership expires`() = withLive { live ->
|
|
169
|
+
ready(live)
|
|
170
|
+
DeviceStore.set("bluetooth", "core_token", "synthetic")
|
|
171
|
+
withCloud { cloud ->
|
|
172
|
+
cloud.status = 500
|
|
173
|
+
val name = IncidentLogBleRelayNaming.bleFileBaseName(incident, 'B')
|
|
174
|
+
live.sendIncidentId(incident, cloud.base)
|
|
175
|
+
receiveRelayFile(live, name, "owner-evidence")
|
|
176
|
+
assertNotNull(cloud.requests.poll(5, TimeUnit.SECONDS))
|
|
177
|
+
awaitMain { wire(live).contains("\"success\":false") }
|
|
178
|
+
assertEquals(incident, relayOwner(live, name))
|
|
179
|
+
expectCode("incident_relay_busy") { live.sendIncidentId(collidingIncident, cloud.base) }
|
|
180
|
+
live.sendIncidentId(incident, cloud.base)
|
|
181
|
+
|
|
182
|
+
ShadowSystemClock.advanceBy(Duration.ofMillis(MentraLive.INCIDENT_RELAY_OWNERSHIP_MS))
|
|
183
|
+
live.sendIncidentId(collidingIncident, cloud.base)
|
|
184
|
+
assertEquals(collidingIncident, relayOwner(live, name))
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@Test fun `dispatch failure of a refused report cannot release the owner's names`() = withLive { live ->
|
|
189
|
+
ready(live)
|
|
190
|
+
DeviceStore.set("bluetooth", "core_token", "synthetic")
|
|
191
|
+
live.sendIncidentId(incident, apiBase)
|
|
192
|
+
set(live, "txCharacteristic", null)
|
|
193
|
+
expectCode("glasses_not_connected") { live.sendIncidentId(collidingIncident, apiBase) }
|
|
194
|
+
assertEquals(incident, relayOwner(live, IncidentLogBleRelayNaming.bleFileBaseName(incident, 'B')))
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// A plain socket server: com.sun.net.httpserver is not on the Android unit-test classpath.
|
|
198
|
+
private class FakeCloud(val server: ServerSocket) {
|
|
199
|
+
@Volatile var status = 200
|
|
200
|
+
val requests = LinkedBlockingQueue<String>()
|
|
201
|
+
val base get() = "http://127.0.0.1:${server.localPort}"
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private fun withCloud(body: (FakeCloud) -> Unit) {
|
|
205
|
+
val server = ServerSocket(0, 50, java.net.InetAddress.getByName("127.0.0.1"))
|
|
206
|
+
val cloud = FakeCloud(server)
|
|
207
|
+
val acceptor = Thread {
|
|
208
|
+
while (!server.isClosed) {
|
|
209
|
+
try {
|
|
210
|
+
server.accept().use { socket ->
|
|
211
|
+
val input = socket.getInputStream().buffered()
|
|
212
|
+
fun line(): String {
|
|
213
|
+
val sb = StringBuilder()
|
|
214
|
+
while (true) {
|
|
215
|
+
val c = input.read()
|
|
216
|
+
if (c < 0 || c == '\n'.code) break
|
|
217
|
+
if (c != '\r'.code) sb.append(c.toChar())
|
|
218
|
+
}
|
|
219
|
+
return sb.toString()
|
|
220
|
+
}
|
|
221
|
+
val path = line().split(" ").getOrElse(1) { "" }.substringBefore('?')
|
|
222
|
+
var length = 0
|
|
223
|
+
while (true) {
|
|
224
|
+
val header = line()
|
|
225
|
+
if (header.isEmpty()) break
|
|
226
|
+
if (header.startsWith("content-length:", ignoreCase = true)) {
|
|
227
|
+
length = header.substringAfter(':').trim().toInt()
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
val received = String(input.readNBytes(length), StandardCharsets.UTF_8)
|
|
231
|
+
cloud.requests.add("$path $received")
|
|
232
|
+
socket.getOutputStream().write(
|
|
233
|
+
"HTTP/1.1 ${cloud.status} X\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"
|
|
234
|
+
.toByteArray(StandardCharsets.US_ASCII))
|
|
235
|
+
socket.getOutputStream().flush()
|
|
236
|
+
}
|
|
237
|
+
} catch (_: SocketException) {
|
|
238
|
+
// closed by the test
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}.apply { isDaemon = true; start() }
|
|
242
|
+
try { body(cloud) } finally { server.close(); acceptor.join(2_000) }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
private fun receiveRelayFile(live: MentraLive, name: String, payload: String) {
|
|
246
|
+
uploadWith(live, (get(live, "bleIncidentLogRelays") as Map<*, *>)[name]!!, name, payload)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private fun uploadWith(live: MentraLive, relay: Any, name: String, payload: String) {
|
|
250
|
+
MentraLive::class.java.declaredMethods.first { it.name == "uploadBleIncidentLogPayload" }
|
|
251
|
+
.apply { isAccessible = true }
|
|
252
|
+
.invoke(live, relay, name, payload.toByteArray(StandardCharsets.UTF_8))
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private fun relayOwner(live: MentraLive, name: String): String? {
|
|
256
|
+
val relay = (get(live, "bleIncidentLogRelays") as Map<*, *>)[name] ?: return null
|
|
257
|
+
return relay.javaClass.getDeclaredField("incidentId").apply { isAccessible = true }.get(relay) as String
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private fun awaitMain(condition: () -> Boolean) {
|
|
261
|
+
val deadline = System.currentTimeMillis() + 5_000
|
|
262
|
+
while (!condition() && System.currentTimeMillis() < deadline) {
|
|
263
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
264
|
+
Thread.sleep(10)
|
|
265
|
+
}
|
|
266
|
+
assertTrue(condition())
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// sendJson wraps each message as {"C":"<escaped json>"}; unescape so assertions read the message.
|
|
270
|
+
private fun wire(live: MentraLive): String =
|
|
271
|
+
queuedWrites(live).joinToString("") { String(it, StandardCharsets.UTF_8) }.replace("\\\"", "\"")
|
|
272
|
+
|
|
90
273
|
private fun ready(live: MentraLive) {
|
|
91
274
|
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
|
|
92
275
|
val gatt = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("AA:BB:CC:DD:EE:FF")
|
|
@@ -193,7 +193,7 @@ class MentraLiveOwnerLossPolicyTest {
|
|
|
193
193
|
@Test
|
|
194
194
|
fun aClearedPairingFlagOnTheSavedGlassesIsNotHiddenFromThePauseWatchScan() {
|
|
195
195
|
assertFalse(
|
|
196
|
-
MentraLiveOwnerLossPolicy.
|
|
196
|
+
MentraLiveOwnerLossPolicy.shouldIgnoreNotPairable(
|
|
197
197
|
savedGlasses = true,
|
|
198
198
|
reconnectScan = false,
|
|
199
199
|
secureTrailer = true,
|
|
@@ -201,7 +201,7 @@ class MentraLiveOwnerLossPolicyTest {
|
|
|
201
201
|
)
|
|
202
202
|
)
|
|
203
203
|
assertTrue(
|
|
204
|
-
MentraLiveOwnerLossPolicy.
|
|
204
|
+
MentraLiveOwnerLossPolicy.shouldIgnoreNotPairable(
|
|
205
205
|
savedGlasses = false,
|
|
206
206
|
reconnectScan = false,
|
|
207
207
|
secureTrailer = true,
|
|
@@ -209,7 +209,7 @@ class MentraLiveOwnerLossPolicyTest {
|
|
|
209
209
|
)
|
|
210
210
|
)
|
|
211
211
|
assertFalse(
|
|
212
|
-
MentraLiveOwnerLossPolicy.
|
|
212
|
+
MentraLiveOwnerLossPolicy.shouldIgnoreNotPairable(
|
|
213
213
|
savedGlasses = false,
|
|
214
214
|
reconnectScan = false,
|
|
215
215
|
secureTrailer = true,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.os.Looper
|
|
4
|
+
import androidx.test.core.app.ApplicationProvider
|
|
5
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
6
|
+
import java.time.Duration
|
|
7
|
+
import org.json.JSONObject
|
|
8
|
+
import org.junit.Assert.assertEquals
|
|
9
|
+
import org.junit.Assert.assertTrue
|
|
10
|
+
import org.junit.Test
|
|
11
|
+
import org.junit.runner.RunWith
|
|
12
|
+
import org.robolectric.RobolectricTestRunner
|
|
13
|
+
import org.robolectric.Shadows.shadowOf
|
|
14
|
+
import org.robolectric.annotation.Config
|
|
15
|
+
import org.robolectric.annotation.LooperMode
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The glasses answer every RGB LED command with `rgb_led_control_response` echoing the command's
|
|
19
|
+
* requestId. MentraLive must forward that reply so the pending SDK request settles instead of
|
|
20
|
+
* timing out.
|
|
21
|
+
*/
|
|
22
|
+
@RunWith(RobolectricTestRunner::class)
|
|
23
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
24
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
25
|
+
class MentraLiveRgbLedResponseTest {
|
|
26
|
+
@Test fun `success reply settles the request it echoes`() {
|
|
27
|
+
val replies = forwardedReplies(
|
|
28
|
+
JSONObject().put("type", "rgb_led_control_response").put("requestId", "led-1")
|
|
29
|
+
.put("state", "success").put("success", true),
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
assertEquals(1, replies.size)
|
|
33
|
+
assertEquals("led-1", replies[0]["requestId"])
|
|
34
|
+
assertEquals("success", replies[0]["state"])
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test fun `error reply carries the glasses error code`() {
|
|
38
|
+
val replies = forwardedReplies(
|
|
39
|
+
JSONObject().put("type", "rgb_led_control_response").put("requestId", "led-2")
|
|
40
|
+
.put("state", "error").put("success", false)
|
|
41
|
+
.put("errorCode", "device_not_supported").put("error", "RGB LED not supported"),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
assertEquals(1, replies.size)
|
|
45
|
+
assertEquals("error", replies[0]["state"])
|
|
46
|
+
assertEquals("device_not_supported", replies[0]["errorCode"])
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Test fun `reply without a requestId is not forwarded`() {
|
|
50
|
+
val replies = forwardedReplies(
|
|
51
|
+
JSONObject().put("type", "rgb_led_control_response").put("state", "success"),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
assertTrue(replies.isEmpty())
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private fun forwardedReplies(reply: JSONObject): List<Map<String, Any?>> {
|
|
58
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
59
|
+
val live = MentraLive()
|
|
60
|
+
val replies = mutableListOf<Map<String, Any?>>()
|
|
61
|
+
val sink = Bridge.addEventSink { type, body ->
|
|
62
|
+
if (type == "rgb_led_control_response") replies.add(body.toMap())
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
MentraLive::class.java.getDeclaredMethod("processJsonMessage", JSONObject::class.java)
|
|
66
|
+
.apply { isAccessible = true }
|
|
67
|
+
.invoke(live, reply)
|
|
68
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
69
|
+
} finally {
|
|
70
|
+
Bridge.removeEventSink(sink)
|
|
71
|
+
live.destroy()
|
|
72
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(2))
|
|
73
|
+
}
|
|
74
|
+
return replies
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -31,12 +31,11 @@ class NimoCanvasCoordinatorTest {
|
|
|
31
31
|
val writes = mutableListOf<ByteArray>()
|
|
32
32
|
val failures = mutableListOf<String>()
|
|
33
33
|
val rejections = mutableListOf<Int>()
|
|
34
|
-
var holdPreemptions = 0
|
|
35
34
|
var rejectWrites = false
|
|
36
35
|
val queue = NimoGattQueue<Any>(clock, { _, bytes -> writes += bytes; !rejectWrites }, { failures += it })
|
|
37
36
|
val canvas = NimoCanvasCoordinator(clock, { 20 },
|
|
38
37
|
{ frames, started, completed -> queue.enqueue(connection, characteristic, frames, started, completed) },
|
|
39
|
-
{ queue.reset(); failures += it }, { rejections += it }
|
|
38
|
+
{ queue.reset(); failures += it }, { rejections += it })
|
|
40
39
|
init { queue.connected(connection) }
|
|
41
40
|
fun written(success: Boolean = true) {
|
|
42
41
|
queue.written(connection, characteristic, success)
|
|
@@ -244,60 +243,6 @@ class NimoCanvasCoordinatorTest {
|
|
|
244
243
|
assertTrue(f.failures.isEmpty())
|
|
245
244
|
}
|
|
246
245
|
|
|
247
|
-
@Test fun diagnosticHoldWaitsForCurrentBusinessAckAndThenResumesLatestScene() {
|
|
248
|
-
val f = Fixture()
|
|
249
|
-
val initial = byteArrayOf(0, 0, 1)
|
|
250
|
-
val latest = byteArrayOf(2, 0, 1)
|
|
251
|
-
f.launch(initial)
|
|
252
|
-
var ready = 0
|
|
253
|
-
f.canvas.hold { ready++ }
|
|
254
|
-
f.canvas.offer(byteArrayOf(1, 0, 1), "one:1")
|
|
255
|
-
f.canvas.offer(latest, "one:1")
|
|
256
|
-
|
|
257
|
-
assertEquals(0, ready)
|
|
258
|
-
f.finishUpdate(initial)
|
|
259
|
-
assertEquals(1, ready)
|
|
260
|
-
val beforeRelease = f.writes.size
|
|
261
|
-
|
|
262
|
-
f.canvas.releaseHold()
|
|
263
|
-
|
|
264
|
-
assertEquals(beforeRelease + 1, f.writes.size)
|
|
265
|
-
assertArrayEquals(NimoCanvasCodec.frames(4, latest, 20).first(), f.writes.last())
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
@Test fun scopeTakeoverPreemptsHoldWithoutFlushingHeldScene() {
|
|
269
|
-
val f = Fixture()
|
|
270
|
-
val initial = byteArrayOf(0, 0, 1)
|
|
271
|
-
val held = byteArrayOf(1, 0, 1)
|
|
272
|
-
val takeover = byteArrayOf(2, 0, 1)
|
|
273
|
-
f.launch(initial); f.finishUpdate(initial)
|
|
274
|
-
var ready = 0
|
|
275
|
-
f.canvas.hold { ready++ }
|
|
276
|
-
f.canvas.offer(held, "one:1")
|
|
277
|
-
val beforeTakeover = f.writes.size
|
|
278
|
-
|
|
279
|
-
f.canvas.offer(takeover, "two:1")
|
|
280
|
-
|
|
281
|
-
assertEquals(1, ready)
|
|
282
|
-
assertEquals(1, f.holdPreemptions)
|
|
283
|
-
assertEquals(beforeTakeover + 1, f.writes.size)
|
|
284
|
-
assertArrayEquals(NimoCanvasCodec.frames(4, takeover, 20).first(), f.writes.last())
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
@Test fun firstScopePreemptsHoldAcquiredBeforeAnyCanvasScene() {
|
|
288
|
-
val f = Fixture()
|
|
289
|
-
var ready = 0
|
|
290
|
-
f.canvas.readiness(true)
|
|
291
|
-
f.canvas.hold { ready++ }
|
|
292
|
-
assertEquals(1, ready)
|
|
293
|
-
|
|
294
|
-
f.canvas.offer(byteArrayOf(0, 0, 1), "first:1")
|
|
295
|
-
|
|
296
|
-
assertEquals(1, f.holdPreemptions)
|
|
297
|
-
assertEquals(1, f.writes.size)
|
|
298
|
-
assertArrayEquals(NimoCanvasCodec.frames(1, writeCapacity = 20).single(), f.writes.single())
|
|
299
|
-
}
|
|
300
|
-
|
|
301
246
|
@Test fun reentrantCompletionCannotReleaseNewConnectionWrite() {
|
|
302
247
|
val f = Fixture(); val old = f.connection
|
|
303
248
|
f.queue.enqueue(old, f.characteristic, listOf(byteArrayOf(1)), completed = {
|
|
@@ -314,26 +314,4 @@ class NimoCanvasSessionTest {
|
|
|
314
314
|
assertThrows(IllegalArgumentException::class.java) { session.offer(ByteArray(12281), "one:1") }
|
|
315
315
|
}
|
|
316
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
317
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertFalse
|
|
4
|
+
import org.junit.Assert.assertTrue
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class NimoFirmwareTargetTest {
|
|
8
|
+
@Test fun acceptsOnlyTheSupportedBuild() {
|
|
9
|
+
assertTrue(NimoFirmwareTarget.isCurrent("0.1.1.1", "FW-VERSION-v0.1.1.1-20260827164351-537cf1-dirty-Debug"))
|
|
10
|
+
assertTrue(NimoFirmwareTarget.isCurrent("0.1.1.1", ""))
|
|
11
|
+
assertFalse(NimoFirmwareTarget.isCurrent("0.1.1.1", "FW-VERSION-v0.1.1.1-20260101000000-abcdef-Release"))
|
|
12
|
+
assertFalse(NimoFirmwareTarget.isCurrent("0.1.0.9", "FW-VERSION-v0.1.0.9-20250101000000-123456-Release"))
|
|
13
|
+
assertFalse(NimoFirmwareTarget.isCurrent("", ""))
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.*
|
|
4
|
+
import org.junit.Test
|
|
5
|
+
|
|
6
|
+
class NimoFirmwareUpdaterTest {
|
|
7
|
+
private class Clock : NimoScheduler {
|
|
8
|
+
val tasks = mutableListOf<Pair<Long, () -> Unit>>(); var now = 0L
|
|
9
|
+
override fun post(delayMs: Long, task: () -> Unit): () -> Unit {
|
|
10
|
+
val e = (now + delayMs) to task; tasks += e; return { tasks.remove(e) }
|
|
11
|
+
}
|
|
12
|
+
fun run(limit: Int = 100000) { var n = 0
|
|
13
|
+
while (tasks.isNotEmpty() && n++ < limit) { val e = tasks.minByOrNull { it.first }!!; tasks.remove(e); now = e.first; e.second() } }
|
|
14
|
+
}
|
|
15
|
+
private fun resp(cmd: Int, seq: Int, body: ByteArray, status: Int = 0): ByteArray {
|
|
16
|
+
val len = body.size + 2
|
|
17
|
+
return byteArrayOf(0x70, 0x07, 0x6E, 0, cmd.toByte(), (len shr 8).toByte(), len.toByte(), status.toByte(), seq.toByte()) + body + 0x33.toByte()
|
|
18
|
+
}
|
|
19
|
+
private fun u32(v: Int) = byteArrayOf((v shr 24).toByte(), (v shr 16).toByte(), (v shr 8).toByte(), v.toByte())
|
|
20
|
+
private fun u16(v: Int) = byteArrayOf((v shr 8).toByte(), v.toByte())
|
|
21
|
+
|
|
22
|
+
@Test fun fullTransferSendsReset() {
|
|
23
|
+
val fw = ByteArray(1000) { it.toByte() }
|
|
24
|
+
val clock = Clock()
|
|
25
|
+
var result: String? = "pending"
|
|
26
|
+
val received = ByteArray(fw.size); var syncCalls = 0
|
|
27
|
+
val commands = mutableListOf<Int>()
|
|
28
|
+
lateinit var updater: NimoFirmwareUpdater
|
|
29
|
+
val blockSize = 256
|
|
30
|
+
updater = NimoFirmwareUpdater(fw, 100, clock, write = { pkt, done ->
|
|
31
|
+
val cmd = pkt[4].toInt() and 255; val seq = pkt[7].toInt() and 255
|
|
32
|
+
val params = pkt.copyOfRange(8, pkt.size - 1)
|
|
33
|
+
commands += cmd
|
|
34
|
+
clock.post(1) { done(true) }
|
|
35
|
+
val reply: ByteArray? = when (cmd) {
|
|
36
|
+
0x02 -> byteArrayOf(2, 3, 1, 2, 5, 1, 3, 2, 80, 80)
|
|
37
|
+
0xE1 -> u32(0) + u16(16)
|
|
38
|
+
0xE2 -> byteArrayOf(0)
|
|
39
|
+
0xE3 -> byteArrayOf(0) + u32(0) + u16(blockSize) + byteArrayOf(1)
|
|
40
|
+
0xE5 -> {
|
|
41
|
+
val off = ((params[0].toInt() and 255) shl 24) or ((params[1].toInt() and 255) shl 16) or ((params[2].toInt() and 255) shl 8) or (params[3].toInt() and 255)
|
|
42
|
+
val data = params.copyOfRange(4, params.size - 4)
|
|
43
|
+
data.copyInto(received, off)
|
|
44
|
+
val end = off + data.size
|
|
45
|
+
if (end % blockSize == 0 || end == fw.size) {
|
|
46
|
+
if (end >= fw.size) byteArrayOf(0) + u32(0) + u16(0) + u16(0)
|
|
47
|
+
else byteArrayOf(0) + u32(end) + u16(minOf(blockSize, fw.size - end)) + u16(10)
|
|
48
|
+
} else null
|
|
49
|
+
}
|
|
50
|
+
0xE6 -> byteArrayOf(0)
|
|
51
|
+
0xE8 -> if (syncCalls++ < 2) byteArrayOf(1) else byteArrayOf(0)
|
|
52
|
+
else -> null
|
|
53
|
+
}
|
|
54
|
+
if (reply != null) clock.post(2) { updater.receive(resp(cmd, seq, reply)) }
|
|
55
|
+
}, progress = {}, finished = { result = it })
|
|
56
|
+
updater.start()
|
|
57
|
+
clock.run()
|
|
58
|
+
assertNull(result)
|
|
59
|
+
assertArrayEquals(fw, received)
|
|
60
|
+
assertEquals(0x03, commands.last())
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Test fun refusalReportsFailureWithoutReset() {
|
|
64
|
+
val clock = Clock(); var result: String? = "pending"; val commands = mutableListOf<Int>()
|
|
65
|
+
lateinit var updater: NimoFirmwareUpdater
|
|
66
|
+
updater = NimoFirmwareUpdater(ByteArray(100), 100, clock, write = { pkt, done ->
|
|
67
|
+
val cmd = pkt[4].toInt() and 255; val seq = pkt[7].toInt() and 255; commands += cmd
|
|
68
|
+
done(true)
|
|
69
|
+
val reply = when (cmd) { 0x02 -> byteArrayOf(2, 3, 1, 2, 5, 1, 3, 2, 10, 10); 0xE1 -> u32(0) + u16(16); 0xE2 -> byteArrayOf(2); else -> null }
|
|
70
|
+
if (reply != null) clock.post(1) { updater.receive(resp(cmd, seq, reply)) }
|
|
71
|
+
}, progress = {}, finished = { result = it })
|
|
72
|
+
updater.start(); clock.run()
|
|
73
|
+
assertNotNull(result); assertNotEquals("pending", result)
|
|
74
|
+
assertFalse(commands.contains(0x03)); assertFalse(commands.contains(0xE3))
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import java.io.File
|
|
4
|
+
import org.json.JSONObject
|
|
5
|
+
import org.junit.Assert.*
|
|
6
|
+
import org.junit.Test
|
|
7
|
+
|
|
8
|
+
class NimoOtaProtocolTest {
|
|
9
|
+
private val fixtures = JSONObject(File("../test-fixtures/nimo-ota.json").readText())
|
|
10
|
+
private fun bytes(hex: String) = hex.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
|
11
|
+
|
|
12
|
+
@Test fun capturedRequestsAndResponsesMatchIncludingResetWithoutBusinessByte() {
|
|
13
|
+
val requests = fixtures.getJSONArray("requests")
|
|
14
|
+
for (index in 0 until requests.length()) {
|
|
15
|
+
val item = requests.getJSONObject(index)
|
|
16
|
+
assertArrayEquals(bytes(item.getString("frame")), NimoOtaProtocol.request(item.getInt("command"), item.getInt("sequence"), bytes(item.getString("params"))))
|
|
17
|
+
}
|
|
18
|
+
val responses = fixtures.getJSONArray("responses")
|
|
19
|
+
var combined = byteArrayOf()
|
|
20
|
+
for (index in 0 until responses.length()) {
|
|
21
|
+
val item = responses.getJSONObject(index)
|
|
22
|
+
val frame = bytes(item.getString("frame"))
|
|
23
|
+
combined += frame
|
|
24
|
+
// Every possible split must produce exactly one identical response.
|
|
25
|
+
for (split in 0..frame.size) {
|
|
26
|
+
val decoder = NimoOtaProtocol.Decoder()
|
|
27
|
+
val actual = (decoder.feed(frame.copyOfRange(0, split)) + decoder.feed(frame.copyOfRange(split, frame.size))).single()
|
|
28
|
+
assertEquals(item.getInt("command"), actual.command)
|
|
29
|
+
assertEquals(item.getInt("sequence"), actual.sequence)
|
|
30
|
+
assertEquals(item.getInt("status"), actual.status)
|
|
31
|
+
assertArrayEquals(bytes(item.getString("body")), actual.body)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
assertEquals(responses.length(), NimoOtaProtocol.Decoder().feed(combined).size)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test fun smallPhoneWritesUsePerChunkCrcAndPreserveRequestedOffset() {
|
|
38
|
+
val firmware = bytes(fixtures.getString("firmware"))
|
|
39
|
+
val blocks = fixtures.getJSONArray("blocks")
|
|
40
|
+
for (index in 0 until blocks.length()) {
|
|
41
|
+
val item = blocks.getJSONObject(index)
|
|
42
|
+
val parts = NimoOtaProtocol.blockParts(firmware, NimoOtaProtocol.Slice(item.getLong("offset"), item.getInt("length")), item.getBoolean("crc"), item.getInt("capacity"))
|
|
43
|
+
val expected = item.getJSONArray("parts")
|
|
44
|
+
assertEquals(expected.length(), parts.size)
|
|
45
|
+
parts.forEachIndexed { i, part ->
|
|
46
|
+
assertArrayEquals(bytes(expected.getString(i)), part)
|
|
47
|
+
assertTrue(NimoOtaProtocol.request(0xE5, i, part).size <= item.getInt("capacity"))
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Test fun rejectsMalformedDeviceDataAndOutOfBoundsRequests() {
|
|
53
|
+
for (hex in listOf("71", "70076ec0", "70076e00020001", "70076e00021001", "70076e0003000200fa00")) {
|
|
54
|
+
assertThrows(IllegalArgumentException::class.java) { NimoOtaProtocol.Decoder().feed(bytes(hex)) }
|
|
55
|
+
}
|
|
56
|
+
for (hex in listOf("00", "0201", "01000100")) {
|
|
57
|
+
assertThrows(IllegalArgumentException::class.java) { NimoOtaProtocol.deviceInfo(bytes(hex)) }
|
|
58
|
+
}
|
|
59
|
+
for (slice in listOf(NimoOtaProtocol.Slice(-1, 1), NimoOtaProtocol.Slice(100, 1), NimoOtaProtocol.Slice(0, 0), NimoOtaProtocol.Slice(Long.MAX_VALUE, 1))) {
|
|
60
|
+
assertThrows(IllegalArgumentException::class.java) { NimoOtaProtocol.firmwareSlice(ByteArray(100), slice) }
|
|
61
|
+
}
|
|
62
|
+
assertThrows(IllegalArgumentException::class.java) { NimoOtaProtocol.blockParts(ByteArray(100), NimoOtaProtocol.Slice(0, 100), true, 20) }
|
|
63
|
+
assertThrows(IllegalArgumentException::class.java) { NimoOtaProtocol.enterResult(bytes("0100000012100001")) }
|
|
64
|
+
assertThrows(IllegalArgumentException::class.java) { NimoOtaProtocol.blockResult(bytes("000000000000007531")) }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Test fun interpretsCapturedPreflightAndBlockRequests() {
|
|
68
|
+
val info = NimoOtaProtocol.deviceInfo(bytes("0600000e000e0205010000020103026464020301020400020501"))
|
|
69
|
+
assertArrayEquals(bytes("00000201"), info[1])
|
|
70
|
+
assertArrayEquals(bytes("6464"), info[2])
|
|
71
|
+
val entered = NimoOtaProtocol.enterResult(bytes("0000000012100001"))
|
|
72
|
+
assertEquals(NimoOtaProtocol.Slice(18, 4096), entered.slice)
|
|
73
|
+
assertTrue(entered.crc)
|
|
74
|
+
assertEquals(NimoOtaProtocol.Slice(4114, 4096), NimoOtaProtocol.blockResult(bytes("000000101210000000")).slice)
|
|
75
|
+
assertEquals(NimoOtaProtocol.Slice(0, 0), NimoOtaProtocol.blockResult(ByteArray(9)).slice)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.utils
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Assert.assertFalse
|
|
5
|
+
import org.junit.Assert.assertTrue
|
|
6
|
+
import org.junit.Test
|
|
7
|
+
|
|
8
|
+
class IncidentLogBleRelayNamingTest {
|
|
9
|
+
@Test fun `relay names built for a report are recognized`() {
|
|
10
|
+
val firmware = IncidentLogBleRelayNaming.bleFileBaseName("rep_01M4HBVT88DFSN8TYNZ1WTV4PB", 'B')
|
|
11
|
+
val logcat = IncidentLogBleRelayNaming.bleFileBaseName("rep_01M4HBVT88DFSN8TYNZ1WTV4PB", 'L')
|
|
12
|
+
assertEquals("Brep_01m4hbvt88d", firmware)
|
|
13
|
+
assertTrue(IncidentLogBleRelayNaming.isRelayFileName(firmware))
|
|
14
|
+
assertTrue(IncidentLogBleRelayNaming.isRelayFileName(logcat))
|
|
15
|
+
assertTrue(IncidentLogBleRelayNaming.isRelayFileName(IncidentLogBleRelayNaming.bleFileBaseName("short", 'B')))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Test fun `photo and other transfers are not relays`() {
|
|
19
|
+
for (name in listOf("I000123456", "I000123456.jpg", "ble_1234567890", "Brep_01m4hbvt88d.json", "Xrep_01m4hbvt88d", "", null)) {
|
|
20
|
+
assertFalse(name.toString(), IncidentLogBleRelayNaming.isRelayFileName(name))
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -162,11 +162,41 @@ class NimoReadinessDriverTest {
|
|
|
162
162
|
assertTrue(failures.isEmpty())
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
@Test fun canvasWaitsForTheSupportedFirmwareVersion() {
|
|
166
|
+
finishHandshake(peer = true, packed = null)
|
|
167
|
+
assertKeys() // No Launch against firmware that has not reported its version.
|
|
168
|
+
emitVersion(SUPPORTED_PACKED, SUPPORTED_DETAIL)
|
|
169
|
+
assertKeys(1)
|
|
170
|
+
assertTrue(failures.isEmpty())
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@Test fun otherFirmwareWithoutAnOtaChannelStillStartsTheCanvas() {
|
|
174
|
+
// The test link exposes no OTA characteristics, so the update is unavailable and the session proceeds.
|
|
175
|
+
finishHandshake(peer = true, packed = (1 shl 21), detail = "FW-VERSION-v0.1.0.0-20250101000000-abcdef-Release")
|
|
176
|
+
assertKeys(1)
|
|
177
|
+
assertTrue(failures.isEmpty())
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private fun finishHandshake(peer: Boolean?, packed: Int? = SUPPORTED_PACKED, detail: String = SUPPORTED_DETAIL) {
|
|
166
181
|
field("twsConnected").set(nimo, true)
|
|
167
182
|
field("peerCompanionReady").set(nimo, peer)
|
|
168
183
|
Nimo::class.java.getDeclaredMethod("finishHandshake").apply { isAccessible = true }.invoke(nimo)
|
|
169
184
|
idle()
|
|
185
|
+
if (packed != null) emitVersion(packed, detail)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** GET_VERSION / GET_VERSION_DETAIL replies; the canvas starts only after the version check. */
|
|
189
|
+
private fun emitVersion(packed: Int, detail: String) {
|
|
190
|
+
val le = byteArrayOf(packed.toByte(), (packed shr 8).toByte(), (packed shr 16).toByte(), (packed shr 24).toByte())
|
|
191
|
+
emit(packet(NimoProtocol.CMD_GET_PARAMETER, NimoProtocol.GET_VERSION, byteArrayOf(0) + le))
|
|
192
|
+
emit(packet(NimoProtocol.CMD_GET_PARAMETER, NimoProtocol.GET_VERSION_DETAIL,
|
|
193
|
+
byteArrayOf(0) + detail.toByteArray(Charsets.UTF_8)))
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private companion object {
|
|
197
|
+
// 0.1.1.1 packed as major<<28 | minor<<21 | micro<<12 | build.
|
|
198
|
+
const val SUPPORTED_PACKED = (1 shl 21) or (1 shl 12) or 1
|
|
199
|
+
const val SUPPORTED_DETAIL = "FW-VERSION-v0.1.1.1-20260827164351-537cf1-dirty-Debug"
|
|
170
200
|
}
|
|
171
201
|
|
|
172
202
|
private fun newGatt(): BluetoothGatt = ShadowBluetoothGatt.newInstance(
|