@mentra/bluetooth-sdk 3.4.0-dev.999 → 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
|
@@ -5,77 +5,6 @@ import XCTest
|
|
|
5
5
|
final class DeviceManagerReconnectTests: XCTestCase {
|
|
6
6
|
private let requests = ["should_send_lc3", "should_send_pcm", "should_send_transcript", "local_stt_fallback_active"]
|
|
7
7
|
|
|
8
|
-
func testActualManagerHandoffCleanupDoesNotInvalidateClosedOriginalStatus() {
|
|
9
|
-
withRecordingDevice { manager, _ in
|
|
10
|
-
let original = manager.sgc as! ReconnectRecordingDevice
|
|
11
|
-
original.type = DeviceTypes.NIMO
|
|
12
|
-
let uuid = "00000000-0000-4000-8000-000000000001"
|
|
13
|
-
let model = NimoResourceSession(captureNonce: uuid, pair: NimoResourcePair(name: "Nimo-Test", peripheralUuid: uuid))
|
|
14
|
-
XCTAssertTrue(model.admit(original, instanceId: uuid, name: "Nimo-Test"))
|
|
15
|
-
XCTAssertTrue(model.beginRelease(nonce: uuid, cancel: true, mic: false, canvas: false))
|
|
16
|
-
model.proveNoTransport()
|
|
17
|
-
let verifiedClosed = model.settled(producers: NimoResourceProducers())
|
|
18
|
-
var cleanupCalls = 0, disconnectEffects = 0
|
|
19
|
-
original.onCleanup = {
|
|
20
|
-
cleanupCalls += 1
|
|
21
|
-
// Same original-session guard used by actual Nimo.disconnect.
|
|
22
|
-
if model.shouldRunOrdinaryDisconnect(original, originalClosed: verifiedClosed) { disconnectEffects += 1 }
|
|
23
|
-
}
|
|
24
|
-
manager.initSGC(DeviceTypes.SIMULATED) // Actual manager replacement; no Bluetooth device.
|
|
25
|
-
XCTAssertEqual(cleanupCalls, 1)
|
|
26
|
-
XCTAssertEqual(disconnectEffects, 0)
|
|
27
|
-
XCTAssertTrue(model.errors.isEmpty)
|
|
28
|
-
XCTAssertTrue(model.settled(producers: NimoResourceProducers())) // Fresh status after cleanup.
|
|
29
|
-
XCTAssertTrue(NimoResourceManagerState.allowsReplacement(fixtureEnabled: true, originalClosed: model.settled(producers: NimoResourceProducers())))
|
|
30
|
-
XCTAssertEqual(manager.sgc?.type, DeviceTypes.SIMULATED)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
func testActualQueuedReplacementDoesNotJoinOriginalNimoProducerRoster() {
|
|
35
|
-
withRecordingDevice { manager, store in
|
|
36
|
-
let original = manager.sgc as! ReconnectRecordingDevice
|
|
37
|
-
original.type = DeviceTypes.NIMO
|
|
38
|
-
let uuid = "00000000-0000-4000-8000-000000000001"
|
|
39
|
-
let model = NimoResourceSession(captureNonce: uuid, pair: NimoResourcePair(name: "Nimo-Test", peripheralUuid: uuid))
|
|
40
|
-
XCTAssertTrue(model.admit(original, instanceId: uuid, name: "Nimo-Test"))
|
|
41
|
-
XCTAssertTrue(model.beginRelease(nonce: uuid, cancel: true, mic: false, canvas: false)); model.proveNoTransport()
|
|
42
|
-
let stopped = expectation(description: "Original disposal inside real queued manager handoff")
|
|
43
|
-
original.onDisconnect = {
|
|
44
|
-
XCTAssertFalse(model.shouldRunOrdinaryDisconnect(original, originalClosed: true))
|
|
45
|
-
stopped.fulfill()
|
|
46
|
-
}
|
|
47
|
-
// Same asynchronous connectByName path as G2; simulated replacement
|
|
48
|
-
// avoids any Bluetooth transport in this source regression.
|
|
49
|
-
store.set("bluetooth", "pending_wearable", DeviceTypes.SIMULATED)
|
|
50
|
-
manager.connectByName("Simulated")
|
|
51
|
-
XCTAssertEqual(NimoResourceFixture.shared.pendingManagerEntries, 1)
|
|
52
|
-
XCTAssertEqual(NimoResourceFixture.shared.pendingOriginalManagerEntries, 0)
|
|
53
|
-
wait(for: [stopped], timeout: 1)
|
|
54
|
-
var producers = NimoResourceProducers()
|
|
55
|
-
producers.postedCallbacks = NimoResourceFixture.shared.pendingOriginalManagerEntries
|
|
56
|
-
XCTAssertTrue(model.settled(producers: producers)) // Fresh status during replacement wait.
|
|
57
|
-
XCTAssertTrue(model.errors.isEmpty)
|
|
58
|
-
let completed = expectation(description: "Replacement queued work has actually settled")
|
|
59
|
-
Task { @MainActor in
|
|
60
|
-
let deadline = ProcessInfo.processInfo.systemUptime + 2
|
|
61
|
-
while ProcessInfo.processInfo.systemUptime < deadline {
|
|
62
|
-
if NimoResourceFixture.shared.pendingManagerEntries == 0,
|
|
63
|
-
manager.sgc?.type == DeviceTypes.SIMULATED {
|
|
64
|
-
completed.fulfill()
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
try? await Task.sleep(nanoseconds: 5_000_000)
|
|
68
|
-
}
|
|
69
|
-
// Leave the expectation unmet on timeout; elapsed delay alone
|
|
70
|
-
// cannot stand in for the queued manager's actual completion.
|
|
71
|
-
}
|
|
72
|
-
wait(for: [completed], timeout: 2.5)
|
|
73
|
-
XCTAssertEqual(NimoResourceFixture.shared.pendingManagerEntries, 0)
|
|
74
|
-
XCTAssertTrue(model.settled(producers: NimoResourceProducers()))
|
|
75
|
-
XCTAssertEqual(manager.sgc?.type, DeviceTypes.SIMULATED)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
8
|
func testDelayedReconnectReplayPreservesNimoDepthEndpoints() {
|
|
80
9
|
for depth in [0, 10] {
|
|
81
10
|
withRecordingDevice { manager, store in
|
|
@@ -138,18 +138,24 @@ final class GlassesAudioSetupPolicyTests: XCTestCase {
|
|
|
138
138
|
)
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
func
|
|
141
|
+
func testPairingProtocolGlassesNeverAskTheUserAfterSetup() {
|
|
142
142
|
var tracker = GlassesAudioSetupTracker()
|
|
143
143
|
tracker.startPhase(.reconnect, nowMs: t0)
|
|
144
144
|
tracker.classicLink(a2dp: true, hfp: true)
|
|
145
145
|
XCTAssertEqual(tracker.evaluate(sessionReady: true, phoneAudioUp: false, nowMs: t0).state, .connected)
|
|
146
146
|
tracker.classicLink(a2dp: false, hfp: false)
|
|
147
147
|
XCTAssertEqual(
|
|
148
|
-
tracker.evaluate(sessionReady: true, phoneAudioUp: false, nowMs: t0 +
|
|
149
|
-
GlassesAudioSetupDecision(state: .connecting, nextDeadlineMs:
|
|
148
|
+
tracker.evaluate(sessionReady: true, phoneAudioUp: false, nowMs: t0 + 3_600_000),
|
|
149
|
+
GlassesAudioSetupDecision(state: .connecting, nextDeadlineMs: nil)
|
|
150
150
|
)
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
func testPairingProtocolGlassesStillAskWhenAudioNeverCameUpAfterPairing() {
|
|
154
|
+
let pairing = inputs(report: (false, false), phase: .pairing(autoAudio: true))
|
|
155
|
+
XCTAssertEqual(state(pairing, at: 7999), .connecting)
|
|
156
|
+
XCTAssertEqual(state(pairing, at: 8000), .needsUserConnectInSettings)
|
|
157
|
+
}
|
|
158
|
+
|
|
153
159
|
func testASessionDropIsIdleAndForgetsTheGlassesReport() {
|
|
154
160
|
var tracker = GlassesAudioSetupTracker()
|
|
155
161
|
tracker.startPhase(.reconnect, nowMs: t0)
|
|
@@ -16,6 +16,41 @@ private final class IncidentLogTransport: MentraLive {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/// Stands in for Cloud so the tests observe the report each relayed file is posted to.
|
|
20
|
+
private final class CloudStub: URLProtocol {
|
|
21
|
+
nonisolated(unsafe) static var status = 200
|
|
22
|
+
nonisolated(unsafe) static var requests: [String] = []
|
|
23
|
+
|
|
24
|
+
override class func canInit(with request: URLRequest) -> Bool {
|
|
25
|
+
request.url?.host == "cloud-stub.invalid"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override class func canonicalRequest(for request: URLRequest) -> URLRequest {
|
|
29
|
+
request
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override func startLoading() {
|
|
33
|
+
var body = request.httpBody ?? Data()
|
|
34
|
+
if body.isEmpty, let stream = request.httpBodyStream {
|
|
35
|
+
stream.open()
|
|
36
|
+
var buffer = [UInt8](repeating: 0, count: 4096)
|
|
37
|
+
while stream.hasBytesAvailable {
|
|
38
|
+
let count = stream.read(&buffer, maxLength: buffer.count)
|
|
39
|
+
if count <= 0 { break }
|
|
40
|
+
body.append(buffer, count: count)
|
|
41
|
+
}
|
|
42
|
+
stream.close()
|
|
43
|
+
}
|
|
44
|
+
let path = request.url?.path ?? ""
|
|
45
|
+
DispatchQueue.main.sync { CloudStub.requests.append("\(path) \(String(decoding: body, as: UTF8.self))") }
|
|
46
|
+
let response = HTTPURLResponse(url: request.url!, statusCode: CloudStub.status, httpVersion: nil, headerFields: nil)!
|
|
47
|
+
client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
|
|
48
|
+
client?.urlProtocolDidFinishLoading(self)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override func stopLoading() {}
|
|
52
|
+
}
|
|
53
|
+
|
|
19
54
|
@MainActor
|
|
20
55
|
final class IncidentLogDispatchTests: XCTestCase {
|
|
21
56
|
private let incident = "rep_01M4HBVT88DFSN8TYNZ1WTV4PB"
|
|
@@ -98,6 +133,129 @@ final class IncidentLogDispatchTests: XCTestCase {
|
|
|
98
133
|
XCTAssertNil(queue.dequeue())
|
|
99
134
|
}
|
|
100
135
|
|
|
136
|
+
func testCollidingReportWaitsForOwnerCloudConfirmationAndNeverReceivesItsEvidence() async throws {
|
|
137
|
+
try await withCloud(status: 200) {
|
|
138
|
+
let live = IncidentLogTransport()
|
|
139
|
+
let name = "Brep_01m4hbvt88d"
|
|
140
|
+
try live.sendIncidentId(incident, apiBaseUrl: cloudBase)
|
|
141
|
+
XCTAssertThrowsError(try live.sendIncidentId(collidingIncident, apiBaseUrl: cloudBase)) { error in
|
|
142
|
+
XCTAssertEqual((error as? BluetoothSdkError)?.code, "incident_relay_busy")
|
|
143
|
+
}
|
|
144
|
+
XCTAssertFalse(wire(live).contains(collidingIncident))
|
|
145
|
+
XCTAssertEqual(live.bleIncidentLogRelays[name]?.incidentId, incident)
|
|
146
|
+
XCTAssertEqual(live.bleIncidentLogRelays["Lrep_01m4hbvt88d"]?.incidentId, incident)
|
|
147
|
+
|
|
148
|
+
let logcat = "Lrep_01m4hbvt88d"
|
|
149
|
+
try await receive(live, name, "owner")
|
|
150
|
+
XCTAssertEqual(CloudStub.requests, ["/api/client/reports/\(incident)/artifacts owner"])
|
|
151
|
+
let confirmation = try XCTUnwrap(sentMessages(live).last { $0.contains("transfer_complete") })
|
|
152
|
+
XCTAssertTrue(confirmation.contains(name) && confirmation.contains("\"success\":true"))
|
|
153
|
+
XCTAssertThrowsError(try live.sendIncidentId(collidingIncident, apiBaseUrl: cloudBase)) { error in
|
|
154
|
+
XCTAssertEqual((error as? BluetoothSdkError)?.code, "incident_relay_busy")
|
|
155
|
+
}
|
|
156
|
+
try await receive(live, logcat, "owner-logcat")
|
|
157
|
+
|
|
158
|
+
try live.sendIncidentId(collidingIncident, apiBaseUrl: cloudBase)
|
|
159
|
+
try await receive(live, name, "second")
|
|
160
|
+
XCTAssertEqual(CloudStub.requests.last, "/api/client/reports/\(collidingIncident)/artifacts second")
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
func testStaleCallbackOfFinishedOwnerCannotConfirmCollidingReportsFile() async throws {
|
|
165
|
+
try await withCloud(status: 200) {
|
|
166
|
+
let live = IncidentLogTransport()
|
|
167
|
+
let name = "Brep_01m4hbvt88d"
|
|
168
|
+
let logcat = "Lrep_01m4hbvt88d"
|
|
169
|
+
try live.sendIncidentId(incident, apiBaseUrl: cloudBase)
|
|
170
|
+
let staleRelay = try XCTUnwrap(live.bleIncidentLogRelays[name])
|
|
171
|
+
try await receive(live, name, "owner")
|
|
172
|
+
try await receive(live, logcat, "owner-logcat")
|
|
173
|
+
try live.sendIncidentId(collidingIncident, apiBaseUrl: cloudBase)
|
|
174
|
+
let confirmationsBefore = sentMessages(live).filter { $0.contains("transfer_complete") }.count
|
|
175
|
+
let requestsBefore = CloudStub.requests.count
|
|
176
|
+
|
|
177
|
+
// A late callback of the first report's request arrives while the colliding report owns the name.
|
|
178
|
+
live.uploadBleIncidentLogRelay(relay: staleRelay, fileName: name, data: Data("late".utf8))
|
|
179
|
+
try await waitFor { CloudStub.requests.count == requestsBefore + 1 }
|
|
180
|
+
try await Task.sleep(nanoseconds: 300_000_000)
|
|
181
|
+
|
|
182
|
+
XCTAssertEqual(sentMessages(live).filter { $0.contains("transfer_complete") }.count, confirmationsBefore)
|
|
183
|
+
XCTAssertEqual(live.bleIncidentLogRelays[name]?.incidentId, collidingIncident)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
func testFailedCloudPostKeepsOwnerUntilOwnershipExpires() async throws {
|
|
188
|
+
try await withCloud(status: 500) {
|
|
189
|
+
let live = IncidentLogTransport()
|
|
190
|
+
var now: TimeInterval = 1000
|
|
191
|
+
live.incidentRelayClock = { now }
|
|
192
|
+
let name = "Brep_01m4hbvt88d"
|
|
193
|
+
try live.sendIncidentId(incident, apiBaseUrl: cloudBase)
|
|
194
|
+
live.uploadBleIncidentLogRelay(
|
|
195
|
+
relay: try XCTUnwrap(live.bleIncidentLogRelays[name]), fileName: name, data: Data("owner".utf8)
|
|
196
|
+
)
|
|
197
|
+
try await waitFor { wire(live).contains("transfer_complete") }
|
|
198
|
+
XCTAssertEqual(live.bleIncidentLogRelays[name]?.incidentId, incident)
|
|
199
|
+
XCTAssertThrowsError(try live.sendIncidentId(collidingIncident, apiBaseUrl: cloudBase)) { error in
|
|
200
|
+
XCTAssertEqual((error as? BluetoothSdkError)?.code, "incident_relay_busy")
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
now += MentraLive.incidentRelayOwnershipSeconds
|
|
204
|
+
try live.sendIncidentId(collidingIncident, apiBaseUrl: cloudBase)
|
|
205
|
+
XCTAssertEqual(live.bleIncidentLogRelays[name]?.incidentId, collidingIncident)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
func testDispatchFailureOfRefusedReportCannotReleaseOwner() throws {
|
|
210
|
+
try withToken("synthetic") {
|
|
211
|
+
let live = IncidentLogTransport()
|
|
212
|
+
try live.sendIncidentId(incident, apiBaseUrl: apiBase)
|
|
213
|
+
live.ready = false
|
|
214
|
+
XCTAssertThrowsError(try live.sendIncidentId(collidingIncident, apiBaseUrl: apiBase))
|
|
215
|
+
XCTAssertEqual(live.bleIncidentLogRelays["Brep_01m4hbvt88d"]?.incidentId, incident)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private let collidingIncident = "rep_01M4HBVT88DZZZZZZZZZZZZZZZ"
|
|
220
|
+
private let cloudBase = "https://cloud-stub.invalid"
|
|
221
|
+
|
|
222
|
+
/// Each message is wrapped as {"C":"<escaped json>"}; unescape so assertions read the message.
|
|
223
|
+
private func sentMessages(_ live: IncidentLogTransport) -> [String] {
|
|
224
|
+
live.writes.map { String(decoding: $0.0, as: UTF8.self).replacingOccurrences(of: "\\\"", with: "\"") }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private func wire(_ live: IncidentLogTransport) -> String {
|
|
228
|
+
sentMessages(live).joined()
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private func withCloud(status: Int, body: () async throws -> Void) async throws {
|
|
232
|
+
CloudStub.status = status
|
|
233
|
+
CloudStub.requests = []
|
|
234
|
+
URLProtocol.registerClass(CloudStub.self)
|
|
235
|
+
defer { URLProtocol.unregisterClass(CloudStub.self) }
|
|
236
|
+
let store = DeviceStore.shared.store
|
|
237
|
+
let saved = store.getCategory("bluetooth")["core_token"]
|
|
238
|
+
store.set("bluetooth", "core_token", "synthetic")
|
|
239
|
+
defer {
|
|
240
|
+
if let saved { store.set("bluetooth", "core_token", saved) }
|
|
241
|
+
else { store.remove("bluetooth", "core_token") }
|
|
242
|
+
}
|
|
243
|
+
try await body()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private func receive(_ live: IncidentLogTransport, _ name: String, _ payload: String) async throws {
|
|
247
|
+
let relay = try XCTUnwrap(live.bleIncidentLogRelays[name])
|
|
248
|
+
live.uploadBleIncidentLogRelay(relay: relay, fileName: name, data: Data(payload.utf8))
|
|
249
|
+
try await waitFor { live.bleIncidentLogRelays[name] !== relay }
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private func waitFor(_ condition: () -> Bool) async throws {
|
|
253
|
+
for _ in 0 ..< 500 where !condition() {
|
|
254
|
+
try await Task.sleep(nanoseconds: 10_000_000)
|
|
255
|
+
}
|
|
256
|
+
XCTAssertTrue(condition())
|
|
257
|
+
}
|
|
258
|
+
|
|
101
259
|
private func withToken<T>(_ value: String, body: () throws -> T) rethrows -> T {
|
|
102
260
|
let store = DeviceStore.shared.store
|
|
103
261
|
let saved = store.getCategory("bluetooth")["core_token"]
|
|
@@ -98,24 +98,18 @@ final class MentraLiveAudioSetupTests: XCTestCase {
|
|
|
98
98
|
try receive(transport, ["type": "classic_link", "a2dp": true, "hfp": false])
|
|
99
99
|
XCTAssertEqual(events.count, eventCount)
|
|
100
100
|
|
|
101
|
-
// Audio lost after connected:
|
|
101
|
+
// Audio lost after connected: this firmware reconnects its owner's audio itself, so
|
|
102
|
+
// the SDK keeps waiting and never asks the user to pair in Settings.
|
|
102
103
|
clock(1_060_000)
|
|
103
104
|
try receive(transport, ["type": "classic_link", "a2dp": false, "hfp": false])
|
|
104
105
|
XCTAssertEqual(audioSetup(store), .connecting)
|
|
105
|
-
clock(1_069_999)
|
|
106
|
-
try receive(transport, ["type": "classic_link", "a2dp": false, "hfp": false])
|
|
107
|
-
XCTAssertEqual(audioSetup(store), .connecting)
|
|
108
|
-
|
|
109
|
-
// The deadline timer gives up at the end of the wait.
|
|
110
|
-
clock(1_069_950)
|
|
111
|
-
try receive(transport, ["type": "classic_link", "a2dp": false, "hfp": false])
|
|
112
106
|
clock(1_070_000)
|
|
113
|
-
let deadline = Date().addingTimeInterval(2)
|
|
114
|
-
while
|
|
107
|
+
let deadline = Date().addingTimeInterval(0.2)
|
|
108
|
+
while Date() < deadline {
|
|
115
109
|
RunLoop.main.run(until: Date().addingTimeInterval(0.01))
|
|
116
110
|
}
|
|
117
|
-
XCTAssertEqual(audioSetup(store), .
|
|
118
|
-
XCTAssertEqual(events.last as NSDictionary?, ["state": "
|
|
111
|
+
XCTAssertEqual(audioSetup(store), .connecting)
|
|
112
|
+
XCTAssertEqual(events.last as NSDictionary?, ["state": "connecting"])
|
|
119
113
|
|
|
120
114
|
// The phone's own signals are enough on their own.
|
|
121
115
|
store.set("glasses", "bluetoothAudioRouted", true)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
@testable import MentraBluetoothSDK
|
|
2
|
+
import XCTest
|
|
3
|
+
|
|
4
|
+
@MainActor
|
|
5
|
+
final class MentraLiveCommandQueueTests: XCTestCase {
|
|
6
|
+
func testStaleGenerationRunIsDiscardedInOnePassAheadOfTheCurrentWrite() {
|
|
7
|
+
let queue = MentraLive.CommandQueue()
|
|
8
|
+
for (id, generation) in [("1", 1), ("2", 1), ("3", 2), ("4", 3), ("5", 3)] {
|
|
9
|
+
_ = queue.enqueue(write(id, generation: generation))
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let next = queue.dequeue(currentGeneration: 3)
|
|
13
|
+
XCTAssertEqual(next.command?.id, "4")
|
|
14
|
+
XCTAssertEqual(next.staleIds, ["1", "2", "3"])
|
|
15
|
+
|
|
16
|
+
let following = queue.dequeue(currentGeneration: 3)
|
|
17
|
+
XCTAssertEqual(following.command?.id, "5")
|
|
18
|
+
XCTAssertEqual(following.staleIds, [])
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func testQueueOfOnlyStaleWritesDrainsToEmpty() {
|
|
22
|
+
let queue = MentraLive.CommandQueue()
|
|
23
|
+
_ = queue.enqueue(write("1", generation: 1))
|
|
24
|
+
_ = queue.enqueue(write("2", generation: 2))
|
|
25
|
+
|
|
26
|
+
let next = queue.dequeue(currentGeneration: 3)
|
|
27
|
+
XCTAssertNil(next.command)
|
|
28
|
+
XCTAssertEqual(next.staleIds, ["1", "2"])
|
|
29
|
+
XCTAssertNil(queue.dequeue())
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private func write(_ id: String, generation: Int) -> MentraLive.PendingMessage {
|
|
33
|
+
MentraLive.PendingMessage(data: Data([1]), id: id, retries: 0, generation: generation)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -9,6 +9,10 @@ private final class SessionReadinessTransport: MentraLive {
|
|
|
9
9
|
override func sendJson(_ jsonOriginal: [String: Any], wakeUp: Bool, requireAck: Bool) {
|
|
10
10
|
commands.append(jsonOriginal)
|
|
11
11
|
}
|
|
12
|
+
|
|
13
|
+
func phoneReadyIds() -> [String] {
|
|
14
|
+
commands.filter { $0["type"] as? String == "phone_ready" }.compactMap { $0["readyId"] as? String }
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
@MainActor
|
|
@@ -107,11 +111,15 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
107
111
|
let saved = ["bluetooth", "glasses"].map { ($0, store.getCategory($0)) }
|
|
108
112
|
let previous = DeviceManager.shared.sgc
|
|
109
113
|
resetPairingState()
|
|
114
|
+
// The fixture models a live link. Pin phone Bluetooth on so the SDK does not tear the
|
|
115
|
+
// transport down when the host has no usable radio (CI runners report it unsupported).
|
|
116
|
+
BluetoothAvailability.shared.stateOverride = .poweredOn
|
|
110
117
|
let transport = SessionReadinessTransport()
|
|
111
118
|
let sdk = MentraBluetoothSDK()
|
|
112
119
|
DeviceManager.shared.sgc = transport
|
|
113
120
|
defer {
|
|
114
121
|
sdk.invalidate()
|
|
122
|
+
BluetoothAvailability.shared.stateOverride = nil
|
|
115
123
|
transport.cleanup()
|
|
116
124
|
DeviceManager.shared.sgc = previous
|
|
117
125
|
resetPairingState()
|
|
@@ -125,6 +133,30 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
125
133
|
try body(transport, sdk, store)
|
|
126
134
|
}
|
|
127
135
|
|
|
136
|
+
/// Transport-only state tests must not observe the host's real Bluetooth availability.
|
|
137
|
+
private func withStateTransport(
|
|
138
|
+
_ body: (SessionReadinessTransport, ObservableStore) throws -> Void
|
|
139
|
+
) rethrows {
|
|
140
|
+
let store = DeviceStore.shared.store
|
|
141
|
+
let saved = ["bluetooth", "glasses"].map { ($0, store.getCategory($0)) }
|
|
142
|
+
let previous = DeviceManager.shared.sgc
|
|
143
|
+
resetPairingState()
|
|
144
|
+
let transport = SessionReadinessTransport()
|
|
145
|
+
DeviceManager.shared.sgc = transport
|
|
146
|
+
defer {
|
|
147
|
+
transport.cleanup()
|
|
148
|
+
DeviceManager.shared.sgc = previous
|
|
149
|
+
resetPairingState()
|
|
150
|
+
for (category, values) in saved {
|
|
151
|
+
for key in store.getCategory(category).keys where values[key] == nil {
|
|
152
|
+
store.remove(category, key)
|
|
153
|
+
}
|
|
154
|
+
for (key, value) in values { store.set(category, key, value) }
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
try body(transport, store)
|
|
158
|
+
}
|
|
159
|
+
|
|
128
160
|
private func receive(_ transport: MentraLive, _ value: [String: Any]) throws {
|
|
129
161
|
try transport.processReceivedData(JSONSerialization.data(withJSONObject: value))
|
|
130
162
|
}
|
|
@@ -203,7 +235,7 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
203
235
|
}
|
|
204
236
|
|
|
205
237
|
func testFlagOffFirmwareEnteringPairingModeIsAPersistentRejection() throws {
|
|
206
|
-
try
|
|
238
|
+
try withStateTransport { transport, store in
|
|
207
239
|
var enteringEvents = 0
|
|
208
240
|
let sink = Bridge.addEventSink { event, _ in
|
|
209
241
|
if event == "entering_pairing_mode" { enteringEvents += 1 }
|
|
@@ -242,7 +274,7 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
242
274
|
}
|
|
243
275
|
|
|
244
276
|
func testPhoneHelloOnEverySecureSessionAndPairSelectOnlyOnAnExplicitAttempt() throws {
|
|
245
|
-
try
|
|
277
|
+
try withStateTransport { transport, store in
|
|
246
278
|
let securePairingInfo: [String: Any] = [
|
|
247
279
|
"type": "pairing_info", "secure_pairing_capable": true, "protocol_version": 4,
|
|
248
280
|
"had_previous_bond": true, "owner_committed": true, "auto_audio": true,
|
|
@@ -280,7 +312,7 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
280
312
|
}
|
|
281
313
|
|
|
282
314
|
func testLegacyFirmwareGetsNoPairingProtocolMessages() throws {
|
|
283
|
-
try
|
|
315
|
+
try withStateTransport { transport, store in
|
|
284
316
|
store.set("bluetooth", "mentra_live_secure_firmware", false)
|
|
285
317
|
store.set("bluetooth", "pending_device_name", "MENTRA_LIVE_BLE_ABCD")
|
|
286
318
|
try receive(transport, ["type": "pairing_info", "had_previous_bond": false])
|
|
@@ -291,7 +323,7 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
291
323
|
}
|
|
292
324
|
|
|
293
325
|
func testError14OnAnExplicitAttemptAsksToForgetThePairingWithItsCode() throws {
|
|
294
|
-
try
|
|
326
|
+
try withStateTransport { transport, store in
|
|
295
327
|
var failures: [[String: Any]] = []
|
|
296
328
|
let sink = Bridge.addEventSink { event, body in
|
|
297
329
|
if event == "pair_failure" { failures.append(body) }
|
|
@@ -339,7 +371,7 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
339
371
|
}
|
|
340
372
|
|
|
341
373
|
func testUnknownCapabilityWithoutPairingInfoIsReportedReadyAfterTheWait() throws {
|
|
342
|
-
try
|
|
374
|
+
try withStateTransport { transport, store in
|
|
343
375
|
transport.unknownCapabilityPairingInfoWaitMs = 50
|
|
344
376
|
startExplicitPair(store, capability: nil)
|
|
345
377
|
try receive(transport, ["type": "glasses_ready", "sid": "legacy"])
|
|
@@ -353,7 +385,7 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
353
385
|
}
|
|
354
386
|
|
|
355
387
|
func testUnknownCapabilityWithASecurePairingInfoFollowsTheSecureRule() throws {
|
|
356
|
-
try
|
|
388
|
+
try withStateTransport { transport, store in
|
|
357
389
|
var failures = 0
|
|
358
390
|
let sink = Bridge.addEventSink { event, _ in
|
|
359
391
|
if event == "pair_failure" { failures += 1 }
|
|
@@ -385,7 +417,7 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
385
417
|
}
|
|
386
418
|
|
|
387
419
|
func testUnknownCapabilityWithALegacyPairingInfoIsReadyAtOnce() throws {
|
|
388
|
-
try
|
|
420
|
+
try withStateTransport { transport, store in
|
|
389
421
|
startExplicitPair(store, capability: nil)
|
|
390
422
|
try receive(transport, ["type": "glasses_ready", "sid": "legacy"])
|
|
391
423
|
XCTAssertFalse(ready(store))
|
|
@@ -395,7 +427,7 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
395
427
|
}
|
|
396
428
|
|
|
397
429
|
func testTheSelectedRowDecidesTheSecureRuleNotTheSession() throws {
|
|
398
|
-
try
|
|
430
|
+
try withStateTransport { transport, store in
|
|
399
431
|
// The row listed legacy firmware: no owner-commit wait and no pair_select, even if
|
|
400
432
|
// the glasses then report secure firmware.
|
|
401
433
|
startExplicitPair(store, capability: false)
|
|
@@ -421,7 +453,7 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
421
453
|
}
|
|
422
454
|
|
|
423
455
|
func testAReadySessionWithoutPairingInfoClearsTheSecureFirmwareFlag() throws {
|
|
424
|
-
try
|
|
456
|
+
try withStateTransport { transport, store in
|
|
425
457
|
transport.secureFirmwareRefreshMs = 50
|
|
426
458
|
store.set("bluetooth", "mentra_live_secure_firmware", true)
|
|
427
459
|
store.set("glasses", "fullyBooted", false)
|
|
@@ -432,8 +464,20 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
432
464
|
}
|
|
433
465
|
}
|
|
434
466
|
|
|
467
|
+
func testDisconnectedSessionCancelsTheSecureFirmwareRefresh() throws {
|
|
468
|
+
try withStateTransport { transport, store in
|
|
469
|
+
transport.secureFirmwareRefreshMs = 50
|
|
470
|
+
store.set("bluetooth", "mentra_live_secure_firmware", true)
|
|
471
|
+
store.set("glasses", "fullyBooted", false)
|
|
472
|
+
try receive(transport, ["type": "glasses_ready", "sid": "disconnected"])
|
|
473
|
+
transport.cleanup()
|
|
474
|
+
RunLoop.main.run(until: Date().addingTimeInterval(0.1))
|
|
475
|
+
XCTAssertEqual(store.get("bluetooth", "mentra_live_secure_firmware") as? Bool, true)
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
435
479
|
func testASecurePairingInfoKeepsTheSecureFirmwareFlag() throws {
|
|
436
|
-
try
|
|
480
|
+
try withStateTransport { transport, store in
|
|
437
481
|
transport.secureFirmwareRefreshMs = 50
|
|
438
482
|
store.set("bluetooth", "mentra_live_secure_firmware", false)
|
|
439
483
|
store.set("glasses", "fullyBooted", false)
|
|
@@ -445,6 +489,131 @@ final class MentraLiveSessionReadinessTests: XCTestCase {
|
|
|
445
489
|
}
|
|
446
490
|
}
|
|
447
491
|
|
|
492
|
+
func testBufferedPhoneReadyCopiesAreOneExchangeWithOneInit() throws {
|
|
493
|
+
try withReadinessTransport { transport, receive, versionRequests in
|
|
494
|
+
// Two SOC-ready heartbeats while the glasses boot: one exchange, sent twice.
|
|
495
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
496
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
497
|
+
let readyIds = transport.phoneReadyIds()
|
|
498
|
+
XCTAssertEqual(readyIds.count, 2)
|
|
499
|
+
XCTAssertEqual(Set(readyIds).count, 1)
|
|
500
|
+
let readyId = try XCTUnwrap(readyIds.first)
|
|
501
|
+
|
|
502
|
+
// The glasses answer every buffered copy; only the first followed a reset.
|
|
503
|
+
for _ in 0 ..< 7 {
|
|
504
|
+
try receive(["type": "glasses_ready", "sid": "booted", "readyId": readyId])
|
|
505
|
+
}
|
|
506
|
+
XCTAssertEqual(versionRequests(), 1)
|
|
507
|
+
XCTAssertEqual(DeviceStore.shared.store.get("glasses", "fullyBooted") as? Bool, true)
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
func testRestartedGlassesProcessStartsANewExchangeAndIgnoresStaleAnswers() throws {
|
|
512
|
+
try withReadinessTransport { transport, receive, versionRequests in
|
|
513
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
514
|
+
let first = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
515
|
+
try receive(["type": "glasses_ready", "sid": "booted", "readyId": first])
|
|
516
|
+
|
|
517
|
+
// asg restarted under the live link: a new exchange, and the old one's answers no
|
|
518
|
+
// longer count even though the new process will reset for its own.
|
|
519
|
+
try receive(["type": "version_info_1", "sid": "restarted", "build_number": "302010073"])
|
|
520
|
+
let second = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
521
|
+
XCTAssertNotEqual(second, first)
|
|
522
|
+
try receive(["type": "glasses_ready", "sid": "booted", "readyId": first])
|
|
523
|
+
XCTAssertEqual(versionRequests(), 1)
|
|
524
|
+
|
|
525
|
+
try receive(["type": "glasses_ready", "sid": "restarted", "readyId": second])
|
|
526
|
+
XCTAssertEqual(versionRequests(), 2)
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
func testAnswerFromAnotherGlassesProcessIsHandledWithNoExchangePending() throws {
|
|
531
|
+
try withReadinessTransport { transport, receive, versionRequests in
|
|
532
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
533
|
+
let readyId = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
534
|
+
try receive(["type": "glasses_ready", "sid": "booted", "readyId": readyId])
|
|
535
|
+
|
|
536
|
+
// A different process reset its transport for this copy, so it is not a repeat.
|
|
537
|
+
try receive(["type": "glasses_ready", "sid": "restarted", "readyId": readyId])
|
|
538
|
+
XCTAssertEqual(versionRequests(), 2)
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
func testRestartedProcessAnsweringAnOlderCopyIsHandledAndThePendingExchangeStillCounts() throws {
|
|
543
|
+
try withReadinessTransport { transport, receive, versionRequests in
|
|
544
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
545
|
+
let first = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
546
|
+
try receive(["type": "glasses_ready", "sid": "booted", "readyId": first])
|
|
547
|
+
try receive(["type": "version_info_1", "sid": "restarted", "build_number": "302010073"])
|
|
548
|
+
let second = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
549
|
+
|
|
550
|
+
// The restarted process reset for a buffered copy of the old exchange, then resets
|
|
551
|
+
// again for the pending one: both answers follow a reset.
|
|
552
|
+
try receive(["type": "glasses_ready", "sid": "restarted", "readyId": first])
|
|
553
|
+
XCTAssertEqual(versionRequests(), 2)
|
|
554
|
+
try receive(["type": "glasses_ready", "sid": "restarted", "readyId": second])
|
|
555
|
+
XCTAssertEqual(versionRequests(), 3)
|
|
556
|
+
try receive(["type": "glasses_ready", "sid": "restarted", "readyId": second])
|
|
557
|
+
XCTAssertEqual(versionRequests(), 3)
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
func testReadinessExchangeEndsWithTheBleSession() throws {
|
|
562
|
+
try withReadinessTransport { transport, receive, _ in
|
|
563
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
564
|
+
let first = try XCTUnwrap(transport.phoneReadyIds().last)
|
|
565
|
+
transport.cleanup()
|
|
566
|
+
DeviceStore.shared.store.set("glasses", "fullyBooted", false)
|
|
567
|
+
|
|
568
|
+
try receive(["C": "sr_hrt", "B": ["ready": 1]])
|
|
569
|
+
XCTAssertNotEqual(try XCTUnwrap(transport.phoneReadyIds().last), first)
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
func testGlassesWithoutReadyIdKeepInitializingOnEveryAnswer() throws {
|
|
574
|
+
try withReadinessTransport { _, receive, versionRequests in
|
|
575
|
+
try receive(["type": "glasses_ready", "sid": "legacy"])
|
|
576
|
+
try receive(["type": "glasses_ready", "sid": "legacy"])
|
|
577
|
+
XCTAssertEqual(versionRequests(), 2)
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/// Runs `body` on a fresh transport whose glasses have not reported readiness yet.
|
|
582
|
+
private func withReadinessTransport(
|
|
583
|
+
_ body: (
|
|
584
|
+
SessionReadinessTransport,
|
|
585
|
+
([String: Any]) throws -> Void,
|
|
586
|
+
() -> Int
|
|
587
|
+
) throws -> Void
|
|
588
|
+
) throws {
|
|
589
|
+
let store = DeviceStore.shared.store
|
|
590
|
+
let saved = ["bluetooth", "glasses"].map { ($0, store.getCategory($0)) }
|
|
591
|
+
let previous = DeviceManager.shared.sgc
|
|
592
|
+
let transport = SessionReadinessTransport()
|
|
593
|
+
DeviceManager.shared.sgc = transport
|
|
594
|
+
defer {
|
|
595
|
+
transport.cleanup()
|
|
596
|
+
DeviceManager.shared.sgc = previous
|
|
597
|
+
for (category, values) in saved {
|
|
598
|
+
for key in store.getCategory(category).keys where values[key] == nil {
|
|
599
|
+
store.remove(category, key)
|
|
600
|
+
}
|
|
601
|
+
for (key, value) in values {
|
|
602
|
+
store.set(category, key, value)
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
store.set("glasses", "fullyBooted", false)
|
|
607
|
+
|
|
608
|
+
func receive(_ value: [String: Any]) throws {
|
|
609
|
+
try transport.processReceivedData(JSONSerialization.data(withJSONObject: value))
|
|
610
|
+
}
|
|
611
|
+
func versionRequests() -> Int {
|
|
612
|
+
transport.commands.filter { $0["type"] as? String == "request_version" }.count
|
|
613
|
+
}
|
|
614
|
+
try body(transport, receive, versionRequests)
|
|
615
|
+
}
|
|
616
|
+
|
|
448
617
|
func testInitialVersionChunkDoesNotStartAnExtraReadinessExchange() throws {
|
|
449
618
|
let store = DeviceStore.shared.store
|
|
450
619
|
let saved = store.getCategory("glasses")
|