@mentra/bluetooth-sdk 3.4.0-dev.999 → 3.5.0-dev.1238
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/README.md +33 -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 +76 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +27 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +98 -120
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +2 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +24 -9
- package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +170 -23
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +13 -316
- 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/SGCManager.kt +6 -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/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/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/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 +98 -1
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +42 -7
- 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/generated/changelogCatalog.d.ts +4 -1
- package/build/generated/changelogCatalog.d.ts.map +1 -1
- package/build/generated/changelogCatalog.js +5 -1
- 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 +6 -0
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +66 -14
- 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/DeviceManager.swift +43 -22
- package/ios/Source/GeneratedChangelogCatalog.swift +2 -1
- package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
- package/ios/Source/MentraBluetoothSDK.swift +27 -15
- 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/BluetoothAvailability.swift +15 -5
- package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +5 -0
- package/ios/Source/sgcs/MentraLive.swift +173 -42
- package/ios/Source/sgcs/Nimo.swift +39 -272
- package/ios/Source/sgcs/NimoCanvasCoordinator.swift +9 -38
- package/ios/Source/sgcs/NimoCanvasSession.swift +0 -1
- package/ios/Source/sgcs/SGCManager.swift +6 -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/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/PcmStreamTests.swift +299 -0
- package/ios/Tests/SpeechActivityTests.swift +238 -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 +102 -1
- package/src/_private/BluetoothSdkModule.ts +45 -7
- package/src/generated/changelogCatalog.ts +5 -1
- package/src/generated/releaseMetadata.ts +6 -6
- package/src/index.ts +12 -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/debug/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -274
- 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/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
|
@@ -30,7 +30,6 @@ import java.nio.ByteOrder
|
|
|
30
30
|
import java.util.Calendar
|
|
31
31
|
import java.util.TimeZone
|
|
32
32
|
import java.util.UUID
|
|
33
|
-
import org.json.JSONObject
|
|
34
33
|
import java.util.concurrent.atomic.AtomicInteger
|
|
35
34
|
import kotlinx.coroutines.Dispatchers
|
|
36
35
|
import kotlinx.coroutines.runBlocking
|
|
@@ -935,219 +934,14 @@ class Nimo : SGCManager() {
|
|
|
935
934
|
hasMic = true
|
|
936
935
|
}
|
|
937
936
|
|
|
938
|
-
|
|
939
|
-
private var resourceSessionGeneration = 0L
|
|
940
|
-
private var resourcePairAddress: String? = null
|
|
941
|
-
private var resourcePairName: String? = null
|
|
942
|
-
private var resourceTwsAt: Long? = null
|
|
943
|
-
private var resourceFirmwareAt: Long? = null
|
|
944
|
-
private var resourceFirmwareVersion: String? = null
|
|
945
|
-
private var resourceHandshakeTwsAt: Long? = null
|
|
946
|
-
private var resourceTimeAckAt: Long? = null
|
|
947
|
-
private var resourceTimeCommandId: String? = null
|
|
948
|
-
private var resourceTimeWriteStartedAt: Long? = null
|
|
949
|
-
@Volatile private var resourceReleasePending = false
|
|
950
|
-
@Volatile private var resourceReceiptPending = false
|
|
951
|
-
@Volatile private var resourceReleased = false
|
|
952
|
-
private val resourcePostedWrites = AtomicInteger(0)
|
|
953
|
-
private var resourceExitStatus: Int? = null
|
|
954
|
-
private var resourceExitAt: Long? = null
|
|
955
|
-
private var resourceMicStopWrittenAt: Long? = null
|
|
956
|
-
private var resourceMicStopStartedAt: Long? = null
|
|
957
|
-
private var resourceMicStopMarkerAt: Long? = null
|
|
958
|
-
private var resourceTransportFailure = false
|
|
959
|
-
private var resourceMicStopRequired = false
|
|
960
|
-
private var resourceExitRequired = false
|
|
961
|
-
private var resourceInitialLaunchPendingAtRelease = false
|
|
962
|
-
private var resourceBondMutationRequested = false
|
|
963
|
-
private var resourceFactoryResetRequested = false
|
|
964
|
-
private var resourceCloseCalled = false
|
|
965
|
-
private var resourceCloseObserved = false
|
|
966
|
-
private var resourceDisconnectCallbackStatus: Int? = null
|
|
967
|
-
private var resourceCloseError: String? = null
|
|
968
|
-
private var resourceClosedWithPending = false
|
|
969
|
-
private var resourceClosingGatt: BluetoothGatt? = null
|
|
970
|
-
private var resourceReleaseResult = "not-requested"
|
|
971
|
-
|
|
972
|
-
private var resourceCaptureNonce: String? = null
|
|
973
|
-
private var resourceArmedElapsedMs: Long? = null
|
|
974
|
-
private var resourceAdmittedElapsedMs: Long? = null
|
|
975
|
-
private var resourceSessionStartedElapsedMs: Long? = null
|
|
976
|
-
private var resourceReleaseNonce: String? = null
|
|
977
|
-
private var resourceReleaseStartedElapsedMs: Long? = null
|
|
978
|
-
private var firmwareElapsedMs: Long? = null
|
|
979
|
-
private var twsElapsedMs: Long? = null
|
|
980
|
-
private var handshakeTwsElapsedMs: Long? = null
|
|
981
|
-
private var timeWriteStartedElapsedMs: Long? = null
|
|
982
|
-
private var timeAckElapsedMs: Long? = null
|
|
983
|
-
private var micStopStartedElapsedMs: Long? = null
|
|
984
|
-
private var micStopMarkerElapsedMs: Long? = null
|
|
985
|
-
private var micStopWrittenElapsedMs: Long? = null
|
|
986
|
-
private var displayExitElapsedMs: Long? = null
|
|
987
|
-
|
|
988
|
-
// Keep paired clock sampling in this class even when the triggering callback
|
|
989
|
-
// is an escaping Kotlin lambda. This preserves event timing and permits APK
|
|
990
|
-
// bytecode inspection without treating an unrelated elapsed clock call as proof.
|
|
991
|
-
private fun recordResourceFirmwareClock() { resourceFirmwareAt = System.currentTimeMillis(); firmwareElapsedMs = android.os.SystemClock.elapsedRealtime() }
|
|
992
|
-
private fun recordResourceTwsClock() { resourceTwsAt = System.currentTimeMillis(); twsElapsedMs = android.os.SystemClock.elapsedRealtime() }
|
|
993
|
-
private fun recordResourceTimeWriteClock() { resourceTimeWriteStartedAt = System.currentTimeMillis(); timeWriteStartedElapsedMs = android.os.SystemClock.elapsedRealtime() }
|
|
994
|
-
private fun recordResourceTimeAckClock() { resourceTimeAckAt = System.currentTimeMillis(); timeAckElapsedMs = android.os.SystemClock.elapsedRealtime() }
|
|
995
|
-
private fun recordResourceMicStopStartedClock() { resourceMicStopStartedAt = System.currentTimeMillis(); micStopStartedElapsedMs = android.os.SystemClock.elapsedRealtime() }
|
|
996
|
-
private fun recordResourceMicStopMarkerClock() { resourceMicStopMarkerAt = System.currentTimeMillis(); micStopMarkerElapsedMs = android.os.SystemClock.elapsedRealtime() }
|
|
997
|
-
private fun recordResourceMicStopWrittenClock() { resourceMicStopWrittenAt = System.currentTimeMillis(); micStopWrittenElapsedMs = android.os.SystemClock.elapsedRealtime() }
|
|
998
|
-
private fun recordResourceExitClock() { resourceExitAt = System.currentTimeMillis(); displayExitElapsedMs = android.os.SystemClock.elapsedRealtime() }
|
|
999
|
-
|
|
1000
|
-
internal fun resourceCaptureAdmission(nonce: String, armed: Long, admitted: Long) {
|
|
1001
|
-
check(Looper.myLooper() == mainHandler.looper)
|
|
1002
|
-
check(resourceCaptureNonce == null && admitted >= armed)
|
|
1003
|
-
resourceCaptureNonce = nonce; resourceArmedElapsedMs = armed; resourceAdmittedElapsedMs = admitted
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
internal fun resourceCaptureEligible(): Boolean {
|
|
1007
|
-
val snapshot = resourceSnapshot()
|
|
1008
|
-
return resourceSessionGeneration == 0L && discoveryReceiver == null &&
|
|
1009
|
-
!snapshot.getBoolean("managedSessionPresent") && !snapshot.getBoolean("initializationPending") &&
|
|
1010
|
-
!snapshot.getBoolean("reconnectPending") && snapshot.getBoolean("localEffectsSettled") &&
|
|
1011
|
-
!resourceReleasePending && !resourceReceiptPending
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
/** Passive local inspection only: no discovery, queries, radio or bond operations. */
|
|
1015
|
-
internal fun resourceSnapshot(): JSONObject {
|
|
1016
|
-
check(Looper.myLooper() == mainHandler.looper)
|
|
1017
|
-
val pending = writes.pendingCount() + canvasEncoder.pendingCount() + audioClient.lifecyclePending() + resourcePostedWrites.get() + pendingAcks.size + canvas.pendingCount()
|
|
1018
|
-
return JSONObject().put("observedAtEpochMs", System.currentTimeMillis()).put("sessionObservationCurrent", true).put("instanceId", resourceInstanceId).put("sessionGeneration", resourceSessionGeneration)
|
|
1019
|
-
.put("clock", JSONObject().put("kind", "android-elapsed-realtime-v1").put("observedElapsedMs", android.os.SystemClock.elapsedRealtime())
|
|
1020
|
-
.put("captureNonce", resourceCaptureNonce ?: JSONObject.NULL).put("armedElapsedMs", resourceArmedElapsedMs ?: JSONObject.NULL)
|
|
1021
|
-
.put("admittedElapsedMs", resourceAdmittedElapsedMs ?: JSONObject.NULL).put("sessionStartedElapsedMs", resourceSessionStartedElapsedMs ?: JSONObject.NULL)
|
|
1022
|
-
.put("releaseNonce", resourceReleaseNonce ?: JSONObject.NULL).put("releaseStartedElapsedMs", resourceReleaseStartedElapsedMs ?: JSONObject.NULL)
|
|
1023
|
-
.put("firmwareElapsedMs", firmwareElapsedMs ?: JSONObject.NULL)
|
|
1024
|
-
.put("twsElapsedMs", twsElapsedMs ?: JSONObject.NULL)
|
|
1025
|
-
.put("handshakeTwsElapsedMs", handshakeTwsElapsedMs ?: JSONObject.NULL)
|
|
1026
|
-
.put("timeWriteStartedElapsedMs", timeWriteStartedElapsedMs ?: JSONObject.NULL)
|
|
1027
|
-
.put("timeAckElapsedMs", timeAckElapsedMs ?: JSONObject.NULL)
|
|
1028
|
-
.put("micStopStartedElapsedMs", micStopStartedElapsedMs ?: JSONObject.NULL)
|
|
1029
|
-
.put("micStopMarkerElapsedMs", micStopMarkerElapsedMs ?: JSONObject.NULL)
|
|
1030
|
-
.put("micStopWrittenElapsedMs", micStopWrittenElapsedMs ?: JSONObject.NULL)
|
|
1031
|
-
.put("displayExitElapsedMs", displayExitElapsedMs ?: JSONObject.NULL)
|
|
1032
|
-
)
|
|
1033
|
-
.put("pair", JSONObject().put("name", resourcePairName ?: lastDeviceName ?: JSONObject.NULL)
|
|
1034
|
-
.put("bluetoothAddress", resourcePairAddress ?: lastDeviceAddress ?: JSONObject.NULL))
|
|
1035
|
-
.put("handshake", handshakeState.name).put("managedSessionPresent", gatt != null)
|
|
1036
|
-
.put("reconnectPending", reconnectionManager.pending()).put("initializationPending", handshakeState in listOf(HandshakeState.AWAITING_TWS, HandshakeState.AWAITING_TIME_ACK) || setTimeRetryRunnable != null || pairingTimeoutRunnable != null || bondReceiver != null)
|
|
1037
|
-
.put("pending", JSONObject().put("gattWritesAndDescriptors", writes.pendingCount()).put("postedWrites", resourcePostedWrites.get())
|
|
1038
|
-
.put("canvasCommands", canvas.pendingCount()).put("canvasEncodes", canvasEncoder.pendingCount())
|
|
1039
|
-
.put("audioWorkersAndPackets", audioClient.lifecyclePending()).put("acks", pendingAcks.size))
|
|
1040
|
-
.put("localEffectsSettled", pending == 0 && !resourceClosedWithPending)
|
|
1041
|
-
.put("firmware", JSONObject().put("version", resourceFirmwareVersion ?: JSONObject.NULL).put("atEpochMs", resourceFirmwareAt ?: JSONObject.NULL).put("sessionGeneration", resourceSessionGeneration))
|
|
1042
|
-
.put("tws", JSONObject().put("handshakeAtEpochMs", resourceHandshakeTwsAt ?: JSONObject.NULL).put("connected", twsConnected).put("atEpochMs", resourceTwsAt ?: JSONObject.NULL).put("sessionGeneration", resourceSessionGeneration))
|
|
1043
|
-
.put("timeAck", JSONObject().put("statusCode", if (resourceTimeAckAt != null) 0 else JSONObject.NULL)
|
|
1044
|
-
.put("writeStartedAtEpochMs", resourceTimeWriteStartedAt ?: JSONObject.NULL).put("atEpochMs", resourceTimeAckAt ?: JSONObject.NULL).put("commandId", resourceTimeCommandId ?: JSONObject.NULL).put("sessionGeneration", resourceSessionGeneration))
|
|
1045
|
-
.put("release", JSONObject().put("result", resourceReleaseResult).put("pending", resourceReleasePending)
|
|
1046
|
-
.put("micStopRequired", resourceMicStopRequired).put("displayExitRequired", resourceExitRequired).put("micStopStartedAtEpochMs", resourceMicStopStartedAt ?: JSONObject.NULL).put("micStopMarkerAtEpochMs", resourceMicStopMarkerAt ?: JSONObject.NULL).put("micStopWrittenAtEpochMs", resourceMicStopWrittenAt ?: JSONObject.NULL).put("micSilence", "unknown")
|
|
1047
|
-
.put("displayExitStatus", resourceExitStatus ?: JSONObject.NULL).put("displayExitAtEpochMs", resourceExitAt ?: JSONObject.NULL)
|
|
1048
|
-
.put("displayVisibleState", "unknown").put("transportFailure", resourceTransportFailure).put("gattCloseCalled", resourceCloseCalled).put("gattDisconnectCallbackObserved", resourceCloseObserved).put("gattDisconnectCallbackStatus", resourceDisconnectCallbackStatus ?: JSONObject.NULL)
|
|
1049
|
-
.put("gattCloseError", resourceCloseError ?: JSONObject.NULL).put("classicAclState", "unknown").put("bondMutationRequested", resourceBondMutationRequested).put("factoryResetRequested", resourceFactoryResetRequested).put("bondState", "unknown"))
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
/** Exact original instance only. Never delegates to the manager's current device. */
|
|
1053
|
-
internal fun releaseResource(expectedGeneration: Long, isCurrent: () -> Boolean, completed: (JSONObject) -> Unit) =
|
|
1054
|
-
releaseOriginalResource(expectedGeneration, false, isCurrent, completed, null, null)
|
|
1055
|
-
|
|
1056
|
-
internal fun releaseResource(expectedGeneration: Long, isCurrent: () -> Boolean, completed: (JSONObject) -> Unit, requestNonce: String, requestReceivedElapsedMs: Long) =
|
|
1057
|
-
releaseOriginalResource(expectedGeneration, false, isCurrent, completed, requestNonce, requestReceivedElapsedMs)
|
|
1058
|
-
|
|
1059
|
-
/** Only the private admitted capture may cancel an original pre-GATT generation-zero attempt. */
|
|
1060
|
-
internal fun releaseCapturedResource(isCurrent: () -> Boolean, completed: (JSONObject) -> Unit) =
|
|
1061
|
-
releaseOriginalResource(resourceSessionGeneration, true, isCurrent, completed, null, null)
|
|
1062
|
-
|
|
1063
|
-
internal fun releaseCapturedResource(isCurrent: () -> Boolean, completed: (JSONObject) -> Unit, requestNonce: String, requestReceivedElapsedMs: Long) =
|
|
1064
|
-
releaseOriginalResource(resourceSessionGeneration, true, isCurrent, completed, requestNonce, requestReceivedElapsedMs)
|
|
1065
|
-
|
|
1066
|
-
private fun releaseOriginalResource(expectedGeneration: Long, captured: Boolean, isCurrent: () -> Boolean, completed: (JSONObject) -> Unit, requestNonce: String?, requestReceivedElapsedMs: Long?) {
|
|
1067
|
-
check(Looper.myLooper() == mainHandler.looper)
|
|
1068
|
-
if (!isCurrent() || expectedGeneration != resourceSessionGeneration || (!captured && expectedGeneration < 1) || resourceReleasePending || resourceReceiptPending) {
|
|
1069
|
-
completed(JSONObject().put("error", "target-mismatch-or-release-pending")); return
|
|
1070
|
-
}
|
|
1071
|
-
if (resourceReleased) { completed(resourceSnapshot()); return }
|
|
1072
|
-
if (requestReceivedElapsedMs != null && android.os.SystemClock.elapsedRealtime() < requestReceivedElapsedMs) {
|
|
1073
|
-
completed(JSONObject().put("error", "invalid-request-clock")); return
|
|
1074
|
-
}
|
|
1075
|
-
resourceReleaseNonce = requestNonce
|
|
1076
|
-
resourceReleaseStartedElapsedMs = android.os.SystemClock.elapsedRealtime()
|
|
1077
|
-
resourceReleasePending = true
|
|
1078
|
-
resourceReleaseResult = "draining"
|
|
1079
|
-
resourceExitStatus = null; resourceExitAt = null; displayExitElapsedMs = null; resourceMicStopStartedAt = null; micStopStartedElapsedMs = null; resourceMicStopMarkerAt = null; micStopMarkerElapsedMs = null; resourceMicStopWrittenAt = null; micStopWrittenElapsedMs = null
|
|
1080
|
-
resourceExitRequired = canvas.active() || canvas.pendingCount() > 0
|
|
1081
|
-
resourceInitialLaunchPendingAtRelease = !canvas.active() && canvas.launchPending()
|
|
1082
|
-
isDisconnecting = true
|
|
1083
|
-
handshakeState = HandshakeState.IDLE
|
|
1084
|
-
cancelPairingTimeout(); cancelTwsTimeout(); cancelSetTimeRetry(); stopTimers(); reconnectionManager.stop()
|
|
1085
|
-
unregisterBondReceiver()
|
|
1086
|
-
// Unregister our discovery listener without stopping the shared adapter scanner.
|
|
1087
|
-
discoveryReceiver?.let { try { context.unregisterReceiver(it) } catch (_: IllegalArgumentException) {} }
|
|
1088
|
-
discoveryReceiver = null
|
|
1089
|
-
diagnostics?.disconnected()
|
|
1090
|
-
canvasEncoder.invalidate()
|
|
1091
|
-
failAllPendingAcks()
|
|
1092
|
-
audioClient.stop()
|
|
1093
|
-
val original = gatt
|
|
1094
|
-
val mic = micChar
|
|
1095
|
-
resourceMicStopRequired = original != null && mic != null
|
|
1096
|
-
if (original != null && mic != null) {
|
|
1097
|
-
writes.enqueue(original, mic, listOf(byteArrayOf(0x52, 0, 0, 0)), finalStarted = { recordResourceMicStopStartedClock() }, completed = { recordResourceMicStopWrittenClock() })
|
|
1098
|
-
}
|
|
1099
|
-
canvas.exit()
|
|
1100
|
-
val deadline = android.os.SystemClock.elapsedRealtime() + 15_000
|
|
1101
|
-
fun finish(result: String) {
|
|
1102
|
-
resourceReleaseResult = result
|
|
1103
|
-
if (result == "drain-timeout-native-effects-unknown") resourceClosedWithPending = true
|
|
1104
|
-
closeResourceGatt()
|
|
1105
|
-
gatt = null; txChar = null; rxChar = null; micChar = null
|
|
1106
|
-
resetSessionState()
|
|
1107
|
-
resourceReleasePending = false; resourceReleased = true
|
|
1108
|
-
resourceReceiptPending = true
|
|
1109
|
-
// Shared state belongs to this instance only while the manager still owns it.
|
|
1110
|
-
if (isCurrent()) {
|
|
1111
|
-
DeviceStore.apply("glasses", "connected", false)
|
|
1112
|
-
DeviceStore.apply("glasses", "fullyBooted", false)
|
|
1113
|
-
DeviceStore.apply("glasses", "connectionState", ConnTypes.DISCONNECTED)
|
|
1114
|
-
}
|
|
1115
|
-
NimoResourceDiagnostics.track(this)
|
|
1116
|
-
mainHandler.postDelayed({
|
|
1117
|
-
// Keep the original bearer/generation fenced through receipt delivery. The
|
|
1118
|
-
// short callback-observation window must not capture a later connection.
|
|
1119
|
-
val originalReceipt = resourceSnapshot()
|
|
1120
|
-
try { completed(originalReceipt) } finally { resourceReceiptPending = false }
|
|
1121
|
-
}, 100)
|
|
1122
|
-
}
|
|
1123
|
-
fun poll() {
|
|
1124
|
-
if (!isCurrent()) {
|
|
1125
|
-
resourceReleasePending = false; resourceReleaseResult = "target-replaced"
|
|
1126
|
-
NimoResourceDiagnostics.track(this); completed(resourceSnapshot()); return
|
|
1127
|
-
}
|
|
1128
|
-
val unsettled = writes.pendingCount() + canvasEncoder.pendingCount() + audioClient.lifecyclePending() + resourcePostedWrites.get() + canvas.pendingCount() +
|
|
1129
|
-
(if (resourceMicStopRequired && resourceMicStopMarkerAt == null) 1 else 0) +
|
|
1130
|
-
(if (resourceExitRequired && resourceExitStatus != 0) 1 else 0)
|
|
1131
|
-
if (unsettled == 0) { finish("local-drained-native-readback-required"); return }
|
|
1132
|
-
if (android.os.SystemClock.elapsedRealtime() >= deadline) { finish("drain-timeout-native-effects-unknown"); return }
|
|
1133
|
-
mainHandler.postDelayed({ poll() }, 25)
|
|
1134
|
-
}
|
|
1135
|
-
mainHandler.post { poll() }
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
private fun closeResourceGatt() {
|
|
937
|
+
private fun closeGatt() {
|
|
1139
938
|
val original = gatt ?: return
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
resourceCloseCalled = true
|
|
1143
|
-
try { original.disconnect() } catch (error: Exception) { resourceCloseError = "disconnect-${error.javaClass.simpleName}" }
|
|
1144
|
-
try { original.close() } catch (error: Exception) { resourceCloseError = "close-${error.javaClass.simpleName}" }
|
|
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}") }
|
|
1145
941
|
}
|
|
1146
942
|
|
|
1147
943
|
private val mainHandler = Handler(Looper.getMainLooper())
|
|
1148
944
|
private val mainScheduler = handlerScheduler(mainHandler)
|
|
1149
|
-
// Variant-specific: release has no receiver or framebuffer protocol implementation.
|
|
1150
|
-
private var diagnostics: NimoDiagnostics? = null
|
|
1151
945
|
private val canvasEncoderThread = HandlerThread("NimoCanvasEncoder").apply { start() }
|
|
1152
946
|
private val canvasEncoder = NimoCanvasEncoder(mainScheduler,
|
|
1153
947
|
handlerScheduler(Handler(canvasEncoderThread.looper)),
|
|
@@ -1155,17 +949,7 @@ class Nimo : SGCManager() {
|
|
|
1155
949
|
{ Bridge.log("NIMO: canvas validation/encoding failed; retaining last valid scene: ${it.message}") })
|
|
1156
950
|
private val canvas = NimoCanvasCoordinator(mainScheduler,
|
|
1157
951
|
{ (negotiatedMtu - 3).coerceIn(20, 512) }, ::enqueueFrames, ::abortTransport,
|
|
1158
|
-
{ Bridge.log("NIMO: canvas rejected status=$it; not a render ACK") }
|
|
1159
|
-
{ diagnostics?.cancelHeldCapture("Canvas scope takeover preempted held capture", resumeCanvas = false) },
|
|
1160
|
-
{ key, status ->
|
|
1161
|
-
if (key == 3) { resourceExitStatus = status; recordResourceExitClock() }
|
|
1162
|
-
if (resourceReleasePending && resourceInitialLaunchPendingAtRelease && key == 1) {
|
|
1163
|
-
// An explicit rejected initial Launch never acquired canvas ownership.
|
|
1164
|
-
// Status 2 is transport-ambiguous and must retain the unknown fence.
|
|
1165
|
-
if (status != 0 && status != 2) resourceExitRequired = false
|
|
1166
|
-
resourceInitialLaunchPendingAtRelease = false
|
|
1167
|
-
}
|
|
1168
|
-
})
|
|
952
|
+
{ Bridge.log("NIMO: canvas rejected status=$it; not a render ACK") })
|
|
1169
953
|
|
|
1170
954
|
private fun handlerScheduler(handler: Handler) = NimoScheduler { delay, task ->
|
|
1171
955
|
val runnable = Runnable(task)
|
|
@@ -1258,8 +1042,6 @@ class Nimo : SGCManager() {
|
|
|
1258
1042
|
// ---------- SGCManager: Connection Management ----------
|
|
1259
1043
|
|
|
1260
1044
|
override fun findCompatibleDevices() {
|
|
1261
|
-
if (NimoResourceDiagnostics.dispatchCapturedEntry { findCompatibleDevices() }) return
|
|
1262
|
-
if (!NimoResourceDiagnostics.admit(this, null, false)) return
|
|
1263
1045
|
Bridge.log("NIMO: findCompatibleDevices()")
|
|
1264
1046
|
DEVICE_SEARCH_ID = "NOT_SET"
|
|
1265
1047
|
DeviceStore.apply("glasses", "connectionState", ConnTypes.SCANNING)
|
|
@@ -1267,11 +1049,6 @@ class Nimo : SGCManager() {
|
|
|
1267
1049
|
}
|
|
1268
1050
|
|
|
1269
1051
|
override fun connectById(id: String) {
|
|
1270
|
-
if (NimoResourceDiagnostics.dispatchCapturedEntry { connectById(id) }) return
|
|
1271
|
-
if (!NimoResourceDiagnostics.admit(this, id, true)) return
|
|
1272
|
-
if (resourceReleasePending || resourceReceiptPending) return
|
|
1273
|
-
resourceReleased = false
|
|
1274
|
-
resourceBondMutationRequested = false; resourceFactoryResetRequested = false
|
|
1275
1052
|
Bridge.log("NIMO: connectById($id)")
|
|
1276
1053
|
DEVICE_SEARCH_ID = id
|
|
1277
1054
|
DeviceStore.apply("glasses", "connectionState", ConnTypes.CONNECTING)
|
|
@@ -1331,7 +1108,7 @@ class Nimo : SGCManager() {
|
|
|
1331
1108
|
reconnectionManager.stop()
|
|
1332
1109
|
failAllPendingAcks()
|
|
1333
1110
|
|
|
1334
|
-
|
|
1111
|
+
closeGatt()
|
|
1335
1112
|
gatt = null
|
|
1336
1113
|
txChar = null
|
|
1337
1114
|
rxChar = null
|
|
@@ -1341,7 +1118,6 @@ class Nimo : SGCManager() {
|
|
|
1341
1118
|
DeviceStore.apply("glasses", "connected", false)
|
|
1342
1119
|
DeviceStore.apply("glasses", "fullyBooted", false)
|
|
1343
1120
|
DeviceStore.apply("glasses", "connectionState", ConnTypes.DISCONNECTED)
|
|
1344
|
-
NimoResourceDiagnostics.track(this)
|
|
1345
1121
|
}
|
|
1346
1122
|
|
|
1347
1123
|
/** Explicit Unpair only. Ordinary forget/cleanup must never reset the glasses. */
|
|
@@ -1357,7 +1133,6 @@ class Nimo : SGCManager() {
|
|
|
1357
1133
|
reconnectionManager.stop()
|
|
1358
1134
|
canvasEncoder.invalidate()
|
|
1359
1135
|
canvas.disconnected()
|
|
1360
|
-
resourceFactoryResetRequested = true
|
|
1361
1136
|
Bridge.log("NIMO: sending factory reset for explicit Unpair")
|
|
1362
1137
|
sendAwaitingAck(NimoProtocol.CMD_CONTROL_FACTORY, NimoProtocol.FACTORY_RECOVER, byteArrayOf()) {
|
|
1363
1138
|
Bridge.log("NIMO: factory reset acknowledged=$it")
|
|
@@ -1367,7 +1142,6 @@ class Nimo : SGCManager() {
|
|
|
1367
1142
|
|
|
1368
1143
|
internal fun removeBluetoothBond() {
|
|
1369
1144
|
val address = gatt?.device?.address ?: lastDeviceAddress ?: return
|
|
1370
|
-
resourceBondMutationRequested = true
|
|
1371
1145
|
removeBluetoothBond(address)
|
|
1372
1146
|
}
|
|
1373
1147
|
|
|
@@ -1390,8 +1164,6 @@ class Nimo : SGCManager() {
|
|
|
1390
1164
|
}
|
|
1391
1165
|
canvasEncoder.close()
|
|
1392
1166
|
disconnect()
|
|
1393
|
-
diagnostics?.close()
|
|
1394
|
-
diagnostics = null
|
|
1395
1167
|
audioClient.stop()
|
|
1396
1168
|
}
|
|
1397
1169
|
|
|
@@ -1415,7 +1187,7 @@ class Nimo : SGCManager() {
|
|
|
1415
1187
|
return
|
|
1416
1188
|
}
|
|
1417
1189
|
DeviceStore.apply("glasses", "micEnabled", enabled)
|
|
1418
|
-
if (enabled
|
|
1190
|
+
if (enabled) {
|
|
1419
1191
|
audioClient.start()
|
|
1420
1192
|
} else {
|
|
1421
1193
|
audioClient.stop()
|
|
@@ -1546,8 +1318,7 @@ class Nimo : SGCManager() {
|
|
|
1546
1318
|
|
|
1547
1319
|
private fun encodeCanvas(scope: String, force: Boolean = false, release: () -> Unit = {},
|
|
1548
1320
|
encode: () -> ByteArray): Boolean =
|
|
1549
|
-
|
|
1550
|
-
else canvasEncoder.submit(encode, release) { bytes -> canvas.offer(bytes, scope, force) }
|
|
1321
|
+
canvasEncoder.submit(encode, release) { bytes -> canvas.offer(bytes, scope, force) }
|
|
1551
1322
|
|
|
1552
1323
|
private fun decodeCanvasSource(data: String): Bitmap {
|
|
1553
1324
|
val bytes = NimoCanvasCodec.imageBytes(data)
|
|
@@ -1625,7 +1396,6 @@ class Nimo : SGCManager() {
|
|
|
1625
1396
|
override fun exit() {
|
|
1626
1397
|
canvasEncoder.invalidate()
|
|
1627
1398
|
mainHandler.post {
|
|
1628
|
-
diagnostics?.cancelHeldCapture("Explicit host exit preempted held capture", resumeCanvas = false)
|
|
1629
1399
|
canvas.exit()
|
|
1630
1400
|
}
|
|
1631
1401
|
}
|
|
@@ -1845,22 +1615,14 @@ class Nimo : SGCManager() {
|
|
|
1845
1615
|
* for Companion service 7033. The separate <name>_BLE ANCS peripheral is not the
|
|
1846
1616
|
* canvas data channel. This matches the vendor transport=BREDR connection path.
|
|
1847
1617
|
*/
|
|
1848
|
-
private data class ResourcePeer(val address: String, val bondState: Int)
|
|
1849
|
-
private fun resourcePeer(device: android.bluetooth.BluetoothDevice): ResourcePeer = ResourcePeer(
|
|
1850
|
-
try { device.address } catch (_: SecurityException) { "" },
|
|
1851
|
-
try { device.bondState } catch (_: SecurityException) { android.bluetooth.BluetoothDevice.BOND_NONE },
|
|
1852
|
-
)
|
|
1853
|
-
|
|
1854
1618
|
private fun connectCompanionGatt(device: android.bluetooth.BluetoothDevice) {
|
|
1855
|
-
val peer = resourcePeer(device)
|
|
1856
|
-
if (!NimoResourceDiagnostics.allowPeer(this, peer.address, peer.bondState == android.bluetooth.BluetoothDevice.BOND_BONDED)) return
|
|
1857
1619
|
if (isDisconnecting || gatt != null) return
|
|
1858
1620
|
// Classic discovery degrades/aborts connections — always cancel first.
|
|
1859
1621
|
try {
|
|
1860
1622
|
bluetoothAdapter?.cancelDiscovery()
|
|
1861
1623
|
} catch (_: Exception) {}
|
|
1862
1624
|
|
|
1863
|
-
val bondState =
|
|
1625
|
+
val bondState = try { device.bondState } catch (_: SecurityException) { android.bluetooth.BluetoothDevice.BOND_NONE }
|
|
1864
1626
|
if (bondState != android.bluetooth.BluetoothDevice.BOND_BONDED) {
|
|
1865
1627
|
// Bond over classic first, then open the Companion bearer on completion.
|
|
1866
1628
|
startBond(device)
|
|
@@ -1875,9 +1637,7 @@ class Nimo : SGCManager() {
|
|
|
1875
1637
|
* called both on the initial attempt and from the BOND_NONE handler.
|
|
1876
1638
|
*/
|
|
1877
1639
|
private fun startBond(device: android.bluetooth.BluetoothDevice) {
|
|
1878
|
-
val
|
|
1879
|
-
if (!NimoResourceDiagnostics.allowPeer(this, peer.address, peer.bondState == android.bluetooth.BluetoothDevice.BOND_BONDED)) return
|
|
1880
|
-
val bondState = peer.bondState
|
|
1640
|
+
val bondState = try { device.bondState } catch (_: SecurityException) { android.bluetooth.BluetoothDevice.BOND_NONE }
|
|
1881
1641
|
// A previous (apparently failed) attempt may have bonded in the background.
|
|
1882
1642
|
if (bondState == android.bluetooth.BluetoothDevice.BOND_BONDED) {
|
|
1883
1643
|
Bridge.log("NIMO: already bonded with ${device.address} — connecting")
|
|
@@ -1918,8 +1678,6 @@ class Nimo : SGCManager() {
|
|
|
1918
1678
|
|
|
1919
1679
|
private fun connectBredrTransport(device: android.bluetooth.BluetoothDevice) {
|
|
1920
1680
|
if (isDisconnecting || gatt != null) return
|
|
1921
|
-
val peer = resourcePeer(device)
|
|
1922
|
-
if (!NimoResourceDiagnostics.beginTransport(this, peer.address, peer.bondState == android.bluetooth.BluetoothDevice.BOND_BONDED)) return
|
|
1923
1681
|
// GATT over BR/EDR: the glasses pair with a legacy (non-SC) link key, so no LE
|
|
1924
1682
|
// keys exist (le_linkkey_known:F) and the controller records the device as
|
|
1925
1683
|
// BR_EDR-only — the 7033 UART service is served over the classic link. This is
|
|
@@ -1927,25 +1685,10 @@ class Nimo : SGCManager() {
|
|
|
1927
1685
|
// why iOS needs Settings pairing (CoreBluetooth bridges GATT over BR/EDR only
|
|
1928
1686
|
// for system-paired dual-mode accessories).
|
|
1929
1687
|
Bridge.log("NIMO: connecting GATT over BR/EDR to ${device.address}")
|
|
1930
|
-
resourceSessionGeneration++
|
|
1931
|
-
resourceSessionStartedElapsedMs = android.os.SystemClock.elapsedRealtime()
|
|
1932
|
-
resourceReleaseNonce = null; resourceReleaseStartedElapsedMs = null
|
|
1933
|
-
resourceExitStatus = null; resourceExitAt = null; displayExitElapsedMs = null; resourceMicStopWrittenAt = null; micStopWrittenElapsedMs = null
|
|
1934
|
-
resourceMicStopStartedAt = null; micStopStartedElapsedMs = null; resourceMicStopMarkerAt = null; micStopMarkerElapsedMs = null; resourceTransportFailure = false; resourceClosingGatt = null
|
|
1935
|
-
resourceClosedWithPending = false; resourceReleaseResult = "not-requested"
|
|
1936
|
-
resourceMicStopRequired = false; resourceExitRequired = false; resourceInitialLaunchPendingAtRelease = false
|
|
1937
|
-
resourceReleased = false
|
|
1938
|
-
resourcePairAddress = peer.address
|
|
1939
|
-
resourcePairName = try { device.name ?: "" } catch (_: SecurityException) { "" }
|
|
1940
|
-
resourceFirmwareAt = null; firmwareElapsedMs = null; resourceFirmwareVersion = null
|
|
1941
|
-
resourceTwsAt = null; twsElapsedMs = null; resourceHandshakeTwsAt = null; handshakeTwsElapsedMs = null; resourceTimeAckAt = null; timeAckElapsedMs = null; resourceTimeCommandId = null; resourceTimeWriteStartedAt = null; timeWriteStartedElapsedMs = null
|
|
1942
|
-
resourceCloseCalled = false; resourceCloseObserved = false; resourceDisconnectCallbackStatus = null; resourceCloseError = null
|
|
1943
|
-
NimoResourceDiagnostics.track(this)
|
|
1944
1688
|
DeviceStore.apply("glasses", "connectionState", ConnTypes.CONNECTING)
|
|
1945
1689
|
gatt = try {
|
|
1946
1690
|
device.connectGatt(context, false, gattCallback, android.bluetooth.BluetoothDevice.TRANSPORT_BREDR)
|
|
1947
1691
|
} catch (error: SecurityException) {
|
|
1948
|
-
resourceTransportFailure = true
|
|
1949
1692
|
Bridge.log("NIMO: connectGatt SecurityException: ${error.message}")
|
|
1950
1693
|
null
|
|
1951
1694
|
}
|
|
@@ -2078,10 +1821,6 @@ class Nimo : SGCManager() {
|
|
|
2078
1821
|
override fun onConnectionStateChange(g: BluetoothGatt, status: Int, newState: Int) {
|
|
2079
1822
|
mainHandler.post {
|
|
2080
1823
|
if (g !== gatt) {
|
|
2081
|
-
if (g === resourceClosingGatt && newState == BluetoothProfile.STATE_DISCONNECTED) {
|
|
2082
|
-
resourceCloseObserved = true
|
|
2083
|
-
resourceDisconnectCallbackStatus = status
|
|
2084
|
-
}
|
|
2085
1824
|
return@post
|
|
2086
1825
|
}
|
|
2087
1826
|
Bridge.log("NIMO: onConnectionStateChange status=$status newState=$newState")
|
|
@@ -2182,9 +1921,6 @@ class Nimo : SGCManager() {
|
|
|
2182
1921
|
handleRxPacket(data)
|
|
2183
1922
|
}
|
|
2184
1923
|
NimoBLE.CHAR_MIC -> {
|
|
2185
|
-
if (resourceReleasePending && resourceMicStopStartedAt != null && data.contentEquals(byteArrayOf(0x52, 0, 0, 0))) {
|
|
2186
|
-
recordResourceMicStopMarkerClock()
|
|
2187
|
-
}
|
|
2188
1924
|
audioClient.enqueue(data)
|
|
2189
1925
|
}
|
|
2190
1926
|
}
|
|
@@ -2235,15 +1971,9 @@ class Nimo : SGCManager() {
|
|
|
2235
1971
|
|
|
2236
1972
|
private fun enqueueWrite(char: BluetoothGattCharacteristic, bytes: ByteArray) {
|
|
2237
1973
|
val expectedGatt = gatt ?: return
|
|
2238
|
-
val timeCommand = if (bytes.size >= 10 && (bytes[8].toInt() and 255) == NimoProtocol.CMD_SET_PARAMETER &&
|
|
2239
|
-
(bytes[9].toInt() and 255) == NimoProtocol.SET_TIME) resourceTimeCommandId else null
|
|
2240
|
-
resourcePostedWrites.incrementAndGet()
|
|
2241
1974
|
mainHandler.post {
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
writes.enqueue(expectedGatt, char, listOf(bytes), finalStarted = {
|
|
2245
|
-
if (timeCommand != null && timeCommand == resourceTimeCommandId) { recordResourceTimeWriteClock() }
|
|
2246
|
-
})
|
|
1975
|
+
if (gatt !== expectedGatt) return@post
|
|
1976
|
+
writes.enqueue(expectedGatt, char, listOf(bytes))
|
|
2247
1977
|
}
|
|
2248
1978
|
}
|
|
2249
1979
|
|
|
@@ -2262,9 +1992,7 @@ class Nimo : SGCManager() {
|
|
|
2262
1992
|
|
|
2263
1993
|
private fun abortTransport(reason: String) {
|
|
2264
1994
|
Bridge.log("NIMO: resetting transport: $reason")
|
|
2265
|
-
|
|
2266
|
-
resourceClosedWithPending = true
|
|
2267
|
-
closeResourceGatt()
|
|
1995
|
+
closeGatt()
|
|
2268
1996
|
gatt = null
|
|
2269
1997
|
txChar = null; rxChar = null; micChar = null
|
|
2270
1998
|
resetSessionState()
|
|
@@ -2321,7 +2049,7 @@ class Nimo : SGCManager() {
|
|
|
2321
2049
|
// ---------- Handshake ----------
|
|
2322
2050
|
|
|
2323
2051
|
private fun startHandshake() {
|
|
2324
|
-
if (isDisconnecting
|
|
2052
|
+
if (isDisconnecting) return
|
|
2325
2053
|
Bridge.log("NIMO: starting handshake (awaiting TWS service-connection state)")
|
|
2326
2054
|
handshakeState = HandshakeState.AWAITING_TWS
|
|
2327
2055
|
if (twsConnected) {
|
|
@@ -2356,7 +2084,6 @@ class Nimo : SGCManager() {
|
|
|
2356
2084
|
private fun proceedToTimeSync() {
|
|
2357
2085
|
if (handshakeState != HandshakeState.AWAITING_TWS) return
|
|
2358
2086
|
cancelTwsTimeout()
|
|
2359
|
-
resourceHandshakeTwsAt = resourceTwsAt; handshakeTwsElapsedMs = twsElapsedMs
|
|
2360
2087
|
handshakeState = HandshakeState.AWAITING_TIME_ACK
|
|
2361
2088
|
Bridge.log("NIMO: TWS OK — sending setTime (awaiting ACK)")
|
|
2362
2089
|
setTimeAttempts = 0
|
|
@@ -2367,21 +2094,13 @@ class Nimo : SGCManager() {
|
|
|
2367
2094
|
if (handshakeState != HandshakeState.AWAITING_TIME_ACK || gatt == null) return
|
|
2368
2095
|
val expectedGatt = gatt
|
|
2369
2096
|
setTimeAttempts++
|
|
2370
|
-
resourceTimeCommandId = UUID.randomUUID().toString()
|
|
2371
|
-
resourceTimeWriteStartedAt = null; timeWriteStartedElapsedMs = null
|
|
2372
2097
|
sendAwaitingAck(
|
|
2373
2098
|
NimoProtocol.CMD_SET_PARAMETER,
|
|
2374
2099
|
NimoProtocol.SET_TIME,
|
|
2375
2100
|
NimoFrameCodec.encodeDeviceTime()
|
|
2376
2101
|
) { ok ->
|
|
2377
2102
|
if (gatt !== expectedGatt || handshakeState != HandshakeState.AWAITING_TIME_ACK) return@sendAwaitingAck
|
|
2378
|
-
if (ok && resourceTimeWriteStartedAt == null) {
|
|
2379
|
-
resourceTransportFailure = true
|
|
2380
|
-
handshakeFailed()
|
|
2381
|
-
return@sendAwaitingAck
|
|
2382
|
-
}
|
|
2383
2103
|
if (ok) {
|
|
2384
|
-
recordResourceTimeAckClock()
|
|
2385
2104
|
finishHandshake()
|
|
2386
2105
|
} else if (setTimeAttempts < SET_TIME_MAX_ATTEMPTS &&
|
|
2387
2106
|
handshakeState == HandshakeState.AWAITING_TIME_ACK &&
|
|
@@ -2426,16 +2145,6 @@ class Nimo : SGCManager() {
|
|
|
2426
2145
|
DeviceStore.apply("glasses", "fullyBooted", true)
|
|
2427
2146
|
DeviceStore.apply("glasses", "connectionState", ConnTypes.CONNECTED)
|
|
2428
2147
|
startTimers()
|
|
2429
|
-
if (diagnostics == null) {
|
|
2430
|
-
diagnostics = NimoDiagnostics(
|
|
2431
|
-
context,
|
|
2432
|
-
mainHandler,
|
|
2433
|
-
{ frame, completed -> enqueueFrames(listOf(frame), {}, completed) },
|
|
2434
|
-
{ ready -> canvas.hold(ready) },
|
|
2435
|
-
{ resume -> canvas.releaseHold(resume) },
|
|
2436
|
-
)
|
|
2437
|
-
}
|
|
2438
|
-
diagnostics?.connected((negotiatedMtu - 3).coerceIn(20, 512))
|
|
2439
2148
|
// Launch checks peer readiness in firmware; do not wait up to a minute for
|
|
2440
2149
|
// the first unsolicited heartbeat just because peer status is still unknown.
|
|
2441
2150
|
canvas.activate()
|
|
@@ -2449,7 +2158,6 @@ class Nimo : SGCManager() {
|
|
|
2449
2158
|
}
|
|
2450
2159
|
|
|
2451
2160
|
private fun resetSessionState() {
|
|
2452
|
-
diagnostics?.disconnected()
|
|
2453
2161
|
handshakeState = HandshakeState.IDLE
|
|
2454
2162
|
cancelTwsTimeout()
|
|
2455
2163
|
cancelSetTimeRetry()
|
|
@@ -2474,7 +2182,6 @@ class Nimo : SGCManager() {
|
|
|
2474
2182
|
if (fullyBooted) {
|
|
2475
2183
|
return@start true
|
|
2476
2184
|
}
|
|
2477
|
-
if (!NimoResourceDiagnostics.admit(this, DEVICE_SEARCH_ID, true)) return@start true
|
|
2478
2185
|
Bridge.log("NIMO: Attempting reconnection...")
|
|
2479
2186
|
isDisconnecting = false
|
|
2480
2187
|
// Each reconnection cycle is a fresh bond budget — the glasses drop their
|
|
@@ -2514,7 +2221,6 @@ class Nimo : SGCManager() {
|
|
|
2514
2221
|
|
|
2515
2222
|
private fun handleRxPacket(packet: ByteArray) {
|
|
2516
2223
|
// Diagnostic packets must retain their original wire CRC and framing.
|
|
2517
|
-
if (diagnostics?.onPacket(packet) == true) return
|
|
2518
2224
|
if (packet.size >= 10 && packet[8].toInt() == 7 && (packet[9].toInt() and 255) in listOf(1, 3, 4)) {
|
|
2519
2225
|
val response = NimoCanvasCodec.response(packet) ?: return
|
|
2520
2226
|
if (response.first == 1) Bridge.log("NIMO: canvas Launch response status=${response.second.firstOrNull()?.toInt()}")
|
|
@@ -2546,15 +2252,9 @@ class Nimo : SGCManager() {
|
|
|
2546
2252
|
Bridge.log("NIMO: app state report appId=$appId phase=$phase")
|
|
2547
2253
|
when (phase) {
|
|
2548
2254
|
NimoProtocol.STATE_ENTER -> {
|
|
2549
|
-
if (appId != NimoCanvasCodec.APP_ID) {
|
|
2550
|
-
diagnostics?.cancelHeldCapture("Native app takeover preempted held capture", resumeCanvas = false)
|
|
2551
|
-
}
|
|
2552
2255
|
canvas.nativeApp(appId, true)
|
|
2553
2256
|
}
|
|
2554
2257
|
NimoProtocol.STATE_EXIT -> {
|
|
2555
|
-
if (appId == NimoCanvasCodec.APP_ID) {
|
|
2556
|
-
diagnostics?.cancelHeldCapture("Canvas exit preempted held capture", resumeCanvas = false)
|
|
2557
|
-
}
|
|
2558
2258
|
canvas.nativeApp(appId, false)
|
|
2559
2259
|
}
|
|
2560
2260
|
}
|
|
@@ -2606,7 +2306,6 @@ class Nimo : SGCManager() {
|
|
|
2606
2306
|
}
|
|
2607
2307
|
|
|
2608
2308
|
private fun onTwsState(connected: Boolean) {
|
|
2609
|
-
recordResourceTwsClock()
|
|
2610
2309
|
twsConnected = connected
|
|
2611
2310
|
if (connected && handshakeState == HandshakeState.AWAITING_TWS) {
|
|
2612
2311
|
proceedToTimeSync()
|
|
@@ -2679,7 +2378,6 @@ class Nimo : SGCManager() {
|
|
|
2679
2378
|
val micro = (v ushr 12) and 0x1FF
|
|
2680
2379
|
val build = v and 0xFFF
|
|
2681
2380
|
firmwareVersionPacked = "$major.$minor.$micro.$build"
|
|
2682
|
-
resourceFirmwareVersion = firmwareVersionPacked; recordResourceFirmwareClock()
|
|
2683
2381
|
emitVersionInfo()
|
|
2684
2382
|
}
|
|
2685
2383
|
}
|
|
@@ -2688,7 +2386,6 @@ class Nimo : SGCManager() {
|
|
|
2688
2386
|
while (end > 0 && data[end - 1].toInt() == 0) end--
|
|
2689
2387
|
firmwareVersionDetail = String(data, 0, end, Charsets.UTF_8).trim()
|
|
2690
2388
|
if (firmwareVersionDetail.isNotEmpty() && firmwareVersionDetail.length <= 240) {
|
|
2691
|
-
resourceFirmwareVersion = firmwareVersionDetail; recordResourceFirmwareClock()
|
|
2692
2389
|
}
|
|
2693
2390
|
emitVersionInfo()
|
|
2694
2391
|
}
|
|
@@ -121,8 +121,6 @@ internal class NimoCanvasCoordinator(
|
|
|
121
121
|
private val enqueue: (List<ByteArray>, () -> Unit, () -> Unit) -> Boolean,
|
|
122
122
|
private val reconnect: (String) -> Unit,
|
|
123
123
|
private val rejected: (Int) -> Unit = {},
|
|
124
|
-
private val holdPreempted: () -> Unit = {},
|
|
125
|
-
private val businessResponse: (Int, Int) -> Unit = { _, _ -> },
|
|
126
124
|
) {
|
|
127
125
|
private class Flight(val action: NimoCanvasSession.Action.Send) {
|
|
128
126
|
var finalStarted = false
|
|
@@ -131,21 +129,13 @@ internal class NimoCanvasCoordinator(
|
|
|
131
129
|
}
|
|
132
130
|
private val session = NimoCanvasSession()
|
|
133
131
|
private var flight: Flight? = null
|
|
134
|
-
private var holdReady: (() -> Unit)? = null
|
|
135
|
-
private var holding = false
|
|
136
|
-
private var heldScope: String? = null
|
|
137
132
|
private var cancelDeadline: (() -> Unit)? = null
|
|
138
133
|
private var cancelRetry: (() -> Unit)? = null
|
|
139
134
|
|
|
140
135
|
fun pendingCount(): Int = if (flight != null) 1 else 0
|
|
141
136
|
fun active(): Boolean = session.active()
|
|
142
|
-
fun launchPending(): Boolean = flight?.action?.key == 1
|
|
143
137
|
|
|
144
138
|
fun offer(bytes: ByteArray, scope: String, force: Boolean = false) {
|
|
145
|
-
if (holding && scope != heldScope) {
|
|
146
|
-
releaseHold(resume = false)
|
|
147
|
-
holdPreempted()
|
|
148
|
-
}
|
|
149
139
|
run(session.offer(bytes, scope, force))
|
|
150
140
|
}
|
|
151
141
|
fun activate() = run(session.activate())
|
|
@@ -157,19 +147,6 @@ internal class NimoCanvasCoordinator(
|
|
|
157
147
|
if (!ready) { cancelRetry?.invoke(); cancelRetry = null }
|
|
158
148
|
run(session.confirmedReadiness(ready))
|
|
159
149
|
}
|
|
160
|
-
fun hold(onReady: () -> Unit) {
|
|
161
|
-
session.hold(true)
|
|
162
|
-
holding = true
|
|
163
|
-
heldScope = session.currentScope()
|
|
164
|
-
holdReady = onReady
|
|
165
|
-
notifyHoldReadyIfIdle()
|
|
166
|
-
}
|
|
167
|
-
fun releaseHold(resume: Boolean = true) {
|
|
168
|
-
holdReady = null
|
|
169
|
-
holding = false
|
|
170
|
-
heldScope = null
|
|
171
|
-
run(session.hold(false, resume))
|
|
172
|
-
}
|
|
173
150
|
fun exit() {
|
|
174
151
|
cancelRetry?.invoke(); cancelRetry = null
|
|
175
152
|
run(session.exit())
|
|
@@ -180,9 +157,6 @@ internal class NimoCanvasCoordinator(
|
|
|
180
157
|
cancelRetry?.invoke(); cancelRetry = null
|
|
181
158
|
cancelDeadline?.invoke(); cancelDeadline = null
|
|
182
159
|
flight = null
|
|
183
|
-
holdReady = null
|
|
184
|
-
holding = false
|
|
185
|
-
heldScope = null
|
|
186
160
|
session.disconnected()
|
|
187
161
|
}
|
|
188
162
|
|
|
@@ -195,16 +169,7 @@ internal class NimoCanvasCoordinator(
|
|
|
195
169
|
}
|
|
196
170
|
cancelDeadline?.invoke(); cancelDeadline = null
|
|
197
171
|
flight = null
|
|
198
|
-
businessResponse(key, payload[0].toInt() and 255)
|
|
199
172
|
run(session.response(key, payload))
|
|
200
|
-
notifyHoldReadyIfIdle()
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
private fun notifyHoldReadyIfIdle() {
|
|
204
|
-
if (flight != null) return
|
|
205
|
-
val ready = holdReady ?: return
|
|
206
|
-
holdReady = null
|
|
207
|
-
ready()
|
|
208
173
|
}
|
|
209
174
|
|
|
210
175
|
private fun run(actions: List<NimoCanvasSession.Action>) {
|