@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,143 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import android.os.SystemClock
|
|
4
|
+
import com.mentra.bluetoothsdk.utils.NativeLog as Log
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Correlated stage logging for the SoftAP calling pipeline (phone side).
|
|
8
|
+
*
|
|
9
|
+
* TEMPORARY DIAGNOSTIC. Every line carries the literal `SOFTAP_TRACE` marker so a single
|
|
10
|
+
* `rg -n 'SOFTAP_TRACE'` finds all of them at cleanup time. Flip [ENABLED] to false to mute the
|
|
11
|
+
* layer for a release without deleting call sites.
|
|
12
|
+
*
|
|
13
|
+
* The logcat tag is deliberately distinct from the module's `ACS-SPIKE` tag so that
|
|
14
|
+
* `adb logcat -s SOFTAP-TRACE` isolates the whole SoftAP pipeline in one stream.
|
|
15
|
+
*
|
|
16
|
+
* The phone mints [traceId] when it starts the hotspot and passes it to the glasses in
|
|
17
|
+
* `start_stream`. Both devices stamp the same id on every line, which is the only way to correlate
|
|
18
|
+
* two logs whose clocks were never synchronised.
|
|
19
|
+
*/
|
|
20
|
+
object SoftApTrace {
|
|
21
|
+
|
|
22
|
+
/** Master switch. Flip to false to mute the trace without removing call sites. */
|
|
23
|
+
const val ENABLED = true
|
|
24
|
+
|
|
25
|
+
/** Grep marker. Never build this by concatenation — a single grep must be exhaustive. */
|
|
26
|
+
const val MARKER = "SOFTAP_TRACE"
|
|
27
|
+
|
|
28
|
+
const val TAG = "SOFTAP-TRACE"
|
|
29
|
+
|
|
30
|
+
private const val REDACTED = "<redacted>"
|
|
31
|
+
|
|
32
|
+
/** Keys whose values must never reach logcat. Matched case-insensitively as substrings. */
|
|
33
|
+
private val SENSITIVE_KEYS = listOf(
|
|
34
|
+
"password", "passwd", "passphrase", "psk", "token", "secret",
|
|
35
|
+
"credential", "authorization", "bearer", "meetingurl",
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
@Volatile
|
|
39
|
+
private var traceId: String = ""
|
|
40
|
+
|
|
41
|
+
@Volatile
|
|
42
|
+
private var originMs: Long = 0L
|
|
43
|
+
|
|
44
|
+
@Volatile
|
|
45
|
+
private var lastStage: String = ""
|
|
46
|
+
|
|
47
|
+
/** Mint a new trace id and reset the elapsed-time origin. Called when the hotspot request starts. */
|
|
48
|
+
fun begin(id: String = newTraceId()): String {
|
|
49
|
+
traceId = id
|
|
50
|
+
originMs = SystemClock.elapsedRealtime()
|
|
51
|
+
lastStage = ""
|
|
52
|
+
return id
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fun reset() {
|
|
56
|
+
traceId = ""
|
|
57
|
+
originMs = 0L
|
|
58
|
+
lastStage = ""
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
fun traceId(): String = traceId
|
|
62
|
+
|
|
63
|
+
/** Last stage successfully logged; use as failure context when reporting an error. */
|
|
64
|
+
fun lastStage(): String = lastStage
|
|
65
|
+
|
|
66
|
+
/** Short, collision-resistant enough for correlating one call's logs. */
|
|
67
|
+
fun newTraceId(): String = java.lang.Long.toHexString(System.nanoTime() and 0xFFFFFFFFL)
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Log one pipeline stage transition.
|
|
71
|
+
*
|
|
72
|
+
* @param stage stable snake_case stage name, e.g. `scoped_network_available`
|
|
73
|
+
*/
|
|
74
|
+
fun stage(stage: String, vararg fields: Pair<String, Any?>) {
|
|
75
|
+
if (!ENABLED) return
|
|
76
|
+
lastStage = stage
|
|
77
|
+
val elapsedMs = if (originMs == 0L) 0L else SystemClock.elapsedRealtime() - originMs
|
|
78
|
+
Log.i(TAG, format(traceId, stage, elapsedMs, *fields))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Error-level variant so genuine failures survive a logcat level filter. */
|
|
82
|
+
fun failure(stage: String, vararg fields: Pair<String, Any?>) {
|
|
83
|
+
if (!ENABLED) return
|
|
84
|
+
val elapsedMs = if (originMs == 0L) 0L else SystemClock.elapsedRealtime() - originMs
|
|
85
|
+
Log.e(TAG, format(traceId, stage, elapsedMs, *fields, "afterStage" to lastStage))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Pure formatter. Split out from [stage] so it can be unit tested without the Android logging
|
|
90
|
+
* framework, which is not available to plain JVM tests in this module.
|
|
91
|
+
*/
|
|
92
|
+
fun format(
|
|
93
|
+
traceId: String,
|
|
94
|
+
stage: String,
|
|
95
|
+
elapsedMs: Long,
|
|
96
|
+
vararg fields: Pair<String, Any?>,
|
|
97
|
+
): String = buildString {
|
|
98
|
+
append('[').append(MARKER).append(']')
|
|
99
|
+
if (traceId.isNotEmpty()) append(" traceId=").append(traceId)
|
|
100
|
+
append(" stage=").append(stage)
|
|
101
|
+
append(" elapsedMs=").append(elapsedMs)
|
|
102
|
+
for ((key, value) in fields) {
|
|
103
|
+
append(' ').append(key).append('=').append(sanitize(key, value))
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Redact secrets outright and strip query strings from URLs. The local WHIP URL is genuinely
|
|
109
|
+
* useful in a trace, but a URL carrying a watch token is not, so query and userinfo go.
|
|
110
|
+
*/
|
|
111
|
+
fun sanitize(key: String, value: Any?): String {
|
|
112
|
+
if (isSensitive(key)) return REDACTED
|
|
113
|
+
if (value == null) return "null"
|
|
114
|
+
|
|
115
|
+
val text = value.toString()
|
|
116
|
+
if (text.isEmpty()) return "\"\""
|
|
117
|
+
val cleaned = stripUrlSecrets(text)
|
|
118
|
+
return if (cleaned.contains(' ')) "\"$cleaned\"" else cleaned
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private fun isSensitive(key: String): Boolean {
|
|
122
|
+
val lower = key.lowercase()
|
|
123
|
+
return SENSITIVE_KEYS.any { lower.contains(it) }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Drop `?query`, `#fragment`, and `user:pass@` from anything URL-shaped. */
|
|
127
|
+
private fun stripUrlSecrets(text: String): String {
|
|
128
|
+
val schemeIndex = text.indexOf("://")
|
|
129
|
+
if (schemeIndex < 0) return text
|
|
130
|
+
|
|
131
|
+
var result = text
|
|
132
|
+
val query = result.indexOf('?')
|
|
133
|
+
if (query >= 0) result = result.substring(0, query) + "?" + REDACTED
|
|
134
|
+
val fragment = result.indexOf('#')
|
|
135
|
+
if (fragment >= 0) result = result.substring(0, fragment)
|
|
136
|
+
|
|
137
|
+
val at = result.indexOf('@', schemeIndex + 3)
|
|
138
|
+
if (at >= 0) {
|
|
139
|
+
result = result.substring(0, schemeIndex + 3) + REDACTED + "@" + result.substring(at + 1)
|
|
140
|
+
}
|
|
141
|
+
return result
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -28,13 +28,6 @@ class MentraOtaServerModule : Module() {
|
|
|
28
28
|
stopOtaServerInternal()
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// API parity with iOS. Android hotspot OTA obtains the authoritative address
|
|
32
|
-
// directly from the scoped Network and does not call this fallback.
|
|
33
|
-
AsyncFunction("waitForWifiAddress") { _: String, _: Int ->
|
|
34
|
-
LocalIpv4.bestLocalIpv4Address()
|
|
35
|
-
?: throw IllegalStateException("No Wi-Fi/LAN IPv4 address found for this phone.")
|
|
36
|
-
}
|
|
37
|
-
|
|
38
31
|
OnDestroy {
|
|
39
32
|
closeOtaServerInternal()
|
|
40
33
|
}
|
|
@@ -2130,6 +2130,20 @@ class MentraLive : SGCManager() {
|
|
|
2130
2130
|
if (isKilled) return
|
|
2131
2131
|
if (isExplicitPairingAttempt()) return
|
|
2132
2132
|
leaveGlassesLink()
|
|
2133
|
+
// The glasses deleted this phone's keys. A bond kept here would make the first Pair Again
|
|
2134
|
+
// connect with them, get refused and fail; removed now, Pair Again bonds afresh.
|
|
2135
|
+
forgetRejectedBond()
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
private fun forgetRejectedBond() {
|
|
2139
|
+
val address = DeviceStore.get("bluetooth", "device_address") as? String ?: return
|
|
2140
|
+
if (!BluetoothAdapter.checkBluetoothAddress(address)) return
|
|
2141
|
+
val device = bluetoothAdapter?.getRemoteDevice(address) ?: return
|
|
2142
|
+
try {
|
|
2143
|
+
if (device.bondState == BluetoothDevice.BOND_BONDED) removeBondStandalone(device)
|
|
2144
|
+
} catch (e: SecurityException) {
|
|
2145
|
+
Bridge.log("LIVE: CTKD: removing the rejected bond was refused: " + e.message)
|
|
2146
|
+
}
|
|
2133
2147
|
}
|
|
2134
2148
|
|
|
2135
2149
|
/** Drop the link and every pending automatic attempt. Bonds and saved identity stay. */
|
|
@@ -67,22 +67,25 @@ data class StreamAudioConfig @JvmOverloads constructor(
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/** STUN server for a WHIP stream whose caller names none: the glasses have none of their own. */
|
|
71
|
+
private const val DEFAULT_WHIP_STUN_SERVER = "stun:stun.cloudflare.com:3478"
|
|
72
|
+
|
|
70
73
|
/** ICE overrides for a WHIP stream. Ignored by the RTMP and SRT paths. */
|
|
71
74
|
data class StreamIceConfig @JvmOverloads constructor(
|
|
72
75
|
/**
|
|
73
76
|
* STUN server the glasses use while gathering candidates.
|
|
74
77
|
*
|
|
75
|
-
* Null and empty are different answers
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
78
|
+
* Null and empty are different answers. Null sends the default Cloudflare STUN server; an
|
|
79
|
+
* empty string is SoftAP calling's explicit request for host-only gathering, because the
|
|
80
|
+
* phone's WHIP server sits on the glasses' own hotspot where a reflexive candidate is
|
|
81
|
+
* meaningless and unreachable.
|
|
79
82
|
*/
|
|
80
83
|
val stun: String? = null,
|
|
81
84
|
) {
|
|
82
85
|
fun toMap(): Map<String, Any> =
|
|
83
86
|
buildMap {
|
|
84
87
|
// Not filtered on blankness, unlike the other optional string fields here: "" is the
|
|
85
|
-
// host-only signal, so dropping it would silently
|
|
88
|
+
// host-only signal, so dropping it would silently send the default STUN server.
|
|
86
89
|
stun?.let { put("stun", it) }
|
|
87
90
|
}
|
|
88
91
|
|
|
@@ -268,11 +271,19 @@ data class StreamRequest @JvmOverloads constructor(
|
|
|
268
271
|
audio?.toMap()?.takeIf { it.isNotEmpty() }?.let { put("audio", it) }
|
|
269
272
|
authToken?.takeIf { it.isNotEmpty() }?.let { put("authToken", it) }
|
|
270
273
|
if (!captureAudio) put("captureAudio", false)
|
|
271
|
-
|
|
274
|
+
iceToSend()?.toMap()?.takeIf { it.isNotEmpty() }?.let { put("ice", it) }
|
|
272
275
|
traceId?.takeIf { it.isNotEmpty() }?.let { put("traceId", it) }
|
|
273
276
|
telemetry?.let { put("telemetry", it) }
|
|
274
277
|
}
|
|
275
278
|
|
|
279
|
+
/** The glasses read an http(s) URL as WHIP, the only protocol that uses ICE. */
|
|
280
|
+
private fun iceToSend(): StreamIceConfig? =
|
|
281
|
+
if (ice?.stun == null && (streamUrl.startsWith("https://") || streamUrl.startsWith("http://"))) {
|
|
282
|
+
StreamIceConfig(stun = DEFAULT_WHIP_STUN_SERVER)
|
|
283
|
+
} else {
|
|
284
|
+
ice
|
|
285
|
+
}
|
|
286
|
+
|
|
276
287
|
companion object {
|
|
277
288
|
@JvmStatic
|
|
278
289
|
fun fromMap(values: Map<String, Any>): StreamRequest =
|
|
@@ -48,18 +48,37 @@ class StreamRequestCaptureAudioTest {
|
|
|
48
48
|
))
|
|
49
49
|
assertThat(request.ice?.stun).isEqualTo("")
|
|
50
50
|
|
|
51
|
-
// The empty string is the host-only request.
|
|
52
|
-
// glasses gathering against
|
|
51
|
+
// The empty string is the host-only request. Replacing it with the default STUN server would
|
|
52
|
+
// leave the glasses gathering against it on an internet-less hotspot.
|
|
53
53
|
@Suppress("UNCHECKED_CAST")
|
|
54
54
|
val ice = request.toMap()["ice"] as Map<String, Any>
|
|
55
55
|
assertThat(ice).containsEntry("stun", "")
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
@Test
|
|
59
|
-
fun
|
|
59
|
+
fun whipWithoutIceSendsTheDefaultStunServer() {
|
|
60
60
|
val request = StreamRequest.fromMap(mapOf("streamUrl" to "https://example.com/whip"))
|
|
61
61
|
assertThat(request.ice).isNull()
|
|
62
|
-
|
|
62
|
+
@Suppress("UNCHECKED_CAST")
|
|
63
|
+
val ice = request.toMap()["ice"] as Map<String, Any>
|
|
64
|
+
assertThat(ice).containsEntry("stun", "stun:stun.cloudflare.com:3478")
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Test
|
|
68
|
+
fun whipKeepsTheStunServerItsCallerNamed() {
|
|
69
|
+
val request = StreamRequest.fromMap(mapOf(
|
|
70
|
+
"streamUrl" to "https://example.com/whip",
|
|
71
|
+
"ice" to mapOf("stun" to "stun:stun.example.com:3478"),
|
|
72
|
+
))
|
|
73
|
+
@Suppress("UNCHECKED_CAST")
|
|
74
|
+
val ice = request.toMap()["ice"] as Map<String, Any>
|
|
75
|
+
assertThat(ice).containsEntry("stun", "stun:stun.example.com:3478")
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Test
|
|
79
|
+
fun rtmpAndSrtSendNoIce() {
|
|
80
|
+
assertThat(StreamRequest(streamUrl = "rtmp://example.com/live").toMap()).doesNotContainKey("ice")
|
|
81
|
+
assertThat(StreamRequest(streamUrl = "srt://example.com:9000").toMap()).doesNotContainKey("ice")
|
|
63
82
|
}
|
|
64
83
|
|
|
65
84
|
@Test
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Assert.assertFalse
|
|
5
|
+
import org.junit.Assert.assertNull
|
|
6
|
+
import org.junit.Assert.assertTrue
|
|
7
|
+
import org.junit.Test
|
|
8
|
+
|
|
9
|
+
class Ipv4PrefixTest {
|
|
10
|
+
|
|
11
|
+
@Test
|
|
12
|
+
fun `contains the phone and the gateway on a 24`() {
|
|
13
|
+
val prefix = Ipv4Prefix("192.168.43.20", 24)
|
|
14
|
+
assertTrue(prefix.contains("192.168.43.1"))
|
|
15
|
+
assertTrue(prefix.contains("192.168.43.20"))
|
|
16
|
+
assertTrue(prefix.contains("192.168.43.255"))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The whole point: a cellular 10/8 address is RFC1918 and still the wrong interface. */
|
|
20
|
+
@Test
|
|
21
|
+
fun `rejects a private address on another interface`() {
|
|
22
|
+
val prefix = Ipv4Prefix("192.168.43.20", 24)
|
|
23
|
+
assertFalse(prefix.contains("10.171.36.4"))
|
|
24
|
+
assertFalse(prefix.contains("192.168.1.20"))
|
|
25
|
+
assertFalse(prefix.contains("172.16.0.1"))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** An OEM hotspot on another subnet must still pass, which is why /24 is never assumed. */
|
|
29
|
+
@Test
|
|
30
|
+
fun `honours the reported prefix length`() {
|
|
31
|
+
assertTrue(Ipv4Prefix("192.168.49.1", 16).contains("192.168.43.7"))
|
|
32
|
+
assertFalse(Ipv4Prefix("192.168.49.1", 24).contains("192.168.43.7"))
|
|
33
|
+
assertTrue(Ipv4Prefix("10.5.4.3", 8).contains("10.99.99.99"))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Test
|
|
37
|
+
fun `non-addresses are not addresses`() {
|
|
38
|
+
val prefix = Ipv4Prefix("192.168.43.20", 24)
|
|
39
|
+
assertFalse(prefix.contains(null))
|
|
40
|
+
assertFalse(prefix.contains("typ"))
|
|
41
|
+
assertFalse(prefix.contains("192.168.43"))
|
|
42
|
+
assertFalse(prefix.contains("192.168.43.256"))
|
|
43
|
+
assertFalse(prefix.contains("192.168.43.20.1"))
|
|
44
|
+
assertFalse(prefix.contains("a4f1c2d3.local"))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Test
|
|
48
|
+
fun `packs and prints`() {
|
|
49
|
+
assertEquals(0x0A000001, Ipv4Prefix.packIpv4("10.0.0.1"))
|
|
50
|
+
assertNull(Ipv4Prefix.packIpv4("not.an.ip.addr"))
|
|
51
|
+
assertEquals("192.168.43.20/24", Ipv4Prefix("192.168.43.20", 24).toString())
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** An unparseable own-address must match nothing rather than everything. */
|
|
55
|
+
@Test
|
|
56
|
+
fun `a malformed prefix contains nothing`() {
|
|
57
|
+
assertFalse(Ipv4Prefix("garbage", 24).contains("192.168.43.1"))
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import com.mentra.bluetoothsdk.hotspot.NetworkFacts.Iface
|
|
4
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The attribution helpers decide what the next SoftAP diagnosis says, so they are pinned rather
|
|
9
|
+
* than eyeballed in a log line.
|
|
10
|
+
*/
|
|
11
|
+
class NetworkFactsTest {
|
|
12
|
+
|
|
13
|
+
private fun iface(
|
|
14
|
+
name: String,
|
|
15
|
+
ipv4: List<String>,
|
|
16
|
+
up: Boolean = true,
|
|
17
|
+
loopback: Boolean = false,
|
|
18
|
+
) = Iface(name, 1, up, loopback, false, false, 1500, ipv4)
|
|
19
|
+
|
|
20
|
+
private val table =
|
|
21
|
+
listOf(
|
|
22
|
+
iface("lo", listOf("127.0.0.1/8"), loopback = true),
|
|
23
|
+
iface("wlan0", listOf("192.168.43.79/24")),
|
|
24
|
+
iface("rmnet_data0", listOf("10.48.51.202/30")),
|
|
25
|
+
iface("dummy0", emptyList()),
|
|
26
|
+
iface("epdg0", listOf("10.9.9.9/32"), up = false),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
@Test
|
|
30
|
+
fun `the owner of an address is the interface the table says carries it`() {
|
|
31
|
+
assertThat(NetworkFacts.ownerOf("192.168.43.79", table)).isEqualTo("wlan0")
|
|
32
|
+
assertThat(NetworkFacts.ownerOf("10.48.51.202", table)).isEqualTo("rmnet_data0")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** An address ICE gathered that is absent here means our two views of the network disagree. */
|
|
36
|
+
@Test
|
|
37
|
+
fun `an address the table has never seen has no owner`() {
|
|
38
|
+
assertThat(NetworkFacts.ownerOf("192.168.50.7", table)).isNull()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Test
|
|
42
|
+
fun `a prefix is not mistaken for the address`() {
|
|
43
|
+
assertThat(NetworkFacts.ownerOf("192.168.43.79/24", table)).isNull()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Test
|
|
47
|
+
fun `gatherable drops loopback, down, and addressless interfaces`() {
|
|
48
|
+
assertThat(NetworkFacts.gatherable(table).map { it.name })
|
|
49
|
+
.containsExactly("wlan0", "rmnet_data0")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Test
|
|
53
|
+
fun `render keeps the name, flags and every address`() {
|
|
54
|
+
val line = NetworkFacts.render(listOf(iface("wlan0", listOf("192.168.43.79/24", "10.1.2.3/24"))))
|
|
55
|
+
|
|
56
|
+
assertThat(line).contains("wlan0#1")
|
|
57
|
+
assertThat(line).contains("192.168.43.79/24,10.1.2.3/24")
|
|
58
|
+
}
|
|
59
|
+
}
|
package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedLocalNetworkPermissionTest.kt
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
4
|
+
import org.junit.Test
|
|
5
|
+
|
|
6
|
+
class ScopedLocalNetworkPermissionTest {
|
|
7
|
+
@Test
|
|
8
|
+
fun `Android 17 preserves implicit access for the SDK 36 host`() {
|
|
9
|
+
assertThat(ScopedSoftApNetwork.hasLocalNetworkPermission(37, 36) {
|
|
10
|
+
error("Legacy targets must not query the unneeded runtime grant")
|
|
11
|
+
}).isTrue()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@Test
|
|
15
|
+
fun `older Android does not query a permission it cannot enforce`() {
|
|
16
|
+
assertThat(ScopedSoftApNetwork.hasLocalNetworkPermission(36, 37) {
|
|
17
|
+
error("Older Android must not query the new permission")
|
|
18
|
+
}).isTrue()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Test
|
|
22
|
+
fun `Android 17 denies a target 37 host without the grant`() {
|
|
23
|
+
assertThat(ScopedSoftApNetwork.hasLocalNetworkPermission(37, 37) { false }).isFalse()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Test
|
|
27
|
+
fun `Android 17 allows a target 37 host with the grant`() {
|
|
28
|
+
assertThat(ScopedSoftApNetwork.hasLocalNetworkPermission(37, 37) { true }).isTrue()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Test
|
|
32
|
+
fun `future Android and target versions still enforce the grant`() {
|
|
33
|
+
assertThat(ScopedSoftApNetwork.hasLocalNetworkPermission(38, 38) { false }).isFalse()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
2
|
+
|
|
3
|
+
import com.mentra.bluetoothsdk.hotspot.ScopedNetworkState.Failure
|
|
4
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class ScopedNetworkErrorTest {
|
|
8
|
+
|
|
9
|
+
@Test
|
|
10
|
+
fun `no failure maps to no error`() {
|
|
11
|
+
assertThat(ScopedNetworkError.from(Failure.NONE, "ssid", 30_000)).isNull()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@Test
|
|
15
|
+
fun `each failure maps to its typed error and stable code`() {
|
|
16
|
+
assertThat(ScopedNetworkError.from(Failure.TIMEOUT, "ap", 30_000))
|
|
17
|
+
.isInstanceOf(ScopedNetworkError.Timeout::class.java)
|
|
18
|
+
.extracting("code")
|
|
19
|
+
.isEqualTo(ScopedNetworkError.CODE_TIMEOUT)
|
|
20
|
+
|
|
21
|
+
assertThat(ScopedNetworkError.from(Failure.UNAVAILABLE, "ap", 30_000))
|
|
22
|
+
.isInstanceOf(ScopedNetworkError.Unavailable::class.java)
|
|
23
|
+
|
|
24
|
+
assertThat(ScopedNetworkError.from(Failure.LOST, "ap", 30_000))
|
|
25
|
+
.isInstanceOf(ScopedNetworkError.Lost::class.java)
|
|
26
|
+
|
|
27
|
+
assertThat(ScopedNetworkError.from(Failure.REQUEST_FAILED, "ap", 30_000))
|
|
28
|
+
.isInstanceOf(ScopedNetworkError.RequestFailed::class.java)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A denied permission must be its own error, not a timeout: otherwise it looks like a flaky
|
|
33
|
+
* hotspot and costs 30 seconds before failing.
|
|
34
|
+
*/
|
|
35
|
+
@Test
|
|
36
|
+
fun `permission denial is distinct from a timeout`() {
|
|
37
|
+
val denied = ScopedNetworkError.from(Failure.PERMISSION_DENIED, "ap", 30_000)
|
|
38
|
+
|
|
39
|
+
assertThat(denied).isInstanceOf(ScopedNetworkError.PermissionDenied::class.java)
|
|
40
|
+
assertThat(denied?.code).isEqualTo(ScopedNetworkError.CODE_PERMISSION_DENIED)
|
|
41
|
+
assertThat(denied?.code).isNotEqualTo(ScopedNetworkError.CODE_TIMEOUT)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Test
|
|
45
|
+
fun `error codes are stable and unique`() {
|
|
46
|
+
val codes =
|
|
47
|
+
listOf(
|
|
48
|
+
ScopedNetworkError.CODE_PERMISSION_DENIED,
|
|
49
|
+
ScopedNetworkError.CODE_TIMEOUT,
|
|
50
|
+
ScopedNetworkError.CODE_UNAVAILABLE,
|
|
51
|
+
ScopedNetworkError.CODE_LOST,
|
|
52
|
+
ScopedNetworkError.CODE_REQUEST_FAILED,
|
|
53
|
+
ScopedNetworkError.CODE_NO_LOCAL_ADDRESS,
|
|
54
|
+
ScopedNetworkError.CODE_NOT_READY,
|
|
55
|
+
ScopedNetworkError.CODE_WIFI_DISABLED,
|
|
56
|
+
ScopedNetworkError.CODE_VPN_ACTIVE,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
assertThat(codes).doesNotHaveDuplicates()
|
|
60
|
+
assertThat(codes).allMatch { it.startsWith("SOFTAP_") }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Test
|
|
64
|
+
fun `messages name the ssid so a log line is actionable`() {
|
|
65
|
+
assertThat(ScopedNetworkError.Timeout("MentraLive-1234", 30_000).message)
|
|
66
|
+
.contains("MentraLive-1234")
|
|
67
|
+
.contains("30000")
|
|
68
|
+
assertThat(ScopedNetworkError.Lost("MentraLive-1234").message).contains("MentraLive-1234")
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Test
|
|
72
|
+
fun `a capturing vpn is named as the cause and tells the user what to change`() {
|
|
73
|
+
val error = ScopedNetworkError.VpnCapturesApp()
|
|
74
|
+
assertThat(error.code).isEqualTo(ScopedNetworkError.CODE_VPN_ACTIVE)
|
|
75
|
+
assertThat(error.message).contains("VPN").contains("split tunneling")
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* "Joined but not usable" has to be its own code. Reported as a join success it becomes an ICE
|
|
80
|
+
* answer with no candidates, which is the symptom several unrelated faults share.
|
|
81
|
+
*/
|
|
82
|
+
@Test
|
|
83
|
+
fun `a network that joined but never became usable names the missing source`() {
|
|
84
|
+
val error = ScopedNetworkError.NotReady("MentraLive-1234", "the kernel interface table")
|
|
85
|
+
|
|
86
|
+
assertThat(error.code).isEqualTo(ScopedNetworkError.CODE_NOT_READY)
|
|
87
|
+
assertThat(error.code).isNotEqualTo(ScopedNetworkError.CODE_NO_LOCAL_ADDRESS)
|
|
88
|
+
assertThat(error.message).contains("MentraLive-1234").contains("the kernel interface table")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Test
|
|
92
|
+
fun `the local network permission name is the platform constant`() {
|
|
93
|
+
assertThat(ScopedNetworkError.LOCAL_NETWORK_PERMISSION)
|
|
94
|
+
.isEqualTo("android.permission.ACCESS_LOCAL_NETWORK")
|
|
95
|
+
}
|
|
96
|
+
}
|