@mentra/bluetooth-sdk 3.2.1 → 3.3.0-beta.1000
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -6
- package/android/build.gradle +15 -0
- package/android/lc3Lib/build.gradle +6 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkAnalytics.kt +63 -14
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkAnalyticsTracker.kt +55 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +1 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkInstallId.kt +23 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +6 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkUpdateCheck.kt +184 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkUsageTracker.kt +388 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +9 -1
- 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 +231 -36
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt +24 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/NetworkDiagnostics.kt +25 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/TouchGesture.kt +19 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/debug/BleTraceLogger.kt +3 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTracker.kt +4 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioServiceDiscovery.kt +70 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1TextSanitizer.kt +11 -32
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/LatinTextSanitizer.kt +39 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +160 -20
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCodec.kt +3 -1
- package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkAnalyticsTrackerTest.kt +58 -3
- package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkUpdateCheckTest.kt +124 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkUsageTrackerTest.kt +263 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/NetworkDiagnosticsTest.kt +55 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/ScanCompletionTest.kt +5 -1
- package/android/src/test/java/com/mentra/bluetoothsdk/TouchGestureCommandTest.kt +112 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/debug/BleTraceLoggerTest.kt +69 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioServiceDiscoveryTest.kt +124 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G1TextSanitizerTest.kt +29 -4
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveClassicDisconnectTest.kt +133 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +137 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +126 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveWifiCredentialLogTest.kt +55 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCodecTest.kt +20 -7
- package/build/BluetoothSdk.types.d.ts +9 -1
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +2 -1
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +2 -1
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/_private/MentraLocalNetworkModule.d.ts +23 -0
- package/build/_private/MentraLocalNetworkModule.d.ts.map +1 -1
- package/build/_private/MentraLocalNetworkModule.js.map +1 -1
- package/build/_private/nativeLogConsole.d.ts +19 -0
- package/build/_private/nativeLogConsole.d.ts.map +1 -1
- package/build/_private/nativeLogConsole.js +12 -0
- package/build/_private/nativeLogConsole.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 +1 -0
- package/build/index.js.map +1 -1
- package/build/ota-transport/index.d.ts +4 -0
- package/build/ota-transport/index.d.ts.map +1 -1
- package/build/ota-transport/index.js +2 -0
- package/build/ota-transport/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +16 -4
- package/ios/Source/BluetoothSdkDefaults.swift +2 -2
- package/ios/Source/DeviceManager.swift +10 -3
- package/ios/Source/GeneratedChangelogCatalog.swift +2 -1
- package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
- package/ios/Source/MentraBluetoothSDK.swift +306 -54
- package/ios/Source/TouchGesture.swift +13 -0
- package/ios/Source/events/BluetoothEvents.swift +4 -0
- package/ios/Source/internal/BluetoothAvailability.swift +6 -0
- package/ios/Source/internal/BluetoothSdkAnalytics.swift +87 -13
- package/ios/Source/internal/BluetoothSdkAnalyticsTracker.swift +54 -1
- package/ios/Source/internal/BluetoothSdkInstallId.swift +21 -0
- package/ios/Source/internal/BluetoothSdkUpdateCheck.swift +223 -0
- package/ios/Source/internal/BluetoothSdkUsageTracker.swift +428 -0
- package/ios/Source/sgcs/MentraLive.swift +167 -64
- package/ios/Source/sgcs/NimoCanvasCodec.swift +4 -1
- package/ios/Source/sgcs/SGCManager.swift +1 -1
- package/ios/Source/utils/AudioSessionMonitor.swift +44 -8
- package/ios/Source/utils/G1Text.swift +2 -24
- package/ios/Source/utils/G1TextSanitizer.swift +27 -0
- package/ios/Source/utils/LatinTextSanitizer.swift +48 -0
- package/ios/Tests/BluetoothAudioRouteTests.swift +26 -0
- package/ios/Tests/BluetoothSdkAnalyticsTrackerTests.swift +54 -3
- package/ios/Tests/BluetoothSdkUpdateCheckTests.swift +153 -0
- package/ios/Tests/BluetoothSdkUsageTrackerTests.swift +296 -0
- package/ios/Tests/G1TextSanitizerTests.swift +32 -0
- package/ios/Tests/IncidentLogDispatchTests.swift +111 -0
- package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
- package/ios/Tests/MentraLiveSessionReadinessTests.swift +292 -0
- package/ios/Tests/NimoCanvasCodecTests.swift +17 -4
- package/ios/Tests/TouchGestureCommandTests.swift +87 -0
- package/ios/Tests/VersionInfoCommandTests.swift +142 -1
- package/ios/Tests/WifiCredentialLoggingTests.swift +42 -0
- package/package.json +2 -2
- package/src/BluetoothSdk.types.ts +16 -0
- package/src/_private/BluetoothSdkModule.ts +4 -1
- package/src/_private/MentraLocalNetworkModule.ts +28 -0
- package/src/_private/nativeLogConsole.ts +19 -0
- package/src/generated/changelogCatalog.ts +5 -1
- package/src/generated/releaseMetadata.ts +6 -6
- package/src/index.ts +2 -0
- package/src/ota-transport/index.ts +10 -1
package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioServiceDiscoveryTest.kt
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothAdapter
|
|
4
|
+
import android.bluetooth.BluetoothDevice
|
|
5
|
+
import android.os.Handler
|
|
6
|
+
import android.os.Looper
|
|
7
|
+
import android.os.ParcelUuid
|
|
8
|
+
import java.time.Duration
|
|
9
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
10
|
+
import org.junit.Test
|
|
11
|
+
import org.junit.runner.RunWith
|
|
12
|
+
import org.robolectric.RobolectricTestRunner
|
|
13
|
+
import org.robolectric.Shadows.shadowOf
|
|
14
|
+
import org.robolectric.annotation.Config
|
|
15
|
+
import org.robolectric.annotation.LooperMode
|
|
16
|
+
|
|
17
|
+
@RunWith(RobolectricTestRunner::class)
|
|
18
|
+
@Config(sdk = [33])
|
|
19
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
20
|
+
class ClassicAudioServiceDiscoveryTest {
|
|
21
|
+
private val target = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("AA:BB:CC:DD:EE:FF")
|
|
22
|
+
private val sink = ParcelUuid.fromString("0000110b-0000-1000-8000-00805f9b34fb")
|
|
23
|
+
private val zero = ParcelUuid.fromString("00000000-0000-0000-0000-000000000000")
|
|
24
|
+
private val messages = mutableListOf<String>()
|
|
25
|
+
private val discovery = ClassicAudioServiceDiscovery(Handler(Looper.getMainLooper()), 30000, messages::add)
|
|
26
|
+
private var connects = 0
|
|
27
|
+
|
|
28
|
+
private fun request(device: BluetoothDevice = target) {
|
|
29
|
+
discovery.connectWhenDiscovered(device) { connects++ }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Test fun `bonded Samsung zero UUID inventory waits for real Audio Sink discovery`() {
|
|
33
|
+
shadowOf(target).setBondState(BluetoothDevice.BOND_BONDED)
|
|
34
|
+
shadowOf(target).setUuids(arrayOf(zero))
|
|
35
|
+
shadowOf(target).setFetchUuidsWithSdpResult(true)
|
|
36
|
+
request()
|
|
37
|
+
assertThat(connects).isZero()
|
|
38
|
+
assertThat(shadowOf(target).fetchUuidsWithSdpCount).isEqualTo(1)
|
|
39
|
+
shadowOf(target).setUuids(arrayOf(sink))
|
|
40
|
+
discovery.onUuids(target)
|
|
41
|
+
discovery.onUuids(target)
|
|
42
|
+
assertThat(connects).isEqualTo(1)
|
|
43
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(30))
|
|
44
|
+
assertThat(messages.none { it.contains("timed out") }).isTrue()
|
|
45
|
+
assertThat(target.bondState).isEqualTo(BluetoothDevice.BOND_BONDED)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Test fun `valid cached Audio Sink needs no refresh`() {
|
|
49
|
+
shadowOf(target).setUuids(arrayOf(sink))
|
|
50
|
+
request()
|
|
51
|
+
assertThat(connects).isEqualTo(1)
|
|
52
|
+
assertThat(shadowOf(target).fetchUuidsWithSdpCount).isZero()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Test fun `early empty UUID broadcast preserves the wait for the actual SDP result`() {
|
|
56
|
+
shadowOf(target).setUuids(arrayOf(zero))
|
|
57
|
+
shadowOf(target).setFetchUuidsWithSdpResult(true)
|
|
58
|
+
request()
|
|
59
|
+
discovery.onUuids(target)
|
|
60
|
+
assertThat(connects).isZero()
|
|
61
|
+
shadowOf(target).setUuids(arrayOf(sink))
|
|
62
|
+
discovery.onUuids(target)
|
|
63
|
+
assertThat(connects).isEqualTo(1)
|
|
64
|
+
assertThat(shadowOf(target).fetchUuidsWithSdpCount).isEqualTo(1)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Test fun `unrelated device and duplicate requests cannot complete or multiply discovery`() {
|
|
68
|
+
shadowOf(target).setFetchUuidsWithSdpResult(true)
|
|
69
|
+
request()
|
|
70
|
+
request()
|
|
71
|
+
val other = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("11:22:33:44:55:66")
|
|
72
|
+
shadowOf(other).setUuids(arrayOf(sink))
|
|
73
|
+
discovery.onUuids(other)
|
|
74
|
+
assertThat(connects).isZero()
|
|
75
|
+
assertThat(shadowOf(target).fetchUuidsWithSdpCount).isEqualTo(1)
|
|
76
|
+
shadowOf(target).setUuids(arrayOf(sink))
|
|
77
|
+
discovery.onUuids(target)
|
|
78
|
+
assertThat(connects).isEqualTo(1)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@Test fun `rejected SDP request does not connect on a later unsolicited event`() {
|
|
82
|
+
shadowOf(target).setFetchUuidsWithSdpResult(false)
|
|
83
|
+
request()
|
|
84
|
+
shadowOf(target).setUuids(arrayOf(sink))
|
|
85
|
+
discovery.onUuids(target)
|
|
86
|
+
assertThat(connects).isZero()
|
|
87
|
+
assertThat(messages.last()).contains("rejected")
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Test fun `missing UUID broadcast times out without connecting on a late event`() {
|
|
91
|
+
shadowOf(target).setFetchUuidsWithSdpResult(true)
|
|
92
|
+
request()
|
|
93
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(20))
|
|
94
|
+
discovery.onUuids(target)
|
|
95
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(10))
|
|
96
|
+
shadowOf(target).setUuids(arrayOf(sink))
|
|
97
|
+
discovery.onUuids(target)
|
|
98
|
+
assertThat(connects).isZero()
|
|
99
|
+
assertThat(messages.last()).contains("timed out")
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@Test fun `teardown cancellation invalidates callback and removes its timeout`() {
|
|
103
|
+
shadowOf(target).setFetchUuidsWithSdpResult(true)
|
|
104
|
+
request()
|
|
105
|
+
discovery.cancel()
|
|
106
|
+
shadowOf(target).setUuids(arrayOf(sink))
|
|
107
|
+
discovery.onUuids(target)
|
|
108
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(30))
|
|
109
|
+
assertThat(connects).isZero()
|
|
110
|
+
assertThat(messages.none { it.contains("timed out") }).isTrue()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@Test fun `previous session timeout cannot cancel rediscovery for the same glasses`() {
|
|
114
|
+
shadowOf(target).setFetchUuidsWithSdpResult(true)
|
|
115
|
+
request()
|
|
116
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(20))
|
|
117
|
+
discovery.cancel()
|
|
118
|
+
request()
|
|
119
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(10))
|
|
120
|
+
shadowOf(target).setUuids(arrayOf(sink))
|
|
121
|
+
discovery.onUuids(target)
|
|
122
|
+
assertThat(connects).isEqualTo(1)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -8,19 +8,19 @@ class G1TextSanitizerTest {
|
|
|
8
8
|
@Test
|
|
9
9
|
fun `strips Vietnamese diacritics unsupported by G1`() {
|
|
10
10
|
assertThat(sanitizeG1DisplayText("Tiếng Việt: Đặng, Nguyễn, phở bò"))
|
|
11
|
-
.isEqualTo("Tieng Viet: Dang, Nguyen, pho
|
|
11
|
+
.isEqualTo("Tieng Viet: Dang, Nguyen, pho bò")
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
@Test
|
|
15
15
|
fun `handles decomposed marks and preserves layout`() {
|
|
16
16
|
assertThat(sanitizeG1DisplayText("Cafe\u0301\nĐa Nang"))
|
|
17
|
-
.isEqualTo("
|
|
17
|
+
.isEqualTo("Café\nDa Nang")
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
@Test
|
|
21
|
-
fun `
|
|
21
|
+
fun `preserves mapped letters and expands only unmapped letters`() {
|
|
22
22
|
assertThat(sanitizeG1DisplayText("Øresund Łódź Æsir Œuvre Straße Ðingvellir Þingvellir"))
|
|
23
|
-
.isEqualTo("
|
|
23
|
+
.isEqualTo("Øresund Łódź Æsir OEuvre Straße Ðingvellir Þingvellir")
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
@Test
|
|
@@ -28,4 +28,29 @@ class G1TextSanitizerTest {
|
|
|
28
28
|
assertThat(sanitizeG1DisplayText("Hello, world! 123"))
|
|
29
29
|
.isEqualTo("Hello, world! 123")
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
@Test
|
|
33
|
+
fun `preserves Swedish accents case punctuation and spacing`() {
|
|
34
|
+
assertThat(sanitizeG1DisplayText("“Hallå, hallå”\nÅÄÖ åäö"))
|
|
35
|
+
.isEqualTo("“Hallå, hallå”\nÅÄÖ åäö")
|
|
36
|
+
assertThat(sanitizeG1DisplayText("Halla\u030A, halla\u030A"))
|
|
37
|
+
.isEqualTo("Hallå, hallå")
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Test
|
|
41
|
+
fun `preserves other scripts and is idempotent`() {
|
|
42
|
+
val otherScripts = "が カ\u3099 한\u302E Α\u0301 مُرَحَّبًا शि ❤️"
|
|
43
|
+
assertThat(sanitizeG1DisplayText(otherScripts)).isEqualTo(otherScripts)
|
|
44
|
+
val normalized = sanitizeG1DisplayText("Hallå Łódź Đặng Œuvre")
|
|
45
|
+
assertThat(normalized).isEqualTo("Hallå Łódź Dang OEuvre")
|
|
46
|
+
assertThat(sanitizeG1DisplayText(normalized)).isEqualTo(normalized)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Test
|
|
50
|
+
fun `preserves every embedded extended Latin glyph in composed and decomposed forms`() {
|
|
51
|
+
val glyphs = "ÀÂÇÈÉÊËÎÏÔÙÛÜàçèéêëîïôùûüÿŸÄäÖößẞâÁáÍíÑñúÓóÚⁱIJijŠšŽžÃÅÆÌÐÒÕØÝÞãåæìðòõøýþĄąĆćČčĎďĘęĚěĞğŁłŃńŇňŘřŚśŞşŤťŮůŹźŻżĂăıȘșȚțǖǘǚǜǎǐǒǔŐőŰű"
|
|
52
|
+
assertThat(sanitizeG1DisplayText(glyphs)).isEqualTo(glyphs)
|
|
53
|
+
val decomposed = java.text.Normalizer.normalize(glyphs, java.text.Normalizer.Form.NFD)
|
|
54
|
+
assertThat(sanitizeG1DisplayText(decomposed)).isEqualTo(glyphs)
|
|
55
|
+
}
|
|
31
56
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothA2dp
|
|
4
|
+
import android.bluetooth.BluetoothAdapter
|
|
5
|
+
import android.bluetooth.BluetoothDevice
|
|
6
|
+
import android.bluetooth.BluetoothGatt
|
|
7
|
+
import android.bluetooth.BluetoothHeadset
|
|
8
|
+
import android.bluetooth.BluetoothProfile
|
|
9
|
+
import android.os.Looper
|
|
10
|
+
import androidx.test.core.app.ApplicationProvider
|
|
11
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
12
|
+
import com.mentra.bluetoothsdk.DeviceStore
|
|
13
|
+
import java.time.Duration
|
|
14
|
+
import org.junit.Assert.assertEquals
|
|
15
|
+
import org.junit.Assert.assertNull
|
|
16
|
+
import org.junit.Before
|
|
17
|
+
import org.junit.Test
|
|
18
|
+
import org.junit.runner.RunWith
|
|
19
|
+
import org.robolectric.RobolectricTestRunner
|
|
20
|
+
import org.robolectric.Shadows.shadowOf
|
|
21
|
+
import org.robolectric.annotation.Config
|
|
22
|
+
import org.robolectric.annotation.Implementation
|
|
23
|
+
import org.robolectric.annotation.Implements
|
|
24
|
+
import org.robolectric.annotation.LooperMode
|
|
25
|
+
import org.robolectric.shadow.api.Shadow
|
|
26
|
+
import org.robolectric.shadows.ShadowBluetoothA2dp
|
|
27
|
+
import org.robolectric.shadows.ShadowBluetoothHeadset
|
|
28
|
+
import org.robolectric.util.ReflectionHelpers
|
|
29
|
+
|
|
30
|
+
@RunWith(RobolectricTestRunner::class)
|
|
31
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class,
|
|
32
|
+
MentraLiveClassicDisconnectTest.RecordingA2dp::class,
|
|
33
|
+
MentraLiveClassicDisconnectTest.RecordingHeadset::class],
|
|
34
|
+
instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
35
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
36
|
+
class MentraLiveClassicDisconnectTest {
|
|
37
|
+
private val adapter = BluetoothAdapter.getDefaultAdapter()
|
|
38
|
+
private val target = adapter.getRemoteDevice("AA:BB:CC:DD:EE:FF")
|
|
39
|
+
private val other = adapter.getRemoteDevice("11:22:33:44:55:66")
|
|
40
|
+
private val a2dp = Shadow.newInstanceOf(BluetoothA2dp::class.java)
|
|
41
|
+
private val headset = Shadow.newInstanceOf(BluetoothHeadset::class.java)
|
|
42
|
+
private val audio: RecordingA2dp = Shadow.extract(a2dp)
|
|
43
|
+
private val handsfree: RecordingHeadset = Shadow.extract(headset)
|
|
44
|
+
|
|
45
|
+
@Before fun setup() {
|
|
46
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
47
|
+
shadowOf(adapter).setState(BluetoothAdapter.STATE_ON)
|
|
48
|
+
shadowOf(target).setName("MENTRA_LIVE_TEST")
|
|
49
|
+
shadowOf(target).setBondState(BluetoothDevice.BOND_BONDED)
|
|
50
|
+
DeviceStore.set("bluetooth", "device_name", "MENTRA_LIVE_TEST")
|
|
51
|
+
DeviceStore.set("bluetooth", "device_address", target.address)
|
|
52
|
+
DeviceStore.set("bluetooth", "pending_device_name", "MENTRA_LIVE_TEST")
|
|
53
|
+
DeviceStore.set("bluetooth", "pending_device_address", target.address)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Test fun `BLE loss followed by explicit disconnect releases both Classic profiles and keeps bond`() {
|
|
57
|
+
assertDisconnect(dropBle = true)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@Test fun `explicit disconnect with BLE still connected releases both Classic profiles`() {
|
|
61
|
+
assertDisconnect(dropBle = false)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private fun assertDisconnect(dropBle: Boolean) {
|
|
65
|
+
val live = MentraLive()
|
|
66
|
+
try {
|
|
67
|
+
live.connectById("MENTRA_LIVE_TEST")
|
|
68
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
69
|
+
shadowOf(target).simulateGattConnectionChange(BluetoothGatt.GATT_SUCCESS, BluetoothProfile.STATE_CONNECTED)
|
|
70
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
71
|
+
if (dropBle) {
|
|
72
|
+
shadowOf(target).simulateGattConnectionChange(BluetoothGatt.GATT_SUCCESS, BluetoothProfile.STATE_DISCONNECTED)
|
|
73
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
74
|
+
assertNull(ReflectionHelpers.getField<BluetoothDevice?>(live, "connectedDevice"))
|
|
75
|
+
}
|
|
76
|
+
installConnectedProfiles()
|
|
77
|
+
live.disconnect()
|
|
78
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
79
|
+
assertEquals(listOf(target), audio.disconnected)
|
|
80
|
+
assertEquals(listOf(target), handsfree.disconnected)
|
|
81
|
+
assertEquals(BluetoothProfile.STATE_CONNECTED, a2dp.getConnectionState(other))
|
|
82
|
+
assertEquals(BluetoothProfile.STATE_CONNECTED, headset.getConnectionState(other))
|
|
83
|
+
assertEquals(BluetoothDevice.BOND_BONDED, target.bondState)
|
|
84
|
+
} finally {
|
|
85
|
+
live.destroy()
|
|
86
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(2))
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Test fun `a manager with no connection session does not disconnect an unrelated bonded device`() {
|
|
91
|
+
val live = MentraLive()
|
|
92
|
+
try {
|
|
93
|
+
installConnectedProfiles()
|
|
94
|
+
live.disconnect()
|
|
95
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
96
|
+
assertEquals(emptyList<BluetoothDevice>(), audio.disconnected)
|
|
97
|
+
assertEquals(emptyList<BluetoothDevice>(), handsfree.disconnected)
|
|
98
|
+
} finally {
|
|
99
|
+
live.destroy()
|
|
100
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(2))
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private fun installConnectedProfiles() {
|
|
105
|
+
for (device in listOf(target, other)) {
|
|
106
|
+
audio.addDevice(device, BluetoothProfile.STATE_CONNECTED)
|
|
107
|
+
handsfree.addDevice(device, BluetoothProfile.STATE_CONNECTED)
|
|
108
|
+
}
|
|
109
|
+
shadowOf(adapter).setProfileProxy(BluetoothProfile.A2DP, a2dp)
|
|
110
|
+
shadowOf(adapter).setProfileProxy(BluetoothProfile.HEADSET, headset)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The real MentraLive lifecycle runs; only Android's audio profile services are simulated.
|
|
114
|
+
@Implements(BluetoothA2dp::class)
|
|
115
|
+
class RecordingA2dp : ShadowBluetoothA2dp() {
|
|
116
|
+
val disconnected = mutableListOf<BluetoothDevice>()
|
|
117
|
+
@Implementation fun disconnect(device: BluetoothDevice): Boolean {
|
|
118
|
+
disconnected.add(device)
|
|
119
|
+
removeDevice(device)
|
|
120
|
+
return true
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@Implements(BluetoothHeadset::class)
|
|
125
|
+
class RecordingHeadset : ShadowBluetoothHeadset() {
|
|
126
|
+
val disconnected = mutableListOf<BluetoothDevice>()
|
|
127
|
+
@Implementation fun disconnect(device: BluetoothDevice): Boolean {
|
|
128
|
+
disconnected.add(device)
|
|
129
|
+
removeDevice(device)
|
|
130
|
+
return true
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.os.Looper
|
|
4
|
+
import androidx.test.core.app.ApplicationProvider
|
|
5
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
6
|
+
import com.mentra.bluetoothsdk.utils.ConnTypes
|
|
7
|
+
import java.time.Duration
|
|
8
|
+
import org.json.JSONObject
|
|
9
|
+
import org.junit.Assert.assertEquals
|
|
10
|
+
import org.junit.Assert.assertNotEquals
|
|
11
|
+
import org.junit.Assert.assertNotNull
|
|
12
|
+
import org.junit.Test
|
|
13
|
+
import org.junit.runner.RunWith
|
|
14
|
+
import org.robolectric.RobolectricTestRunner
|
|
15
|
+
import org.robolectric.Shadows.shadowOf
|
|
16
|
+
import org.robolectric.annotation.Config
|
|
17
|
+
import org.robolectric.annotation.LooperMode
|
|
18
|
+
|
|
19
|
+
@RunWith(RobolectricTestRunner::class)
|
|
20
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
21
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
22
|
+
class MentraLiveGlassesReadyBurstTest {
|
|
23
|
+
@Test fun `buffered phone_ready copies are one exchange with one init`() = withLive { live, inits ->
|
|
24
|
+
// Two SOC-ready heartbeats while the glasses boot: one exchange, sent twice.
|
|
25
|
+
receive(live, socReady())
|
|
26
|
+
val readyId = pendingReadyId(live)
|
|
27
|
+
receive(live, socReady())
|
|
28
|
+
assertEquals(readyId, pendingReadyId(live))
|
|
29
|
+
|
|
30
|
+
// The glasses answer every buffered copy; only the first followed a reset.
|
|
31
|
+
repeat(7) { receive(live, glassesReady("booted", readyId)) }
|
|
32
|
+
assertEquals(1, inits())
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Test fun `answers to a superseded exchange are ignored until the pending one arrives`() = withLive { live, inits ->
|
|
36
|
+
receive(live, socReady())
|
|
37
|
+
val first = pendingReadyId(live)
|
|
38
|
+
receive(live, glassesReady("booted", first))
|
|
39
|
+
invoke(live, "sendPhoneReady", "readiness re-run")
|
|
40
|
+
val second = pendingReadyId(live)
|
|
41
|
+
|
|
42
|
+
// The same process already reset for the first exchange; the pending one is still to come.
|
|
43
|
+
receive(live, glassesReady("booted", first))
|
|
44
|
+
assertEquals(1, inits())
|
|
45
|
+
receive(live, glassesReady("booted", second))
|
|
46
|
+
assertEquals(2, inits())
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Test fun `an answer from another glasses process is handled with no exchange pending`() = withLive { live, inits ->
|
|
50
|
+
receive(live, socReady())
|
|
51
|
+
val readyId = pendingReadyId(live)
|
|
52
|
+
receive(live, glassesReady("booted", readyId))
|
|
53
|
+
|
|
54
|
+
// A restarted process reset its transport for this copy, so it is not a repeat.
|
|
55
|
+
receive(live, glassesReady("restarted", readyId))
|
|
56
|
+
assertEquals(2, inits())
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Test fun `a restarted process answering an older copy is handled and the pending exchange still counts`() = withLive { live, inits ->
|
|
60
|
+
receive(live, socReady())
|
|
61
|
+
val first = pendingReadyId(live)
|
|
62
|
+
receive(live, glassesReady("booted", first))
|
|
63
|
+
invoke(live, "sendPhoneReady", "glasses session changed")
|
|
64
|
+
val second = pendingReadyId(live)
|
|
65
|
+
|
|
66
|
+
// The restarted process reset for a buffered copy of the old exchange, then resets
|
|
67
|
+
// again for the pending one: both answers follow a reset.
|
|
68
|
+
receive(live, glassesReady("restarted", first))
|
|
69
|
+
assertEquals(2, inits())
|
|
70
|
+
receive(live, glassesReady("restarted", second))
|
|
71
|
+
assertEquals(3, inits())
|
|
72
|
+
receive(live, glassesReady("restarted", second))
|
|
73
|
+
assertEquals(3, inits())
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Test fun `the readiness exchange ends with the BLE session`() = withLive { live, _ ->
|
|
77
|
+
receive(live, socReady())
|
|
78
|
+
val first = pendingReadyId(live)
|
|
79
|
+
invoke(live, "updateConnectionState", ConnTypes.DISCONNECTED)
|
|
80
|
+
|
|
81
|
+
receive(live, socReady())
|
|
82
|
+
assertNotEquals(first, pendingReadyId(live))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Test fun `glasses without readyId keep initializing on every answer`() = withLive { live, inits ->
|
|
86
|
+
receive(live, glassesReady("legacy", null))
|
|
87
|
+
receive(live, glassesReady("legacy", null))
|
|
88
|
+
assertEquals(2, inits())
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Runs `body` on a fresh MentraLive, counting SOC inits (one version request each). */
|
|
92
|
+
private fun withLive(body: (MentraLive, () -> Int) -> Unit) {
|
|
93
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
94
|
+
val live = MentraLive()
|
|
95
|
+
var inits = 0
|
|
96
|
+
val sink = Bridge.addEventSink { type, event ->
|
|
97
|
+
if (type == "log" && event["message"].toString().contains("Requesting version info from ASG client")) {
|
|
98
|
+
inits++
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
body(live) { inits }
|
|
103
|
+
} finally {
|
|
104
|
+
Bridge.removeEventSink(sink)
|
|
105
|
+
live.destroy()
|
|
106
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(2))
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private fun socReady() = JSONObject().put("C", "sr_hrt").put("B", JSONObject().put("ready", 1))
|
|
111
|
+
|
|
112
|
+
private fun glassesReady(sid: String, readyId: String?) = JSONObject().apply {
|
|
113
|
+
put("type", "glasses_ready")
|
|
114
|
+
put("sid", sid)
|
|
115
|
+
if (readyId != null) put("readyId", readyId)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private fun pendingReadyId(live: MentraLive): String {
|
|
119
|
+
val readyId = MentraLive::class.java.getDeclaredField("pendingReadyId")
|
|
120
|
+
.apply { isAccessible = true }
|
|
121
|
+
.get(live) as String?
|
|
122
|
+
assertNotNull("SOC ready should start a readiness exchange", readyId)
|
|
123
|
+
return readyId!!
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private fun receive(live: MentraLive, json: JSONObject) {
|
|
127
|
+
MentraLive::class.java.getDeclaredMethod("processJsonMessage", JSONObject::class.java)
|
|
128
|
+
.apply { isAccessible = true }
|
|
129
|
+
.invoke(live, json)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private fun invoke(live: MentraLive, name: String, argument: String) {
|
|
133
|
+
MentraLive::class.java.getDeclaredMethod(name, String::class.java)
|
|
134
|
+
.apply { isAccessible = true }
|
|
135
|
+
.invoke(live, argument)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothAdapter
|
|
4
|
+
import android.bluetooth.BluetoothGattCallback
|
|
5
|
+
import android.bluetooth.BluetoothGattCharacteristic
|
|
6
|
+
import android.os.Looper
|
|
7
|
+
import androidx.test.core.app.ApplicationProvider
|
|
8
|
+
import com.mentra.bluetoothsdk.BluetoothSdkException
|
|
9
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
10
|
+
import com.mentra.bluetoothsdk.DeviceStore
|
|
11
|
+
import java.nio.charset.StandardCharsets
|
|
12
|
+
import java.time.Duration
|
|
13
|
+
import java.util.UUID
|
|
14
|
+
import java.util.concurrent.atomic.AtomicLong
|
|
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.Shadows.shadowOf
|
|
20
|
+
import org.robolectric.annotation.Config
|
|
21
|
+
import org.robolectric.annotation.LooperMode
|
|
22
|
+
import org.robolectric.shadows.ShadowLog
|
|
23
|
+
|
|
24
|
+
@RunWith(RobolectricTestRunner::class)
|
|
25
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
26
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
27
|
+
class MentraLiveIncidentDispatchTest {
|
|
28
|
+
private val incident = "rep_01M4HBVT88DFSN8TYNZ1WTV4PB"
|
|
29
|
+
private val apiBase = "https://core.dev.us-west-2.mentraglass.com"
|
|
30
|
+
|
|
31
|
+
@Test fun `missing native BLE link rejects even when cached status is connected`() = withLive { live ->
|
|
32
|
+
DeviceStore.set("glasses", "connected", true)
|
|
33
|
+
expectCode("glasses_not_connected") { live.sendIncidentId(incident, apiBase) }
|
|
34
|
+
assertTrue(queuedWrites(live).isEmpty())
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test fun `missing current token does not fall back to old stored credentials`() = withLive { live ->
|
|
38
|
+
ready(live)
|
|
39
|
+
DeviceStore.set("bluetooth", "core_token", "")
|
|
40
|
+
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
|
|
41
|
+
val prefs = context.getSharedPreferences("augmentos_auth_prefs", android.content.Context.MODE_PRIVATE)
|
|
42
|
+
prefs.edit().putString("core_token", "stale-synthetic-token").commit()
|
|
43
|
+
expectCode("core_token_unavailable") { live.sendIncidentId(incident, apiBase) }
|
|
44
|
+
assertTrue(queuedWrites(live).isEmpty())
|
|
45
|
+
prefs.edit().remove("core_token").commit()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Test fun `current token is queued before upload and never logged`() = withLive { live ->
|
|
49
|
+
ready(live)
|
|
50
|
+
val token = "synthetic-${UUID.randomUUID()}"
|
|
51
|
+
DeviceStore.set("bluetooth", "core_token", token)
|
|
52
|
+
ShadowLog.clear()
|
|
53
|
+
live.sendIncidentId(incident, apiBase)
|
|
54
|
+
val writes = queuedWrites(live)
|
|
55
|
+
val wire = writes.joinToString("") { String(it, StandardCharsets.UTF_8) }
|
|
56
|
+
assertEquals(2, writes.size)
|
|
57
|
+
assertTrue(wire.indexOf("auth_token") < wire.indexOf("upload_incident_logs"))
|
|
58
|
+
assertTrue(wire.contains(token))
|
|
59
|
+
assertTrue(wire.contains(incident))
|
|
60
|
+
assertFalse("token logged", ShadowLog.getLogs().any { it.msg.contains(token) })
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Test fun `link losing TX characteristic rejects instead of retaining incident relay`() = withLive { live ->
|
|
64
|
+
ready(live)
|
|
65
|
+
DeviceStore.set("bluetooth", "core_token", "synthetic")
|
|
66
|
+
set(live, "txCharacteristic", null)
|
|
67
|
+
expectCode("glasses_not_connected") { live.sendIncidentId(incident, apiBase) }
|
|
68
|
+
assertTrue(queuedWrites(live).isEmpty())
|
|
69
|
+
val relays = get(live, "bleIncidentLogRelays") as Map<*, *>
|
|
70
|
+
assertTrue(relays.isEmpty())
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Test fun `session loss during token serialization cannot queue an upload into the next session`() = withLive { live ->
|
|
74
|
+
ready(live)
|
|
75
|
+
DeviceStore.set("bluetooth", "core_token", "synthetic-token")
|
|
76
|
+
val generation = get(live, "bleSessionGeneration") as AtomicLong
|
|
77
|
+
val sink = Bridge.addEventSink { type, body ->
|
|
78
|
+
if (type == "log" && body["message"].toString().contains("<auth_token with credentials omitted>")) {
|
|
79
|
+
generation.incrementAndGet()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
expectCode("incident_dispatch_failed") { live.sendIncidentId(incident, apiBase) }
|
|
84
|
+
val wire = queuedWrites(live).joinToString("") { String(it, StandardCharsets.UTF_8) }
|
|
85
|
+
assertFalse(wire.contains("upload_incident_logs"))
|
|
86
|
+
assertTrue((get(live, "bleIncidentLogRelays") as Map<*, *>).isEmpty())
|
|
87
|
+
} finally { Bridge.removeEventSink(sink) }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private fun ready(live: MentraLive) {
|
|
91
|
+
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
|
|
92
|
+
val gatt = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("AA:BB:CC:DD:EE:FF")
|
|
93
|
+
.connectGatt(context, false, object : BluetoothGattCallback() {})
|
|
94
|
+
set(live, "isConnected", true)
|
|
95
|
+
set(live, "bluetoothGatt", gatt)
|
|
96
|
+
set(live, "txCharacteristic", BluetoothGattCharacteristic(UUID.randomUUID(), 0, 0))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private fun withLive(body: (MentraLive) -> Unit) {
|
|
100
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
101
|
+
val live = MentraLive()
|
|
102
|
+
val token = DeviceStore.get("bluetooth", "core_token")
|
|
103
|
+
val connected = DeviceStore.get("glasses", "connected")
|
|
104
|
+
try { body(live) } finally {
|
|
105
|
+
DeviceStore.set("bluetooth", "core_token", token ?: "")
|
|
106
|
+
DeviceStore.set("glasses", "connected", connected ?: false)
|
|
107
|
+
live.destroy()
|
|
108
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(2))
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private fun expectCode(code: String, body: () -> Unit) {
|
|
113
|
+
try { body(); fail("Expected $code") } catch (error: BluetoothSdkException) { assertEquals(code, error.code) }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private fun get(live: MentraLive, name: String): Any? =
|
|
117
|
+
MentraLive::class.java.getDeclaredField(name).apply { isAccessible = true }.get(live)
|
|
118
|
+
|
|
119
|
+
private fun set(live: MentraLive, name: String, value: Any?) {
|
|
120
|
+
MentraLive::class.java.getDeclaredField(name).apply { isAccessible = true }.set(live, value)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private fun queuedWrites(live: MentraLive): List<ByteArray> = (get(live, "sendQueue") as Iterable<*>).map { write ->
|
|
124
|
+
write!!.javaClass.getDeclaredField("data").apply { isAccessible = true }.get(write) as ByteArray
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.os.Looper
|
|
4
|
+
import androidx.test.core.app.ApplicationProvider
|
|
5
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
6
|
+
import java.nio.charset.StandardCharsets
|
|
7
|
+
import java.time.Duration
|
|
8
|
+
import java.util.UUID
|
|
9
|
+
import org.junit.Assert.assertFalse
|
|
10
|
+
import org.junit.Assert.assertTrue
|
|
11
|
+
import org.junit.Test
|
|
12
|
+
import org.junit.runner.RunWith
|
|
13
|
+
import org.robolectric.RobolectricTestRunner
|
|
14
|
+
import org.robolectric.Shadows.shadowOf
|
|
15
|
+
import org.robolectric.annotation.Config
|
|
16
|
+
import org.robolectric.annotation.LooperMode
|
|
17
|
+
import org.robolectric.shadows.ShadowLog
|
|
18
|
+
|
|
19
|
+
@RunWith(RobolectricTestRunner::class)
|
|
20
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
21
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
22
|
+
class MentraLiveWifiCredentialLogTest {
|
|
23
|
+
@Test fun `wifi credentials reach the BLE queue without being logged`() {
|
|
24
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
25
|
+
val ssid = "synthetic-${UUID.randomUUID()}"
|
|
26
|
+
val password = UUID.randomUUID().toString()
|
|
27
|
+
val events = mutableListOf<String>()
|
|
28
|
+
val sink = Bridge.addEventSink { type, body -> if (type == "log") events.add(body["message"].toString()) }
|
|
29
|
+
val live = MentraLive()
|
|
30
|
+
try {
|
|
31
|
+
ShadowLog.clear()
|
|
32
|
+
live.sendWifiCredentials(ssid, password)
|
|
33
|
+
|
|
34
|
+
val logs = events + ShadowLog.getLogs().map { it.msg }
|
|
35
|
+
assertFalse("password logged", logs.any { it.contains(password) })
|
|
36
|
+
assertTrue(events.any { it.endsWith("LIVE: Sending data to glasses: <set_wifi_credentials with credentials omitted>") })
|
|
37
|
+
// The glasses still receive the unchanged credentials.
|
|
38
|
+
val wire = queuedWrites(live).joinToString("") { String(it, StandardCharsets.UTF_8) }
|
|
39
|
+
assertTrue(wire.contains("set_wifi_credentials"))
|
|
40
|
+
assertTrue(wire.contains(ssid))
|
|
41
|
+
assertTrue(wire.contains(password))
|
|
42
|
+
} finally {
|
|
43
|
+
Bridge.removeEventSink(sink)
|
|
44
|
+
live.destroy()
|
|
45
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(2))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private fun queuedWrites(live: MentraLive): List<ByteArray> {
|
|
50
|
+
val queue = MentraLive::class.java.getDeclaredField("sendQueue").apply { isAccessible = true }.get(live)
|
|
51
|
+
return (queue as Iterable<*>).map { write ->
|
|
52
|
+
write!!.javaClass.getDeclaredField("data").apply { isAccessible = true }.get(write) as ByteArray
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|