@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
|
@@ -696,25 +696,28 @@ private struct BlePhotoTransfer {
|
|
|
696
696
|
}
|
|
697
697
|
}
|
|
698
698
|
|
|
699
|
-
|
|
699
|
+
enum BleIncidentLogRelayKind {
|
|
700
700
|
case firmware
|
|
701
701
|
case logcat
|
|
702
702
|
}
|
|
703
703
|
|
|
704
|
-
|
|
704
|
+
final class BleIncidentLogRelayEntry {
|
|
705
705
|
let fileBaseKey: String
|
|
706
706
|
let incidentId: String
|
|
707
707
|
let apiBaseUrl: String
|
|
708
708
|
let kind: BleIncidentLogRelayKind
|
|
709
|
+
let reservedAt: TimeInterval
|
|
709
710
|
var session: MentraLiveFileTransferSession?
|
|
710
711
|
|
|
711
712
|
init(
|
|
712
|
-
fileBaseKey: String, incidentId: String, apiBaseUrl: String, kind: BleIncidentLogRelayKind
|
|
713
|
+
fileBaseKey: String, incidentId: String, apiBaseUrl: String, kind: BleIncidentLogRelayKind,
|
|
714
|
+
reservedAt: TimeInterval
|
|
713
715
|
) {
|
|
714
716
|
self.fileBaseKey = fileBaseKey
|
|
715
717
|
self.incidentId = incidentId
|
|
716
718
|
self.apiBaseUrl = apiBaseUrl
|
|
717
719
|
self.kind = kind
|
|
720
|
+
self.reservedAt = reservedAt
|
|
718
721
|
}
|
|
719
722
|
}
|
|
720
723
|
|
|
@@ -783,26 +786,8 @@ extension MentraLive: CBCentralManagerDelegate {
|
|
|
783
786
|
if !isReconnectTarget && advertisesPairingFlag(advertisementData)
|
|
784
787
|
&& !isPairingDiscoverable(advertisementData)
|
|
785
788
|
{
|
|
786
|
-
//
|
|
787
|
-
|
|
788
|
-
pairFlow(
|
|
789
|
-
"discover",
|
|
790
|
-
"name=\(name) id=\(peripheral.identifier.uuidString) saved=\(savedDeviceName ?? "-") pairingMode=false secure=true connect=false"
|
|
791
|
-
)
|
|
792
|
-
discoveredPeripherals[name] = peripheral
|
|
793
|
-
rememberPeripheral(peripheral, name: name)
|
|
794
|
-
if cacheAdvPairing(
|
|
795
|
-
name,
|
|
796
|
-
pairingMode: false,
|
|
797
|
-
pairingCode: nil,
|
|
798
|
-
securePairingCapable: true
|
|
799
|
-
) {
|
|
800
|
-
emitDiscoveredDeviceFromCache(
|
|
801
|
-
name,
|
|
802
|
-
identifier: peripheral.identifier.uuidString,
|
|
803
|
-
rssi: rssi?.intValue
|
|
804
|
-
)
|
|
805
|
-
}
|
|
789
|
+
// Only glasses that can pair now are listed; a closed window drops them.
|
|
790
|
+
unlistNotPairable(name)
|
|
806
791
|
return
|
|
807
792
|
}
|
|
808
793
|
|
|
@@ -828,11 +813,13 @@ extension MentraLive: CBCentralManagerDelegate {
|
|
|
828
813
|
discoveredPeripherals[name] = peripheral
|
|
829
814
|
rememberPeripheral(peripheral, name: name)
|
|
830
815
|
|
|
831
|
-
if !
|
|
816
|
+
if trailer.secureCapable && !trailer.pairingMode {
|
|
817
|
+
unlistNotPairable(name)
|
|
818
|
+
} else if !partialAdvertisement, cacheAdvPairing(
|
|
832
819
|
name,
|
|
833
820
|
// Field firmware has no pairing flag. Treat it as pairable so the
|
|
834
821
|
// new Mentra App can still find old glasses.
|
|
835
|
-
pairingMode:
|
|
822
|
+
pairingMode: true,
|
|
836
823
|
pairingCode: trailer.pairingCode,
|
|
837
824
|
securePairingCapable: trailer.secureCapable
|
|
838
825
|
) {
|
|
@@ -1504,6 +1491,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1504
1491
|
if state == ConnTypes.DISCONNECTED {
|
|
1505
1492
|
resetPendingAckState(reason: "BLE session ended")
|
|
1506
1493
|
resetWireNegotiationState()
|
|
1494
|
+
resetReadinessExchange()
|
|
1507
1495
|
resetAncsRelayState()
|
|
1508
1496
|
// Queued writes are session-bound: transmitting them into the NEXT session
|
|
1509
1497
|
// (e.g. a stale handshake whose reply activates v2 before the new session
|
|
@@ -1546,13 +1534,16 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1546
1534
|
func dbg1() {}
|
|
1547
1535
|
func dbg2() {}
|
|
1548
1536
|
|
|
1537
|
+
/// Clear the saved device name so the pairing filter is not bypassed on rescan.
|
|
1538
|
+
static func clearSavedPeripheral() {
|
|
1539
|
+
secureTrailerMemory.clear()
|
|
1540
|
+
UserDefaults.standard.removeObject(forKey: prefsDeviceName)
|
|
1541
|
+
UserDefaults.standard.removeObject(forKey: prefsPeripheralIds)
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1549
1544
|
func forget() {
|
|
1550
1545
|
Bridge.log("LIVE: Forgetting Mentra Live glasses")
|
|
1551
|
-
Self.
|
|
1552
|
-
|
|
1553
|
-
// Clear saved device name so the pairing filter is not bypassed on rescan
|
|
1554
|
-
UserDefaults.standard.removeObject(forKey: PREFS_DEVICE_NAME)
|
|
1555
|
-
UserDefaults.standard.removeObject(forKey: PREFS_PERIPHERAL_IDS)
|
|
1546
|
+
Self.clearSavedPeripheral()
|
|
1556
1547
|
pairFlow("forget", "cleared_saved_peripheral")
|
|
1557
1548
|
|
|
1558
1549
|
// Stop scanning first
|
|
@@ -1642,7 +1633,11 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1642
1633
|
private var fileWriteCharacteristic: CBCharacteristic?
|
|
1643
1634
|
private var activeFileTransfers = [String: MentraLiveFileTransferSession]()
|
|
1644
1635
|
private var blePhotoTransfers = [String: BlePhotoTransfer]()
|
|
1645
|
-
private var bleIncidentLogRelays = [String: BleIncidentLogRelayEntry]()
|
|
1636
|
+
private(set) var bleIncidentLogRelays = [String: BleIncidentLogRelayEntry]()
|
|
1637
|
+
// Longer than the glasses' bounded relay of one report (BES logs, two file transfers, the
|
|
1638
|
+
// phone POST), so an unreleased name cannot be reused while its report is in flight.
|
|
1639
|
+
static let incidentRelayOwnershipSeconds: TimeInterval = 600
|
|
1640
|
+
var incidentRelayClock: () -> TimeInterval = { ProcessInfo.processInfo.systemUptime }
|
|
1646
1641
|
private var l2capFileChannel: MentraLiveL2capChannel?
|
|
1647
1642
|
private var l2capFileChannelId: UUID?
|
|
1648
1643
|
private var l2capFileChannelOpening = false
|
|
@@ -1685,8 +1680,10 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1685
1680
|
private let SIGNIFICANT_BLE_TRACE_QUEUE_SIZE = 5
|
|
1686
1681
|
|
|
1687
1682
|
/// Device Settings Keys
|
|
1688
|
-
private let
|
|
1689
|
-
private let
|
|
1683
|
+
private static let prefsDeviceName = "MentraLiveLastConnectedDeviceName"
|
|
1684
|
+
private static let prefsPeripheralIds = "MentraLivePeripheralIds"
|
|
1685
|
+
private let PREFS_DEVICE_NAME = MentraLive.prefsDeviceName
|
|
1686
|
+
private let PREFS_PERIPHERAL_IDS = MentraLive.prefsPeripheralIds
|
|
1690
1687
|
|
|
1691
1688
|
// MARK: - Properties
|
|
1692
1689
|
|
|
@@ -1811,6 +1808,13 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1811
1808
|
// the physical connection — so a first-seen sid after an upgrade OTA cannot be
|
|
1812
1809
|
// mistaken for a fresh pairing just because a not-ready heartbeat slipped in first.
|
|
1813
1810
|
private var readinessCompletedThisBleSession = false
|
|
1811
|
+
/// Readiness exchange the phone is waiting on. Every phone_ready carries it until the
|
|
1812
|
+
/// matching glasses_ready arrives, so retries and the copies the BES buffers while the
|
|
1813
|
+
/// glasses boot are one exchange: the glasses reset their transport once for it and answer
|
|
1814
|
+
/// later copies without resetting. Both exchange fields are scoped to the BLE session.
|
|
1815
|
+
private var pendingReadyId: String?
|
|
1816
|
+
/// `sid` of the glasses process whose glasses_ready this BLE session last handled.
|
|
1817
|
+
private var readyGlassesSessionId: String?
|
|
1814
1818
|
private var globalMessageId = 0
|
|
1815
1819
|
private var lastReceivedMessageId = 0
|
|
1816
1820
|
private var bleWriteTraceSequence = 0
|
|
@@ -2255,6 +2259,17 @@ class MentraLive: NSObject, SGCManager {
|
|
|
2255
2259
|
Bridge.saveSetting("mentra_live_secure_firmware", secure)
|
|
2256
2260
|
}
|
|
2257
2261
|
|
|
2262
|
+
/// The glasses keep a former owner's keys for a reclaim in pairing mode (pairing-spec V9), so
|
|
2263
|
+
/// the app keeps this phone's pairing on Unpair instead of sending the person to Settings.
|
|
2264
|
+
private func rememberFormerOwnerKeys(_ kept: Bool) {
|
|
2265
|
+
guard (DeviceStore.shared.get("bluetooth", "mentra_live_former_owner_keys") as? Bool == true) != kept
|
|
2266
|
+
else { return }
|
|
2267
|
+
Task { @MainActor in
|
|
2268
|
+
DeviceStore.shared.apply("bluetooth", "mentra_live_former_owner_keys", kept)
|
|
2269
|
+
}
|
|
2270
|
+
Bridge.saveSetting("mentra_live_former_owner_keys", kept)
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2258
2273
|
/// One authentication-type failure. The state machine decides whether it settles a takeover
|
|
2259
2274
|
/// (the one verification after `OWNER_CHANGED`) or completes the 3-strike streak.
|
|
2260
2275
|
/// - Returns: true when this phone is now `pairing_rejected`.
|
|
@@ -2756,6 +2771,18 @@ class MentraLive: NSObject, SGCManager {
|
|
|
2756
2771
|
}
|
|
2757
2772
|
|
|
2758
2773
|
var count: Int { commands.count }
|
|
2774
|
+
|
|
2775
|
+
/// Discards the run of writes from earlier wire-session generations at the head of
|
|
2776
|
+
/// the queue in one pass and dequeues the first current one. Stale writes are never
|
|
2777
|
+
/// sent, so they must not each cost a drain tick: a burst of epoch resets would
|
|
2778
|
+
/// otherwise park every current write behind seconds of dead entries.
|
|
2779
|
+
func dequeue(currentGeneration: Int) -> (command: PendingMessage?, staleIds: [String]) {
|
|
2780
|
+
let firstCurrent = commands.firstIndex { $0.generation == currentGeneration } ?? commands.endIndex
|
|
2781
|
+
let staleIds = commands[..<firstCurrent].map(\.id)
|
|
2782
|
+
commands.removeSubrange(..<firstCurrent)
|
|
2783
|
+
return (commands.isEmpty ? nil : commands.removeFirst(), staleIds)
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2759
2786
|
func removeAll() {
|
|
2760
2787
|
commands.removeAll()
|
|
2761
2788
|
}
|
|
@@ -2768,21 +2795,25 @@ class MentraLive: NSObject, SGCManager {
|
|
|
2768
2795
|
guard let self else { return }
|
|
2769
2796
|
while true {
|
|
2770
2797
|
let pendingIsNil = await MainActor.run { self.pending == nil }
|
|
2771
|
-
if pendingIsNil {
|
|
2772
|
-
|
|
2773
|
-
let currentGeneration = await MainActor.run { self.wireSessionGeneration }
|
|
2774
|
-
if command.generation != currentGeneration {
|
|
2775
|
-
Bridge.log("LIVE: Dropping stale queued write from a previous session epoch (id: \(command.id))")
|
|
2776
|
-
} else {
|
|
2777
|
-
await self.processSendQueue(command)
|
|
2778
|
-
}
|
|
2779
|
-
}
|
|
2798
|
+
if pendingIsNil, let command = await self.dequeueCurrentGenerationWrite() {
|
|
2799
|
+
await self.processSendQueue(command)
|
|
2780
2800
|
}
|
|
2781
2801
|
try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
|
|
2782
2802
|
}
|
|
2783
2803
|
}
|
|
2784
2804
|
}
|
|
2785
2805
|
|
|
2806
|
+
private func dequeueCurrentGenerationWrite() -> PendingMessage? {
|
|
2807
|
+
let next = commandQueue.dequeue(currentGeneration: wireSessionGeneration)
|
|
2808
|
+
if !next.staleIds.isEmpty {
|
|
2809
|
+
Bridge.log(
|
|
2810
|
+
"LIVE: Dropping \(next.staleIds.count) stale queued write(s) from a previous session epoch " +
|
|
2811
|
+
"(ids: \(next.staleIds.joined(separator: ", ")))"
|
|
2812
|
+
)
|
|
2813
|
+
}
|
|
2814
|
+
return next.command
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2786
2817
|
private func processSendQueue(_ message: PendingMessage) async {
|
|
2787
2818
|
guard let peripheral = connectedPeripheral,
|
|
2788
2819
|
let txChar = txCharacteristic
|
|
@@ -2889,7 +2920,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
2889
2920
|
|
|
2890
2921
|
// The choose-glasses scan has to hear a later advertisement when the glasses
|
|
2891
2922
|
// enter pairing mode. iOS reports each peripheral once unless duplicates are
|
|
2892
|
-
// allowed, so the
|
|
2923
|
+
// allowed, so the glasses would stay off the list. Reconnect scans stay
|
|
2893
2924
|
// duplicate-free so a saved glasses advertisement cannot start another connect.
|
|
2894
2925
|
let scanOptions: [String: Any] = [
|
|
2895
2926
|
CBCentralManagerScanOptionAllowDuplicatesKey: manualDiscoveryActive,
|
|
@@ -3376,6 +3407,11 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3376
3407
|
}
|
|
3377
3408
|
|
|
3378
3409
|
switch type {
|
|
3410
|
+
case "hotspot_keepalive":
|
|
3411
|
+
// Sent every few seconds while the glasses hotspot is up. Receiving it is the whole
|
|
3412
|
+
// point: each BLE notification lets iOS run this app a little longer, so a gallery or
|
|
3413
|
+
// OTA download over the hotspot keeps going while backgrounded or locked.
|
|
3414
|
+
return
|
|
3379
3415
|
case "glasses_ready":
|
|
3380
3416
|
// A queued glasses_ready from the connection just left for a pairing window
|
|
3381
3417
|
// must not count as a session. Only accept readiness on a live GATT.
|
|
@@ -3383,6 +3419,16 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3383
3419
|
Bridge.log("LIVE: Ignoring stale glasses_ready during pairing pause")
|
|
3384
3420
|
return
|
|
3385
3421
|
}
|
|
3422
|
+
let sid = (json["sid"] as? String).flatMap { $0.isEmpty ? nil : $0 }
|
|
3423
|
+
let readyId = (json["readyId"] as? String).flatMap { $0.isEmpty ? nil : $0 }
|
|
3424
|
+
if let readyId, isRepeatedGlassesReady(readyId: readyId, sid: sid) {
|
|
3425
|
+
Bridge.log("LIVE: Ignoring repeated glasses_ready for readiness exchange \(readyId) - the glasses did not reset for it")
|
|
3426
|
+
return
|
|
3427
|
+
}
|
|
3428
|
+
if readyId != nil, readyId == pendingReadyId {
|
|
3429
|
+
pendingReadyId = nil
|
|
3430
|
+
}
|
|
3431
|
+
readyGlassesSessionId = sid
|
|
3386
3432
|
// glasses_ready is a REMOTE wire-session reset: the glasses ran
|
|
3387
3433
|
// onTransportReset() before sending it, so their side is back on legacy
|
|
3388
3434
|
// framing regardless of what this side negotiated earlier. Start a fresh
|
|
@@ -3394,7 +3440,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3394
3440
|
// Record the session id BEFORE marking ready: an unsolicited glasses_ready
|
|
3395
3441
|
// already runs this full remote-reset flow, so recording (not re-triggering)
|
|
3396
3442
|
// is correct here; version_info detection covers the restart case.
|
|
3397
|
-
glassesSessionId =
|
|
3443
|
+
glassesSessionId = sid
|
|
3398
3444
|
streamControlVersion = json["streamControlVersion"] as? Int ?? 0
|
|
3399
3445
|
Bridge.sendTypedMessage(
|
|
3400
3446
|
"wifi_protocol_session_ready",
|
|
@@ -3633,6 +3679,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3633
3679
|
// Read before any readiness below: the audio wait of a pairing depends on it.
|
|
3634
3680
|
pairingInfoAutoAudio = json["auto_audio"] as? Bool ?? false
|
|
3635
3681
|
rememberSecureFirmware(securePairingCapable)
|
|
3682
|
+
rememberFormerOwnerKeys(json["former_owner_keys"] as? Bool ?? false)
|
|
3636
3683
|
if securePairingCapable {
|
|
3637
3684
|
pairingInfoSeenThisSession = true
|
|
3638
3685
|
cancelSecureFirmwareRefresh()
|
|
@@ -3730,6 +3777,11 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3730
3777
|
Bridge.log("LIVE: 📱 Received ota_start_ack from glasses")
|
|
3731
3778
|
Bridge.sendOtaStartAck()
|
|
3732
3779
|
|
|
3780
|
+
case "bes_crash_detected", "bes_crash_reported_ack":
|
|
3781
|
+
let ok = json["ok"].map { "\($0)" } ?? "-"
|
|
3782
|
+
Bridge.log("LIVE: \(type) incidentKey=\(json["incidentKey"] as? String ?? "") state=\(json["state"] as? String ?? "-") ok=\(ok)")
|
|
3783
|
+
Bridge.sendTypedMessage(type, body: json)
|
|
3784
|
+
|
|
3733
3785
|
case "ota_status":
|
|
3734
3786
|
// Short keys (sid/ts/cs/st/sq/sp/op/err) are used by new firmware to keep BLE payload small.
|
|
3735
3787
|
// Verbose keys (session_id/total_steps/…) are the fallback for older firmware.
|
|
@@ -4054,12 +4106,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
4054
4106
|
// This prevents re-initialization on every heartbeat after initial connection
|
|
4055
4107
|
// The ready flag is reset on disconnect/reconnect, so this won't prevent proper reconnection
|
|
4056
4108
|
if !fullyBooted {
|
|
4057
|
-
|
|
4058
|
-
"type": "phone_ready",
|
|
4059
|
-
"timestamp": Int64(Date().timeIntervalSince1970 * 1000),
|
|
4060
|
-
]
|
|
4061
|
-
// Send it through our data channel
|
|
4062
|
-
sendJson(readyMsg, wakeUp: true)
|
|
4109
|
+
sendPhoneReady(reason: "SOC ready")
|
|
4063
4110
|
}
|
|
4064
4111
|
}
|
|
4065
4112
|
}
|
|
@@ -4476,12 +4523,14 @@ class MentraLive: NSObject, SGCManager {
|
|
|
4476
4523
|
}
|
|
4477
4524
|
let bKey = MentraLive.incidentBleFileBase(incidentId: incidentId, prefix: "B")
|
|
4478
4525
|
let lKey = MentraLive.incidentBleFileBase(incidentId: incidentId, prefix: "L")
|
|
4479
|
-
|
|
4480
|
-
|
|
4526
|
+
let now = incidentRelayClock()
|
|
4527
|
+
let bRelay = BleIncidentLogRelayEntry(
|
|
4528
|
+
fileBaseKey: bKey, incidentId: incidentId, apiBaseUrl: base, kind: .firmware, reservedAt: now
|
|
4481
4529
|
)
|
|
4482
|
-
|
|
4483
|
-
fileBaseKey: lKey, incidentId: incidentId, apiBaseUrl: base, kind: .logcat
|
|
4530
|
+
let lRelay = BleIncidentLogRelayEntry(
|
|
4531
|
+
fileBaseKey: lKey, incidentId: incidentId, apiBaseUrl: base, kind: .logcat, reservedAt: now
|
|
4484
4532
|
)
|
|
4533
|
+
try reserveIncidentRelays([bRelay, lRelay], now: now)
|
|
4485
4534
|
|
|
4486
4535
|
let auth: [String: Any] = [
|
|
4487
4536
|
"type": "auth_token", "coreToken": coreToken,
|
|
@@ -4492,13 +4541,56 @@ class MentraLive: NSObject, SGCManager {
|
|
|
4492
4541
|
sendJson(["type": "upload_incident_logs", "incidentId": incidentId, "apiBaseUrl": base],
|
|
4493
4542
|
wakeUp: true, requireAck: true, bridgeLogging: true)
|
|
4494
4543
|
else {
|
|
4495
|
-
|
|
4496
|
-
|
|
4544
|
+
releaseIncidentRelay(bRelay)
|
|
4545
|
+
releaseIncidentRelay(lRelay)
|
|
4497
4546
|
throw BluetoothSdkError(code: "incident_dispatch_failed", message: "Could not queue the glasses incident-log request.")
|
|
4498
4547
|
}
|
|
4499
4548
|
Bridge.log("LIVE: Queued incidentId to glasses for log upload: \(incidentId) (BLE relay \(bKey), \(lKey))")
|
|
4500
4549
|
}
|
|
4501
4550
|
|
|
4551
|
+
/// The 16-character relay file names keep only 15 characters of the report id, so two reports
|
|
4552
|
+
/// can share them. A received file goes to the report registered under its name; refuse a
|
|
4553
|
+
/// second report until the owner's Cloud POST is confirmed or its ownership expires.
|
|
4554
|
+
private func reserveIncidentRelays(_ relays: [BleIncidentLogRelayEntry], now: TimeInterval) throws {
|
|
4555
|
+
for relay in relays {
|
|
4556
|
+
if let owner = bleIncidentLogRelays[relay.fileBaseKey],
|
|
4557
|
+
owner.incidentId != relay.incidentId,
|
|
4558
|
+
now - owner.reservedAt < MentraLive.incidentRelayOwnershipSeconds
|
|
4559
|
+
{
|
|
4560
|
+
throw BluetoothSdkError(
|
|
4561
|
+
code: "incident_relay_busy",
|
|
4562
|
+
message: "BLE relay \(relay.fileBaseKey) is still owned by report \(owner.incidentId)."
|
|
4563
|
+
)
|
|
4564
|
+
}
|
|
4565
|
+
}
|
|
4566
|
+
for relay in relays {
|
|
4567
|
+
bleIncidentLogRelays[relay.fileBaseKey] = relay
|
|
4568
|
+
}
|
|
4569
|
+
}
|
|
4570
|
+
|
|
4571
|
+
private func releaseIncidentRelay(_ relay: BleIncidentLogRelayEntry) {
|
|
4572
|
+
if bleIncidentLogRelays[relay.fileBaseKey] === relay {
|
|
4573
|
+
bleIncidentLogRelays.removeValue(forKey: relay.fileBaseKey)
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
|
|
4577
|
+
func sendBesCrashReported(incidentKey: String, reportId: String) throws {
|
|
4578
|
+
guard incidentLogTransportReady else {
|
|
4579
|
+
throw BluetoothSdkError(code: "glasses_not_connected", message: "Cannot report the BES crash because the glasses BLE link is not ready.")
|
|
4580
|
+
}
|
|
4581
|
+
guard sendJson(["type": "bes_crash_reported", "incidentKey": incidentKey, "reportId": reportId],
|
|
4582
|
+
wakeUp: true, requireAck: true, bridgeLogging: true)
|
|
4583
|
+
else {
|
|
4584
|
+
throw BluetoothSdkError(code: "bes_crash_dispatch_failed", message: "Could not queue bes_crash_reported to the glasses.")
|
|
4585
|
+
}
|
|
4586
|
+
Bridge.log("LIVE: Queued bes_crash_reported incidentKey=\(incidentKey) reportId=\(reportId)")
|
|
4587
|
+
}
|
|
4588
|
+
|
|
4589
|
+
static func isIncidentRelayFileName(_ fileName: String) -> Bool {
|
|
4590
|
+
guard fileName.count == 16, let first = fileName.first, first == "B" || first == "L" else { return false }
|
|
4591
|
+
return fileName.dropFirst().allSatisfy { ("a" ... "z").contains($0) || ("0" ... "9").contains($0) || $0 == "_" }
|
|
4592
|
+
}
|
|
4593
|
+
|
|
4502
4594
|
private static func incidentBleFileBase(incidentId: String, prefix: Character) -> String {
|
|
4503
4595
|
var compact = incidentId.replacingOccurrences(of: "-", with: "").lowercased()
|
|
4504
4596
|
if compact.count < 15 {
|
|
@@ -4670,6 +4762,20 @@ class MentraLive: NSObject, SGCManager {
|
|
|
4670
4762
|
|
|
4671
4763
|
// MARK: - Message Handlers
|
|
4672
4764
|
|
|
4765
|
+
/// A glasses_ready that echoes a readyId answers a phone_ready exchange. The answer to the
|
|
4766
|
+
/// exchange the phone is waiting on, and any answer from a glasses process other than the
|
|
4767
|
+
/// one this link last handled (an asg restart resets for every exchange it first sees),
|
|
4768
|
+
/// followed a transport reset. Any other answer repeats an exchange that process already
|
|
4769
|
+
/// reset for, or one superseded by the pending exchange, whose answer is still to come.
|
|
4770
|
+
private func isRepeatedGlassesReady(readyId: String, sid: String?) -> Bool {
|
|
4771
|
+
readyId != pendingReadyId && sid == readyGlassesSessionId
|
|
4772
|
+
}
|
|
4773
|
+
|
|
4774
|
+
private func resetReadinessExchange() {
|
|
4775
|
+
pendingReadyId = nil
|
|
4776
|
+
readyGlassesSessionId = nil
|
|
4777
|
+
}
|
|
4778
|
+
|
|
4673
4779
|
private func handleGlassesReady() {
|
|
4674
4780
|
pairFlow(
|
|
4675
4781
|
"glasses_ready",
|
|
@@ -5312,6 +5418,15 @@ class MentraLive: NSObject, SGCManager {
|
|
|
5312
5418
|
if sess.isComplete {
|
|
5313
5419
|
Bridge.log("LIVE: 📦 File transfer complete: \(packetInfo.fileName)")
|
|
5314
5420
|
|
|
5421
|
+
if Self.isIncidentRelayFileName(packetInfo.fileName) {
|
|
5422
|
+
// No relay registered (e.g. the app restarted mid-relay): nothing reached
|
|
5423
|
+
// Cloud, so success would make the glasses mark the incident uploaded.
|
|
5424
|
+
Bridge.log("LIVE: Incident log relay without a registered report: \(packetInfo.fileName)")
|
|
5425
|
+
sendTransferCompleteConfirmation(fileName: packetInfo.fileName, success: false)
|
|
5426
|
+
activeFileTransfers.removeValue(forKey: packetInfo.fileName)
|
|
5427
|
+
return
|
|
5428
|
+
}
|
|
5429
|
+
|
|
5315
5430
|
if let fileData = sess.assembleFile() {
|
|
5316
5431
|
saveReceivedFile(
|
|
5317
5432
|
fileName: packetInfo.fileName, fileData: fileData,
|
|
@@ -5413,7 +5528,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
5413
5528
|
]
|
|
5414
5529
|
}
|
|
5415
5530
|
|
|
5416
|
-
|
|
5531
|
+
func uploadBleIncidentLogRelay(
|
|
5417
5532
|
relay: BleIncidentLogRelayEntry, fileName: String, data: Data
|
|
5418
5533
|
) {
|
|
5419
5534
|
let token = DeviceStore.shared.get("bluetooth", "core_token") as? String ?? ""
|
|
@@ -5464,14 +5579,24 @@ class MentraLive: NSObject, SGCManager {
|
|
|
5464
5579
|
statusCode = nil
|
|
5465
5580
|
}
|
|
5466
5581
|
DispatchQueue.main.async {
|
|
5582
|
+
// A different report now owns this name (it was admitted after our owner finished),
|
|
5583
|
+
// so a completion here would mark ITS file done. Drop the stale callback.
|
|
5584
|
+
if let owner = self.bleIncidentLogRelays[relay.fileBaseKey], owner.incidentId != relay.incidentId {
|
|
5585
|
+
Bridge.log("LIVE: Dropping stale incident relay callback for \(relay.fileBaseKey)")
|
|
5586
|
+
return
|
|
5587
|
+
}
|
|
5467
5588
|
if ok {
|
|
5468
5589
|
Bridge.log("LIVE: ✅ Incident log BLE relay uploaded (\(relay.kind))")
|
|
5469
|
-
self.bleIncidentLogRelays.removeValue(forKey: relay.fileBaseKey)
|
|
5470
5590
|
} else if let existing = self.bleIncidentLogRelays[relay.fileBaseKey] {
|
|
5471
5591
|
// Keep relay entry for glasses retry after transfer_complete:false.
|
|
5472
5592
|
existing.session = nil
|
|
5473
5593
|
}
|
|
5474
5594
|
self.sendTransferCompleteConfirmation(fileName: fileName, success: ok)
|
|
5595
|
+
// Release only after the glasses' confirmation is queued, so a report that reuses
|
|
5596
|
+
// this name is ordered behind the owner's completion.
|
|
5597
|
+
if ok {
|
|
5598
|
+
self.releaseIncidentRelay(relay)
|
|
5599
|
+
}
|
|
5475
5600
|
}
|
|
5476
5601
|
}.resume()
|
|
5477
5602
|
}
|
|
@@ -5899,7 +6024,8 @@ class MentraLive: NSObject, SGCManager {
|
|
|
5899
6024
|
wireBytes: data.count,
|
|
5900
6025
|
packetCount: Int(info.fragCount),
|
|
5901
6026
|
protocolVersion: BleWireProtocol.protocolV2,
|
|
5902
|
-
direction: "glasses_to_phone"
|
|
6027
|
+
direction: "glasses_to_phone",
|
|
6028
|
+
bridgeLogging: !BleTraceLogger.isQuietJson(jsonString)
|
|
5903
6029
|
)
|
|
5904
6030
|
processJsonMessage(jsonString)
|
|
5905
6031
|
}
|
|
@@ -6674,12 +6800,13 @@ class MentraLive: NSObject, SGCManager {
|
|
|
6674
6800
|
)
|
|
6675
6801
|
// requestReadyK900()
|
|
6676
6802
|
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
]
|
|
6681
|
-
|
|
6682
|
-
|
|
6803
|
+
// The timer fires on bluetoothQueue; the pending readiness exchange is main-actor state.
|
|
6804
|
+
// A tick queued just before glasses_ready stopped the loop must not start a new exchange.
|
|
6805
|
+
let check = self.readinessCheckCounter
|
|
6806
|
+
DispatchQueue.main.async { [weak self] in
|
|
6807
|
+
guard let self, self.readinessCheckDispatchTimer != nil else { return }
|
|
6808
|
+
self.sendPhoneReady(reason: "readiness check #\(check)")
|
|
6809
|
+
}
|
|
6683
6810
|
}
|
|
6684
6811
|
|
|
6685
6812
|
readinessCheckDispatchTimer!.resume()
|
|
@@ -6816,6 +6943,14 @@ class MentraLive: NSObject, SGCManager {
|
|
|
6816
6943
|
return true
|
|
6817
6944
|
}
|
|
6818
6945
|
|
|
6946
|
+
/// Drops glasses that are not in pairing mode from the search results, once per change, so the
|
|
6947
|
+
/// next pairable advertisement lists them again.
|
|
6948
|
+
private func unlistNotPairable(_ name: String) {
|
|
6949
|
+
if cacheAdvPairing(name, pairingMode: false, pairingCode: nil, securePairingCapable: true) {
|
|
6950
|
+
Bridge.removeDiscoveredDevice("Mentra Live", name)
|
|
6951
|
+
}
|
|
6952
|
+
}
|
|
6953
|
+
|
|
6819
6954
|
private func emitDiscoveredDeviceFromCache(
|
|
6820
6955
|
_ name: String,
|
|
6821
6956
|
identifier: String = "",
|
|
@@ -6959,6 +7094,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
6959
7094
|
// Stop all timers
|
|
6960
7095
|
stopAllTimers()
|
|
6961
7096
|
resetWireNegotiationState()
|
|
7097
|
+
resetReadinessExchange()
|
|
6962
7098
|
commandQueue.removeAll() // stale writes die with the session
|
|
6963
7099
|
closeL2capFileChannel()
|
|
6964
7100
|
|
|
@@ -7174,11 +7310,16 @@ extension MentraLive {
|
|
|
7174
7310
|
|
|
7175
7311
|
/// Sends phone_ready to (re)start the glasses-driven readiness flow.
|
|
7176
7312
|
private func sendPhoneReady(reason: String) {
|
|
7313
|
+
let readyId = pendingReadyId ?? UUID().uuidString
|
|
7314
|
+
pendingReadyId = readyId
|
|
7177
7315
|
pairFlow("phone_ready", "reason=\(reason) gatt=\(txCharacteristic != nil) id=\(connectedPeripheral?.identifier.uuidString ?? "-")")
|
|
7178
|
-
Bridge.log(
|
|
7316
|
+
Bridge.log(
|
|
7317
|
+
"LIVE: 📱 Sending phone_ready to glasses (\(reason), exchange \(readyId)) - waiting for glasses_ready response"
|
|
7318
|
+
)
|
|
7179
7319
|
let readyMsg: [String: Any] = [
|
|
7180
7320
|
"type": "phone_ready",
|
|
7181
7321
|
"timestamp": Int64(Date().timeIntervalSince1970 * 1000),
|
|
7322
|
+
"readyId": readyId,
|
|
7182
7323
|
]
|
|
7183
7324
|
sendJson(readyMsg, wakeUp: true)
|
|
7184
7325
|
}
|