@mentra/bluetooth-sdk 3.3.0-dev.944 → 3.4.0-beta.1237
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 +61 -0
- package/README.md +111 -11
- package/android/build.gradle +60 -51
- package/android/gradle.properties +3 -0
- package/android/settings.gradle +47 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/BesCrashReportWaiters.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +5 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +89 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +35 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +159 -110
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +21 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +2 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +35 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/TouchGesture.kt +19 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/connection/ConnectionModels.kt +5 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicy.kt +64 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +1002 -157
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +227 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +19 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicy.kt +94 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachine.kt +411 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateStore.kt +124 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +54 -59
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +5 -32
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasEncoder.kt +8 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +3 -10
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +50 -0
- 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/DeviceManagerOwnerLossTest.kt +146 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusAudioSetupTest.kt +51 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusClassicAudioTest.kt +2 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/TouchGestureCommandTest.kt +112 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/WifiAdbPeerIntentTest.kt +19 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicyTest.kt +65 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveAudioSetupReadinessTest.kt +231 -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 +368 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +20 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicyTest.kt +136 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachineTest.kt +346 -0
- 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/utils/IncidentLogBleRelayNamingTest.kt +23 -0
- 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 +207 -2
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +45 -6
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +2 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/generated/changelogCatalog.d.ts +4 -1
- package/build/generated/changelogCatalog.d.ts.map +1 -1
- package/build/generated/changelogCatalog.js +5 -1
- package/build/generated/changelogCatalog.js.map +1 -1
- package/build/generated/releaseMetadata.js +6 -6
- 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 +10 -0
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +84 -12
- package/ios/MentraBluetoothSDK.podspec +4 -0
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
- package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
- package/ios/Source/BesCrashReportWaiters.swift +64 -0
- package/ios/Source/BluetoothSdkDefaults.swift +2 -2
- package/ios/Source/Bridge.swift +11 -3
- package/ios/Source/DeviceManager.swift +135 -18
- package/ios/Source/DeviceStore.swift +27 -0
- package/ios/Source/GeneratedChangelogCatalog.swift +2 -1
- package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
- package/ios/Source/MentraBluetoothSDK.swift +51 -5
- package/ios/Source/TouchGesture.swift +13 -0
- 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/errors/BluetoothSdkError.swift +5 -1
- package/ios/Source/events/BluetoothEvents.swift +45 -0
- package/ios/Source/internal/BleTraceLogger.swift +9 -6
- package/ios/Source/internal/BluetoothAvailability.swift +15 -5
- package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +186 -0
- package/ios/Source/sgcs/MentraLive.swift +1366 -212
- package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +260 -1
- package/ios/Source/sgcs/MentraLivePairingStateMachine.swift +385 -0
- package/ios/Source/sgcs/MentraLivePairingStateStore.swift +121 -0
- package/ios/Source/sgcs/Nimo.swift +10 -3
- package/ios/Source/sgcs/NimoCanvasCoordinator.swift +39 -9
- package/ios/Source/sgcs/SGCManager.swift +13 -0
- package/ios/Source/sgcs/Simulated.swift +2 -0
- package/ios/Source/status/DeviceStatus.swift +35 -0
- 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/types/DeviceModels.swift +8 -1
- package/ios/Source/utils/AudioSessionMonitor.swift +158 -5
- 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/BluetoothAudioRouteTests.swift +82 -0
- package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
- package/ios/Tests/DeviceManagerReconnectTests.swift +4 -2
- package/ios/Tests/GlassesAudioSetupPolicyTests.swift +197 -0
- package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
- package/ios/Tests/MentraLiveAudioSetupTests.swift +209 -0
- package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
- package/ios/Tests/MentraLiveConnectionOptionsTests.swift +55 -0
- package/ios/Tests/MentraLivePairingAdvertisementTests.swift +327 -0
- package/ios/Tests/MentraLivePairingStateMachineTests.swift +402 -0
- package/ios/Tests/MentraLiveSessionReadinessTests.swift +497 -26
- package/ios/Tests/NimoCanvasTransportTests.swift +58 -0
- package/ios/Tests/PcmStreamTests.swift +299 -0
- package/ios/Tests/SpeechActivityTests.swift +238 -0
- package/ios/Tests/SttModelTraitsTests.swift +62 -0
- package/ios/Tests/TouchGestureCommandTests.swift +87 -0
- package/ios/Tests/WifiAdbDispatchTests.swift +118 -0
- package/package.json +3 -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 +216 -1
- package/src/_private/BluetoothSdkModule.ts +49 -5
- package/src/generated/changelogCatalog.ts +5 -1
- package/src/generated/releaseMetadata.ts +6 -6
- package/src/index.ts +24 -0
- 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/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/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 -288
- /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
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import androidx.test.core.app.ApplicationProvider
|
|
5
|
+
import com.mentra.bluetoothsdk.sgcs.MentraLivePairingState
|
|
6
|
+
import com.mentra.bluetoothsdk.sgcs.MentraLivePairingStateMachine
|
|
7
|
+
import com.mentra.bluetoothsdk.sgcs.MentraLivePairingStateStore
|
|
8
|
+
import org.junit.After
|
|
9
|
+
import org.junit.Assert.assertEquals
|
|
10
|
+
import org.junit.Assert.assertFalse
|
|
11
|
+
import org.junit.Assert.assertTrue
|
|
12
|
+
import org.junit.Before
|
|
13
|
+
import org.junit.Test
|
|
14
|
+
import org.junit.runner.RunWith
|
|
15
|
+
import org.robolectric.RobolectricTestRunner
|
|
16
|
+
import org.robolectric.annotation.Config
|
|
17
|
+
import org.robolectric.annotation.LooperMode
|
|
18
|
+
|
|
19
|
+
@RunWith(RobolectricTestRunner::class)
|
|
20
|
+
@Config(sdk = [33])
|
|
21
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
22
|
+
class DeviceManagerOwnerLossTest {
|
|
23
|
+
private val device = "MENTRA_LIVE_BLE_ABCD"
|
|
24
|
+
private lateinit var savedBluetooth: Map<String, Any>
|
|
25
|
+
private lateinit var savedGlasses: Map<String, Any>
|
|
26
|
+
|
|
27
|
+
@Before fun setUp() {
|
|
28
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
29
|
+
savedBluetooth = DeviceStore.store.getCategory("bluetooth")
|
|
30
|
+
savedGlasses = DeviceStore.store.getCategory("glasses")
|
|
31
|
+
prefs().edit().clear().commit()
|
|
32
|
+
MentraLivePairingStateStore.resetForTest()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@After fun tearDown() {
|
|
36
|
+
MentraLivePairingStateStore.resetForTest()
|
|
37
|
+
prefs().edit().clear().commit()
|
|
38
|
+
restore("bluetooth", savedBluetooth)
|
|
39
|
+
restore("glasses", savedGlasses)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Test fun `forgetting glasses clears the saved secure firmware flag`() {
|
|
43
|
+
val manager = DeviceManager(initializeHardware = false)
|
|
44
|
+
try {
|
|
45
|
+
DeviceStore.set("bluetooth", "mentra_live_secure_firmware", true)
|
|
46
|
+
manager.clearSecureFirmware()
|
|
47
|
+
assertFalse(DeviceStore.store.get("bluetooth", "mentra_live_secure_firmware") as Boolean)
|
|
48
|
+
} finally {
|
|
49
|
+
manager.cleanup()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Test fun `bluetooth-on still reaches the manager while rejected so Pair Again stays possible`() {
|
|
54
|
+
val manager = DeviceManager(initializeHardware = false)
|
|
55
|
+
try {
|
|
56
|
+
DeviceStore.set("bluetooth", "default_wearable", "Mentra Live")
|
|
57
|
+
DeviceStore.set("bluetooth", "device_name", device)
|
|
58
|
+
rejectViaFlagOffNotice()
|
|
59
|
+
assertTrue(manager.shouldReconnectAfterBluetoothOn())
|
|
60
|
+
} finally {
|
|
61
|
+
manager.cleanup()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Test fun `a pause and its window id survive a process restart`() {
|
|
66
|
+
MentraLivePairingStateStore.ensureRestored(device)
|
|
67
|
+
val now = System.currentTimeMillis()
|
|
68
|
+
MentraLivePairingStateStore.update("test") {
|
|
69
|
+
it.onEnteringPairingMode(120_000L, 99, true, false, device, now)
|
|
70
|
+
}
|
|
71
|
+
assertTrue(MentraLivePairingStateStore.isPaused)
|
|
72
|
+
|
|
73
|
+
MentraLivePairingStateStore.resetForTest()
|
|
74
|
+
assertEquals(MentraLivePairingState.Normal, MentraLivePairingStateStore.state)
|
|
75
|
+
MentraLivePairingStateStore.ensureRestored(device)
|
|
76
|
+
|
|
77
|
+
val state = MentraLivePairingStateStore.state as MentraLivePairingState.PairingMode
|
|
78
|
+
assertEquals(99, state.windowId)
|
|
79
|
+
assertEquals(now + 150_000L, state.endsAtMs)
|
|
80
|
+
@Suppress("UNCHECKED_CAST")
|
|
81
|
+
val published = DeviceStore.store.get("glasses", "pairingState") as Map<String, Any>
|
|
82
|
+
assertEquals("pairing_mode", published["state"])
|
|
83
|
+
assertEquals(99, published["windowId"])
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Test fun `a rejection survives a restart and is not touched by the replayed owner-lost setting`() {
|
|
87
|
+
MentraLivePairingStateStore.ensureRestored(device)
|
|
88
|
+
rejectViaFlagOffNotice()
|
|
89
|
+
// The old app replays mentra_live_owner_lost=false; that must not clear the native state.
|
|
90
|
+
DeviceStore.set("bluetooth", "mentra_live_owner_lost", false)
|
|
91
|
+
MentraLivePairingStateStore.resetForTest()
|
|
92
|
+
MentraLivePairingStateStore.ensureRestored(device)
|
|
93
|
+
assertTrue(MentraLivePairingStateStore.isRejected)
|
|
94
|
+
assertFalse(MentraLivePairingStateStore.allowsAutomaticReconnect)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Test fun `forget clears pairing_rejected and the pre-v4 owner-lost setting`() {
|
|
98
|
+
val manager = DeviceManager(initializeHardware = false)
|
|
99
|
+
try {
|
|
100
|
+
MentraLivePairingStateStore.ensureRestored(device)
|
|
101
|
+
rejectViaFlagOffNotice()
|
|
102
|
+
DeviceStore.set("bluetooth", "mentra_live_owner_lost", true)
|
|
103
|
+
manager.clearPairingStateOnForget()
|
|
104
|
+
assertEquals(MentraLivePairingState.Normal, MentraLivePairingStateStore.state)
|
|
105
|
+
assertFalse(DeviceStore.store.get("bluetooth", "mentra_live_owner_lost") as Boolean)
|
|
106
|
+
MentraLivePairingStateStore.resetForTest()
|
|
107
|
+
MentraLivePairingStateStore.ensureRestored(device)
|
|
108
|
+
assertEquals(MentraLivePairingState.Normal, MentraLivePairingStateStore.state)
|
|
109
|
+
} finally {
|
|
110
|
+
manager.cleanup()
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@Test fun `rollback tolerance - legacy keys migrate and unknown keys are ignored`() {
|
|
115
|
+
prefs()
|
|
116
|
+
.edit()
|
|
117
|
+
.putString(MentraLivePairingStateMachine.LEGACY_REJECTION_PHASE_KEY, "inside")
|
|
118
|
+
.putLong("pairing_yield_until_wall_ms", System.currentTimeMillis() + 60_000L)
|
|
119
|
+
.putString("pairing_v9_unknown", "x")
|
|
120
|
+
.commit()
|
|
121
|
+
MentraLivePairingStateStore.ensureRestored(device)
|
|
122
|
+
assertTrue(MentraLivePairingStateStore.isRejected)
|
|
123
|
+
// Legacy keys are removed after migration so an older build cannot re-apply them.
|
|
124
|
+
assertFalse(prefs().contains(MentraLivePairingStateMachine.LEGACY_REJECTION_PHASE_KEY))
|
|
125
|
+
assertFalse(prefs().contains("pairing_yield_until_wall_ms"))
|
|
126
|
+
assertTrue(prefs().contains("pairing_v9_unknown"))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private fun rejectViaFlagOffNotice() {
|
|
130
|
+
MentraLivePairingStateStore.update("test") {
|
|
131
|
+
it.onEnteringPairingMode(120_000L, null, false, false, device, System.currentTimeMillis())
|
|
132
|
+
}
|
|
133
|
+
assertTrue(MentraLivePairingStateStore.isRejected)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private fun prefs() =
|
|
137
|
+
ApplicationProvider.getApplicationContext<Context>()
|
|
138
|
+
.getSharedPreferences("mentra_live_owner", Context.MODE_PRIVATE)
|
|
139
|
+
|
|
140
|
+
private fun restore(category: String, saved: Map<String, Any>) {
|
|
141
|
+
(DeviceStore.store.getCategory(category).keys - saved.keys).forEach {
|
|
142
|
+
DeviceStore.store.remove(category, it)
|
|
143
|
+
}
|
|
144
|
+
saved.forEach { (key, value) -> DeviceStore.set(category, key, value) }
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Assert.assertFalse
|
|
5
|
+
import org.junit.Assert.assertNull
|
|
6
|
+
import org.junit.Test
|
|
7
|
+
|
|
8
|
+
class GlassesStatusAudioSetupTest {
|
|
9
|
+
private val notApplicable = mapOf("state" to "not_applicable")
|
|
10
|
+
private val idle = mapOf("state" to "idle")
|
|
11
|
+
|
|
12
|
+
@Test
|
|
13
|
+
fun `a ready snapshot carries not_applicable`() {
|
|
14
|
+
val status = GlassesStatus.fromMap(mapOf("fullyBooted" to true, "connected" to true))
|
|
15
|
+
assertEquals(notApplicable, status.audioSetup)
|
|
16
|
+
assertEquals(notApplicable, status.toMap()["audioSetup"])
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Test
|
|
20
|
+
fun `a snapshot without a ready session carries idle`() {
|
|
21
|
+
assertEquals(idle, GlassesStatus.fromMap(mapOf("fullyBooted" to false)).toMap()["audioSetup"])
|
|
22
|
+
// Connected but not yet ready (for example parked for the owner commit) is still idle.
|
|
23
|
+
assertEquals(
|
|
24
|
+
idle,
|
|
25
|
+
GlassesStatus.fromMap(mapOf("fullyBooted" to false, "connected" to true)).toMap()["audioSetup"],
|
|
26
|
+
)
|
|
27
|
+
assertEquals(idle, GlassesStatus.fromMap(emptyMap()).toMap()["audioSetup"])
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Test
|
|
31
|
+
fun `audioSetup follows readiness, never a stored copy`() {
|
|
32
|
+
// Even if something wrote a stale value, the snapshot reports the readiness rule.
|
|
33
|
+
val status = GlassesStatus.fromMap(mapOf("fullyBooted" to true, "audioSetup" to idle))
|
|
34
|
+
assertEquals(notApplicable, status.toMap()["audioSetup"])
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test
|
|
38
|
+
fun `an update that marks the glasses ready carries not_applicable in the same update`() {
|
|
39
|
+
assertEquals(notApplicable, GlassesStatusUpdate(fullyBooted = true).toMap()["audioSetup"])
|
|
40
|
+
assertEquals(idle, GlassesStatusUpdate(fullyBooted = false).toMap()["audioSetup"])
|
|
41
|
+
assertFalse(GlassesStatusUpdate(batteryLevel = 50).toMap().containsKey("audioSetup"))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Test
|
|
45
|
+
fun `update maps keep only a known audio setup state`() {
|
|
46
|
+
val needsUser = mapOf("state" to "needs_user", "action" to "connect_in_settings")
|
|
47
|
+
assertEquals(needsUser, GlassesStatusUpdate.fromMap(mapOf("audioSetup" to needsUser)).audioSetup)
|
|
48
|
+
assertNull(GlassesStatusUpdate.fromMap(mapOf("audioSetup" to mapOf("state" to "bogus"))).audioSetup)
|
|
49
|
+
assertNull(GlassesStatusUpdate.fromMap(mapOf("audioSetup" to "connected")).audioSetup)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -10,5 +10,7 @@ class GlassesStatusClassicAudioTest {
|
|
|
10
10
|
GlassesStatus.fromMap(mapOf("bluetoothClassicConnected" to true)).toMap()
|
|
11
11
|
|
|
12
12
|
assertThat(serialized["bluetoothClassicConnected"]).isEqualTo(true)
|
|
13
|
+
assertThat(serialized["bluetoothClassicProfilesConnected"]).isEqualTo(true)
|
|
14
|
+
assertThat(serialized["bluetoothAudioRouted"]).isEqualTo(true)
|
|
13
15
|
}
|
|
14
16
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk
|
|
2
|
+
|
|
3
|
+
import androidx.test.core.app.ApplicationProvider
|
|
4
|
+
import com.mentra.bluetoothsdk.sgcs.G1PairingTest
|
|
5
|
+
import com.mentra.bluetoothsdk.sgcs.MentraLive
|
|
6
|
+
import java.util.concurrent.ConcurrentLinkedQueue
|
|
7
|
+
import com.mentra.bluetoothsdk.utils.K900ProtocolUtils
|
|
8
|
+
import com.mentra.bluetoothsdk.utils.K900LengthCodec
|
|
9
|
+
import org.robolectric.annotation.Implementation
|
|
10
|
+
import org.robolectric.annotation.Implements
|
|
11
|
+
import org.robolectric.shadow.api.Shadow
|
|
12
|
+
import org.robolectric.util.ReflectionHelpers.ClassParameter
|
|
13
|
+
import java.util.concurrent.atomic.AtomicLong
|
|
14
|
+
import org.json.JSONObject
|
|
15
|
+
import org.junit.Assert.*
|
|
16
|
+
import org.junit.Test
|
|
17
|
+
import org.junit.runner.RunWith
|
|
18
|
+
import org.robolectric.RobolectricTestRunner
|
|
19
|
+
import org.robolectric.annotation.Config
|
|
20
|
+
|
|
21
|
+
@RunWith(RobolectricTestRunner::class)
|
|
22
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class, TouchGestureCommandTest.ShadowK900Encoder::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
23
|
+
class TouchGestureCommandTest {
|
|
24
|
+
@Implements(K900ProtocolUtils::class)
|
|
25
|
+
class ShadowK900Encoder {
|
|
26
|
+
companion object {
|
|
27
|
+
var beforeEncode: (() -> Unit)? = null
|
|
28
|
+
@JvmStatic
|
|
29
|
+
@Implementation
|
|
30
|
+
fun packDataToK900(data: ByteArray, cmdType: Byte, endian: K900LengthCodec.Endian): ByteArray? {
|
|
31
|
+
beforeEncode?.invoke()
|
|
32
|
+
return Shadow.directlyOn(K900ProtocolUtils::class.java, "packDataToK900",
|
|
33
|
+
ClassParameter.from(ByteArray::class.java, data),
|
|
34
|
+
ClassParameter.from(Byte::class.javaPrimitiveType!!, cmdType),
|
|
35
|
+
ClassParameter.from(K900LengthCodec.Endian::class.java, endian))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Test
|
|
41
|
+
fun `disconnect during encoding cannot promote touch setting into next session`() {
|
|
42
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
43
|
+
val live = MentraLive()
|
|
44
|
+
val connection = MentraLive::class.java.getDeclaredField("isConnected").apply { isAccessible = true }
|
|
45
|
+
connection.setBoolean(live, true)
|
|
46
|
+
val queue = MentraLive::class.java.getDeclaredField("sendQueue").apply { isAccessible = true }
|
|
47
|
+
.get(live) as ConcurrentLinkedQueue<*>
|
|
48
|
+
val generation = MentraLive::class.java.getDeclaredField("bleSessionGeneration").apply { isAccessible = true }
|
|
49
|
+
.get(live) as AtomicLong
|
|
50
|
+
val admittedGeneration = generation.get()
|
|
51
|
+
val reset = MentraLive::class.java.getDeclaredMethod("resetPendingAckState").apply { isAccessible = true }
|
|
52
|
+
ShadowK900Encoder.beforeEncode = {
|
|
53
|
+
connection.setBoolean(live, false)
|
|
54
|
+
reset.invoke(live)
|
|
55
|
+
queue.clear()
|
|
56
|
+
connection.setBoolean(live, true)
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
live.sendTouchGestureDefaultBehaviorEnabled("old-session", TouchGesture.DOUBLE_TAP, false)
|
|
60
|
+
val queued = queue.poll()!!
|
|
61
|
+
val queuedGeneration = queued.javaClass.getDeclaredField("sessionGeneration").apply { isAccessible = true }.getLong(queued)
|
|
62
|
+
assertEquals(admittedGeneration, queuedGeneration)
|
|
63
|
+
assertNotEquals(generation.get(), queuedGeneration)
|
|
64
|
+
} finally { ShadowK900Encoder.beforeEncode = null }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Test
|
|
68
|
+
fun `each gesture serializes independently and acknowledgements retain typed event values`() {
|
|
69
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
70
|
+
val live = MentraLive()
|
|
71
|
+
val connection = MentraLive::class.java.getDeclaredField("isConnected").apply { isAccessible = true }
|
|
72
|
+
connection.setBoolean(live, true)
|
|
73
|
+
val queue = MentraLive::class.java.getDeclaredField("sendQueue").apply { isAccessible = true }
|
|
74
|
+
.get(live) as ConcurrentLinkedQueue<*>
|
|
75
|
+
val receive = MentraLive::class.java.getDeclaredMethod("processK900JsonMessage", JSONObject::class.java)
|
|
76
|
+
.apply { isAccessible = true }
|
|
77
|
+
val events = mutableListOf<Map<String, Any>>()
|
|
78
|
+
val sink = Bridge.addEventSink { name, values -> if (name == "settings_ack") events.add(values) }
|
|
79
|
+
try {
|
|
80
|
+
for (gesture in TouchGesture.entries) for (enabled in listOf(false, true)) {
|
|
81
|
+
live.sendTouchGestureDefaultBehaviorEnabled("request-${gesture.wireName}-$enabled", gesture, enabled)
|
|
82
|
+
val queued = queue.poll()!!
|
|
83
|
+
val bytes = queued.javaClass.getDeclaredField("data").apply { isAccessible = true }.get(queued) as ByteArray
|
|
84
|
+
assertEquals('#'.code.toByte(), bytes[0])
|
|
85
|
+
assertEquals('$'.code.toByte(), bytes.last())
|
|
86
|
+
val envelope = JSONObject(String(bytes, 5, bytes.size - 7, Charsets.UTF_8))
|
|
87
|
+
assertEquals("cs_tpdef", envelope.getString("C"))
|
|
88
|
+
val body = JSONObject(envelope.getString("B"))
|
|
89
|
+
assertEquals(gesture.wireName, body.getString("gesture"))
|
|
90
|
+
assertEquals(enabled, body.getBoolean("enabled"))
|
|
91
|
+
val ack = JSONObject().put("type", "settings_ack").put("setting", "touch_gesture_default")
|
|
92
|
+
.put("status", "applied").put("request_id", body.getString("request_id"))
|
|
93
|
+
.put("gesture", gesture.wireName).put("enabled", enabled)
|
|
94
|
+
receive.invoke(live, JSONObject().put("C", "sr_tpdef").put("B", if (enabled) ack.toString() else ack))
|
|
95
|
+
assertEquals(body.getString("request_id"), events.last()["requestId"])
|
|
96
|
+
assertEquals(enabled, events.last()["enabled"])
|
|
97
|
+
assertEquals(gesture.wireName, events.last()["gesture"])
|
|
98
|
+
}
|
|
99
|
+
assertEquals(16, events.size)
|
|
100
|
+
} finally { Bridge.removeEventSink(sink) }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@Test
|
|
104
|
+
fun `invalid gesture and disconnected radio reject before sending`() {
|
|
105
|
+
assertThrows(BluetoothSdkException::class.java) { TouchGesture.fromWireName("unknown") }
|
|
106
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
107
|
+
val live = MentraLive()
|
|
108
|
+
assertThrows(BluetoothSdkException::class.java) {
|
|
109
|
+
live.sendTouchGestureDefaultBehaviorEnabled("request", TouchGesture.DOUBLE_TAP, false)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk
|
|
2
|
+
|
|
3
|
+
import com.mentra.bluetoothsdk.sgcs.MentraLive
|
|
4
|
+
import org.junit.Assert.assertFalse
|
|
5
|
+
import org.junit.Assert.assertTrue
|
|
6
|
+
import org.junit.Test
|
|
7
|
+
|
|
8
|
+
class WifiAdbPeerIntentTest {
|
|
9
|
+
private val mac = "AA:BB:CC:DD:EE:01"
|
|
10
|
+
@Test fun onlyFullCurrentSessionIdentityCanAdmitACommand() {
|
|
11
|
+
assertTrue(MentraLive.wifiAdbPeerMatches(mac.lowercase(), 7L to mac, 7L, true))
|
|
12
|
+
assertFalse(MentraLive.wifiAdbPeerMatches(mac, 7L to "AA:BB:CC:DD:EE:02", 7L, true))
|
|
13
|
+
assertFalse(MentraLive.wifiAdbPeerMatches(mac, 6L to mac, 7L, true))
|
|
14
|
+
assertFalse(MentraLive.wifiAdbPeerMatches(mac, null, 7L, true))
|
|
15
|
+
assertFalse(MentraLive.wifiAdbPeerMatches(mac, 7L to mac, 7L, false))
|
|
16
|
+
assertFalse(MentraLive.wifiAdbPeerMatches("EE:01", 7L to mac, 7L, true))
|
|
17
|
+
assertFalse(MentraLive.wifiAdbPeerMatches(" " + mac, 7L to mac, 7L, true))
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import org.json.JSONObject
|
|
4
|
+
import org.junit.Assert.assertEquals
|
|
5
|
+
import org.junit.Assert.assertNull
|
|
6
|
+
import org.junit.Test
|
|
7
|
+
|
|
8
|
+
class GlassesAudioSetupPolicyTest {
|
|
9
|
+
@Test
|
|
10
|
+
fun `android needs no user step on any model - not_applicable when ready, idle otherwise`() {
|
|
11
|
+
assertEquals(GlassesAudioSetupState.NOT_APPLICABLE, GlassesAudioSetupPolicy.state(ready = true))
|
|
12
|
+
assertEquals(GlassesAudioSetupState.IDLE, GlassesAudioSetupPolicy.state(ready = false))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Test
|
|
16
|
+
fun `states encode as the shared map shape`() {
|
|
17
|
+
assertEquals(mapOf("state" to "idle"), GlassesAudioSetupState.IDLE.toMap())
|
|
18
|
+
assertEquals(mapOf("state" to "not_applicable"), GlassesAudioSetupState.NOT_APPLICABLE.toMap())
|
|
19
|
+
assertEquals(mapOf("state" to "connecting"), GlassesAudioSetupState.CONNECTING.toMap())
|
|
20
|
+
assertEquals(mapOf("state" to "connected"), GlassesAudioSetupState.CONNECTED.toMap())
|
|
21
|
+
assertEquals(
|
|
22
|
+
mapOf("state" to "needs_user", "action" to "connect_in_settings"),
|
|
23
|
+
GlassesAudioSetupState.NEEDS_USER.toMap(),
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Test
|
|
28
|
+
fun `every state round-trips and unknown values are rejected`() {
|
|
29
|
+
for (state in GlassesAudioSetupState.values()) {
|
|
30
|
+
assertEquals(state, GlassesAudioSetupState.fromMap(state.toMap()))
|
|
31
|
+
}
|
|
32
|
+
assertNull(GlassesAudioSetupState.fromMap(mapOf("state" to "paired")))
|
|
33
|
+
assertNull(GlassesAudioSetupState.fromMap(mapOf("action" to "connect_in_settings")))
|
|
34
|
+
assertNull(GlassesAudioSetupState.fromMap("not_applicable"))
|
|
35
|
+
assertNull(GlassesAudioSetupState.fromMap(null))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Test
|
|
39
|
+
fun `audio_setup_changed fires only when readiness changes the state`() {
|
|
40
|
+
assertEquals(GlassesAudioSetupState.NOT_APPLICABLE, GlassesAudioSetupPolicy.change(wasReady = false, ready = true))
|
|
41
|
+
assertEquals(GlassesAudioSetupState.IDLE, GlassesAudioSetupPolicy.change(wasReady = true, ready = false))
|
|
42
|
+
assertNull(GlassesAudioSetupPolicy.change(wasReady = true, ready = true))
|
|
43
|
+
assertNull(GlassesAudioSetupPolicy.change(wasReady = false, ready = false))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Test
|
|
47
|
+
fun `classic_link reads both links and tolerates missing or odd fields`() {
|
|
48
|
+
assertEquals(
|
|
49
|
+
MentraLiveClassicLink(a2dp = true, hfp = false),
|
|
50
|
+
MentraLiveClassicLink.parse(JSONObject("""{"type":"classic_link","a2dp":true,"hfp":false}""")),
|
|
51
|
+
)
|
|
52
|
+
assertEquals(
|
|
53
|
+
MentraLiveClassicLink(a2dp = false, hfp = true),
|
|
54
|
+
MentraLiveClassicLink.parse(JSONObject("""{"type":"classic_link","a2dp":false,"hfp":true}""")),
|
|
55
|
+
)
|
|
56
|
+
assertEquals(
|
|
57
|
+
MentraLiveClassicLink(a2dp = false, hfp = false),
|
|
58
|
+
MentraLiveClassicLink.parse(JSONObject("""{"type":"classic_link"}""")),
|
|
59
|
+
)
|
|
60
|
+
assertEquals(
|
|
61
|
+
MentraLiveClassicLink(a2dp = false, hfp = false),
|
|
62
|
+
MentraLiveClassicLink.parse(JSONObject("""{"type":"classic_link","a2dp":"up","hfp":null}""")),
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
}
|