@mentra/bluetooth-sdk 3.4.0-beta.1277 → 3.4.0-beta.1281
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/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +5 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt +57 -196
- 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 +109 -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 +53 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkState.kt +127 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedSoftApNetwork.kt +604 -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/MentraLive.kt +14 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/streaming/StreamModels.kt +17 -6
- 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 +96 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkLifecycleTest.kt +187 -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 +69 -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/build/BluetoothSdk.types.d.ts +2 -3
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.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/releaseMetadata.js +5 -5
- package/build/generated/releaseMetadata.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/ios/LocalIPv4.swift +0 -61
- package/ios/MentraOtaServerModule.swift +0 -16
- package/ios/Source/BluetoothSdkDefaults.swift +1 -1
- package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
- package/ios/Source/streaming/StreamModels.swift +15 -6
- package/ios/Tests/StreamRequestTests.swift +18 -0
- package/package.json +2 -2
- package/src/BluetoothSdk.types.ts +2 -3
- package/src/_private/MentraLocalNetworkModule.ts +5 -1
- package/src/generated/releaseMetadata.ts +5 -5
- 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/android/src/main/java/com/mentra/bluetoothsdk/ScopedNetworkReadiness.kt +0 -17
- package/android/src/test/java/com/mentra/bluetoothsdk/ScopedNetworkReadinessTest.kt +0 -39
|
@@ -0,0 +1,187 @@
|
|
|
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 `timeout while still requesting fails as TIMEOUT`() {
|
|
67
|
+
val state = ScopedNetworkState()
|
|
68
|
+
val generation = state.startRequest()
|
|
69
|
+
|
|
70
|
+
assertThat(state.onTimeout(generation)).isTrue()
|
|
71
|
+
assertThat(state.phase).isEqualTo(Phase.LOST)
|
|
72
|
+
assertThat(state.failure).isEqualTo(Failure.TIMEOUT)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The join succeeded just before the watchdog fired; the network must stay usable. */
|
|
76
|
+
@Test
|
|
77
|
+
fun `a timeout arriving after onAvailable is ignored`() {
|
|
78
|
+
val state = ScopedNetworkState()
|
|
79
|
+
val generation = state.startRequest()
|
|
80
|
+
state.onAvailable(generation)
|
|
81
|
+
|
|
82
|
+
assertThat(state.onTimeout(generation)).isFalse()
|
|
83
|
+
assertThat(state.phase).isEqualTo(Phase.AVAILABLE)
|
|
84
|
+
assertThat(state.failure).isEqualTo(Failure.NONE)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@Test
|
|
88
|
+
fun `onUnavailable fails as UNAVAILABLE`() {
|
|
89
|
+
val state = ScopedNetworkState()
|
|
90
|
+
val generation = state.startRequest()
|
|
91
|
+
|
|
92
|
+
assertThat(state.onUnavailable(generation)).isTrue()
|
|
93
|
+
assertThat(state.failure).isEqualTo(Failure.UNAVAILABLE)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@Test
|
|
97
|
+
fun `a SecurityException maps to PERMISSION_DENIED`() {
|
|
98
|
+
val state = ScopedNetworkState()
|
|
99
|
+
val generation = state.startRequest()
|
|
100
|
+
|
|
101
|
+
assertThat(state.onRequestFailed(generation, permissionDenied = true)).isTrue()
|
|
102
|
+
assertThat(state.failure).isEqualTo(Failure.PERMISSION_DENIED)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Test
|
|
106
|
+
fun `any other request throw maps to REQUEST_FAILED`() {
|
|
107
|
+
val state = ScopedNetworkState()
|
|
108
|
+
val generation = state.startRequest()
|
|
109
|
+
|
|
110
|
+
assertThat(state.onRequestFailed(generation, permissionDenied = false)).isTrue()
|
|
111
|
+
assertThat(state.failure).isEqualTo(Failure.REQUEST_FAILED)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// -----------------------------------------------------------------
|
|
115
|
+
// Stale generations
|
|
116
|
+
// -----------------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
@Test
|
|
119
|
+
fun `callbacks from a superseded request are rejected`() {
|
|
120
|
+
val state = ScopedNetworkState()
|
|
121
|
+
val first = state.startRequest()
|
|
122
|
+
val second = state.startRequest()
|
|
123
|
+
assertThat(second).isNotEqualTo(first)
|
|
124
|
+
|
|
125
|
+
assertThat(state.onAvailable(first)).isFalse()
|
|
126
|
+
assertThat(state.onLost(first)).isFalse()
|
|
127
|
+
assertThat(state.onUnavailable(first)).isFalse()
|
|
128
|
+
assertThat(state.onTimeout(first)).isFalse()
|
|
129
|
+
assertThat(state.phase).isEqualTo(Phase.REQUESTING)
|
|
130
|
+
|
|
131
|
+
assertThat(state.onAvailable(second)).isTrue()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@Test
|
|
135
|
+
fun `a late onLost after release does not resurrect state`() {
|
|
136
|
+
val state = ScopedNetworkState()
|
|
137
|
+
val generation = state.startRequest()
|
|
138
|
+
state.onAvailable(generation)
|
|
139
|
+
state.release()
|
|
140
|
+
|
|
141
|
+
assertThat(state.onLost(generation)).isFalse()
|
|
142
|
+
assertThat(state.failure).isEqualTo(Failure.NONE)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@Test
|
|
146
|
+
fun `release is idempotent`() {
|
|
147
|
+
val state = ScopedNetworkState()
|
|
148
|
+
val generation = state.startRequest()
|
|
149
|
+
state.onAvailable(generation)
|
|
150
|
+
|
|
151
|
+
assertThat(state.release()).isTrue()
|
|
152
|
+
assertThat(state.release()).isFalse()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@Test
|
|
156
|
+
fun `release from idle is a no-op`() {
|
|
157
|
+
assertThat(ScopedNetworkState().release()).isFalse()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@Test
|
|
161
|
+
fun `reset returns the machine to idle for reuse`() {
|
|
162
|
+
val state = ScopedNetworkState()
|
|
163
|
+
val generation = state.startRequest()
|
|
164
|
+
state.onLost(generation)
|
|
165
|
+
state.reset()
|
|
166
|
+
|
|
167
|
+
assertThat(state.phase).isEqualTo(Phase.IDLE)
|
|
168
|
+
assertThat(state.failure).isEqualTo(Failure.NONE)
|
|
169
|
+
|
|
170
|
+
val next = state.startRequest()
|
|
171
|
+
assertThat(state.onAvailable(next)).isTrue()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Ten start/stop cycles must leave no residue, matching the rejoin soak requirement. */
|
|
175
|
+
@Test
|
|
176
|
+
fun `ten join and release cycles end clean`() {
|
|
177
|
+
val state = ScopedNetworkState()
|
|
178
|
+
repeat(10) {
|
|
179
|
+
val generation = state.startRequest()
|
|
180
|
+
assertThat(state.onAvailable(generation)).isTrue()
|
|
181
|
+
assertThat(state.release()).isTrue()
|
|
182
|
+
state.reset()
|
|
183
|
+
assertThat(state.phase).isEqualTo(Phase.IDLE)
|
|
184
|
+
}
|
|
185
|
+
assertThat(state.generation).isEqualTo(10)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import com.mentra.bluetoothsdk.hotspot.ScopedNetworkReadiness.Verdict
|
|
4
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The race these cases pin cost a misdiagnosis: ingest started on `onAvailable`, the hotspot address
|
|
9
|
+
* was not yet in the kernel table, and the resulting candidate-less answer was blamed on socket
|
|
10
|
+
* binding. Readiness now has to agree from three sources, and the missing one has to be named.
|
|
11
|
+
*/
|
|
12
|
+
class ScopedNetworkReadinessTest {
|
|
13
|
+
|
|
14
|
+
private val readiness = ScopedNetworkReadiness()
|
|
15
|
+
|
|
16
|
+
private fun joined() {
|
|
17
|
+
readiness.onAvailable()
|
|
18
|
+
readiness.onCapabilities()
|
|
19
|
+
readiness.onLinkProperties("wlan0", "192.168.43.79")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Test
|
|
23
|
+
fun `a fresh gate waits for onAvailable`() {
|
|
24
|
+
assertThat(readiness.verdict()).isEqualTo(Verdict.Waiting("onAvailable"))
|
|
25
|
+
assertThat(readiness.callbacksSatisfied()).isFalse
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Android's guidance, and the reason `onAvailable` alone was not enough. */
|
|
29
|
+
@Test
|
|
30
|
+
fun `onAvailable alone is not ready`() {
|
|
31
|
+
readiness.onAvailable()
|
|
32
|
+
|
|
33
|
+
assertThat(readiness.verdict()).isEqualTo(Verdict.Waiting("onCapabilitiesChanged"))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Test
|
|
37
|
+
fun `capabilities without an address is not ready`() {
|
|
38
|
+
readiness.onAvailable()
|
|
39
|
+
readiness.onCapabilities()
|
|
40
|
+
|
|
41
|
+
assertThat(readiness.verdict()).isEqualTo(Verdict.Waiting("an IPv4 address from onLinkPropertiesChanged"))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The whole point: the callbacks can all agree while ICE still has nothing to gather. */
|
|
45
|
+
@Test
|
|
46
|
+
fun `every callback reporting is not ready until the kernel table has the address`() {
|
|
47
|
+
joined()
|
|
48
|
+
|
|
49
|
+
assertThat(readiness.callbacksSatisfied()).isTrue
|
|
50
|
+
assertThat(readiness.verdict())
|
|
51
|
+
.isEqualTo(Verdict.Waiting("the kernel interface table to carry 192.168.43.79"))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Test
|
|
55
|
+
fun `the address appearing in the table late completes readiness`() {
|
|
56
|
+
joined()
|
|
57
|
+
|
|
58
|
+
readiness.onInterfaceTable("wlan0")
|
|
59
|
+
|
|
60
|
+
assertThat(readiness.verdict()).isEqualTo(Verdict.Ready("192.168.43.79", "wlan0", "wlan0"))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A name disagreement is reported, not blocked on: ICE gathers per address, so the address being
|
|
65
|
+
* in the table is what matters. Blocking here would fail calls that actually work.
|
|
66
|
+
*/
|
|
67
|
+
@Test
|
|
68
|
+
fun `the kernel owning the address under another name is still ready`() {
|
|
69
|
+
joined()
|
|
70
|
+
|
|
71
|
+
readiness.onInterfaceTable("wlan1")
|
|
72
|
+
|
|
73
|
+
val verdict = readiness.verdict() as Verdict.Ready
|
|
74
|
+
assertThat(verdict.interfaceName).isEqualTo("wlan0")
|
|
75
|
+
assertThat(verdict.owner).isEqualTo("wlan1")
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A later poll that no longer finds the address must un-ready the gate, not latch. */
|
|
79
|
+
@Test
|
|
80
|
+
fun `the address leaving the table takes readiness away again`() {
|
|
81
|
+
joined()
|
|
82
|
+
readiness.onInterfaceTable("wlan0")
|
|
83
|
+
|
|
84
|
+
readiness.onInterfaceTable(null)
|
|
85
|
+
|
|
86
|
+
assertThat(readiness.verdict()).isInstanceOf(Verdict.Waiting::class.java)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** LinkProperties is a whole-state snapshot, so a later one without an address means gone. */
|
|
90
|
+
@Test
|
|
91
|
+
fun `a link properties update without an address clears the observation`() {
|
|
92
|
+
joined()
|
|
93
|
+
readiness.onInterfaceTable("wlan0")
|
|
94
|
+
|
|
95
|
+
readiness.onLinkProperties("wlan0", null)
|
|
96
|
+
|
|
97
|
+
assertThat(readiness.callbacksSatisfied()).isFalse
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The synchronous read inside `onAvailable` is a hint; it must not erase a real callback. */
|
|
101
|
+
@Test
|
|
102
|
+
fun `seeding with no address does not clear what a callback reported`() {
|
|
103
|
+
readiness.onLinkProperties("wlan0", "192.168.43.79")
|
|
104
|
+
|
|
105
|
+
readiness.seedLinkProperties(null, null)
|
|
106
|
+
|
|
107
|
+
assertThat(readiness.observations.linkAddress).isEqualTo("192.168.43.79")
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@Test
|
|
111
|
+
fun `seeding supplies the address when the callback has not arrived`() {
|
|
112
|
+
readiness.onAvailable()
|
|
113
|
+
readiness.seedLinkProperties("wlan0", "192.168.43.79")
|
|
114
|
+
readiness.onCapabilities()
|
|
115
|
+
|
|
116
|
+
assertThat(readiness.callbacksSatisfied()).isTrue
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Rejoin reuses the instance, so a stale Ready from the previous call would be fatal. */
|
|
120
|
+
@Test
|
|
121
|
+
fun `reset returns the gate to waiting for onAvailable`() {
|
|
122
|
+
joined()
|
|
123
|
+
readiness.onInterfaceTable("wlan0")
|
|
124
|
+
|
|
125
|
+
readiness.reset()
|
|
126
|
+
|
|
127
|
+
assertThat(readiness.verdict()).isEqualTo(Verdict.Waiting("onAvailable"))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@Test
|
|
131
|
+
fun `callbacks arriving out of order still resolve`() {
|
|
132
|
+
readiness.onCapabilities()
|
|
133
|
+
readiness.onLinkProperties("wlan0", "192.168.43.79")
|
|
134
|
+
readiness.onInterfaceTable("wlan0")
|
|
135
|
+
assertThat(readiness.verdict()).isEqualTo(Verdict.Waiting("onAvailable"))
|
|
136
|
+
|
|
137
|
+
readiness.onAvailable()
|
|
138
|
+
|
|
139
|
+
assertThat(readiness.verdict()).isInstanceOf(Verdict.Ready::class.java)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import android.net.NetworkCapabilities
|
|
4
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Guards the one property the whole dual-homing design rests on: the SoftAP request must not ask
|
|
9
|
+
* for `NET_CAPABILITY_INTERNET`. If that regresses, Android can promote the glasses hotspot to the
|
|
10
|
+
* default network and ACS traffic silently stops using cellular.
|
|
11
|
+
*/
|
|
12
|
+
class ScopedNetworkRequestSpecTest {
|
|
13
|
+
|
|
14
|
+
@Test
|
|
15
|
+
fun `the softap request removes the internet capability`() {
|
|
16
|
+
val spec = ScopedNetworkRequestSpec.forSoftAp("MentraLive-1234", "hunter2")
|
|
17
|
+
|
|
18
|
+
assertThat(spec.removedCapabilities).contains(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
|
19
|
+
assertThat(spec.avoidsInternetCapability).isTrue()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Test
|
|
23
|
+
fun `the softap request is wifi only`() {
|
|
24
|
+
val spec = ScopedNetworkRequestSpec.forSoftAp("MentraLive-1234", "hunter2")
|
|
25
|
+
|
|
26
|
+
assertThat(spec.transportTypes).containsExactly(NetworkCapabilities.TRANSPORT_WIFI)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Test
|
|
30
|
+
fun `ssid and passphrase are carried through`() {
|
|
31
|
+
val spec = ScopedNetworkRequestSpec.forSoftAp("MentraLive-1234", "hunter2")
|
|
32
|
+
|
|
33
|
+
assertThat(spec.ssid).isEqualTo("MentraLive-1234")
|
|
34
|
+
assertThat(spec.passphrase).isEqualTo("hunter2")
|
|
35
|
+
assertThat(spec.hasPassphrase).isTrue()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Test
|
|
39
|
+
fun `an open network reports no passphrase`() {
|
|
40
|
+
assertThat(ScopedNetworkRequestSpec.forSoftAp("Open-AP", "").hasPassphrase).isFalse()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Test
|
|
44
|
+
fun `the default timeout matches the bluetooth sdk hotspot join`() {
|
|
45
|
+
assertThat(ScopedNetworkRequestSpec.forSoftAp("x", "y").timeoutMs).isEqualTo(30_000)
|
|
46
|
+
assertThat(ScopedNetworkRequestSpec.DEFAULT_TIMEOUT_MS).isEqualTo(30_000)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Test
|
|
50
|
+
fun `the timeout is overridable`() {
|
|
51
|
+
assertThat(ScopedNetworkRequestSpec.forSoftAp("x", "y", timeoutMs = 5_000).timeoutMs)
|
|
52
|
+
.isEqualTo(5_000)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A spec that kept the internet capability must not read as safe. */
|
|
56
|
+
@Test
|
|
57
|
+
fun `avoidsInternetCapability is false when the capability is not removed`() {
|
|
58
|
+
val unsafe =
|
|
59
|
+
ScopedNetworkRequestSpec(
|
|
60
|
+
ssid = "x",
|
|
61
|
+
passphrase = "y",
|
|
62
|
+
transportTypes = setOf(NetworkCapabilities.TRANSPORT_WIFI),
|
|
63
|
+
removedCapabilities = emptySet(),
|
|
64
|
+
timeoutMs = 1_000,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
assertThat(unsafe.avoidsInternetCapability).isFalse()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
4
|
+
import org.junit.Test
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Covers the pure formatter. The `Log.i` wrapper is a one-liner and is exercised on device.
|
|
8
|
+
*/
|
|
9
|
+
class SoftApTraceTest {
|
|
10
|
+
|
|
11
|
+
@Test
|
|
12
|
+
fun `format carries the grep marker`() {
|
|
13
|
+
assertThat(SoftApTrace.format("t1", "scoped_network_available", 12))
|
|
14
|
+
.contains("SOFTAP_TRACE")
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Test
|
|
18
|
+
fun `format includes traceId stage and elapsed`() {
|
|
19
|
+
assertThat(SoftApTrace.format("abc123", "ice_selected_pair", 450))
|
|
20
|
+
.isEqualTo("[SOFTAP_TRACE] traceId=abc123 stage=ice_selected_pair elapsedMs=450")
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Test
|
|
24
|
+
fun `format omits traceId when absent`() {
|
|
25
|
+
assertThat(SoftApTrace.format("", "boot", 0))
|
|
26
|
+
.isEqualTo("[SOFTAP_TRACE] stage=boot elapsedMs=0")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Test
|
|
30
|
+
fun `format appends fields in order`() {
|
|
31
|
+
assertThat(SoftApTrace.format("t", "whip_request", 7, "method" to "POST", "status" to 201))
|
|
32
|
+
.endsWith("method=POST status=201")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Test
|
|
36
|
+
fun `sanitize redacts the hotspot password`() {
|
|
37
|
+
assertThat(SoftApTrace.sanitize("password", "hunter2")).isEqualTo("<redacted>")
|
|
38
|
+
assertThat(SoftApTrace.sanitize("hotspotPassword", "hunter2")).isEqualTo("<redacted>")
|
|
39
|
+
assertThat(SoftApTrace.sanitize("psk", "hunter2")).isEqualTo("<redacted>")
|
|
40
|
+
assertThat(SoftApTrace.sanitize("passphrase", "hunter2")).isEqualTo("<redacted>")
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Test
|
|
44
|
+
fun `sanitize redacts tokens and credentials`() {
|
|
45
|
+
assertThat(SoftApTrace.sanitize("token", "eyJhbGciOi")).isEqualTo("<redacted>")
|
|
46
|
+
assertThat(SoftApTrace.sanitize("acsToken", "eyJhbGciOi")).isEqualTo("<redacted>")
|
|
47
|
+
assertThat(SoftApTrace.sanitize("Authorization", "Bearer x")).isEqualTo("<redacted>")
|
|
48
|
+
assertThat(SoftApTrace.sanitize("meetingUrl", "https://teams.microsoft.com/l/x"))
|
|
49
|
+
.isEqualTo("<redacted>")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Test
|
|
53
|
+
fun `format never leaks a secret value into the line`() {
|
|
54
|
+
val line = SoftApTrace.format(
|
|
55
|
+
"t", "hotspot_started", 5,
|
|
56
|
+
"ssid" to "MentraLive", "password" to "hunter2",
|
|
57
|
+
)
|
|
58
|
+
assertThat(line).doesNotContain("hunter2")
|
|
59
|
+
assertThat(line).contains("ssid=MentraLive")
|
|
60
|
+
assertThat(line).contains("password=<redacted>")
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Test
|
|
64
|
+
fun `sanitize keeps the local whip url which is diagnostic`() {
|
|
65
|
+
assertThat(SoftApTrace.sanitize("whipUrl", "http://192.168.43.20:8790/whip/abc"))
|
|
66
|
+
.isEqualTo("http://192.168.43.20:8790/whip/abc")
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@Test
|
|
70
|
+
fun `sanitize strips query strings that may carry tokens`() {
|
|
71
|
+
assertThat(SoftApTrace.sanitize("playbackUrl", "https://example.com/live?token=secret123"))
|
|
72
|
+
.isEqualTo("https://example.com/live?<redacted>")
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Test
|
|
76
|
+
fun `sanitize strips userinfo from urls`() {
|
|
77
|
+
val result = SoftApTrace.sanitize("endpoint", "https://user:pw@example.com/x")
|
|
78
|
+
assertThat(result).doesNotContain("pw@")
|
|
79
|
+
assertThat(result).contains("<redacted>@example.com/x")
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Test
|
|
83
|
+
fun `sanitize quotes values containing spaces`() {
|
|
84
|
+
assertThat(SoftApTrace.sanitize("reason", "two words")).isEqualTo("\"two words\"")
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@Test
|
|
88
|
+
fun `sanitize renders null and empty`() {
|
|
89
|
+
assertThat(SoftApTrace.sanitize("reason", null)).isEqualTo("null")
|
|
90
|
+
assertThat(SoftApTrace.sanitize("reason", "")).isEqualTo("\"\"")
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Test
|
|
94
|
+
fun `newTraceId produces distinct ids`() {
|
|
95
|
+
assertThat(SoftApTrace.newTraceId()).isNotEqualTo(SoftApTrace.newTraceId())
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
4
|
+
import org.assertj.core.api.Assertions.assertThatThrownBy
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class UnavailableRetryTest {
|
|
8
|
+
|
|
9
|
+
@Test
|
|
10
|
+
fun `asks once more after an Unavailable`() {
|
|
11
|
+
var requests = 0
|
|
12
|
+
val result = ScopedSoftApNetwork.retryUnavailableOnce(
|
|
13
|
+
request = { if (++requests == 1) throw ScopedNetworkError.Unavailable("glasses") else "joined" },
|
|
14
|
+
settle = {},
|
|
15
|
+
released = { false },
|
|
16
|
+
)
|
|
17
|
+
assertThat(result).isEqualTo("joined")
|
|
18
|
+
assertThat(requests).isEqualTo(2)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Test
|
|
22
|
+
fun `a release during the settle stops the second request`() {
|
|
23
|
+
var requests = 0
|
|
24
|
+
var released = false
|
|
25
|
+
assertThatThrownBy {
|
|
26
|
+
ScopedSoftApNetwork.retryUnavailableOnce(
|
|
27
|
+
request = { requests++; throw ScopedNetworkError.Unavailable("glasses") },
|
|
28
|
+
settle = { released = true },
|
|
29
|
+
released = { released },
|
|
30
|
+
)
|
|
31
|
+
}.isInstanceOf(ScopedNetworkError.Unavailable::class.java)
|
|
32
|
+
assertThat(requests).isEqualTo(1)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Test
|
|
36
|
+
fun `a release before the settle skips it`() {
|
|
37
|
+
var settled = false
|
|
38
|
+
assertThatThrownBy {
|
|
39
|
+
ScopedSoftApNetwork.retryUnavailableOnce<String>(
|
|
40
|
+
request = { throw ScopedNetworkError.Unavailable("glasses") },
|
|
41
|
+
settle = { settled = true },
|
|
42
|
+
released = { true },
|
|
43
|
+
)
|
|
44
|
+
}.isInstanceOf(ScopedNetworkError.Unavailable::class.java)
|
|
45
|
+
assertThat(settled).isFalse()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -712,11 +712,10 @@ export type StreamIceConfig = {
|
|
|
712
712
|
/**
|
|
713
713
|
* STUN server the glasses should use while gathering candidates.
|
|
714
714
|
*
|
|
715
|
-
* Omit to
|
|
715
|
+
* Omit to send the default Cloudflare STUN server. Pass an empty string to force host-only
|
|
716
716
|
* gathering, which is what SoftAP calling needs: the WHIP server runs on the phone across the
|
|
717
717
|
* glasses' own hotspot, so a server-reflexive candidate is meaningless and there is no route to
|
|
718
|
-
* a STUN server anyway.
|
|
719
|
-
* kept, so a malformed override cannot silently disable ICE.
|
|
718
|
+
* a STUN server anyway. The glasses treat a value that is not a `stun:`/`stuns:` URI as host-only.
|
|
720
719
|
*/
|
|
721
720
|
stun?: string;
|
|
722
721
|
};
|