@mentra/glasses-media 3.5.0-dev.1274 → 3.5.0-dev.1278
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/build.gradle +1 -0
- package/android/src/main/java/com/mentra/glassesmedia/GlassesMediaRelayModule.kt +2 -0
- package/android/src/main/java/com/mentra/glassesmedia/network/InternetHold.kt +1 -1
- package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkChangeDetector.kt +3 -1
- package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkObserver.kt +1 -1
- package/android/src/main/java/com/mentra/glassesmedia/publisher/PhoneWhipPublisher.kt +1 -1
- package/android/src/main/java/com/mentra/glassesmedia/source/GlassesMediaSource.kt +1 -1
- package/android/src/main/java/com/mentra/glassesmedia/source/LocalWhipIngestSource.kt +3 -3
- package/android/src/main/java/com/mentra/glassesmedia/source/SelectedIcePair.kt +1 -1
- package/android/src/main/java/com/mentra/glassesmedia/source/SoftApIceDiagnosis.kt +3 -2
- package/android/src/main/java/com/mentra/glassesmedia/source/SoftApSdpGuard.kt +1 -1
- package/android/src/main/java/com/mentra/glassesmedia/source/VideoSourceArm.kt +2 -0
- package/android/src/main/java/com/mentra/glassesmedia/source/WhipIngestServer.kt +2 -2
- package/ios/GlassesHotspotNetwork.swift +8 -10
- package/ios/GlassesMediaRelayModule.swift +6 -1
- package/ios/LocalWhipIngestSource.swift +2 -2
- package/ios/MediaLog.swift +13 -0
- package/ios/WhepVideoSource.swift +8 -8
- package/package.json +4 -1
- package/android/src/main/java/com/mentra/glassesmedia/network/Ipv4Prefix.kt +0 -51
- package/android/src/main/java/com/mentra/glassesmedia/network/NetworkFacts.kt +0 -81
- package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkError.kt +0 -109
- package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkReadiness.kt +0 -103
- package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkRequestSpec.kt +0 -53
- package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkState.kt +0 -127
- package/android/src/main/java/com/mentra/glassesmedia/network/ScopedSoftApNetwork.kt +0 -584
- package/android/src/main/java/com/mentra/glassesmedia/trace/SoftApTrace.kt +0 -143
package/android/build.gradle
CHANGED
|
@@ -66,6 +66,7 @@ afterEvaluate {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
dependencies {
|
|
69
|
+
implementation project(':mentra-bluetooth-sdk')
|
|
69
70
|
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4'
|
|
70
71
|
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
|
|
71
72
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1'
|
|
@@ -8,7 +8,7 @@ import android.net.NetworkCapabilities
|
|
|
8
8
|
import android.net.NetworkRequest
|
|
9
9
|
import android.net.wifi.WifiManager
|
|
10
10
|
import android.os.SystemClock
|
|
11
|
-
import com.mentra.
|
|
11
|
+
import com.mentra.bluetoothsdk.hotspot.SoftApTrace
|
|
12
12
|
import java.net.Inet4Address
|
|
13
13
|
import java.util.concurrent.CountDownLatch
|
|
14
14
|
import java.util.concurrent.TimeUnit
|
package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkChangeDetector.kt
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
package com.mentra.glassesmedia.network
|
|
2
2
|
|
|
3
|
+
import com.mentra.bluetoothsdk.hotspot.ScopedSoftApNetwork
|
|
4
|
+
import com.mentra.bluetoothsdk.hotspot.NetworkFacts
|
|
3
5
|
import android.content.Context
|
|
4
6
|
import android.net.ConnectivityManager
|
|
5
|
-
import com.mentra.
|
|
7
|
+
import com.mentra.bluetoothsdk.hotspot.SoftApTrace
|
|
6
8
|
import java.net.Inet4Address
|
|
7
9
|
import org.webrtc.NetworkChangeDetector
|
|
8
10
|
import org.webrtc.NetworkMonitor
|
|
@@ -5,7 +5,7 @@ import android.net.ConnectivityManager
|
|
|
5
5
|
import android.os.Handler
|
|
6
6
|
import android.os.HandlerThread
|
|
7
7
|
import com.mentra.glassesmedia.network.InternetHold
|
|
8
|
-
import com.mentra.
|
|
8
|
+
import com.mentra.bluetoothsdk.hotspot.SoftApTrace
|
|
9
9
|
import com.mentra.glassesmedia.source.I420Planes
|
|
10
10
|
import java.io.IOException
|
|
11
11
|
import java.util.concurrent.CountDownLatch
|
|
@@ -3,11 +3,11 @@ package com.mentra.glassesmedia.source
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.media.AudioAttributes
|
|
5
5
|
import com.mentra.glassesmedia.trace.MediaLog as Log
|
|
6
|
-
import com.mentra.
|
|
6
|
+
import com.mentra.bluetoothsdk.hotspot.NetworkFacts
|
|
7
7
|
import com.mentra.glassesmedia.network.ScopedNetworkChangeDetector
|
|
8
|
-
import com.mentra.
|
|
8
|
+
import com.mentra.bluetoothsdk.hotspot.ScopedSoftApNetwork
|
|
9
9
|
import com.mentra.glassesmedia.telemetry.PipelineStats
|
|
10
|
-
import com.mentra.
|
|
10
|
+
import com.mentra.bluetoothsdk.hotspot.SoftApTrace
|
|
11
11
|
import org.webrtc.AudioTrack
|
|
12
12
|
import org.webrtc.DefaultVideoDecoderFactory
|
|
13
13
|
import org.webrtc.DefaultVideoEncoderFactory
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.mentra.glassesmedia.source
|
|
2
2
|
|
|
3
|
-
import com.mentra.
|
|
3
|
+
import com.mentra.bluetoothsdk.hotspot.NetworkFacts
|
|
4
|
+
import com.mentra.bluetoothsdk.hotspot.Ipv4Prefix
|
|
4
5
|
import com.mentra.glassesmedia.network.ScopedNetworkChangeDetector.PublishedEntry
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -64,7 +65,7 @@ object SoftApIceDiagnosis {
|
|
|
64
65
|
get() = candidates.filterNot { it.onHotspot }
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
|
-
* Flattened for [SoftApTrace][com.mentra.
|
|
68
|
+
* Flattened for [SoftApTrace][com.mentra.bluetoothsdk.hotspot.SoftApTrace] and the analyzer.
|
|
68
69
|
* Field names are the contract `softap-call-proof.mjs` reads, so they are stable.
|
|
69
70
|
*/
|
|
70
71
|
fun fields(): Array<Pair<String, Any?>> =
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
package com.mentra.glassesmedia.source
|
|
2
2
|
|
|
3
3
|
import com.mentra.glassesmedia.trace.MediaLog as Log
|
|
4
|
-
import com.mentra.
|
|
4
|
+
import com.mentra.bluetoothsdk.hotspot.SoftApTrace
|
|
5
5
|
import java.io.BufferedInputStream
|
|
6
6
|
import java.io.BufferedOutputStream
|
|
7
7
|
import java.io.IOException
|
|
@@ -92,7 +92,7 @@ class WhipIngestServer(
|
|
|
92
92
|
* Binds and begins accepting.
|
|
93
93
|
*
|
|
94
94
|
* @param address the phone's own address on the SoftAP, from
|
|
95
|
-
* [com.mentra.
|
|
95
|
+
* [com.mentra.bluetoothsdk.hotspot.ScopedSoftApNetwork.localIpv4]
|
|
96
96
|
* @param port 0 to let the OS choose, which is what production does; the fixed-port form exists
|
|
97
97
|
* for tests
|
|
98
98
|
*/
|
|
@@ -2,11 +2,9 @@ import Darwin
|
|
|
2
2
|
import Foundation
|
|
3
3
|
import Network
|
|
4
4
|
import NetworkExtension
|
|
5
|
-
import OSLog
|
|
6
5
|
|
|
7
6
|
/// Shared hotspot association owner. Only local glasses traffic uses Wi-Fi.
|
|
8
7
|
public final class GlassesHotspotNetwork {
|
|
9
|
-
private let logger = Logger(subsystem: "com.mentra.glassesmedia", category: "hotspot")
|
|
10
8
|
private let queue = DispatchQueue(label: "com.mentra.glassesmedia.hotspot")
|
|
11
9
|
private var ssid: String?
|
|
12
10
|
private var lastHotspotSSID: String?
|
|
@@ -333,7 +331,7 @@ public final class GlassesHotspotNetwork {
|
|
|
333
331
|
applying = true
|
|
334
332
|
ownsConfiguration = true
|
|
335
333
|
applies += 1
|
|
336
|
-
|
|
334
|
+
MediaLog.log("HOTSPOT_JOIN apply_start attempt=\(self.applies) ios_on_mac=\(ProcessInfo.processInfo.isiOSAppOnMac)")
|
|
337
335
|
NEHotspotConfigurationManager.shared.apply(config) { error in
|
|
338
336
|
self.queue.async {
|
|
339
337
|
guard gen == self.generation else { return }
|
|
@@ -346,11 +344,11 @@ public final class GlassesHotspotNetwork {
|
|
|
346
344
|
if !alreadyAssociated {
|
|
347
345
|
// Error identifiers are useful without credentials or full userInfo.
|
|
348
346
|
let underlying = nativeError.userInfo[NSUnderlyingErrorKey] as? NSError
|
|
349
|
-
|
|
347
|
+
MediaLog.log("HOTSPOT_JOIN apply_failed domain=\(nativeError.domain) code=\(nativeError.code) underlying_domain=\(underlying?.domain ?? "none") underlying_code=\(underlying.map { String($0.code) } ?? "none")")
|
|
350
348
|
self.finishJoin(.failure(error)); self.finishLeave(); return
|
|
351
349
|
}
|
|
352
350
|
}
|
|
353
|
-
|
|
351
|
+
MediaLog.log("HOTSPOT_JOIN apply_accepted")
|
|
354
352
|
self.waitForAddress(ssid: ssid, passphrase: passphrase, generation: gen, remaining: remaining, pollsSinceApply: 0)
|
|
355
353
|
}
|
|
356
354
|
}
|
|
@@ -368,7 +366,7 @@ public final class GlassesHotspotNetwork {
|
|
|
368
366
|
} else if remaining > 0, network?.ssid != ssid,
|
|
369
367
|
self.reapplyPolicy.shouldReapply(applies: self.applies, pollsSinceApply: pollsSinceApply) {
|
|
370
368
|
// iOS reports the request applied even when its one scan missed the hotspot.
|
|
371
|
-
|
|
369
|
+
MediaLog.log("HOTSPOT_JOIN reapply after_polls=\(pollsSinceApply)")
|
|
372
370
|
self.applyConfiguration(ssid: ssid, passphrase: passphrase, generation: gen, remaining: remaining)
|
|
373
371
|
} else if remaining > 0 {
|
|
374
372
|
self.queue.asyncAfter(deadline: .now() + 0.5) {
|
|
@@ -431,7 +429,7 @@ public final class GlassesHotspotNetwork {
|
|
|
431
429
|
let evidence = wifiIdentity.trusted[selected.interface] == selected.index ? "wifi_report" : "hotspot_client"
|
|
432
430
|
wifiIdentity.adopt(selected)
|
|
433
431
|
binding = selected
|
|
434
|
-
|
|
432
|
+
MediaLog.log("HOTSPOT_JOIN address_verified interface=\(selected.interface) evidence=\(evidence)")
|
|
435
433
|
}
|
|
436
434
|
|
|
437
435
|
/// Interface names and their IPv4 addresses only; never credentials or SSIDs.
|
|
@@ -463,13 +461,13 @@ public final class GlassesHotspotNetwork {
|
|
|
463
461
|
localAccess = request
|
|
464
462
|
request.start(onPermissionRequired: { [weak self] in
|
|
465
463
|
guard let self, gen == generation, !cancelled else { return }
|
|
466
|
-
|
|
464
|
+
MediaLog.log("GLASSES-MEDIA local_network_permission=waiting")
|
|
467
465
|
onPermissionRequired?()
|
|
468
466
|
}) { [weak self] result in
|
|
469
467
|
guard let self, gen == generation, !cancelled else { return }
|
|
470
468
|
switch result {
|
|
471
469
|
case .success:
|
|
472
|
-
|
|
470
|
+
MediaLog.log("GLASSES-MEDIA local_network_permission=ready")
|
|
473
471
|
finishJoin(.success(address))
|
|
474
472
|
case let .failure(error):
|
|
475
473
|
finishJoin(.failure(error))
|
|
@@ -542,7 +540,7 @@ public final class GlassesHotspotNetwork {
|
|
|
542
540
|
// bounded observation ends. Route readiness is not HTTP success;
|
|
543
541
|
// the following ordinary update check still owns that result.
|
|
544
542
|
startInternetObservation(allowWifiAfterRelease: true) { ready, reason in
|
|
545
|
-
|
|
543
|
+
MediaLog.log("HOTSPOT_LEAVE internet_recovery ready=\(ready) reason=\(reason)")
|
|
546
544
|
finish()
|
|
547
545
|
}
|
|
548
546
|
} else { finish() }
|
|
@@ -9,7 +9,11 @@ public final class GlassesMediaRelayModule: Module {
|
|
|
9
9
|
|
|
10
10
|
public func definition() -> ModuleDefinition {
|
|
11
11
|
Name("MentraGlassesMediaRelay")
|
|
12
|
-
Events("onRelayState", "onLocalHotspotPermissionRequired")
|
|
12
|
+
Events("onRelayState", "onLocalHotspotPermissionRequired", "onNativeLog")
|
|
13
|
+
|
|
14
|
+
OnCreate {
|
|
15
|
+
MediaLog.sink = { [weak self] message in self?.sendEvent("onNativeLog", ["message": message]) }
|
|
16
|
+
}
|
|
13
17
|
|
|
14
18
|
AsyncFunction("joinLocalHotspot") { (id: String, ssid: String, password: String, gateway: String?, purpose: String, promise: Promise) in
|
|
15
19
|
self.queue.async {
|
|
@@ -92,6 +96,7 @@ public final class GlassesMediaRelayModule: Module {
|
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
OnDestroy {
|
|
99
|
+
MediaLog.sink = nil
|
|
95
100
|
self.queue.async {
|
|
96
101
|
self.session?.stop { result in
|
|
97
102
|
if case .success = result { self.session = nil }
|
|
@@ -90,7 +90,7 @@ public final class LocalWhipIngestSource: NSObject, DecodedGlassesMediaSource {
|
|
|
90
90
|
}
|
|
91
91
|
self.forceCloseIngestLocked()
|
|
92
92
|
let closed = self.awaitIngestClosedLocked(timeoutMs: timeoutMs)
|
|
93
|
-
|
|
93
|
+
MediaLog.log("SOFTAP_TRACE stage=ingest_rebind oldUrl=\(oldUrl ?? "none") newUrl=\(newUrl) closed=\(closed)")
|
|
94
94
|
if !closed {
|
|
95
95
|
completion(.failure(LocalMediaError("SoftAP ingest rebind did not release the old listener")))
|
|
96
96
|
return
|
|
@@ -350,7 +350,7 @@ public final class LocalWhipIngestSource: NSObject, DecodedGlassesMediaSource {
|
|
|
350
350
|
private func transition(_ state: SourceState, _ reason: String) {
|
|
351
351
|
guard currentState != state else { return }
|
|
352
352
|
currentState = state
|
|
353
|
-
|
|
353
|
+
MediaLog.log("GLASSES-MEDIA source=\(state.rawValue) reason=\(reason)")
|
|
354
354
|
onStateChange?(state, reason)
|
|
355
355
|
}
|
|
356
356
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// The console plus the app's JavaScript console, which bug reports upload. glasses-media and
|
|
4
|
+
/// acs-meeting log through it, so the hotspot, relay, ingest and ACS traces reach a report.
|
|
5
|
+
public enum MediaLog {
|
|
6
|
+
/// Set by `GlassesMediaRelayModule` while it exists.
|
|
7
|
+
public static var sink: ((String) -> Void)?
|
|
8
|
+
|
|
9
|
+
public static func log(_ message: String) {
|
|
10
|
+
NSLog("%@", message)
|
|
11
|
+
sink?(message)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -103,7 +103,7 @@ public final class WhepVideoSource: NSObject, DecodedGlassesMediaSource {
|
|
|
103
103
|
/// networks; ICE may not have noticed the dead candidate pair yet).
|
|
104
104
|
public func forceRestart() {
|
|
105
105
|
guard let url = currentUrl else { return }
|
|
106
|
-
|
|
106
|
+
MediaLog.log("ACS-SPIKE WHEP forced rebuild state=\(state.rawValue)")
|
|
107
107
|
start(whepUrl: url)
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -118,7 +118,7 @@ public final class WhepVideoSource: NSObject, DecodedGlassesMediaSource {
|
|
|
118
118
|
public func setPcmEnabled(_ enabled: Bool) {
|
|
119
119
|
pcmEnabled = enabled
|
|
120
120
|
audioTracks.forEach { $0.isEnabled = enabled }
|
|
121
|
-
|
|
121
|
+
MediaLog.log("ACS-SPIKE WHEP audio track enabled=\(enabled)")
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
public func stop() {
|
|
@@ -149,7 +149,7 @@ public final class WhepVideoSource: NSObject, DecodedGlassesMediaSource {
|
|
|
149
149
|
let previous = state
|
|
150
150
|
state = next
|
|
151
151
|
guard previous != next else { return }
|
|
152
|
-
|
|
152
|
+
MediaLog.log("ACS-SPIKE WHEP source \(previous.rawValue) -> \(next.rawValue) (\(reason))")
|
|
153
153
|
onStateChange?(next, reason)
|
|
154
154
|
}
|
|
155
155
|
|
|
@@ -193,11 +193,11 @@ public final class WhepVideoSource: NSObject, DecodedGlassesMediaSource {
|
|
|
193
193
|
http.dataTask(with: request) { [weak self] data, response, error in
|
|
194
194
|
guard let self, self.generation == gen else { return }
|
|
195
195
|
let code = (response as? HTTPURLResponse)?.statusCode ?? -1
|
|
196
|
-
|
|
196
|
+
MediaLog.log("ACS-SPIKE P3 WHEP \(code) answer bytes=\(data?.count ?? 0)")
|
|
197
197
|
guard error == nil, (200 ..< 300).contains(code),
|
|
198
198
|
let data, let answer = String(data: data, encoding: .utf8)
|
|
199
199
|
else {
|
|
200
|
-
|
|
200
|
+
MediaLog.log("ACS-SPIKE WHEP answer rejected code=\(code) error=\(error?.localizedDescription ?? "none")")
|
|
201
201
|
self.transition(.failed, reason: error != nil ? "whep_post_failed" : "whep_http_\(code)")
|
|
202
202
|
return
|
|
203
203
|
}
|
|
@@ -221,7 +221,7 @@ public final class WhepVideoSource: NSObject, DecodedGlassesMediaSource {
|
|
|
221
221
|
guard let self else { return }
|
|
222
222
|
self.firstFrameDeadline = nil
|
|
223
223
|
guard self.generation == gen, self.firstFrameGeneration == gen, !self.firstFramePromoted else { return }
|
|
224
|
-
|
|
224
|
+
MediaLog.log("ACS-SPIKE WHEP answered but delivered no frame in \(Self.firstFrameTimeout)s")
|
|
225
225
|
self.transition(.failed, reason: "no_first_frame")
|
|
226
226
|
}
|
|
227
227
|
firstFrameDeadline = work
|
|
@@ -261,7 +261,7 @@ extension WhepVideoSource: RTCPeerConnectionDelegate {
|
|
|
261
261
|
public func peerConnection(_: RTCPeerConnection, didRemove _: RTCMediaStream) {}
|
|
262
262
|
public func peerConnectionShouldNegotiate(_: RTCPeerConnection) {}
|
|
263
263
|
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceConnectionState) {
|
|
264
|
-
|
|
264
|
+
MediaLog.log("ACS-SPIKE ICE \(newState.rawValue)")
|
|
265
265
|
guard isCurrent(peerConnection) else { return }
|
|
266
266
|
if newState == .failed || newState == .disconnected {
|
|
267
267
|
transition(.failed, reason: newState == .failed ? "ice_failed" : "ice_disconnected")
|
|
@@ -305,7 +305,7 @@ extension WhepVideoSource: RTCVideoRenderer {
|
|
|
305
305
|
frameCount += 1
|
|
306
306
|
let now = Date()
|
|
307
307
|
if now.timeIntervalSince(lastFpsLog) >= 1 {
|
|
308
|
-
|
|
308
|
+
MediaLog.log("ACS-SPIKE P3 video \(Int(frame.width))x\(Int(frame.height)) fps=\(frameCount)")
|
|
309
309
|
frameCount = 0
|
|
310
310
|
lastFpsLog = now
|
|
311
311
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentra/glasses-media",
|
|
3
|
-
"version": "3.5.0-dev.
|
|
3
|
+
"version": "3.5.0-dev.1278",
|
|
4
4
|
"description": "Shared native glasses media receivers and local network transport",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mentra Community",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@mentra/bluetooth-sdk": "3.5.0-dev.1278"
|
|
20
|
+
},
|
|
18
21
|
"peerDependencies": {
|
|
19
22
|
"expo-modules-core": "~55.0.25"
|
|
20
23
|
},
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
package com.mentra.glassesmedia.network
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* An IPv4 subnet, taken from the phone's own address on a joined network.
|
|
5
|
-
*
|
|
6
|
-
* SoftAP correctness is an interface question, not an address-range question: the media path is
|
|
7
|
-
* right when the selected candidate sits on the network we joined, and wrong otherwise. Matching
|
|
8
|
-
* "looks RFC1918" or "starts with 192.168.43" answers a different question and stops being true the
|
|
9
|
-
* moment an OEM picks another hotspot subnet, so every SoftAP check compares against the prefix
|
|
10
|
-
* `LinkProperties` actually reported.
|
|
11
|
-
*/
|
|
12
|
-
data class Ipv4Prefix(val address: String, val prefixLength: Int) {
|
|
13
|
-
|
|
14
|
-
private val network: Int? = packIpv4(address)?.let { it and maskFor(prefixLength) }
|
|
15
|
-
|
|
16
|
-
/** True when [candidate] is a dotted-quad IPv4 address inside this prefix. */
|
|
17
|
-
fun contains(candidate: String?): Boolean {
|
|
18
|
-
val base = network ?: return false
|
|
19
|
-
val value = packIpv4(candidate) ?: return false
|
|
20
|
-
return (value and maskFor(prefixLength)) == base
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
override fun toString(): String = "$address/$prefixLength"
|
|
24
|
-
|
|
25
|
-
companion object {
|
|
26
|
-
/**
|
|
27
|
-
* Dotted-quad to a packed int, or null when [token] is not one. Deliberately strict: a
|
|
28
|
-
* token like `192.168.43` or `candidate:1` must not be read as an address, because the
|
|
29
|
-
* callers scan whitespace-split SDP lines where most tokens are not addresses at all.
|
|
30
|
-
*/
|
|
31
|
-
fun packIpv4(token: String?): Int? {
|
|
32
|
-
val text = token ?: return null
|
|
33
|
-
val octets = text.split('.')
|
|
34
|
-
if (octets.size != 4) return null
|
|
35
|
-
var packed = 0
|
|
36
|
-
for (octet in octets) {
|
|
37
|
-
if (octet.isEmpty() || octet.length > 3) return null
|
|
38
|
-
val value = octet.toIntOrNull() ?: return null
|
|
39
|
-
if (value < 0 || value > 255) return null
|
|
40
|
-
packed = (packed shl 8) or value
|
|
41
|
-
}
|
|
42
|
-
return packed
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** A /0 masks nothing; Kotlin's `shl 32` is a no-op, so that case is spelled out. */
|
|
46
|
-
private fun maskFor(prefixLength: Int): Int {
|
|
47
|
-
val bits = prefixLength.coerceIn(0, 32)
|
|
48
|
-
return if (bits == 0) 0 else (-1 shl (32 - bits))
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
package com.mentra.glassesmedia.network
|
|
2
|
-
|
|
3
|
-
import java.net.Inet4Address
|
|
4
|
-
import java.net.NetworkInterface
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The kernel's interface table, as libwebrtc's `getifaddrs` sees it.
|
|
8
|
-
*
|
|
9
|
-
* Every SoftAP ICE failure so far has come from our view of the network disagreeing with
|
|
10
|
-
* libwebrtc's, and the two views come from different sources. We publish
|
|
11
|
-
* [ConnectivityManager.getLinkProperties][android.net.ConnectivityManager.getLinkProperties] for
|
|
12
|
-
* the scoped `Network`; libwebrtc enumerates `getifaddrs` and only asks our monitor for each
|
|
13
|
-
* *interface name*'s adapter type. When those disagree — an address on a name we never typed, or a
|
|
14
|
-
* scoped address absent from the table entirely — no mask and no inventory can help, because ICE
|
|
15
|
-
* gathers per address, not per `Network`.
|
|
16
|
-
*
|
|
17
|
-
* `java.net.NetworkInterface` is getifaddrs-backed, so this is the closest thing to libwebrtc's
|
|
18
|
-
* own input that we can read from Kotlin. Pure enough to unit test, which matters: it is the
|
|
19
|
-
* evidence the next diagnosis rests on.
|
|
20
|
-
*/
|
|
21
|
-
object NetworkFacts {
|
|
22
|
-
|
|
23
|
-
/** One interface, with the flags libwebrtc's enumeration also keys off. */
|
|
24
|
-
data class Iface(
|
|
25
|
-
val name: String,
|
|
26
|
-
val index: Int,
|
|
27
|
-
val up: Boolean,
|
|
28
|
-
val loopback: Boolean,
|
|
29
|
-
val virtual: Boolean,
|
|
30
|
-
val pointToPoint: Boolean,
|
|
31
|
-
val mtu: Int,
|
|
32
|
-
/** IPv4 only, as `address/prefixLength` — the form libwebrtc turns into a Network key. */
|
|
33
|
-
val ipv4: List<String>,
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
/** Read the table. Never throws: a diagnostic that crashes the call is worse than no data. */
|
|
37
|
-
fun snapshot(): List<Iface> =
|
|
38
|
-
runCatching {
|
|
39
|
-
NetworkInterface.getNetworkInterfaces()?.toList().orEmpty().map { candidate ->
|
|
40
|
-
Iface(
|
|
41
|
-
name = candidate.name ?: "?",
|
|
42
|
-
index = runCatching { candidate.index }.getOrDefault(-1),
|
|
43
|
-
up = runCatching { candidate.isUp }.getOrDefault(false),
|
|
44
|
-
loopback = runCatching { candidate.isLoopback }.getOrDefault(false),
|
|
45
|
-
virtual = runCatching { candidate.isVirtual }.getOrDefault(false),
|
|
46
|
-
pointToPoint = runCatching { candidate.isPointToPoint }.getOrDefault(false),
|
|
47
|
-
mtu = runCatching { candidate.mtu }.getOrDefault(-1),
|
|
48
|
-
ipv4 =
|
|
49
|
-
runCatching {
|
|
50
|
-
candidate.interfaceAddresses
|
|
51
|
-
.filter { it.address is Inet4Address }
|
|
52
|
-
.map { "${it.address.hostAddress}/${it.networkPrefixLength}" }
|
|
53
|
-
}.getOrDefault(emptyList()),
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
}.getOrElse { emptyList() }
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Only interfaces that can carry a host candidate: up, non-loopback, with an IPv4 address.
|
|
60
|
-
* Anything here is something ICE may gather on.
|
|
61
|
-
*/
|
|
62
|
-
fun gatherable(table: List<Iface> = snapshot()): List<Iface> =
|
|
63
|
-
table.filter { it.up && !it.loopback && it.ipv4.isNotEmpty() }
|
|
64
|
-
|
|
65
|
-
/** The interface the kernel says owns [address], or null when the table has never seen it. */
|
|
66
|
-
fun ownerOf(address: String, table: List<Iface> = snapshot()): String? =
|
|
67
|
-
table.firstOrNull { iface -> iface.ipv4.any { it.substringBefore('/') == address } }?.name
|
|
68
|
-
|
|
69
|
-
/** One log line per interface, flags abbreviated so a full table fits in a logcat entry. */
|
|
70
|
-
fun render(table: List<Iface>): String =
|
|
71
|
-
table.joinToString(" ") { iface ->
|
|
72
|
-
val flags =
|
|
73
|
-
buildString {
|
|
74
|
-
if (iface.up) append("U")
|
|
75
|
-
if (iface.loopback) append("L")
|
|
76
|
-
if (iface.virtual) append("V")
|
|
77
|
-
if (iface.pointToPoint) append("P")
|
|
78
|
-
}
|
|
79
|
-
"${iface.name}#${iface.index}[$flags mtu=${iface.mtu}](${iface.ipv4.joinToString(",")})"
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
package com.mentra.glassesmedia.network
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Typed failures for a scoped SoftAP join.
|
|
5
|
-
*
|
|
6
|
-
* A denied local-network permission must surface as a distinct, immediate error rather than a
|
|
7
|
-
* 30-second hang that looks like a flaky hotspot. `ACCESS_LOCAL_NETWORK` sits in the nearby-devices
|
|
8
|
-
* group, so it is often already granted during development and easy to miss until a user without it
|
|
9
|
-
* hits a silent timeout.
|
|
10
|
-
*/
|
|
11
|
-
sealed class ScopedNetworkError(val code: String, message: String) : Exception(message) {
|
|
12
|
-
|
|
13
|
-
/** `ACCESS_LOCAL_NETWORK` (or the nearby-devices prerequisite) was not granted. */
|
|
14
|
-
class PermissionDenied(val permission: String) :
|
|
15
|
-
ScopedNetworkError(
|
|
16
|
-
CODE_PERMISSION_DENIED,
|
|
17
|
-
"Local network permission not granted: $permission",
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
/** No usable network arrived before the request timeout. */
|
|
21
|
-
class Timeout(val ssid: String, val timeoutMs: Int) :
|
|
22
|
-
ScopedNetworkError(CODE_TIMEOUT, "Timed out joining $ssid after ${timeoutMs}ms")
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The framework reported it cannot provide this network at all.
|
|
26
|
-
*
|
|
27
|
-
* WifiNetworkSpecifier does not keep scanning for the request timeout. If the glasses AP is
|
|
28
|
-
* not in the current scan — or the user dismissed the system join sheet — this arrives in
|
|
29
|
-
* well under a second.
|
|
30
|
-
*/
|
|
31
|
-
class Unavailable(val ssid: String) :
|
|
32
|
-
ScopedNetworkError(
|
|
33
|
-
CODE_UNAVAILABLE,
|
|
34
|
-
"Could not join $ssid (SSID not in scan, Wi-Fi off, or the system join prompt was dismissed)",
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
/** The network was joined and then went away mid-call. */
|
|
38
|
-
class Lost(val ssid: String) :
|
|
39
|
-
ScopedNetworkError(CODE_LOST, "Lost the connection to $ssid")
|
|
40
|
-
|
|
41
|
-
/** `requestNetwork` itself threw. */
|
|
42
|
-
class RequestFailed(val reason: String) :
|
|
43
|
-
ScopedNetworkError(CODE_REQUEST_FAILED, "Scoped network request failed: $reason")
|
|
44
|
-
|
|
45
|
-
/** Joined, but no IPv4 address was assigned, so nothing can bind to the link. */
|
|
46
|
-
class NoLocalAddress(val ssid: String) :
|
|
47
|
-
ScopedNetworkError(CODE_NO_LOCAL_ADDRESS, "Joined $ssid but no IPv4 address was assigned")
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Joined, but the network never became usable for ICE: a callback never reported, or the
|
|
51
|
-
* address never appeared in the kernel's interface table.
|
|
52
|
-
*
|
|
53
|
-
* Failing here is deliberate. Proceeding produces an ICE answer with no hotspot candidate,
|
|
54
|
-
* which is the same symptom as several unrelated faults and cost real time to attribute.
|
|
55
|
-
*/
|
|
56
|
-
class NotReady(val ssid: String, val missing: String) :
|
|
57
|
-
ScopedNetworkError(
|
|
58
|
-
CODE_NOT_READY,
|
|
59
|
-
"Joined $ssid but the network never became usable: still waiting for $missing",
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
/** Phone Wi-Fi radio is off. WifiNetworkSpecifier then fails as Unavailable in under a second. */
|
|
63
|
-
class WifiDisabled :
|
|
64
|
-
ScopedNetworkError(CODE_WIFI_DISABLED, "Phone Wi-Fi is off; turn it on before joining the glasses hotspot")
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* A VPN owns this app's UID. netd then refuses to bind our sockets to the hotspot network
|
|
68
|
-
* (`EPERM`), and the glasses' TCP handshake to the WHIP listener never completes because the
|
|
69
|
-
* reply path is captured by the tunnel. Verified on-device: a shell-UID listener on the same
|
|
70
|
-
* address accepts the glasses' connection while an app-UID listener times out. The scoped join
|
|
71
|
-
* itself succeeds, so without this check the failure only shows up ten seconds into the camera
|
|
72
|
-
* step as an opaque connect timeout.
|
|
73
|
-
*/
|
|
74
|
-
class VpnCapturesApp :
|
|
75
|
-
ScopedNetworkError(
|
|
76
|
-
CODE_VPN_ACTIVE,
|
|
77
|
-
"A VPN is routing this app's traffic, so the glasses cannot reach the phone. " +
|
|
78
|
-
"Exclude Mentra from the VPN (split tunneling) or turn the VPN off, then retry",
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
companion object {
|
|
82
|
-
const val CODE_PERMISSION_DENIED = "SOFTAP_PERMISSION_DENIED"
|
|
83
|
-
const val CODE_TIMEOUT = "SOFTAP_JOIN_TIMEOUT"
|
|
84
|
-
const val CODE_UNAVAILABLE = "SOFTAP_UNAVAILABLE"
|
|
85
|
-
const val CODE_LOST = "SOFTAP_NETWORK_LOST"
|
|
86
|
-
const val CODE_REQUEST_FAILED = "SOFTAP_REQUEST_FAILED"
|
|
87
|
-
const val CODE_NO_LOCAL_ADDRESS = "SOFTAP_NO_LOCAL_ADDRESS"
|
|
88
|
-
const val CODE_NOT_READY = "SOFTAP_NETWORK_NOT_READY"
|
|
89
|
-
const val CODE_WIFI_DISABLED = "SOFTAP_WIFI_DISABLED"
|
|
90
|
-
const val CODE_VPN_ACTIVE = "SOFTAP_VPN_ACTIVE"
|
|
91
|
-
|
|
92
|
-
/** Map a terminal state-machine failure onto the typed error the call path reports. */
|
|
93
|
-
fun from(failure: ScopedNetworkState.Failure, ssid: String, timeoutMs: Int): ScopedNetworkError? =
|
|
94
|
-
when (failure) {
|
|
95
|
-
ScopedNetworkState.Failure.NONE -> null
|
|
96
|
-
ScopedNetworkState.Failure.TIMEOUT -> Timeout(ssid, timeoutMs)
|
|
97
|
-
ScopedNetworkState.Failure.UNAVAILABLE -> Unavailable(ssid)
|
|
98
|
-
ScopedNetworkState.Failure.LOST -> Lost(ssid)
|
|
99
|
-
ScopedNetworkState.Failure.PERMISSION_DENIED -> PermissionDenied(LOCAL_NETWORK_PERMISSION)
|
|
100
|
-
ScopedNetworkState.Failure.REQUEST_FAILED -> RequestFailed("requestNetwork threw")
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Enforced on Android 17+ for apps targeting SDK 37+. Hosts targeting older SDKs
|
|
105
|
-
* retain implicit access through INTERNET and must not request this permission.
|
|
106
|
-
*/
|
|
107
|
-
const val LOCAL_NETWORK_PERMISSION = "android.permission.ACCESS_LOCAL_NETWORK"
|
|
108
|
-
}
|
|
109
|
-
}
|