@mentra/bluetooth-sdk 3.3.0 → 3.4.0-beta.1241
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 +61 -0
- package/README.md +80 -11
- package/android/build.gradle +60 -51
- package/android/gradle.properties +3 -0
- package/android/settings.gradle +47 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/BesCrashReportWaiters.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +5 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +85 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +35 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +154 -110
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +21 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +1 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +27 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/connection/ConnectionModels.kt +5 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicy.kt +64 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +925 -155
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +227 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +19 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicy.kt +94 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachine.kt +411 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateStore.kt +124 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +54 -59
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +5 -32
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasEncoder.kt +8 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +3 -10
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +50 -0
- 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/DeviceManagerOwnerLossTest.kt +146 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusAudioSetupTest.kt +51 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusClassicAudioTest.kt +2 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/WifiAdbPeerIntentTest.kt +19 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicyTest.kt +65 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveAudioSetupReadinessTest.kt +231 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +5 -1
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +183 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +368 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +20 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicyTest.kt +136 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachineTest.kt +346 -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/utils/IncidentLogBleRelayNamingTest.kt +23 -0
- 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 +201 -1
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +43 -5
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +2 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/generated/changelogCatalog.d.ts +3 -0
- package/build/generated/changelogCatalog.d.ts.map +1 -1
- package/build/generated/changelogCatalog.js +4 -0
- 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 +9 -0
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +76 -12
- package/ios/MentraBluetoothSDK.podspec +4 -0
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
- package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
- package/ios/Source/BesCrashReportWaiters.swift +64 -0
- package/ios/Source/BluetoothSdkDefaults.swift +2 -2
- package/ios/Source/Bridge.swift +11 -3
- package/ios/Source/DeviceManager.swift +131 -18
- package/ios/Source/DeviceStore.swift +27 -0
- package/ios/Source/GeneratedChangelogCatalog.swift +1 -0
- package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
- package/ios/Source/MentraBluetoothSDK.swift +40 -5
- 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/errors/BluetoothSdkError.swift +5 -1
- package/ios/Source/events/BluetoothEvents.swift +41 -0
- package/ios/Source/internal/BleTraceLogger.swift +9 -6
- package/ios/Source/internal/BluetoothAvailability.swift +15 -5
- package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +186 -0
- package/ios/Source/sgcs/MentraLive.swift +1270 -189
- package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +260 -1
- package/ios/Source/sgcs/MentraLivePairingStateMachine.swift +385 -0
- package/ios/Source/sgcs/MentraLivePairingStateStore.swift +121 -0
- package/ios/Source/sgcs/Nimo.swift +10 -3
- package/ios/Source/sgcs/NimoCanvasCoordinator.swift +39 -9
- package/ios/Source/sgcs/SGCManager.swift +13 -0
- package/ios/Source/sgcs/Simulated.swift +2 -0
- package/ios/Source/status/DeviceStatus.swift +35 -0
- 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/types/DeviceModels.swift +8 -1
- package/ios/Source/utils/AudioSessionMonitor.swift +158 -5
- 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/BluetoothAudioRouteTests.swift +82 -0
- package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
- package/ios/Tests/DeviceManagerReconnectTests.swift +4 -2
- package/ios/Tests/GlassesAudioSetupPolicyTests.swift +197 -0
- package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
- package/ios/Tests/MentraLiveAudioSetupTests.swift +209 -0
- package/ios/Tests/MentraLiveConnectionOptionsTests.swift +55 -0
- package/ios/Tests/MentraLivePairingAdvertisementTests.swift +327 -0
- package/ios/Tests/MentraLivePairingStateMachineTests.swift +402 -0
- package/ios/Tests/MentraLiveSessionReadinessTests.swift +368 -26
- package/ios/Tests/NimoCanvasTransportTests.swift +58 -0
- package/ios/Tests/PcmStreamTests.swift +299 -0
- package/ios/Tests/SpeechActivityTests.swift +238 -0
- package/ios/Tests/SttModelTraitsTests.swift +62 -0
- package/ios/Tests/WifiAdbDispatchTests.swift +118 -0
- package/package.json +3 -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 +201 -1
- package/src/_private/BluetoothSdkModule.ts +47 -5
- package/src/generated/changelogCatalog.ts +4 -0
- package/src/generated/releaseMetadata.ts +6 -6
- package/src/index.ts +22 -0
- 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/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/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 -288
- /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
|
@@ -30,6 +30,7 @@ import java.nio.ByteOrder
|
|
|
30
30
|
import java.util.Calendar
|
|
31
31
|
import java.util.TimeZone
|
|
32
32
|
import java.util.UUID
|
|
33
|
+
import java.util.concurrent.atomic.AtomicInteger
|
|
33
34
|
import kotlinx.coroutines.Dispatchers
|
|
34
35
|
import kotlinx.coroutines.runBlocking
|
|
35
36
|
import kotlinx.coroutines.withContext
|
|
@@ -641,6 +642,8 @@ private class NimoAudioClient(
|
|
|
641
642
|
private var decoder: NimoOpusDecoder? = null
|
|
642
643
|
@Volatile private var started = false
|
|
643
644
|
private val pendingCount = java.util.concurrent.atomic.AtomicInteger(0)
|
|
645
|
+
private val retiringWorkers = AtomicInteger(0)
|
|
646
|
+
fun lifecyclePending(): Int = pendingCount.get() + retiringWorkers.get() + (if (started) 1 else 0)
|
|
644
647
|
private var droppedCount = 0
|
|
645
648
|
private var lastRightPacketMs = 0L
|
|
646
649
|
private var preferRight = true
|
|
@@ -676,7 +679,7 @@ private class NimoAudioClient(
|
|
|
676
679
|
sendCommand(byteArrayOf(0x52, 0x01, 0x00, 0x00))
|
|
677
680
|
}
|
|
678
681
|
|
|
679
|
-
fun stop() {
|
|
682
|
+
@Synchronized fun stop() {
|
|
680
683
|
if (!started) return
|
|
681
684
|
// Halt processing and drop in-flight frames BEFORE releasing the decoder —
|
|
682
685
|
// the glasses keep sending a few frames after the stop command, and decoding
|
|
@@ -692,9 +695,9 @@ private class NimoAudioClient(
|
|
|
692
695
|
thread = null
|
|
693
696
|
decoder = null
|
|
694
697
|
if (h != null) {
|
|
698
|
+
retiringWorkers.incrementAndGet()
|
|
695
699
|
h.post {
|
|
696
|
-
d?.release()
|
|
697
|
-
t?.quitSafely()
|
|
700
|
+
try { d?.release(); t?.quitSafely() } finally { retiringWorkers.decrementAndGet() }
|
|
698
701
|
}
|
|
699
702
|
} else {
|
|
700
703
|
d?.release()
|
|
@@ -717,7 +720,7 @@ private class NimoAudioClient(
|
|
|
717
720
|
}
|
|
718
721
|
pendingCount.incrementAndGet()
|
|
719
722
|
h.post {
|
|
720
|
-
pendingCount.
|
|
723
|
+
pendingCount.updateAndGet { if (it > 0) it - 1 else 0 }
|
|
721
724
|
process(bytes)
|
|
722
725
|
}
|
|
723
726
|
}
|
|
@@ -768,8 +771,8 @@ private class NimoAudioClient(
|
|
|
768
771
|
}
|
|
769
772
|
return
|
|
770
773
|
}
|
|
771
|
-
//
|
|
772
|
-
onActivity()
|
|
774
|
+
// The owning session may stop while a decoder callback is already running.
|
|
775
|
+
synchronized(this) { if (!started) return; onActivity() }
|
|
773
776
|
|
|
774
777
|
val now = System.currentTimeMillis()
|
|
775
778
|
when (packet.type) {
|
|
@@ -807,7 +810,7 @@ private class NimoAudioClient(
|
|
|
807
810
|
}
|
|
808
811
|
statsFrames++
|
|
809
812
|
statsPcmBytes += pcm16.size
|
|
810
|
-
onPcm(pcm16)
|
|
813
|
+
synchronized(this) { if (!started) return; onPcm(pcm16) }
|
|
811
814
|
}
|
|
812
815
|
}
|
|
813
816
|
|
|
@@ -847,12 +850,15 @@ private class NimoReconnectionManager(
|
|
|
847
850
|
private var runnable: Runnable? = null
|
|
848
851
|
private var attempts = 0
|
|
849
852
|
|
|
853
|
+
fun pending(): Boolean = runnable != null
|
|
854
|
+
|
|
850
855
|
fun start(onAttempt: () -> Boolean) {
|
|
851
856
|
stop()
|
|
852
857
|
attempts = 0
|
|
853
858
|
val r =
|
|
854
859
|
object : Runnable {
|
|
855
860
|
override fun run() {
|
|
861
|
+
if (runnable !== this) return
|
|
856
862
|
if (maxAttempts > 0 && attempts >= maxAttempts) {
|
|
857
863
|
Bridge.log("NIMO: Max reconnection attempts ($maxAttempts) reached")
|
|
858
864
|
stop()
|
|
@@ -865,7 +871,7 @@ private class NimoReconnectionManager(
|
|
|
865
871
|
stop()
|
|
866
872
|
return
|
|
867
873
|
}
|
|
868
|
-
handler.postDelayed(this, intervalMs)
|
|
874
|
+
if (runnable === this) handler.postDelayed(this, intervalMs)
|
|
869
875
|
}
|
|
870
876
|
}
|
|
871
877
|
runnable = r
|
|
@@ -928,10 +934,14 @@ class Nimo : SGCManager() {
|
|
|
928
934
|
hasMic = true
|
|
929
935
|
}
|
|
930
936
|
|
|
937
|
+
private fun closeGatt() {
|
|
938
|
+
val original = gatt ?: return
|
|
939
|
+
try { original.disconnect() } catch (error: Exception) { Bridge.log("NIMO: disconnect failed: ${error.javaClass.simpleName}") }
|
|
940
|
+
try { original.close() } catch (error: Exception) { Bridge.log("NIMO: close failed: ${error.javaClass.simpleName}") }
|
|
941
|
+
}
|
|
942
|
+
|
|
931
943
|
private val mainHandler = Handler(Looper.getMainLooper())
|
|
932
944
|
private val mainScheduler = handlerScheduler(mainHandler)
|
|
933
|
-
// Variant-specific: release has no receiver or framebuffer protocol implementation.
|
|
934
|
-
private var diagnostics: NimoDiagnostics? = null
|
|
935
945
|
private val canvasEncoderThread = HandlerThread("NimoCanvasEncoder").apply { start() }
|
|
936
946
|
private val canvasEncoder = NimoCanvasEncoder(mainScheduler,
|
|
937
947
|
handlerScheduler(Handler(canvasEncoderThread.looper)),
|
|
@@ -939,8 +949,7 @@ class Nimo : SGCManager() {
|
|
|
939
949
|
{ Bridge.log("NIMO: canvas validation/encoding failed; retaining last valid scene: ${it.message}") })
|
|
940
950
|
private val canvas = NimoCanvasCoordinator(mainScheduler,
|
|
941
951
|
{ (negotiatedMtu - 3).coerceIn(20, 512) }, ::enqueueFrames, ::abortTransport,
|
|
942
|
-
{ Bridge.log("NIMO: canvas rejected status=$it; not a render ACK") }
|
|
943
|
-
{ diagnostics?.cancelHeldCapture("Canvas scope takeover preempted held capture", resumeCanvas = false) })
|
|
952
|
+
{ Bridge.log("NIMO: canvas rejected status=$it; not a render ACK") })
|
|
944
953
|
|
|
945
954
|
private fun handlerScheduler(handler: Handler) = NimoScheduler { delay, task ->
|
|
946
955
|
val runnable = Runnable(task)
|
|
@@ -1099,8 +1108,7 @@ class Nimo : SGCManager() {
|
|
|
1099
1108
|
reconnectionManager.stop()
|
|
1100
1109
|
failAllPendingAcks()
|
|
1101
1110
|
|
|
1102
|
-
|
|
1103
|
-
gatt?.close()
|
|
1111
|
+
closeGatt()
|
|
1104
1112
|
gatt = null
|
|
1105
1113
|
txChar = null
|
|
1106
1114
|
rxChar = null
|
|
@@ -1156,8 +1164,6 @@ class Nimo : SGCManager() {
|
|
|
1156
1164
|
}
|
|
1157
1165
|
canvasEncoder.close()
|
|
1158
1166
|
disconnect()
|
|
1159
|
-
diagnostics?.close()
|
|
1160
|
-
diagnostics = null
|
|
1161
1167
|
audioClient.stop()
|
|
1162
1168
|
}
|
|
1163
1169
|
|
|
@@ -1390,7 +1396,6 @@ class Nimo : SGCManager() {
|
|
|
1390
1396
|
override fun exit() {
|
|
1391
1397
|
canvasEncoder.invalidate()
|
|
1392
1398
|
mainHandler.post {
|
|
1393
|
-
diagnostics?.cancelHeldCapture("Explicit host exit preempted held capture", resumeCanvas = false)
|
|
1394
1399
|
canvas.exit()
|
|
1395
1400
|
}
|
|
1396
1401
|
}
|
|
@@ -1617,12 +1622,7 @@ class Nimo : SGCManager() {
|
|
|
1617
1622
|
bluetoothAdapter?.cancelDiscovery()
|
|
1618
1623
|
} catch (_: Exception) {}
|
|
1619
1624
|
|
|
1620
|
-
val bondState =
|
|
1621
|
-
try {
|
|
1622
|
-
device.bondState
|
|
1623
|
-
} catch (e: SecurityException) {
|
|
1624
|
-
android.bluetooth.BluetoothDevice.BOND_NONE
|
|
1625
|
-
}
|
|
1625
|
+
val bondState = try { device.bondState } catch (_: SecurityException) { android.bluetooth.BluetoothDevice.BOND_NONE }
|
|
1626
1626
|
if (bondState != android.bluetooth.BluetoothDevice.BOND_BONDED) {
|
|
1627
1627
|
// Bond over classic first, then open the Companion bearer on completion.
|
|
1628
1628
|
startBond(device)
|
|
@@ -1637,12 +1637,7 @@ class Nimo : SGCManager() {
|
|
|
1637
1637
|
* called both on the initial attempt and from the BOND_NONE handler.
|
|
1638
1638
|
*/
|
|
1639
1639
|
private fun startBond(device: android.bluetooth.BluetoothDevice) {
|
|
1640
|
-
val bondState =
|
|
1641
|
-
try {
|
|
1642
|
-
device.bondState
|
|
1643
|
-
} catch (e: SecurityException) {
|
|
1644
|
-
android.bluetooth.BluetoothDevice.BOND_NONE
|
|
1645
|
-
}
|
|
1640
|
+
val bondState = try { device.bondState } catch (_: SecurityException) { android.bluetooth.BluetoothDevice.BOND_NONE }
|
|
1646
1641
|
// A previous (apparently failed) attempt may have bonded in the background.
|
|
1647
1642
|
if (bondState == android.bluetooth.BluetoothDevice.BOND_BONDED) {
|
|
1648
1643
|
Bridge.log("NIMO: already bonded with ${device.address} — connecting")
|
|
@@ -1691,13 +1686,12 @@ class Nimo : SGCManager() {
|
|
|
1691
1686
|
// for system-paired dual-mode accessories).
|
|
1692
1687
|
Bridge.log("NIMO: connecting GATT over BR/EDR to ${device.address}")
|
|
1693
1688
|
DeviceStore.apply("glasses", "connectionState", ConnTypes.CONNECTING)
|
|
1694
|
-
gatt =
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
)
|
|
1689
|
+
gatt = try {
|
|
1690
|
+
device.connectGatt(context, false, gattCallback, android.bluetooth.BluetoothDevice.TRANSPORT_BREDR)
|
|
1691
|
+
} catch (error: SecurityException) {
|
|
1692
|
+
Bridge.log("NIMO: connectGatt SecurityException: ${error.message}")
|
|
1693
|
+
null
|
|
1694
|
+
}
|
|
1701
1695
|
gatt?.let { writes.connected(it) }
|
|
1702
1696
|
}
|
|
1703
1697
|
|
|
@@ -1826,9 +1820,12 @@ class Nimo : SGCManager() {
|
|
|
1826
1820
|
object : BluetoothGattCallback() {
|
|
1827
1821
|
override fun onConnectionStateChange(g: BluetoothGatt, status: Int, newState: Int) {
|
|
1828
1822
|
mainHandler.post {
|
|
1829
|
-
if (g !== gatt)
|
|
1823
|
+
if (g !== gatt) {
|
|
1824
|
+
return@post
|
|
1825
|
+
}
|
|
1830
1826
|
Bridge.log("NIMO: onConnectionStateChange status=$status newState=$newState")
|
|
1831
1827
|
if (newState == BluetoothProfile.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) {
|
|
1828
|
+
if (isDisconnecting) return@post
|
|
1832
1829
|
Bridge.log("NIMO: Connected to ${g.device?.name ?: "unknown"}")
|
|
1833
1830
|
lastDeviceAddress = g.device?.address
|
|
1834
1831
|
// Do NOT request a large MTU here: the vendor transport warns that
|
|
@@ -1877,6 +1874,7 @@ class Nimo : SGCManager() {
|
|
|
1877
1874
|
}
|
|
1878
1875
|
mainHandler.post {
|
|
1879
1876
|
if (g !== gatt) return@post
|
|
1877
|
+
if (isDisconnecting) return@post
|
|
1880
1878
|
val service = g.getService(NimoBLE.SERVICE_UUID)
|
|
1881
1879
|
if (service == null) {
|
|
1882
1880
|
// Dump everything so a UUID mismatch is diagnosable from logs.
|
|
@@ -1922,7 +1920,9 @@ class Nimo : SGCManager() {
|
|
|
1922
1920
|
NimoBLE.CHAR_RX -> if (characteristic.service?.uuid == NimoBLE.SERVICE_UUID) {
|
|
1923
1921
|
handleRxPacket(data)
|
|
1924
1922
|
}
|
|
1925
|
-
NimoBLE.CHAR_MIC ->
|
|
1923
|
+
NimoBLE.CHAR_MIC -> {
|
|
1924
|
+
audioClient.enqueue(data)
|
|
1925
|
+
}
|
|
1926
1926
|
}
|
|
1927
1927
|
}
|
|
1928
1928
|
}
|
|
@@ -1992,11 +1992,10 @@ class Nimo : SGCManager() {
|
|
|
1992
1992
|
|
|
1993
1993
|
private fun abortTransport(reason: String) {
|
|
1994
1994
|
Bridge.log("NIMO: resetting transport: $reason")
|
|
1995
|
-
|
|
1995
|
+
closeGatt()
|
|
1996
1996
|
gatt = null
|
|
1997
1997
|
txChar = null; rxChar = null; micChar = null
|
|
1998
1998
|
resetSessionState()
|
|
1999
|
-
try { old?.disconnect(); old?.close() } catch (_: Exception) {}
|
|
2000
1999
|
DeviceStore.apply("glasses", "connected", false)
|
|
2001
2000
|
DeviceStore.apply("glasses", "fullyBooted", false)
|
|
2002
2001
|
DeviceStore.apply("glasses", "connectionState", ConnTypes.DISCONNECTED)
|
|
@@ -2050,6 +2049,7 @@ class Nimo : SGCManager() {
|
|
|
2050
2049
|
// ---------- Handshake ----------
|
|
2051
2050
|
|
|
2052
2051
|
private fun startHandshake() {
|
|
2052
|
+
if (isDisconnecting) return
|
|
2053
2053
|
Bridge.log("NIMO: starting handshake (awaiting TWS service-connection state)")
|
|
2054
2054
|
handshakeState = HandshakeState.AWAITING_TWS
|
|
2055
2055
|
if (twsConnected) {
|
|
@@ -2075,6 +2075,11 @@ class Nimo : SGCManager() {
|
|
|
2075
2075
|
}
|
|
2076
2076
|
|
|
2077
2077
|
private var setTimeAttempts = 0
|
|
2078
|
+
private var setTimeRetryRunnable: Runnable? = null
|
|
2079
|
+
private fun cancelSetTimeRetry() {
|
|
2080
|
+
setTimeRetryRunnable?.let(mainHandler::removeCallbacks)
|
|
2081
|
+
setTimeRetryRunnable = null
|
|
2082
|
+
}
|
|
2078
2083
|
|
|
2079
2084
|
private fun proceedToTimeSync() {
|
|
2080
2085
|
if (handshakeState != HandshakeState.AWAITING_TWS) return
|
|
@@ -2104,7 +2109,12 @@ class Nimo : SGCManager() {
|
|
|
2104
2109
|
// The firmware can answer "busy" right after the link comes up —
|
|
2105
2110
|
// give it a moment and retry instead of dropping the connection.
|
|
2106
2111
|
Bridge.log("NIMO: setTime attempt $setTimeAttempts failed — retrying")
|
|
2107
|
-
|
|
2112
|
+
val retry = Runnable {
|
|
2113
|
+
setTimeRetryRunnable = null
|
|
2114
|
+
if (gatt === expectedGatt) attemptSetTime()
|
|
2115
|
+
}
|
|
2116
|
+
setTimeRetryRunnable = retry
|
|
2117
|
+
mainHandler.postDelayed(retry, SET_TIME_RETRY_DELAY_MS)
|
|
2108
2118
|
} else {
|
|
2109
2119
|
Bridge.log("NIMO: setTime failed after $setTimeAttempts attempts — handshake failed")
|
|
2110
2120
|
handshakeFailed()
|
|
@@ -2135,16 +2145,6 @@ class Nimo : SGCManager() {
|
|
|
2135
2145
|
DeviceStore.apply("glasses", "fullyBooted", true)
|
|
2136
2146
|
DeviceStore.apply("glasses", "connectionState", ConnTypes.CONNECTED)
|
|
2137
2147
|
startTimers()
|
|
2138
|
-
if (diagnostics == null) {
|
|
2139
|
-
diagnostics = NimoDiagnostics(
|
|
2140
|
-
context,
|
|
2141
|
-
mainHandler,
|
|
2142
|
-
{ frame, completed -> enqueueFrames(listOf(frame), {}, completed) },
|
|
2143
|
-
{ ready -> canvas.hold(ready) },
|
|
2144
|
-
{ resume -> canvas.releaseHold(resume) },
|
|
2145
|
-
)
|
|
2146
|
-
}
|
|
2147
|
-
diagnostics?.connected((negotiatedMtu - 3).coerceIn(20, 512))
|
|
2148
2148
|
// Launch checks peer readiness in firmware; do not wait up to a minute for
|
|
2149
2149
|
// the first unsolicited heartbeat just because peer status is still unknown.
|
|
2150
2150
|
canvas.activate()
|
|
@@ -2158,9 +2158,9 @@ class Nimo : SGCManager() {
|
|
|
2158
2158
|
}
|
|
2159
2159
|
|
|
2160
2160
|
private fun resetSessionState() {
|
|
2161
|
-
diagnostics?.disconnected()
|
|
2162
2161
|
handshakeState = HandshakeState.IDLE
|
|
2163
2162
|
cancelTwsTimeout()
|
|
2163
|
+
cancelSetTimeRetry()
|
|
2164
2164
|
twsConnected = false
|
|
2165
2165
|
peerCompanionReady = null
|
|
2166
2166
|
canvasEncoder.invalidate()
|
|
@@ -2221,7 +2221,6 @@ class Nimo : SGCManager() {
|
|
|
2221
2221
|
|
|
2222
2222
|
private fun handleRxPacket(packet: ByteArray) {
|
|
2223
2223
|
// Diagnostic packets must retain their original wire CRC and framing.
|
|
2224
|
-
if (diagnostics?.onPacket(packet) == true) return
|
|
2225
2224
|
if (packet.size >= 10 && packet[8].toInt() == 7 && (packet[9].toInt() and 255) in listOf(1, 3, 4)) {
|
|
2226
2225
|
val response = NimoCanvasCodec.response(packet) ?: return
|
|
2227
2226
|
if (response.first == 1) Bridge.log("NIMO: canvas Launch response status=${response.second.firstOrNull()?.toInt()}")
|
|
@@ -2253,15 +2252,9 @@ class Nimo : SGCManager() {
|
|
|
2253
2252
|
Bridge.log("NIMO: app state report appId=$appId phase=$phase")
|
|
2254
2253
|
when (phase) {
|
|
2255
2254
|
NimoProtocol.STATE_ENTER -> {
|
|
2256
|
-
if (appId != NimoCanvasCodec.APP_ID) {
|
|
2257
|
-
diagnostics?.cancelHeldCapture("Native app takeover preempted held capture", resumeCanvas = false)
|
|
2258
|
-
}
|
|
2259
2255
|
canvas.nativeApp(appId, true)
|
|
2260
2256
|
}
|
|
2261
2257
|
NimoProtocol.STATE_EXIT -> {
|
|
2262
|
-
if (appId == NimoCanvasCodec.APP_ID) {
|
|
2263
|
-
diagnostics?.cancelHeldCapture("Canvas exit preempted held capture", resumeCanvas = false)
|
|
2264
|
-
}
|
|
2265
2258
|
canvas.nativeApp(appId, false)
|
|
2266
2259
|
}
|
|
2267
2260
|
}
|
|
@@ -2392,6 +2385,8 @@ class Nimo : SGCManager() {
|
|
|
2392
2385
|
var end = data.size
|
|
2393
2386
|
while (end > 0 && data[end - 1].toInt() == 0) end--
|
|
2394
2387
|
firmwareVersionDetail = String(data, 0, end, Charsets.UTF_8).trim()
|
|
2388
|
+
if (firmwareVersionDetail.isNotEmpty() && firmwareVersionDetail.length <= 240) {
|
|
2389
|
+
}
|
|
2395
2390
|
emitVersionInfo()
|
|
2396
2391
|
}
|
|
2397
2392
|
NimoProtocol.GET_TWS_STATUS -> {
|
|
@@ -25,6 +25,8 @@ internal class NimoGattQueue<C : Any>(
|
|
|
25
25
|
private var descriptorCompletion: (() -> Unit)? = null
|
|
26
26
|
private var cancelDeadline: (() -> Unit)? = null
|
|
27
27
|
|
|
28
|
+
fun pendingCount(): Int = queue.size + (if (current != null) 1 else 0) + (if (descriptor != null) 1 else 0)
|
|
29
|
+
|
|
28
30
|
fun connected(connection: Any) { reset(); this.connection = connection }
|
|
29
31
|
|
|
30
32
|
fun reset() {
|
|
@@ -119,7 +121,6 @@ internal class NimoCanvasCoordinator(
|
|
|
119
121
|
private val enqueue: (List<ByteArray>, () -> Unit, () -> Unit) -> Boolean,
|
|
120
122
|
private val reconnect: (String) -> Unit,
|
|
121
123
|
private val rejected: (Int) -> Unit = {},
|
|
122
|
-
private val holdPreempted: () -> Unit = {},
|
|
123
124
|
) {
|
|
124
125
|
private class Flight(val action: NimoCanvasSession.Action.Send) {
|
|
125
126
|
var finalStarted = false
|
|
@@ -128,17 +129,13 @@ internal class NimoCanvasCoordinator(
|
|
|
128
129
|
}
|
|
129
130
|
private val session = NimoCanvasSession()
|
|
130
131
|
private var flight: Flight? = null
|
|
131
|
-
private var holdReady: (() -> Unit)? = null
|
|
132
|
-
private var holding = false
|
|
133
|
-
private var heldScope: String? = null
|
|
134
132
|
private var cancelDeadline: (() -> Unit)? = null
|
|
135
133
|
private var cancelRetry: (() -> Unit)? = null
|
|
136
134
|
|
|
135
|
+
fun pendingCount(): Int = if (flight != null) 1 else 0
|
|
136
|
+
fun active(): Boolean = session.active()
|
|
137
|
+
|
|
137
138
|
fun offer(bytes: ByteArray, scope: String, force: Boolean = false) {
|
|
138
|
-
if (holding && scope != heldScope) {
|
|
139
|
-
releaseHold(resume = false)
|
|
140
|
-
holdPreempted()
|
|
141
|
-
}
|
|
142
139
|
run(session.offer(bytes, scope, force))
|
|
143
140
|
}
|
|
144
141
|
fun activate() = run(session.activate())
|
|
@@ -150,19 +147,6 @@ internal class NimoCanvasCoordinator(
|
|
|
150
147
|
if (!ready) { cancelRetry?.invoke(); cancelRetry = null }
|
|
151
148
|
run(session.confirmedReadiness(ready))
|
|
152
149
|
}
|
|
153
|
-
fun hold(onReady: () -> Unit) {
|
|
154
|
-
session.hold(true)
|
|
155
|
-
holding = true
|
|
156
|
-
heldScope = session.currentScope()
|
|
157
|
-
holdReady = onReady
|
|
158
|
-
notifyHoldReadyIfIdle()
|
|
159
|
-
}
|
|
160
|
-
fun releaseHold(resume: Boolean = true) {
|
|
161
|
-
holdReady = null
|
|
162
|
-
holding = false
|
|
163
|
-
heldScope = null
|
|
164
|
-
run(session.hold(false, resume))
|
|
165
|
-
}
|
|
166
150
|
fun exit() {
|
|
167
151
|
cancelRetry?.invoke(); cancelRetry = null
|
|
168
152
|
run(session.exit())
|
|
@@ -173,9 +157,6 @@ internal class NimoCanvasCoordinator(
|
|
|
173
157
|
cancelRetry?.invoke(); cancelRetry = null
|
|
174
158
|
cancelDeadline?.invoke(); cancelDeadline = null
|
|
175
159
|
flight = null
|
|
176
|
-
holdReady = null
|
|
177
|
-
holding = false
|
|
178
|
-
heldScope = null
|
|
179
160
|
session.disconnected()
|
|
180
161
|
}
|
|
181
162
|
|
|
@@ -189,14 +170,6 @@ internal class NimoCanvasCoordinator(
|
|
|
189
170
|
cancelDeadline?.invoke(); cancelDeadline = null
|
|
190
171
|
flight = null
|
|
191
172
|
run(session.response(key, payload))
|
|
192
|
-
notifyHoldReadyIfIdle()
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
private fun notifyHoldReadyIfIdle() {
|
|
196
|
-
if (flight != null) return
|
|
197
|
-
val ready = holdReady ?: return
|
|
198
|
-
holdReady = null
|
|
199
|
-
ready()
|
|
200
173
|
}
|
|
201
174
|
|
|
202
175
|
private fun run(actions: List<NimoCanvasSession.Action>) {
|
|
@@ -14,6 +14,10 @@ internal class NimoCanvasEncoder(
|
|
|
14
14
|
private var generation = 0L
|
|
15
15
|
private var pending: Request? = null
|
|
16
16
|
private var closed = false
|
|
17
|
+
private var running = 0
|
|
18
|
+
private var deliveries = 0
|
|
19
|
+
|
|
20
|
+
@Synchronized fun pendingCount(): Int = (if (pending != null) 1 else 0) + running + deliveries
|
|
17
21
|
|
|
18
22
|
@Synchronized
|
|
19
23
|
fun submit(encode: () -> ByteArray, release: () -> Unit = {}, deliver: (ByteArray) -> Unit): Boolean {
|
|
@@ -44,15 +48,18 @@ internal class NimoCanvasEncoder(
|
|
|
44
48
|
synchronized(this) {
|
|
45
49
|
if (pending !== request) return
|
|
46
50
|
pending = null // Running work releases its own source, never the invalidator.
|
|
51
|
+
running++
|
|
47
52
|
}
|
|
48
53
|
try {
|
|
49
54
|
val bytes = request.encode()
|
|
55
|
+
synchronized(this) { deliveries++ }
|
|
50
56
|
main.post(0) {
|
|
51
57
|
synchronized(this) {
|
|
58
|
+
deliveries--
|
|
52
59
|
if (!closed && generation == request.generation) request.deliver(bytes)
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
62
|
} catch (error: Exception) { failed(error) }
|
|
56
|
-
finally { request.release() }
|
|
63
|
+
finally { request.release(); synchronized(this) { running-- } }
|
|
57
64
|
}
|
|
58
65
|
}
|
|
@@ -11,7 +11,6 @@ internal class NimoCanvasSession {
|
|
|
11
11
|
private var ready = false
|
|
12
12
|
private var transportReady = false
|
|
13
13
|
private var active = false
|
|
14
|
-
private var held = false
|
|
15
14
|
private var locked = false
|
|
16
15
|
private var launchBlocked = false
|
|
17
16
|
private var waitingReadiness = false
|
|
@@ -54,13 +53,7 @@ internal class NimoCanvasSession {
|
|
|
54
53
|
return pump()
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
fun hold(value: Boolean, resume: Boolean = true): List<Action> {
|
|
59
|
-
held = value
|
|
60
|
-
return if (!value && resume) pump() else emptyList()
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
fun currentScope(): String? = scope
|
|
56
|
+
fun active(): Boolean = active
|
|
64
57
|
|
|
65
58
|
fun readiness(value: Boolean): List<Action> = updateReadiness(value, confirmed = false)
|
|
66
59
|
|
|
@@ -87,7 +80,7 @@ internal class NimoCanvasSession {
|
|
|
87
80
|
|
|
88
81
|
/** A new transport generation has no accepted frame. Retain only the latest desired scene. */
|
|
89
82
|
fun disconnected() {
|
|
90
|
-
ready = false; transportReady = false; active = false;
|
|
83
|
+
ready = false; transportReady = false; active = false; locked = false; launchBlocked = false
|
|
91
84
|
waitingReadiness = false; observedNotReady = false
|
|
92
85
|
readinessRetries = 0; probeRetries = 0
|
|
93
86
|
accepted = null; rejected = null; flight = null; ticket++; forceRevision++
|
|
@@ -160,7 +153,7 @@ internal class NimoCanvasSession {
|
|
|
160
153
|
}
|
|
161
154
|
|
|
162
155
|
private fun pump(): List<Action> {
|
|
163
|
-
if (!ready ||
|
|
156
|
+
if (!ready || locked || launchBlocked || waitingReadiness || flight != null) return emptyList()
|
|
164
157
|
val next = desired
|
|
165
158
|
val key = when {
|
|
166
159
|
exitRequested && active -> 3
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.mentra.bluetoothsdk.sgcs
|
|
2
2
|
|
|
3
3
|
import com.mentra.bluetoothsdk.BluetoothSdkDefaults
|
|
4
|
+
import com.mentra.bluetoothsdk.BluetoothSdkException
|
|
4
5
|
import com.mentra.bluetoothsdk.Bridge
|
|
5
6
|
import com.mentra.bluetoothsdk.DeviceStore
|
|
6
7
|
import com.mentra.bluetoothsdk.PhotoRequest
|
|
@@ -348,6 +349,11 @@ abstract class SGCManager {
|
|
|
348
349
|
// Incident Reporting
|
|
349
350
|
abstract fun sendIncidentId(incidentId: String, apiBaseUrl: String? = null)
|
|
350
351
|
|
|
352
|
+
/** Tell the glasses Cloud recorded [reportId] for a BES crash incident (Mentra Live only). */
|
|
353
|
+
open fun sendBesCrashReported(incidentKey: String, reportId: String) {
|
|
354
|
+
throw BluetoothSdkException("unsupported_device", "BES crash reporting is not supported on $type.")
|
|
355
|
+
}
|
|
356
|
+
|
|
351
357
|
// Gallery
|
|
352
358
|
abstract fun queryGalleryStatus()
|
|
353
359
|
abstract fun sendGalleryMode()
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
package com.mentra.bluetoothsdk
|
|
2
2
|
|
|
3
|
+
import com.mentra.bluetoothsdk.sgcs.GlassesAudioSetupPolicy
|
|
4
|
+
import com.mentra.bluetoothsdk.sgcs.GlassesAudioSetupState
|
|
5
|
+
|
|
3
6
|
data class WifiScanResult(
|
|
4
7
|
val ssid: String,
|
|
5
8
|
val requiresPassword: Boolean,
|
|
@@ -35,6 +38,8 @@ internal data class GlassesStatus(
|
|
|
35
38
|
val voiceActivityDetectionEnabled: Boolean,
|
|
36
39
|
val connectionState: GlassesConnectionState,
|
|
37
40
|
val bluetoothClassicConnected: Boolean,
|
|
41
|
+
val bluetoothClassicProfilesConnected: Boolean,
|
|
42
|
+
val bluetoothAudioRouted: Boolean,
|
|
38
43
|
val signalStrength: Int,
|
|
39
44
|
val signalStrengthUpdatedAt: Long,
|
|
40
45
|
val deviceModel: String,
|
|
@@ -77,6 +82,14 @@ internal data class GlassesStatus(
|
|
|
77
82
|
val controllerBatteryLevel: Int,
|
|
78
83
|
val controllerSignalStrength: Int,
|
|
79
84
|
val ringSignalStrength: Int,
|
|
85
|
+
/** Mentra Live `MentraLivePairingState` map (`{state, windowId?, endsAtMs?}`); absent for other glasses. */
|
|
86
|
+
val pairingState: Map<String, Any>? = null,
|
|
87
|
+
/**
|
|
88
|
+
* `GlassesAudioSetupState` map, on every model. Derived from [fullyBooted] by
|
|
89
|
+
* [GlassesAudioSetupPolicy] rather than stored, so a snapshot that reports ready never
|
|
90
|
+
* carries a stale `idle`.
|
|
91
|
+
*/
|
|
92
|
+
val audioSetup: Map<String, Any> = GlassesAudioSetupPolicy.state(fullyBooted).toMap(),
|
|
80
93
|
) {
|
|
81
94
|
internal fun toMap(): Map<String, Any> {
|
|
82
95
|
val values =
|
|
@@ -85,6 +98,8 @@ internal data class GlassesStatus(
|
|
|
85
98
|
"micEnabled" to micEnabled,
|
|
86
99
|
"voiceActivityDetectionEnabled" to voiceActivityDetectionEnabled,
|
|
87
100
|
"bluetoothClassicConnected" to bluetoothClassicConnected,
|
|
101
|
+
"bluetoothClassicProfilesConnected" to bluetoothClassicProfilesConnected,
|
|
102
|
+
"bluetoothAudioRouted" to bluetoothAudioRouted,
|
|
88
103
|
"signalStrength" to signalStrength,
|
|
89
104
|
"signalStrengthUpdatedAt" to signalStrengthUpdatedAt,
|
|
90
105
|
"deviceModel" to deviceModel,
|
|
@@ -123,6 +138,8 @@ internal data class GlassesStatus(
|
|
|
123
138
|
"ringSignalStrength" to ringSignalStrength,
|
|
124
139
|
)
|
|
125
140
|
systemTimeMs?.let { values["systemTimeMs"] = it }
|
|
141
|
+
pairingState?.let { values["pairingState"] = it }
|
|
142
|
+
values["audioSetup"] = audioSetup
|
|
126
143
|
return values
|
|
127
144
|
}
|
|
128
145
|
|
|
@@ -137,6 +154,9 @@ internal data class GlassesStatus(
|
|
|
137
154
|
?: BluetoothSdkDefaults.VOICE_ACTIVITY_DETECTION_ENABLED,
|
|
138
155
|
connectionState = GlassesConnectionState.fromValue(stringValue(values, "connectionState")),
|
|
139
156
|
bluetoothClassicConnected = boolValue(values, "bluetoothClassicConnected") ?: false,
|
|
157
|
+
// Android has no separate profile/route signal; both mirror the Classic audio state.
|
|
158
|
+
bluetoothClassicProfilesConnected = boolValue(values, "bluetoothClassicConnected") ?: false,
|
|
159
|
+
bluetoothAudioRouted = boolValue(values, "bluetoothClassicConnected") ?: false,
|
|
140
160
|
signalStrength = numberValue(values, "signalStrength") ?: -1,
|
|
141
161
|
signalStrengthUpdatedAt = longValue(values, "signalStrengthUpdatedAt") ?: 0L,
|
|
142
162
|
deviceModel = stringValue(values, "deviceModel") ?: "",
|
|
@@ -174,10 +194,25 @@ internal data class GlassesStatus(
|
|
|
174
194
|
controllerBatteryLevel = numberValue(values, "controllerBatteryLevel") ?: -1,
|
|
175
195
|
controllerSignalStrength = numberValue(values, "controllerSignalStrength") ?: -1,
|
|
176
196
|
ringSignalStrength = numberValue(values, "ringSignalStrength") ?: -1,
|
|
197
|
+
pairingState = pairingStateValue(values),
|
|
177
198
|
)
|
|
178
199
|
}
|
|
179
200
|
}
|
|
180
201
|
|
|
202
|
+
/** `audioSetup` from an event or update map, keeping only a known state and its action. */
|
|
203
|
+
internal fun audioSetupValue(values: Map<String, Any>): Map<String, Any>? =
|
|
204
|
+
GlassesAudioSetupState.fromMap(values["audioSetup"])?.toMap()
|
|
205
|
+
|
|
206
|
+
/** `pairingState` from a store or event map, keeping only string keys. */
|
|
207
|
+
internal fun pairingStateValue(values: Map<String, Any>): Map<String, Any>? {
|
|
208
|
+
val raw = values["pairingState"] as? Map<*, *> ?: return null
|
|
209
|
+
val state = raw["state"] as? String ?: return null
|
|
210
|
+
val result = mutableMapOf<String, Any>("state" to state)
|
|
211
|
+
(raw["windowId"] as? Number)?.let { result["windowId"] = it.toInt() }
|
|
212
|
+
(raw["endsAtMs"] as? Number)?.let { result["endsAtMs"] = it.toLong() }
|
|
213
|
+
return result
|
|
214
|
+
}
|
|
215
|
+
|
|
181
216
|
data class VersionInfoResult(
|
|
182
217
|
val androidVersion: String,
|
|
183
218
|
val firmwareVersion: String,
|
|
@@ -406,6 +441,8 @@ internal data class GlassesStatusUpdate(
|
|
|
406
441
|
val voiceActivityDetectionEnabled: Boolean? = null,
|
|
407
442
|
val connectionState: GlassesConnectionState? = null,
|
|
408
443
|
val bluetoothClassicConnected: Boolean? = null,
|
|
444
|
+
val bluetoothClassicProfilesConnected: Boolean? = null,
|
|
445
|
+
val bluetoothAudioRouted: Boolean? = null,
|
|
409
446
|
val signalStrength: Int? = null,
|
|
410
447
|
val signalStrengthUpdatedAt: Long? = null,
|
|
411
448
|
val deviceModel: String? = null,
|
|
@@ -442,6 +479,9 @@ internal data class GlassesStatusUpdate(
|
|
|
442
479
|
val controllerBatteryLevel: Int? = null,
|
|
443
480
|
val controllerSignalStrength: Int? = null,
|
|
444
481
|
val ringSignalStrength: Int? = null,
|
|
482
|
+
val pairingState: Map<String, Any>? = null,
|
|
483
|
+
/** Explicit `GlassesAudioSetupState` map. When absent, an update that sets [fullyBooted] carries the matching state. */
|
|
484
|
+
val audioSetup: Map<String, Any>? = null,
|
|
445
485
|
) {
|
|
446
486
|
internal fun toMap(): Map<String, Any> =
|
|
447
487
|
buildMap {
|
|
@@ -458,6 +498,8 @@ internal data class GlassesStatusUpdate(
|
|
|
458
498
|
putIfNotNull("micEnabled", micEnabled)
|
|
459
499
|
putIfNotNull("voiceActivityDetectionEnabled", voiceActivityDetectionEnabled)
|
|
460
500
|
putIfNotNull("bluetoothClassicConnected", bluetoothClassicConnected)
|
|
501
|
+
putIfNotNull("bluetoothClassicProfilesConnected", bluetoothClassicProfilesConnected)
|
|
502
|
+
putIfNotNull("bluetoothAudioRouted", bluetoothAudioRouted)
|
|
461
503
|
putIfNotNull("signalStrength", signalStrength)
|
|
462
504
|
putIfNotNull("signalStrengthUpdatedAt", signalStrengthUpdatedAt)
|
|
463
505
|
putIfNotNull("deviceModel", deviceModel)
|
|
@@ -498,6 +540,10 @@ internal data class GlassesStatusUpdate(
|
|
|
498
540
|
putIfNotNull("controllerBatteryLevel", controllerBatteryLevel)
|
|
499
541
|
putIfNotNull("controllerSignalStrength", controllerSignalStrength)
|
|
500
542
|
putIfNotNull("ringSignalStrength", ringSignalStrength)
|
|
543
|
+
pairingState?.let { put("pairingState", it) }
|
|
544
|
+
(audioSetup ?: fullyBooted?.let { GlassesAudioSetupPolicy.state(it).toMap() })?.let {
|
|
545
|
+
put("audioSetup", it)
|
|
546
|
+
}
|
|
501
547
|
}
|
|
502
548
|
|
|
503
549
|
companion object {
|
|
@@ -509,6 +555,8 @@ internal data class GlassesStatusUpdate(
|
|
|
509
555
|
voiceActivityDetectionEnabled = optionalBoolValue(values, "voiceActivityDetectionEnabled"),
|
|
510
556
|
connectionState = GlassesConnectionState.optionalFromValue(optionalStringValue(values, "connectionState")),
|
|
511
557
|
bluetoothClassicConnected = optionalBoolValue(values, "bluetoothClassicConnected"),
|
|
558
|
+
bluetoothClassicProfilesConnected = optionalBoolValue(values, "bluetoothClassicProfilesConnected"),
|
|
559
|
+
bluetoothAudioRouted = optionalBoolValue(values, "bluetoothAudioRouted"),
|
|
512
560
|
signalStrength = optionalNumberValue(values, "signalStrength"),
|
|
513
561
|
signalStrengthUpdatedAt = optionalLongValue(values, "signalStrengthUpdatedAt"),
|
|
514
562
|
deviceModel = optionalStringValue(values, "deviceModel"),
|
|
@@ -559,6 +607,8 @@ internal data class GlassesStatusUpdate(
|
|
|
559
607
|
controllerBatteryLevel = optionalNumberValue(values, "controllerBatteryLevel"),
|
|
560
608
|
controllerSignalStrength = optionalNumberValue(values, "controllerSignalStrength"),
|
|
561
609
|
ringSignalStrength = optionalNumberValue(values, "ringSignalStrength"),
|
|
610
|
+
pairingState = pairingStateValue(values),
|
|
611
|
+
audioSetup = audioSetupValue(values),
|
|
562
612
|
)
|
|
563
613
|
}
|
|
564
614
|
}
|