@mentra/bluetooth-sdk 3.4.0-dev.999 → 3.4.1-beta.1409
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION.md +16 -7
- package/README.md +41 -14
- package/android/build.gradle +60 -51
- package/android/gradle.properties +3 -0
- package/android/settings.gradle +47 -3
- package/android/src/main/assets/nimo/nimo-firmware-0.1.1.1-537cf1.bin +0 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BesCrashReportWaiters.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +5 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +77 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +41 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +131 -122
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +3 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +31 -10
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt +57 -196
- package/android/src/main/java/com/mentra/bluetoothsdk/OtaManifest.kt +1 -16
- package/android/src/main/java/com/mentra/bluetoothsdk/debug/BleTraceLogger.kt +10 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
- 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 +108 -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 +44 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkState.kt +117 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedSoftApNetwork.kt +598 -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/ClassicAudioConnectionTracker.kt +15 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +308 -60
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +14 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +210 -325
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +0 -35
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +2 -10
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareUpdater.kt +213 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoOtaProtocol.kt +112 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/streaming/StreamModels.kt +17 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueue.kt +92 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHost.kt +169 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +74 -115
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +348 -357
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetector.kt +211 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngine.kt +137 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SttTextFormatter.kt +52 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/WakeWordDetector.kt +235 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AvifExifStripper.java +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +3 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +11 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/AudioRouteWatcher.kt +120 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +181 -16
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlayback.kt +177 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/BesCrashReportWaitersTest.kt +112 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/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 +85 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkLifecycleTest.kt +164 -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 +56 -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/android/src/test/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTrackerTest.kt +26 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +141 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +183 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +9 -3
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveRgbLedResponseTest.kt +76 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +1 -56
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +0 -22
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareTargetTest.kt +15 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareUpdaterTest.kt +76 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoOtaProtocolTest.kt +77 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNamingTest.kt +23 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoReadinessDriverTest.kt +31 -1
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueueTest.kt +81 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHostTest.kt +216 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/STTToolsExtractionTest.kt +108 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetectorTest.kt +126 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngineTest.kt +245 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SttTextFormatterTest.kt +67 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlaybackTest.kt +76 -0
- package/build/BluetoothSdk.types.d.ts +103 -5
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +42 -8
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +1 -0
- package/build/_private/BluetoothSdkModule.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/changelogCatalog.d.ts +5 -2
- package/build/generated/changelogCatalog.d.ts.map +1 -1
- package/build/generated/changelogCatalog.js +6 -2
- 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 +7 -1
- package/build/index.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/build/react/useGlassesConnection.d.ts +1 -1
- package/build/react/useGlassesConnection.d.ts.map +1 -1
- package/build/react/useGlassesConnection.js +3 -3
- package/build/react/useGlassesConnection.js.map +1 -1
- package/build/react/useMentraBluetooth.d.ts +1 -1
- package/build/react/useMentraBluetooth.d.ts.map +1 -1
- package/build/react/useMentraBluetooth.js +1 -1
- package/build/react/useMentraBluetooth.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +73 -22
- package/ios/LocalIPv4.swift +0 -61
- package/ios/MentraBluetoothSDK.podspec +7 -1
- package/ios/MentraOtaServerModule.swift +0 -16
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
- package/ios/Resources/NimoFirmware/nimo-firmware-0.1.1.1-537cf1.bin +0 -0
- package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
- package/ios/Source/BesCrashReportWaiters.swift +64 -0
- package/ios/Source/BluetoothSdkDefaults.swift +4 -4
- package/ios/Source/Bridge.swift +14 -0
- package/ios/Source/DeviceManager.swift +52 -22
- package/ios/Source/GeneratedChangelogCatalog.swift +3 -2
- package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
- package/ios/Source/MentraBluetoothSDK.swift +35 -16
- package/ios/Source/OtaManifest.swift +1 -17
- package/ios/Source/audio/PcmStreamPlayer.swift +290 -57
- package/ios/Source/audio/PcmUrlPlayback.swift +231 -0
- package/ios/Source/audio/SpeechActivity.swift +277 -0
- package/ios/Source/events/BluetoothEvents.swift +41 -0
- package/ios/Source/internal/BleTraceLogger.swift +14 -1
- package/ios/Source/internal/BluetoothAvailability.swift +15 -5
- package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +5 -0
- package/ios/Source/sgcs/MentraLive.swift +207 -66
- package/ios/Source/sgcs/Nimo.swift +249 -276
- package/ios/Source/sgcs/NimoCanvasCoordinator.swift +9 -38
- package/ios/Source/sgcs/NimoCanvasSession.swift +0 -1
- package/ios/Source/sgcs/NimoFirmwareUpdater.swift +260 -0
- package/ios/Source/sgcs/NimoOtaProtocol.swift +159 -0
- package/ios/Source/sgcs/SGCManager.swift +6 -0
- package/ios/Source/streaming/StreamModels.swift +15 -6
- package/ios/Source/stt/STTTools.swift +13 -31
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +204 -162
- package/ios/Source/stt/SileroSpeechActivity.swift +87 -0
- package/ios/Source/stt/WakeWordDetector.swift +145 -0
- package/ios/Source/utils/BoundedWait.swift +44 -0
- package/ios/Source/utils/DemandDrivenAudioWorker.swift +79 -0
- package/ios/Source/utils/SttModelTraits.swift +62 -0
- package/ios/Tests/BesCrashReportTests.swift +142 -0
- package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
- package/ios/Tests/DeviceManagerReconnectTests.swift +0 -71
- package/ios/Tests/GlassesAudioSetupPolicyTests.swift +9 -3
- package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
- package/ios/Tests/MentraLiveAudioSetupTests.swift +6 -12
- package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
- package/ios/Tests/MentraLiveSessionReadinessTests.swift +179 -10
- package/ios/Tests/NimoCanvasTransportTests.swift +0 -89
- package/ios/Tests/NimoOtaProtocolTests.swift +78 -0
- package/ios/Tests/PcmStreamTests.swift +299 -0
- package/ios/Tests/SpeechActivityTests.swift +238 -0
- package/ios/Tests/StreamRequestTests.swift +18 -0
- package/ios/Tests/SttModelTraitsTests.swift +62 -0
- package/package.json +2 -2
- package/plugin/build/withAndroid.js +9 -11
- package/plugin/build/withKotlinVersion.d.ts +2 -0
- package/plugin/build/withKotlinVersion.js +46 -0
- package/src/BluetoothSdk.types.ts +107 -5
- package/src/_private/BluetoothSdkModule.ts +45 -8
- package/src/_private/MentraLocalNetworkModule.ts +5 -1
- package/src/generated/changelogCatalog.ts +6 -2
- package/src/generated/releaseMetadata.ts +6 -6
- package/src/index.ts +13 -1
- 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/src/react/useGlassesConnection.ts +4 -4
- package/src/react/useMentraBluetooth.ts +2 -2
- package/android/silero/LICENSE.md +0 -17
- package/android/silero/build.gradle +0 -50
- package/android/silero/proguard-rules.pro +0 -24
- package/android/silero/src/androidTest/assets/hello.wav +0 -0
- package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +0 -79
- package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +0 -160
- package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +0 -449
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +0 -15
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +0 -14
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +0 -12
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +0 -47
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +0 -41
- package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +0 -44
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -368
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +0 -156
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -274
- package/android/src/main/java/com/mentra/bluetoothsdk/ScopedNetworkReadiness.kt +0 -17
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +0 -229
- package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -20
- package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -16
- package/android/src/test/java/com/mentra/bluetoothsdk/ScopedNetworkReadinessTest.kt +0 -39
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +0 -287
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +0 -127
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +0 -851
- package/ios/Source/sgcs/NimoMacResourceTransport.swift +0 -217
- package/ios/Source/sgcs/NimoResourceFixture.swift +0 -384
- package/ios/Source/sgcs/NimoResourceSession.swift +0 -406
- package/ios/Tests/NimoResourceSessionTests.swift +0 -476
- /package/android/{silero/src/main/assets/LICENSE → src/main/assets/vad/LICENSE.silero_vad} +0 -0
- /package/android/{silero/src/main/assets → src/main/assets/vad}/silero_vad.onnx +0 -0
|
@@ -10,7 +10,6 @@ import android.os.Handler
|
|
|
10
10
|
import android.os.Looper
|
|
11
11
|
import android.util.Log
|
|
12
12
|
import com.mentra.bluetoothsdk.sgcs.MentraLive
|
|
13
|
-
import com.mentra.bluetoothsdk.sgcs.NimoResourceDiagnostics
|
|
14
13
|
import com.mentra.bluetoothsdk.streaming.StreamSessionState
|
|
15
14
|
import com.mentra.bluetoothsdk.utils.ControllerTypes
|
|
16
15
|
import com.mentra.bluetoothsdk.utils.PhoneAudioMonitor
|
|
@@ -95,6 +94,7 @@ class MentraBluetoothSdk private constructor(
|
|
|
95
94
|
private var pendingHotspotStatus: PendingHotspotStatusRequest? = null
|
|
96
95
|
private val hotspotMutex = Mutex()
|
|
97
96
|
private var pendingVersionInfo: PendingVersionInfoRequest? = null
|
|
97
|
+
private val besCrashReports = BesCrashReportWaiters()
|
|
98
98
|
private val wifiSessionCapabilities = WifiSessionCapabilities()
|
|
99
99
|
@Volatile private var configuredOtaVersionUrl: String? = null
|
|
100
100
|
|
|
@@ -149,6 +149,7 @@ class MentraBluetoothSdk private constructor(
|
|
|
149
149
|
private const val VIDEO_UPLOAD_STOP_TIMEOUT_MS = 10 * 60 * 1000L
|
|
150
150
|
private const val STREAM_START_TIMEOUT_MS = 30_000L
|
|
151
151
|
private const val STREAM_STOP_TIMEOUT_MS = 15_000L
|
|
152
|
+
private const val BES_CRASH_REPORTED_TIMEOUT_MS = 10_000L
|
|
152
153
|
private const val OTA_BES_VERSION_WAIT_MS = 5_000L
|
|
153
154
|
private const val OTA_MTK_VERSION_WAIT_MS = 2_000L
|
|
154
155
|
private const val OTA_VERSION_POLL_MS = 100L
|
|
@@ -349,7 +350,7 @@ class MentraBluetoothSdk private constructor(
|
|
|
349
350
|
dispatchDefaultDeviceChanged()
|
|
350
351
|
}
|
|
351
352
|
|
|
352
|
-
fun clearDefaultDevice() {
|
|
353
|
+
private fun clearDefaultDevice() {
|
|
353
354
|
suppressDefaultDeviceEvents = true
|
|
354
355
|
try {
|
|
355
356
|
DeviceStore.apply(ObservableStore.BLUETOOTH_CATEGORY, "default_wearable", "")
|
|
@@ -366,8 +367,6 @@ class MentraBluetoothSdk private constructor(
|
|
|
366
367
|
}
|
|
367
368
|
|
|
368
369
|
fun startScan(model: DeviceModel) {
|
|
369
|
-
if (NimoResourceDiagnostics.dispatchCapturedEntry { startScan(model) }) return
|
|
370
|
-
if (!NimoResourceDiagnostics.allowManagerConnect(model.deviceType)) return
|
|
371
370
|
if (model != DeviceModel.SIMULATED) {
|
|
372
371
|
requireBluetoothReady("scan for glasses")
|
|
373
372
|
}
|
|
@@ -474,13 +473,11 @@ class MentraBluetoothSdk private constructor(
|
|
|
474
473
|
|
|
475
474
|
@JvmOverloads
|
|
476
475
|
fun connect(device: Device, options: ConnectOptions = ConnectOptions()) {
|
|
477
|
-
if (NimoResourceDiagnostics.dispatchCapturedEntry { connect(device, options) }) return
|
|
478
|
-
if (!NimoResourceDiagnostics.allowManagerConnect(device.model.deviceType, device.name)) return
|
|
479
476
|
if (device.model != DeviceModel.SIMULATED) {
|
|
480
477
|
requireBluetoothReady("connect to glasses")
|
|
481
478
|
}
|
|
482
479
|
val isController = ControllerTypes.ALL.contains(device.model.deviceType)
|
|
483
|
-
if (options.cancelExistingConnectionAttempt
|
|
480
|
+
if (options.cancelExistingConnectionAttempt) {
|
|
484
481
|
if (isController) {
|
|
485
482
|
deviceManager.disconnectController()
|
|
486
483
|
} else {
|
|
@@ -517,18 +514,16 @@ class MentraBluetoothSdk private constructor(
|
|
|
517
514
|
|
|
518
515
|
@JvmOverloads
|
|
519
516
|
fun connectDefault(options: ConnectOptions = ConnectOptions()) {
|
|
520
|
-
if (NimoResourceDiagnostics.dispatchCapturedEntry { connectDefault(options) }) return
|
|
521
517
|
val defaultDevice =
|
|
522
518
|
currentDefaultDevice()
|
|
523
519
|
?: throw BluetoothSdkException(
|
|
524
520
|
"default_device_missing",
|
|
525
521
|
"Set a default glasses device before calling connectDefault.",
|
|
526
522
|
)
|
|
527
|
-
if (!NimoResourceDiagnostics.allowManagerConnect(defaultDevice.model.deviceType, defaultDevice.name)) return
|
|
528
523
|
if (defaultDevice.model != DeviceModel.SIMULATED) {
|
|
529
524
|
requireBluetoothReady("connect to glasses")
|
|
530
525
|
}
|
|
531
|
-
if (options.cancelExistingConnectionAttempt
|
|
526
|
+
if (options.cancelExistingConnectionAttempt) {
|
|
532
527
|
cancelConnectionAttempt()
|
|
533
528
|
}
|
|
534
529
|
deviceManager.connectDefault()
|
|
@@ -559,6 +554,12 @@ class MentraBluetoothSdk private constructor(
|
|
|
559
554
|
deviceManager.forget()
|
|
560
555
|
}
|
|
561
556
|
|
|
557
|
+
/** Unpair the glasses: disconnect, forget the default device and, on Mentra Live, remove the phone's Bluetooth bond. */
|
|
558
|
+
suspend fun unpair() {
|
|
559
|
+
analytics.noteDisconnectRequested(BluetoothSdkAnalyticsTracker.DISCONNECT_FORGET)
|
|
560
|
+
deviceManager.unpair()
|
|
561
|
+
}
|
|
562
|
+
|
|
562
563
|
@JvmOverloads
|
|
563
564
|
fun displayText(text: String, x: Int = 0, y: Int = 0, size: Int = 24) {
|
|
564
565
|
displayText(DisplayTextRequest(text = text, x = x, y = y, size = size))
|
|
@@ -1684,6 +1685,14 @@ class MentraBluetoothSdk private constructor(
|
|
|
1684
1685
|
deviceManager.sendIncidentId(incidentId, apiBaseUrl)
|
|
1685
1686
|
}
|
|
1686
1687
|
|
|
1688
|
+
/** Resolves on the glasses' matching `ok:true` ack; throws on `ok:false`, disconnect or timeout. */
|
|
1689
|
+
internal suspend fun sendBesCrashReported(incidentKey: String, reportId: String) {
|
|
1690
|
+
requireGlassesConnected("report the BES crash")
|
|
1691
|
+
besCrashReports.await(incidentKey, reportId, BES_CRASH_REPORTED_TIMEOUT_MS) {
|
|
1692
|
+
deviceManager.sendBesCrashReported(incidentKey, reportId)
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1687
1696
|
override fun close() {
|
|
1688
1697
|
resetWifiProtocolSession("", "sdk_closed")
|
|
1689
1698
|
if (activityLifecycleCallbacksRegistered) {
|
|
@@ -1704,6 +1713,12 @@ class MentraBluetoothSdk private constructor(
|
|
|
1704
1713
|
"glasses" -> {
|
|
1705
1714
|
if (changes["connected"] == false) {
|
|
1706
1715
|
resetWifiProtocolSession("", "wifi_session_disconnected")
|
|
1716
|
+
besCrashReports.rejectAll(
|
|
1717
|
+
BluetoothSdkException(
|
|
1718
|
+
"glasses_not_connected",
|
|
1719
|
+
"Glasses disconnected before acknowledging bes_crash_reported.",
|
|
1720
|
+
)
|
|
1721
|
+
)
|
|
1707
1722
|
}
|
|
1708
1723
|
analytics.observeGlassesStatus(getRawGlassesStatus(), ::isPhoneBluetoothOff)
|
|
1709
1724
|
val state = getState()
|
|
@@ -2065,6 +2080,12 @@ class MentraBluetoothSdk private constructor(
|
|
|
2065
2080
|
}
|
|
2066
2081
|
dispatchToListeners { it.onOtaStatus(event) }
|
|
2067
2082
|
}
|
|
2083
|
+
"bes_crash_detected" -> {
|
|
2084
|
+
val event = BesCrashDetectedEvent(data + mapOf("type" to "bes_crash_detected"))
|
|
2085
|
+
dispatchToListeners { it.onBesCrashDetected(event) }
|
|
2086
|
+
}
|
|
2087
|
+
// Request-scoped: consumed by the waiting sendBesCrashReported call, never a listener event.
|
|
2088
|
+
"bes_crash_reported_ack" -> besCrashReports.onAck(data)
|
|
2068
2089
|
"mic_health" -> {
|
|
2069
2090
|
dispatchToListeners { it.onMicHealth(MicHealthEvent.fromMap(data)) }
|
|
2070
2091
|
}
|
|
@@ -3,11 +3,9 @@ package com.mentra.bluetoothsdk
|
|
|
3
3
|
import android.net.ConnectivityManager
|
|
4
4
|
import android.net.Network
|
|
5
5
|
import android.net.NetworkCapabilities
|
|
6
|
-
import android.net.NetworkRequest
|
|
7
|
-
import android.net.wifi.WifiNetworkSpecifier
|
|
8
|
-
import android.os.Handler
|
|
9
|
-
import android.os.Looper
|
|
10
6
|
import android.util.Base64
|
|
7
|
+
import com.mentra.bluetoothsdk.hotspot.ScopedNetworkError
|
|
8
|
+
import com.mentra.bluetoothsdk.hotspot.ScopedSoftApNetwork
|
|
11
9
|
import com.mentra.bluetoothsdk.utils.NativeLog as Log
|
|
12
10
|
import expo.modules.kotlin.Promise
|
|
13
11
|
import expo.modules.kotlin.modules.Module
|
|
@@ -15,27 +13,27 @@ import expo.modules.kotlin.modules.ModuleDefinition
|
|
|
15
13
|
import java.io.File
|
|
16
14
|
import java.io.FileOutputStream
|
|
17
15
|
import java.net.HttpURLConnection
|
|
18
|
-
import java.net.Inet4Address
|
|
19
16
|
import java.net.URL
|
|
20
17
|
import java.util.concurrent.ConcurrentHashMap
|
|
21
18
|
import java.util.concurrent.Executors
|
|
22
19
|
|
|
23
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* MentraOS-internal transport for glasses-local traffic without process network binding. Gallery
|
|
22
|
+
* sync and hotspot OTA join through [ScopedSoftApNetwork], the same join Mentra Call and the
|
|
23
|
+
* managed relay use, and send their HTTP over the `Network` it returns.
|
|
24
|
+
*/
|
|
24
25
|
class MentraLocalNetworkModule : Module() {
|
|
25
26
|
private companion object {
|
|
26
27
|
const val TAG = "MentraLocalNetwork"
|
|
27
|
-
const val NETWORK_READINESS_TIMEOUT_MS = 5_000L
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
private val lock = Any()
|
|
31
31
|
private val executor = Executors.newCachedThreadPool()
|
|
32
|
-
|
|
32
|
+
// Joins block, so they run one at a time off the JS thread. Disconnect does not queue
|
|
33
|
+
// behind them: releasing the network ends a join in progress at once.
|
|
34
|
+
private val joins = Executors.newSingleThreadExecutor()
|
|
33
35
|
private val activeConnections = ConcurrentHashMap<String, HttpURLConnection>()
|
|
34
|
-
private
|
|
35
|
-
private var localNetwork: Network? = null
|
|
36
|
-
private var networkCallback: ConnectivityManager.NetworkCallback? = null
|
|
37
|
-
private var pendingConnectPromise: Promise? = null
|
|
38
|
-
private var pendingReadinessTimeout: Runnable? = null
|
|
36
|
+
private var scoped: ScopedSoftApNetwork? = null
|
|
39
37
|
|
|
40
38
|
override fun definition() = ModuleDefinition {
|
|
41
39
|
Name("MentraLocalNetwork")
|
|
@@ -49,7 +47,7 @@ class MentraLocalNetworkModule : Module() {
|
|
|
49
47
|
sampledAtMs,
|
|
50
48
|
manager.boundNetworkForProcess,
|
|
51
49
|
manager.activeNetwork,
|
|
52
|
-
synchronized(lock) {
|
|
50
|
+
synchronized(lock) { scoped }?.network(),
|
|
53
51
|
) { network ->
|
|
54
52
|
manager.getNetworkCapabilities(network)?.let { capabilities ->
|
|
55
53
|
mapOf(
|
|
@@ -65,8 +63,8 @@ class MentraLocalNetworkModule : Module() {
|
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
|
|
68
|
-
AsyncFunction("connect") { ssid: String, password: String, promise: Promise ->
|
|
69
|
-
connect(ssid, password, promise)
|
|
66
|
+
AsyncFunction("connect") { ssid: String, password: String, incoming: Boolean, promise: Promise ->
|
|
67
|
+
connect(ssid, password, incoming, promise)
|
|
70
68
|
}
|
|
71
69
|
|
|
72
70
|
AsyncFunction("request") {
|
|
@@ -106,6 +104,7 @@ class MentraLocalNetworkModule : Module() {
|
|
|
106
104
|
|
|
107
105
|
OnDestroy {
|
|
108
106
|
disconnect()
|
|
107
|
+
joins.shutdown()
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
|
|
@@ -114,113 +113,51 @@ class MentraLocalNetworkModule : Module() {
|
|
|
114
113
|
"ConnectivityManager is unavailable"
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
private fun connect(ssid: String, password: String, promise: Promise) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
.
|
|
129
|
-
|
|
130
|
-
.build()
|
|
116
|
+
private fun connect(ssid: String, password: String, incoming: Boolean, promise: Promise) {
|
|
117
|
+
joins.execute {
|
|
118
|
+
disconnect()
|
|
119
|
+
val context = appContext.reactContext?.applicationContext
|
|
120
|
+
if (context == null) {
|
|
121
|
+
promise.reject("ERR_LOCAL_WIFI_REQUEST", "No React context", null)
|
|
122
|
+
return@execute
|
|
123
|
+
}
|
|
124
|
+
val network = ScopedSoftApNetwork(context)
|
|
125
|
+
synchronized(lock) { scoped = network }
|
|
126
|
+
val listener =
|
|
127
|
+
object : ScopedSoftApNetwork.Listener {
|
|
128
|
+
override fun onAvailable(network: Network, localIpv4: String) = Unit
|
|
131
129
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (networkCallback !== this) {
|
|
137
|
-
Log.d(TAG, "Ignoring onAvailable from a stale network request")
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
networkReadiness.onAvailable(network)
|
|
130
|
+
override fun onLost(error: ScopedNetworkError) {
|
|
131
|
+
if (synchronized(lock) { scoped !== network }) return
|
|
132
|
+
cancelAll()
|
|
133
|
+
sendEvent("networkLost", mapOf("ssid" to ssid))
|
|
141
134
|
}
|
|
142
|
-
Log.i(
|
|
143
|
-
TAG,
|
|
144
|
-
"Captured glasses WiFi network=$network; waiting for foreground capability " +
|
|
145
|
-
"processBoundNetwork=${manager.boundNetworkForProcess}",
|
|
146
|
-
)
|
|
147
|
-
scheduleReadinessTimeout(this, ssid)
|
|
148
135
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
network,
|
|
156
|
-
capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_FOREGROUND),
|
|
157
|
-
)
|
|
158
|
-
) {
|
|
159
|
-
return
|
|
160
|
-
}
|
|
161
|
-
localNetwork = network
|
|
162
|
-
connectPromise = pendingConnectPromise
|
|
163
|
-
pendingConnectPromise = null
|
|
164
|
-
cancelReadinessTimeoutLocked()
|
|
165
|
-
}
|
|
166
|
-
Log.i(
|
|
167
|
-
TAG,
|
|
168
|
-
"Glasses WiFi network=$network is foreground and ready " +
|
|
169
|
-
"processBoundNetwork=${manager.boundNetworkForProcess}",
|
|
170
|
-
)
|
|
171
|
-
val localAddress =
|
|
172
|
-
manager.getLinkProperties(network)
|
|
173
|
-
?.linkAddresses
|
|
174
|
-
?.firstOrNull { it.address is Inet4Address }
|
|
175
|
-
?.address
|
|
176
|
-
?.hostAddress
|
|
177
|
-
connectPromise?.resolve(
|
|
178
|
-
buildMap<String, Any> {
|
|
179
|
-
put("connected", true)
|
|
180
|
-
put("ssid", ssid)
|
|
181
|
-
if (!localAddress.isNullOrBlank()) put("localAddress", localAddress)
|
|
182
|
-
},
|
|
183
|
-
)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
override fun onUnavailable() {
|
|
187
|
-
synchronized(lock) {
|
|
188
|
-
if (networkCallback !== this) {
|
|
189
|
-
Log.d(TAG, "Ignoring onUnavailable from a stale network request")
|
|
190
|
-
return
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
rejectPendingConnect("ERR_LOCAL_WIFI_UNAVAILABLE", "Could not connect to $ssid")
|
|
194
|
-
clearNetworkCallback(this)
|
|
136
|
+
try {
|
|
137
|
+
network.join(ssid, password, listener, incoming)
|
|
138
|
+
if (synchronized(lock) { scoped !== network }) {
|
|
139
|
+
network.release()
|
|
140
|
+
promise.reject("ERR_LOCAL_WIFI_CANCELLED", "Local WiFi connection cancelled", null)
|
|
141
|
+
return@execute
|
|
195
142
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
143
|
+
Log.i(TAG, "Glasses WiFi network=${network.network()} is ready")
|
|
144
|
+
promise.resolve(
|
|
145
|
+
buildMap<String, Any> {
|
|
146
|
+
put("connected", true)
|
|
147
|
+
put("ssid", ssid)
|
|
148
|
+
network.localIpv4()?.let { put("localAddress", it) }
|
|
149
|
+
},
|
|
150
|
+
)
|
|
151
|
+
} catch (error: Exception) {
|
|
152
|
+
val cancelled = synchronized(lock) { (scoped !== network).also { if (!it) scoped = null } }
|
|
153
|
+
if (cancelled) {
|
|
154
|
+
promise.reject("ERR_LOCAL_WIFI_CANCELLED", "Local WiFi connection cancelled", error)
|
|
155
|
+
} else {
|
|
156
|
+
network.release()
|
|
157
|
+
val code = (error as? ScopedNetworkError)?.code ?: "ERR_LOCAL_WIFI_REQUEST"
|
|
158
|
+
promise.reject(code, error.message ?: "Could not connect to $ssid", error)
|
|
212
159
|
}
|
|
213
160
|
}
|
|
214
|
-
|
|
215
|
-
synchronized(lock) {
|
|
216
|
-
pendingConnectPromise = promise
|
|
217
|
-
networkCallback = callback
|
|
218
|
-
}
|
|
219
|
-
try {
|
|
220
|
-
manager.requestNetwork(request, callback, 30_000)
|
|
221
|
-
} catch (error: Exception) {
|
|
222
|
-
clearNetworkCallback(callback)
|
|
223
|
-
rejectPendingConnect("ERR_LOCAL_WIFI_REQUEST", error.message ?: "Local WiFi request failed", error)
|
|
224
161
|
}
|
|
225
162
|
}
|
|
226
163
|
|
|
@@ -334,7 +271,7 @@ class MentraLocalNetworkModule : Module() {
|
|
|
334
271
|
}
|
|
335
272
|
|
|
336
273
|
private fun openConnection(requestId: String, url: String): HttpURLConnection {
|
|
337
|
-
val network = synchronized(lock) {
|
|
274
|
+
val network = synchronized(lock) { scoped }?.network()
|
|
338
275
|
?: throw IllegalStateException("Local WiFi is not connected")
|
|
339
276
|
val connection = network.openConnection(URL(url)) as HttpURLConnection
|
|
340
277
|
activeConnections[requestId] = connection
|
|
@@ -354,85 +291,9 @@ class MentraLocalNetworkModule : Module() {
|
|
|
354
291
|
activeConnections.keys.toList().forEach(::cancel)
|
|
355
292
|
}
|
|
356
293
|
|
|
357
|
-
private fun scheduleReadinessTimeout(
|
|
358
|
-
callback: ConnectivityManager.NetworkCallback,
|
|
359
|
-
ssid: String,
|
|
360
|
-
) {
|
|
361
|
-
val timeout =
|
|
362
|
-
Runnable {
|
|
363
|
-
val connectPromise = synchronized(lock) {
|
|
364
|
-
if (networkCallback !== callback || pendingConnectPromise == null) return@Runnable
|
|
365
|
-
pendingReadinessTimeout = null
|
|
366
|
-
val promise = pendingConnectPromise
|
|
367
|
-
pendingConnectPromise = null
|
|
368
|
-
promise
|
|
369
|
-
}
|
|
370
|
-
connectPromise?.reject(
|
|
371
|
-
"ERR_LOCAL_WIFI_NOT_READY",
|
|
372
|
-
"Connected to $ssid but the network did not become ready",
|
|
373
|
-
null,
|
|
374
|
-
)
|
|
375
|
-
clearNetworkCallback(callback)
|
|
376
|
-
}
|
|
377
|
-
synchronized(lock) {
|
|
378
|
-
if (networkCallback !== callback || pendingConnectPromise == null) return
|
|
379
|
-
cancelReadinessTimeoutLocked()
|
|
380
|
-
pendingReadinessTimeout = timeout
|
|
381
|
-
}
|
|
382
|
-
handler.postDelayed(timeout, NETWORK_READINESS_TIMEOUT_MS)
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
private fun cancelReadinessTimeoutLocked() {
|
|
386
|
-
pendingReadinessTimeout?.let(handler::removeCallbacks)
|
|
387
|
-
pendingReadinessTimeout = null
|
|
388
|
-
}
|
|
389
|
-
|
|
390
294
|
private fun disconnect() {
|
|
391
295
|
cancelAll()
|
|
392
|
-
val
|
|
393
|
-
|
|
394
|
-
synchronized(lock) {
|
|
395
|
-
callback = networkCallback
|
|
396
|
-
networkCallback = null
|
|
397
|
-
localNetwork = null
|
|
398
|
-
networkReadiness.clear()
|
|
399
|
-
cancelReadinessTimeoutLocked()
|
|
400
|
-
}
|
|
401
|
-
if (callback != null && manager != null) {
|
|
402
|
-
try {
|
|
403
|
-
manager.unregisterNetworkCallback(callback)
|
|
404
|
-
} catch (_: IllegalArgumentException) {
|
|
405
|
-
// Already unregistered by the platform.
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
rejectPendingConnect("ERR_LOCAL_WIFI_CANCELLED", "Local WiFi connection cancelled")
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
private fun clearNetworkCallback(callback: ConnectivityManager.NetworkCallback) {
|
|
412
|
-
val manager = appContext.reactContext?.getSystemService(ConnectivityManager::class.java)
|
|
413
|
-
synchronized(lock) {
|
|
414
|
-
if (networkCallback == callback) {
|
|
415
|
-
networkCallback = null
|
|
416
|
-
localNetwork = null
|
|
417
|
-
networkReadiness.clear()
|
|
418
|
-
cancelReadinessTimeoutLocked()
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
if (manager != null) {
|
|
422
|
-
try {
|
|
423
|
-
manager.unregisterNetworkCallback(callback)
|
|
424
|
-
} catch (_: IllegalArgumentException) {
|
|
425
|
-
// Callback was not registered or has already been removed.
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
private fun rejectPendingConnect(code: String, message: String, cause: Throwable? = null) {
|
|
431
|
-
val promise: Promise?
|
|
432
|
-
synchronized(lock) {
|
|
433
|
-
promise = pendingConnectPromise
|
|
434
|
-
pendingConnectPromise = null
|
|
435
|
-
}
|
|
436
|
-
promise?.reject(code, message, cause)
|
|
296
|
+
val network = synchronized(lock) { scoped.also { scoped = null } }
|
|
297
|
+
network?.release()
|
|
437
298
|
}
|
|
438
299
|
}
|
|
@@ -180,22 +180,7 @@ internal object OtaManifestChecker {
|
|
|
180
180
|
throw BluetoothSdkException("invalid_ota_manifest", "OTA manifest bes_firmware.version is missing.")
|
|
181
181
|
}
|
|
182
182
|
if (currentVersion.isBlank()) return true
|
|
183
|
-
return
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
private fun compareVersions(version1: String, version2: String): Int {
|
|
187
|
-
if (version1.contains(".") && version2.contains(".")) {
|
|
188
|
-
val parts1 = version1.split(".")
|
|
189
|
-
val parts2 = version2.split(".")
|
|
190
|
-
val maxLength = maxOf(parts1.size, parts2.size)
|
|
191
|
-
for (index in 0 until maxLength) {
|
|
192
|
-
val value1 = parts1.getOrNull(index)?.toIntOrNull() ?: 0
|
|
193
|
-
val value2 = parts2.getOrNull(index)?.toIntOrNull() ?: 0
|
|
194
|
-
if (value1 != value2) return value1 - value2
|
|
195
|
-
}
|
|
196
|
-
return 0
|
|
197
|
-
}
|
|
198
|
-
return version1.compareTo(version2)
|
|
183
|
+
return serverVersion != currentVersion
|
|
199
184
|
}
|
|
200
185
|
|
|
201
186
|
private fun JSONObject.hasNumber(key: String): Boolean = !isNull(key) && opt(key) is Number
|
|
@@ -21,8 +21,10 @@ object BleTraceLogger {
|
|
|
21
21
|
return
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
val type = extractType(payload)
|
|
25
|
+
if (isQuietType(type)) return
|
|
24
26
|
val sanitized = sanitize(payload)
|
|
25
|
-
Log.i(TAG, format(direction, layer, caller(),
|
|
27
|
+
Log.i(TAG, format(direction, layer, caller(), type, bytes, sanitized.toString()))
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
@JvmStatic
|
|
@@ -74,6 +76,13 @@ object BleTraceLogger {
|
|
|
74
76
|
return "BLE_TRACE direction=$direction layer=$layer source=$source type=$type$bytesText payload=${truncate(payload)}"
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Messages sent every few seconds (the glasses' hotspot keepalive); tracing each would push
|
|
81
|
+
* everything else out of the logs attached to bug reports.
|
|
82
|
+
*/
|
|
83
|
+
@JvmStatic
|
|
84
|
+
fun isQuietType(type: String?): Boolean = type == "hotspot_keepalive"
|
|
85
|
+
|
|
77
86
|
private fun extractType(payload: JSONObject): String {
|
|
78
87
|
payload.optString("type").takeIf { it.isNotBlank() }?.let { return it }
|
|
79
88
|
payload.optString("C").takeIf { it.isNotBlank() }?.let { cValue ->
|
|
@@ -106,6 +106,21 @@ data class OtaStatusEvent(
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/** Mentra Live stored a BES crash incident; [values] is the glasses message with JSON nulls omitted. */
|
|
110
|
+
data class BesCrashDetectedEvent(
|
|
111
|
+
val values: Map<String, Any>,
|
|
112
|
+
) {
|
|
113
|
+
val incidentKey: String get() = stringValue(values, "incidentKey").orEmpty()
|
|
114
|
+
val reason: String get() = stringValue(values, "reason").orEmpty()
|
|
115
|
+
val state: String get() = stringValue(values, "state").orEmpty()
|
|
116
|
+
val reportId: String? get() = stringValue(values, "reportId")?.takeIf { it.isNotEmpty() }
|
|
117
|
+
@Suppress("UNCHECKED_CAST")
|
|
118
|
+
val summary: Map<String, Any> get() = values["summary"] as? Map<String, Any> ?: emptyMap()
|
|
119
|
+
|
|
120
|
+
/** Event body for JavaScript; `reportId` is null rather than absent before a report exists. */
|
|
121
|
+
fun toEventMap(): Map<String, Any?> = values + ("reportId" to reportId)
|
|
122
|
+
}
|
|
123
|
+
|
|
109
124
|
data class OtaQueryResult(
|
|
110
125
|
val values: Map<String, Any>,
|
|
111
126
|
) {
|
|
@@ -170,6 +185,7 @@ interface MentraBluetoothSdkListener {
|
|
|
170
185
|
fun onKeepAliveAck(event: KeepAliveAckEvent) {}
|
|
171
186
|
fun onOtaStartAck(event: OtaStartAckEvent) {}
|
|
172
187
|
fun onOtaStatus(event: OtaStatusEvent) {}
|
|
188
|
+
fun onBesCrashDetected(event: BesCrashDetectedEvent) {}
|
|
173
189
|
fun onSettingsAck(event: SettingsAckEvent) {}
|
|
174
190
|
fun onVersionInfo(event: VersionInfoResult) {}
|
|
175
191
|
fun onMicPcm(event: MicPcmEvent) {}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
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
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.hotspot
|
|
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
|
+
}
|