@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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk
|
|
2
|
+
|
|
3
|
+
import kotlinx.coroutines.CompletableDeferred
|
|
4
|
+
import kotlinx.coroutines.async
|
|
5
|
+
import kotlinx.coroutines.runBlocking
|
|
6
|
+
import org.junit.Assert.assertEquals
|
|
7
|
+
import org.junit.Assert.assertTrue
|
|
8
|
+
import org.junit.Assert.fail
|
|
9
|
+
import org.junit.Test
|
|
10
|
+
|
|
11
|
+
class BesCrashReportWaitersTest {
|
|
12
|
+
private val keyA = "ML395018B-dump-0000002a-1f2e3d4c"
|
|
13
|
+
private val keyB = "ML395018B-reset-9f3a0c1b2d4e5f60"
|
|
14
|
+
|
|
15
|
+
private fun ack(key: String, reportId: String?, ok: Boolean, error: String? = null): Map<String, Any> =
|
|
16
|
+
buildMap {
|
|
17
|
+
put("type", "bes_crash_reported_ack")
|
|
18
|
+
put("incidentKey", key)
|
|
19
|
+
reportId?.let { put("reportId", it) }
|
|
20
|
+
put("ok", ok)
|
|
21
|
+
error?.let { put("error", it) }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private suspend fun expectCode(code: String, block: suspend () -> Unit): BluetoothSdkException {
|
|
25
|
+
try {
|
|
26
|
+
block()
|
|
27
|
+
} catch (error: BluetoothSdkException) {
|
|
28
|
+
assertEquals(code, error.code)
|
|
29
|
+
return error
|
|
30
|
+
}
|
|
31
|
+
fail("expected $code")
|
|
32
|
+
throw AssertionError()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Test fun `ack delivered during send resolves the call`() = runBlocking {
|
|
36
|
+
val waiters = BesCrashReportWaiters()
|
|
37
|
+
waiters.await(keyA, "rep_1", 1_000) { waiters.onAck(ack(keyA, "rep_1", ok = true)) }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Test fun `concurrent incidents settle only their own call`() = runBlocking {
|
|
41
|
+
val waiters = BesCrashReportWaiters()
|
|
42
|
+
val sentA = CompletableDeferred<Unit>()
|
|
43
|
+
val sentB = CompletableDeferred<Unit>()
|
|
44
|
+
val a = async { waiters.await(keyA, "rep_a", 2_000) { sentA.complete(Unit) } }
|
|
45
|
+
val b = async { runCatching { waiters.await(keyB, "rep_b", 300) { sentB.complete(Unit) } } }
|
|
46
|
+
sentA.await()
|
|
47
|
+
sentB.await()
|
|
48
|
+
assertEquals(1, waiters.onAck(ack(keyA, "rep_a", ok = true)))
|
|
49
|
+
a.await()
|
|
50
|
+
val bResult = b.await()
|
|
51
|
+
assertEquals("request_timeout", (bResult.exceptionOrNull() as BluetoothSdkException).code)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Test fun `ack for another reportId of the same incident is ignored`() = runBlocking {
|
|
55
|
+
val waiters = BesCrashReportWaiters()
|
|
56
|
+
expectCode("request_timeout") {
|
|
57
|
+
waiters.await(keyA, "rep_new", 200) {
|
|
58
|
+
assertEquals(0, waiters.onAck(ack(keyA, "rep_old", ok = true)))
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
Unit
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Test fun `ok false rejects with the glasses error`() = runBlocking {
|
|
65
|
+
val waiters = BesCrashReportWaiters()
|
|
66
|
+
val error = expectCode("bes_crash_report_rejected") {
|
|
67
|
+
waiters.await(keyA, "rep_1", 1_000) {
|
|
68
|
+
waiters.onAck(ack(keyA, "rep_1", ok = false, error = "unknown_incident"))
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
assertTrue(error.message!!.contains("unknown_incident"))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@Test fun `ok false without reportId rejects every call for that incident only`() = runBlocking {
|
|
75
|
+
val waiters = BesCrashReportWaiters()
|
|
76
|
+
val sent = CompletableDeferred<Unit>()
|
|
77
|
+
val other = async { runCatching { waiters.await(keyB, "rep_b", 300) { sent.complete(Unit) } } }
|
|
78
|
+
sent.await()
|
|
79
|
+
expectCode("bes_crash_report_rejected") {
|
|
80
|
+
waiters.await(keyA, "rep_1", 1_000) {
|
|
81
|
+
assertEquals(1, waiters.onAck(ack(keyA, null, ok = false, error = "unknown_incident")))
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
assertEquals("request_timeout", (other.await().exceptionOrNull() as BluetoothSdkException).code)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@Test fun `ok true without reportId does not resolve`() = runBlocking {
|
|
88
|
+
val waiters = BesCrashReportWaiters()
|
|
89
|
+
expectCode("request_timeout") {
|
|
90
|
+
waiters.await(keyA, "rep_1", 200) { assertEquals(0, waiters.onAck(ack(keyA, null, ok = true))) }
|
|
91
|
+
}
|
|
92
|
+
Unit
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@Test fun `disconnect rejects pending calls`() = runBlocking {
|
|
96
|
+
val waiters = BesCrashReportWaiters()
|
|
97
|
+
expectCode("glasses_not_connected") {
|
|
98
|
+
waiters.await(keyA, "rep_1", 5_000) {
|
|
99
|
+
waiters.rejectAll(BluetoothSdkException("glasses_not_connected", "disconnected"))
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
Unit
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Test fun `send failure propagates and leaves no waiter behind`() = runBlocking {
|
|
106
|
+
val waiters = BesCrashReportWaiters()
|
|
107
|
+
expectCode("glasses_not_connected") {
|
|
108
|
+
waiters.await(keyA, "rep_1", 1_000) { throw BluetoothSdkException("glasses_not_connected", "no link") }
|
|
109
|
+
}
|
|
110
|
+
assertEquals(0, waiters.onAck(ack(keyA, "rep_1", ok = true)))
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -48,18 +48,37 @@ class StreamRequestCaptureAudioTest {
|
|
|
48
48
|
))
|
|
49
49
|
assertThat(request.ice?.stun).isEqualTo("")
|
|
50
50
|
|
|
51
|
-
// The empty string is the host-only request.
|
|
52
|
-
// glasses gathering against
|
|
51
|
+
// The empty string is the host-only request. Replacing it with the default STUN server would
|
|
52
|
+
// leave the glasses gathering against it on an internet-less hotspot.
|
|
53
53
|
@Suppress("UNCHECKED_CAST")
|
|
54
54
|
val ice = request.toMap()["ice"] as Map<String, Any>
|
|
55
55
|
assertThat(ice).containsEntry("stun", "")
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
@Test
|
|
59
|
-
fun
|
|
59
|
+
fun whipWithoutIceSendsTheDefaultStunServer() {
|
|
60
60
|
val request = StreamRequest.fromMap(mapOf("streamUrl" to "https://example.com/whip"))
|
|
61
61
|
assertThat(request.ice).isNull()
|
|
62
|
-
|
|
62
|
+
@Suppress("UNCHECKED_CAST")
|
|
63
|
+
val ice = request.toMap()["ice"] as Map<String, Any>
|
|
64
|
+
assertThat(ice).containsEntry("stun", "stun:stun.cloudflare.com:3478")
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Test
|
|
68
|
+
fun whipKeepsTheStunServerItsCallerNamed() {
|
|
69
|
+
val request = StreamRequest.fromMap(mapOf(
|
|
70
|
+
"streamUrl" to "https://example.com/whip",
|
|
71
|
+
"ice" to mapOf("stun" to "stun:stun.example.com:3478"),
|
|
72
|
+
))
|
|
73
|
+
@Suppress("UNCHECKED_CAST")
|
|
74
|
+
val ice = request.toMap()["ice"] as Map<String, Any>
|
|
75
|
+
assertThat(ice).containsEntry("stun", "stun:stun.example.com:3478")
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Test
|
|
79
|
+
fun rtmpAndSrtSendNoIce() {
|
|
80
|
+
assertThat(StreamRequest(streamUrl = "rtmp://example.com/live").toMap()).doesNotContainKey("ice")
|
|
81
|
+
assertThat(StreamRequest(streamUrl = "srt://example.com:9000").toMap()).doesNotContainKey("ice")
|
|
63
82
|
}
|
|
64
83
|
|
|
65
84
|
@Test
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Assert.assertFalse
|
|
5
|
+
import org.junit.Assert.assertNull
|
|
6
|
+
import org.junit.Assert.assertTrue
|
|
7
|
+
import org.junit.Test
|
|
8
|
+
|
|
9
|
+
class Ipv4PrefixTest {
|
|
10
|
+
|
|
11
|
+
@Test
|
|
12
|
+
fun `contains the phone and the gateway on a 24`() {
|
|
13
|
+
val prefix = Ipv4Prefix("192.168.43.20", 24)
|
|
14
|
+
assertTrue(prefix.contains("192.168.43.1"))
|
|
15
|
+
assertTrue(prefix.contains("192.168.43.20"))
|
|
16
|
+
assertTrue(prefix.contains("192.168.43.255"))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The whole point: a cellular 10/8 address is RFC1918 and still the wrong interface. */
|
|
20
|
+
@Test
|
|
21
|
+
fun `rejects a private address on another interface`() {
|
|
22
|
+
val prefix = Ipv4Prefix("192.168.43.20", 24)
|
|
23
|
+
assertFalse(prefix.contains("10.171.36.4"))
|
|
24
|
+
assertFalse(prefix.contains("192.168.1.20"))
|
|
25
|
+
assertFalse(prefix.contains("172.16.0.1"))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** An OEM hotspot on another subnet must still pass, which is why /24 is never assumed. */
|
|
29
|
+
@Test
|
|
30
|
+
fun `honours the reported prefix length`() {
|
|
31
|
+
assertTrue(Ipv4Prefix("192.168.49.1", 16).contains("192.168.43.7"))
|
|
32
|
+
assertFalse(Ipv4Prefix("192.168.49.1", 24).contains("192.168.43.7"))
|
|
33
|
+
assertTrue(Ipv4Prefix("10.5.4.3", 8).contains("10.99.99.99"))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Test
|
|
37
|
+
fun `non-addresses are not addresses`() {
|
|
38
|
+
val prefix = Ipv4Prefix("192.168.43.20", 24)
|
|
39
|
+
assertFalse(prefix.contains(null))
|
|
40
|
+
assertFalse(prefix.contains("typ"))
|
|
41
|
+
assertFalse(prefix.contains("192.168.43"))
|
|
42
|
+
assertFalse(prefix.contains("192.168.43.256"))
|
|
43
|
+
assertFalse(prefix.contains("192.168.43.20.1"))
|
|
44
|
+
assertFalse(prefix.contains("a4f1c2d3.local"))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Test
|
|
48
|
+
fun `packs and prints`() {
|
|
49
|
+
assertEquals(0x0A000001, Ipv4Prefix.packIpv4("10.0.0.1"))
|
|
50
|
+
assertNull(Ipv4Prefix.packIpv4("not.an.ip.addr"))
|
|
51
|
+
assertEquals("192.168.43.20/24", Ipv4Prefix("192.168.43.20", 24).toString())
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** An unparseable own-address must match nothing rather than everything. */
|
|
55
|
+
@Test
|
|
56
|
+
fun `a malformed prefix contains nothing`() {
|
|
57
|
+
assertFalse(Ipv4Prefix("garbage", 24).contains("192.168.43.1"))
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import com.mentra.bluetoothsdk.hotspot.NetworkFacts.Iface
|
|
4
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The attribution helpers decide what the next SoftAP diagnosis says, so they are pinned rather
|
|
9
|
+
* than eyeballed in a log line.
|
|
10
|
+
*/
|
|
11
|
+
class NetworkFactsTest {
|
|
12
|
+
|
|
13
|
+
private fun iface(
|
|
14
|
+
name: String,
|
|
15
|
+
ipv4: List<String>,
|
|
16
|
+
up: Boolean = true,
|
|
17
|
+
loopback: Boolean = false,
|
|
18
|
+
) = Iface(name, 1, up, loopback, false, false, 1500, ipv4)
|
|
19
|
+
|
|
20
|
+
private val table =
|
|
21
|
+
listOf(
|
|
22
|
+
iface("lo", listOf("127.0.0.1/8"), loopback = true),
|
|
23
|
+
iface("wlan0", listOf("192.168.43.79/24")),
|
|
24
|
+
iface("rmnet_data0", listOf("10.48.51.202/30")),
|
|
25
|
+
iface("dummy0", emptyList()),
|
|
26
|
+
iface("epdg0", listOf("10.9.9.9/32"), up = false),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
@Test
|
|
30
|
+
fun `the owner of an address is the interface the table says carries it`() {
|
|
31
|
+
assertThat(NetworkFacts.ownerOf("192.168.43.79", table)).isEqualTo("wlan0")
|
|
32
|
+
assertThat(NetworkFacts.ownerOf("10.48.51.202", table)).isEqualTo("rmnet_data0")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** An address ICE gathered that is absent here means our two views of the network disagree. */
|
|
36
|
+
@Test
|
|
37
|
+
fun `an address the table has never seen has no owner`() {
|
|
38
|
+
assertThat(NetworkFacts.ownerOf("192.168.50.7", table)).isNull()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Test
|
|
42
|
+
fun `a prefix is not mistaken for the address`() {
|
|
43
|
+
assertThat(NetworkFacts.ownerOf("192.168.43.79/24", table)).isNull()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Test
|
|
47
|
+
fun `gatherable drops loopback, down, and addressless interfaces`() {
|
|
48
|
+
assertThat(NetworkFacts.gatherable(table).map { it.name })
|
|
49
|
+
.containsExactly("wlan0", "rmnet_data0")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Test
|
|
53
|
+
fun `render keeps the name, flags and every address`() {
|
|
54
|
+
val line = NetworkFacts.render(listOf(iface("wlan0", listOf("192.168.43.79/24", "10.1.2.3/24"))))
|
|
55
|
+
|
|
56
|
+
assertThat(line).contains("wlan0#1")
|
|
57
|
+
assertThat(line).contains("192.168.43.79/24,10.1.2.3/24")
|
|
58
|
+
}
|
|
59
|
+
}
|
package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedLocalNetworkPermissionTest.kt
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
4
|
+
import org.junit.Test
|
|
5
|
+
|
|
6
|
+
class ScopedLocalNetworkPermissionTest {
|
|
7
|
+
@Test
|
|
8
|
+
fun `Android 17 preserves implicit access for the SDK 36 host`() {
|
|
9
|
+
assertThat(ScopedSoftApNetwork.hasLocalNetworkPermission(37, 36) {
|
|
10
|
+
error("Legacy targets must not query the unneeded runtime grant")
|
|
11
|
+
}).isTrue()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@Test
|
|
15
|
+
fun `older Android does not query a permission it cannot enforce`() {
|
|
16
|
+
assertThat(ScopedSoftApNetwork.hasLocalNetworkPermission(36, 37) {
|
|
17
|
+
error("Older Android must not query the new permission")
|
|
18
|
+
}).isTrue()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Test
|
|
22
|
+
fun `Android 17 denies a target 37 host without the grant`() {
|
|
23
|
+
assertThat(ScopedSoftApNetwork.hasLocalNetworkPermission(37, 37) { false }).isFalse()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Test
|
|
27
|
+
fun `Android 17 allows a target 37 host with the grant`() {
|
|
28
|
+
assertThat(ScopedSoftApNetwork.hasLocalNetworkPermission(37, 37) { true }).isTrue()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Test
|
|
32
|
+
fun `future Android and target versions still enforce the grant`() {
|
|
33
|
+
assertThat(ScopedSoftApNetwork.hasLocalNetworkPermission(38, 38) { false }).isFalse()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import com.mentra.bluetoothsdk.hotspot.ScopedNetworkState.Failure
|
|
4
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class ScopedNetworkErrorTest {
|
|
8
|
+
|
|
9
|
+
@Test
|
|
10
|
+
fun `no failure maps to no error`() {
|
|
11
|
+
assertThat(ScopedNetworkError.from(Failure.NONE, "ssid")).isNull()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@Test
|
|
15
|
+
fun `each failure maps to its typed error and stable code`() {
|
|
16
|
+
assertThat(ScopedNetworkError.from(Failure.UNAVAILABLE, "ap"))
|
|
17
|
+
.isInstanceOf(ScopedNetworkError.Unavailable::class.java)
|
|
18
|
+
|
|
19
|
+
assertThat(ScopedNetworkError.from(Failure.LOST, "ap"))
|
|
20
|
+
.isInstanceOf(ScopedNetworkError.Lost::class.java)
|
|
21
|
+
|
|
22
|
+
assertThat(ScopedNetworkError.from(Failure.REQUEST_FAILED, "ap"))
|
|
23
|
+
.isInstanceOf(ScopedNetworkError.RequestFailed::class.java)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A denied permission must be its own error: otherwise it looks like a flaky hotspot. */
|
|
27
|
+
@Test
|
|
28
|
+
fun `permission denial is its own error`() {
|
|
29
|
+
val denied = ScopedNetworkError.from(Failure.PERMISSION_DENIED, "ap")
|
|
30
|
+
|
|
31
|
+
assertThat(denied).isInstanceOf(ScopedNetworkError.PermissionDenied::class.java)
|
|
32
|
+
assertThat(denied?.code).isEqualTo(ScopedNetworkError.CODE_PERMISSION_DENIED)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Test
|
|
36
|
+
fun `error codes are stable and unique`() {
|
|
37
|
+
val codes =
|
|
38
|
+
listOf(
|
|
39
|
+
ScopedNetworkError.CODE_PERMISSION_DENIED,
|
|
40
|
+
ScopedNetworkError.CODE_CANCELLED,
|
|
41
|
+
ScopedNetworkError.CODE_UNAVAILABLE,
|
|
42
|
+
ScopedNetworkError.CODE_LOST,
|
|
43
|
+
ScopedNetworkError.CODE_REQUEST_FAILED,
|
|
44
|
+
ScopedNetworkError.CODE_NO_LOCAL_ADDRESS,
|
|
45
|
+
ScopedNetworkError.CODE_NOT_READY,
|
|
46
|
+
ScopedNetworkError.CODE_WIFI_DISABLED,
|
|
47
|
+
ScopedNetworkError.CODE_VPN_ACTIVE,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
assertThat(codes).doesNotHaveDuplicates()
|
|
51
|
+
assertThat(codes).allMatch { it.startsWith("SOFTAP_") }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Test
|
|
55
|
+
fun `messages name the ssid so a log line is actionable`() {
|
|
56
|
+
assertThat(ScopedNetworkError.Cancelled("MentraLive-1234").message).contains("MentraLive-1234")
|
|
57
|
+
assertThat(ScopedNetworkError.Lost("MentraLive-1234").message).contains("MentraLive-1234")
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@Test
|
|
61
|
+
fun `a capturing vpn is named as the cause and tells the user what to change`() {
|
|
62
|
+
val error = ScopedNetworkError.VpnCapturesApp()
|
|
63
|
+
assertThat(error.code).isEqualTo(ScopedNetworkError.CODE_VPN_ACTIVE)
|
|
64
|
+
assertThat(error.message).contains("VPN").contains("split tunneling")
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* "Joined but not usable" has to be its own code. Reported as a join success it becomes an ICE
|
|
69
|
+
* answer with no candidates, which is the symptom several unrelated faults share.
|
|
70
|
+
*/
|
|
71
|
+
@Test
|
|
72
|
+
fun `a network that joined but never became usable names the missing source`() {
|
|
73
|
+
val error = ScopedNetworkError.NotReady("MentraLive-1234", "the kernel interface table")
|
|
74
|
+
|
|
75
|
+
assertThat(error.code).isEqualTo(ScopedNetworkError.CODE_NOT_READY)
|
|
76
|
+
assertThat(error.code).isNotEqualTo(ScopedNetworkError.CODE_NO_LOCAL_ADDRESS)
|
|
77
|
+
assertThat(error.message).contains("MentraLive-1234").contains("the kernel interface table")
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Test
|
|
81
|
+
fun `the local network permission name is the platform constant`() {
|
|
82
|
+
assertThat(ScopedNetworkError.LOCAL_NETWORK_PERMISSION)
|
|
83
|
+
.isEqualTo("android.permission.ACCESS_LOCAL_NETWORK")
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import com.mentra.bluetoothsdk.hotspot.ScopedNetworkState.Failure
|
|
4
|
+
import com.mentra.bluetoothsdk.hotspot.ScopedNetworkState.Phase
|
|
5
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
6
|
+
import org.junit.Test
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ConnectivityManager gives no ordering or at-most-once guarantee, so these cover the awkward
|
|
10
|
+
* orderings that would otherwise only show up on a device: duplicate callbacks, a callback from a
|
|
11
|
+
* request that was already replaced, and a timeout racing a late onAvailable.
|
|
12
|
+
*/
|
|
13
|
+
class ScopedNetworkLifecycleTest {
|
|
14
|
+
|
|
15
|
+
@Test
|
|
16
|
+
fun `starts idle`() {
|
|
17
|
+
val state = ScopedNetworkState()
|
|
18
|
+
assertThat(state.phase).isEqualTo(Phase.IDLE)
|
|
19
|
+
assertThat(state.failure).isEqualTo(Failure.NONE)
|
|
20
|
+
assertThat(state.isActive).isFalse()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Test
|
|
24
|
+
fun `happy path is idle to requesting to available`() {
|
|
25
|
+
val state = ScopedNetworkState()
|
|
26
|
+
val generation = state.startRequest()
|
|
27
|
+
assertThat(state.phase).isEqualTo(Phase.REQUESTING)
|
|
28
|
+
|
|
29
|
+
assertThat(state.onAvailable(generation)).isTrue()
|
|
30
|
+
assertThat(state.phase).isEqualTo(Phase.AVAILABLE)
|
|
31
|
+
assertThat(state.failure).isEqualTo(Failure.NONE)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Test
|
|
35
|
+
fun `a duplicate onAvailable does not re-transition`() {
|
|
36
|
+
val state = ScopedNetworkState()
|
|
37
|
+
val generation = state.startRequest()
|
|
38
|
+
|
|
39
|
+
assertThat(state.onAvailable(generation)).isTrue()
|
|
40
|
+
assertThat(state.onAvailable(generation)).isFalse()
|
|
41
|
+
assertThat(state.phase).isEqualTo(Phase.AVAILABLE)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Test
|
|
45
|
+
fun `losing an available network reports LOST`() {
|
|
46
|
+
val state = ScopedNetworkState()
|
|
47
|
+
val generation = state.startRequest()
|
|
48
|
+
state.onAvailable(generation)
|
|
49
|
+
|
|
50
|
+
assertThat(state.onLost(generation)).isTrue()
|
|
51
|
+
assertThat(state.phase).isEqualTo(Phase.LOST)
|
|
52
|
+
assertThat(state.failure).isEqualTo(Failure.LOST)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Test
|
|
56
|
+
fun `a second onLost is a no-op`() {
|
|
57
|
+
val state = ScopedNetworkState()
|
|
58
|
+
val generation = state.startRequest()
|
|
59
|
+
state.onAvailable(generation)
|
|
60
|
+
state.onLost(generation)
|
|
61
|
+
|
|
62
|
+
assertThat(state.onLost(generation)).isFalse()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Test
|
|
66
|
+
fun `onUnavailable fails as UNAVAILABLE`() {
|
|
67
|
+
val state = ScopedNetworkState()
|
|
68
|
+
val generation = state.startRequest()
|
|
69
|
+
|
|
70
|
+
assertThat(state.onUnavailable(generation)).isTrue()
|
|
71
|
+
assertThat(state.failure).isEqualTo(Failure.UNAVAILABLE)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@Test
|
|
75
|
+
fun `a SecurityException maps to PERMISSION_DENIED`() {
|
|
76
|
+
val state = ScopedNetworkState()
|
|
77
|
+
val generation = state.startRequest()
|
|
78
|
+
|
|
79
|
+
assertThat(state.onRequestFailed(generation, permissionDenied = true)).isTrue()
|
|
80
|
+
assertThat(state.failure).isEqualTo(Failure.PERMISSION_DENIED)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@Test
|
|
84
|
+
fun `any other request throw maps to REQUEST_FAILED`() {
|
|
85
|
+
val state = ScopedNetworkState()
|
|
86
|
+
val generation = state.startRequest()
|
|
87
|
+
|
|
88
|
+
assertThat(state.onRequestFailed(generation, permissionDenied = false)).isTrue()
|
|
89
|
+
assertThat(state.failure).isEqualTo(Failure.REQUEST_FAILED)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// -----------------------------------------------------------------
|
|
93
|
+
// Stale generations
|
|
94
|
+
// -----------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
@Test
|
|
97
|
+
fun `callbacks from a superseded request are rejected`() {
|
|
98
|
+
val state = ScopedNetworkState()
|
|
99
|
+
val first = state.startRequest()
|
|
100
|
+
val second = state.startRequest()
|
|
101
|
+
assertThat(second).isNotEqualTo(first)
|
|
102
|
+
|
|
103
|
+
assertThat(state.onAvailable(first)).isFalse()
|
|
104
|
+
assertThat(state.onLost(first)).isFalse()
|
|
105
|
+
assertThat(state.onUnavailable(first)).isFalse()
|
|
106
|
+
assertThat(state.phase).isEqualTo(Phase.REQUESTING)
|
|
107
|
+
|
|
108
|
+
assertThat(state.onAvailable(second)).isTrue()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@Test
|
|
112
|
+
fun `a late onLost after release does not resurrect state`() {
|
|
113
|
+
val state = ScopedNetworkState()
|
|
114
|
+
val generation = state.startRequest()
|
|
115
|
+
state.onAvailable(generation)
|
|
116
|
+
state.release()
|
|
117
|
+
|
|
118
|
+
assertThat(state.onLost(generation)).isFalse()
|
|
119
|
+
assertThat(state.failure).isEqualTo(Failure.NONE)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@Test
|
|
123
|
+
fun `release is idempotent`() {
|
|
124
|
+
val state = ScopedNetworkState()
|
|
125
|
+
val generation = state.startRequest()
|
|
126
|
+
state.onAvailable(generation)
|
|
127
|
+
|
|
128
|
+
assertThat(state.release()).isTrue()
|
|
129
|
+
assertThat(state.release()).isFalse()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@Test
|
|
133
|
+
fun `release from idle is a no-op`() {
|
|
134
|
+
assertThat(ScopedNetworkState().release()).isFalse()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@Test
|
|
138
|
+
fun `reset returns the machine to idle for reuse`() {
|
|
139
|
+
val state = ScopedNetworkState()
|
|
140
|
+
val generation = state.startRequest()
|
|
141
|
+
state.onLost(generation)
|
|
142
|
+
state.reset()
|
|
143
|
+
|
|
144
|
+
assertThat(state.phase).isEqualTo(Phase.IDLE)
|
|
145
|
+
assertThat(state.failure).isEqualTo(Failure.NONE)
|
|
146
|
+
|
|
147
|
+
val next = state.startRequest()
|
|
148
|
+
assertThat(state.onAvailable(next)).isTrue()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Ten start/stop cycles must leave no residue, matching the rejoin soak requirement. */
|
|
152
|
+
@Test
|
|
153
|
+
fun `ten join and release cycles end clean`() {
|
|
154
|
+
val state = ScopedNetworkState()
|
|
155
|
+
repeat(10) {
|
|
156
|
+
val generation = state.startRequest()
|
|
157
|
+
assertThat(state.onAvailable(generation)).isTrue()
|
|
158
|
+
assertThat(state.release()).isTrue()
|
|
159
|
+
state.reset()
|
|
160
|
+
assertThat(state.phase).isEqualTo(Phase.IDLE)
|
|
161
|
+
}
|
|
162
|
+
assertThat(state.generation).isEqualTo(10)
|
|
163
|
+
}
|
|
164
|
+
}
|