@mentra/bluetooth-sdk 3.4.0-dev.998 → 3.4.0

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.
Files changed (215) hide show
  1. package/MIGRATION.md +16 -7
  2. package/README.md +40 -13
  3. package/android/build.gradle +60 -51
  4. package/android/gradle.properties +3 -0
  5. package/android/settings.gradle +47 -3
  6. package/android/src/main/assets/nimo/nimo-firmware-0.1.1.1-537cf1.bin +0 -0
  7. package/android/src/main/java/com/mentra/bluetoothsdk/BesCrashReportWaiters.kt +68 -0
  8. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +5 -1
  9. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +77 -6
  10. package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +41 -0
  11. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +114 -122
  12. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +2 -2
  13. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
  14. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +31 -10
  15. package/android/src/main/java/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt +57 -196
  16. package/android/src/main/java/com/mentra/bluetoothsdk/OtaManifest.kt +1 -16
  17. package/android/src/main/java/com/mentra/bluetoothsdk/debug/BleTraceLogger.kt +10 -1
  18. package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
  19. package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/Ipv4Prefix.kt +51 -0
  20. package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/NetworkFacts.kt +81 -0
  21. package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkError.kt +108 -0
  22. package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkReadiness.kt +103 -0
  23. package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkRequestSpec.kt +44 -0
  24. package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkState.kt +117 -0
  25. package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedSoftApNetwork.kt +598 -0
  26. package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/SoftApTrace.kt +143 -0
  27. package/android/src/main/java/com/mentra/bluetoothsdk/otaserver/MentraOtaServerModule.kt +0 -7
  28. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTracker.kt +15 -0
  29. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +274 -56
  30. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +5 -5
  31. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +210 -325
  32. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +0 -35
  33. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +2 -10
  34. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareUpdater.kt +213 -0
  35. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoOtaProtocol.kt +112 -0
  36. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
  37. package/android/src/main/java/com/mentra/bluetoothsdk/streaming/StreamModels.kt +17 -6
  38. package/android/src/main/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueue.kt +92 -0
  39. package/android/src/main/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHost.kt +169 -0
  40. package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +74 -115
  41. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +348 -357
  42. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetector.kt +211 -0
  43. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngine.kt +137 -0
  44. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SttTextFormatter.kt +52 -0
  45. package/android/src/main/java/com/mentra/bluetoothsdk/stt/WakeWordDetector.kt +235 -0
  46. package/android/src/main/java/com/mentra/bluetoothsdk/utils/AvifExifStripper.java +2 -2
  47. package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +3 -3
  48. package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +11 -0
  49. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/AudioRouteWatcher.kt +120 -0
  50. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +181 -16
  51. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlayback.kt +177 -0
  52. package/android/src/test/java/com/mentra/bluetoothsdk/BesCrashReportWaitersTest.kt +112 -0
  53. package/android/src/test/java/com/mentra/bluetoothsdk/StreamRequestCaptureAudioTest.kt +23 -4
  54. package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/Ipv4PrefixTest.kt +59 -0
  55. package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/NetworkFactsTest.kt +59 -0
  56. package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedLocalNetworkPermissionTest.kt +35 -0
  57. package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkErrorTest.kt +85 -0
  58. package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkLifecycleTest.kt +164 -0
  59. package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkReadinessTest.kt +141 -0
  60. package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkRequestSpecTest.kt +56 -0
  61. package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/SoftApTraceTest.kt +97 -0
  62. package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/UnavailableRetryTest.kt +47 -0
  63. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTrackerTest.kt +26 -0
  64. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +141 -0
  65. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +183 -0
  66. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +3 -3
  67. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveRgbLedResponseTest.kt +76 -0
  68. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +1 -56
  69. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +0 -22
  70. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareTargetTest.kt +15 -0
  71. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareUpdaterTest.kt +76 -0
  72. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoOtaProtocolTest.kt +77 -0
  73. package/android/src/test/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNamingTest.kt +23 -0
  74. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoReadinessDriverTest.kt +31 -1
  75. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueueTest.kt +81 -0
  76. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHostTest.kt +216 -0
  77. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/STTToolsExtractionTest.kt +108 -0
  78. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetectorTest.kt +126 -0
  79. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngineTest.kt +245 -0
  80. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SttTextFormatterTest.kt +67 -0
  81. package/android/src/testDebug/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlaybackTest.kt +76 -0
  82. package/build/BluetoothSdk.types.d.ts +103 -5
  83. package/build/BluetoothSdk.types.d.ts.map +1 -1
  84. package/build/BluetoothSdk.types.js.map +1 -1
  85. package/build/_private/BluetoothSdkModule.d.ts +42 -8
  86. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  87. package/build/_private/BluetoothSdkModule.js +1 -0
  88. package/build/_private/BluetoothSdkModule.js.map +1 -1
  89. package/build/_private/MentraLocalNetworkModule.d.ts +1 -1
  90. package/build/_private/MentraLocalNetworkModule.d.ts.map +1 -1
  91. package/build/_private/MentraLocalNetworkModule.js.map +1 -1
  92. package/build/generated/changelogCatalog.d.ts +2 -2
  93. package/build/generated/changelogCatalog.js +2 -2
  94. package/build/generated/changelogCatalog.js.map +1 -1
  95. package/build/generated/releaseMetadata.js +5 -5
  96. package/build/generated/releaseMetadata.js.map +1 -1
  97. package/build/index.d.ts +1 -1
  98. package/build/index.d.ts.map +1 -1
  99. package/build/index.js +7 -1
  100. package/build/index.js.map +1 -1
  101. package/build/ota-server/MentraOtaServerModule.d.ts +0 -2
  102. package/build/ota-server/MentraOtaServerModule.d.ts.map +1 -1
  103. package/build/ota-server/MentraOtaServerModule.js.map +1 -1
  104. package/build/ota-server/MentraOtaServerModule.web.d.ts +0 -1
  105. package/build/ota-server/MentraOtaServerModule.web.d.ts.map +1 -1
  106. package/build/ota-server/MentraOtaServerModule.web.js +0 -3
  107. package/build/ota-server/MentraOtaServerModule.web.js.map +1 -1
  108. package/build/ota-transport/index.d.ts +3 -3
  109. package/build/ota-transport/index.d.ts.map +1 -1
  110. package/build/ota-transport/index.js +4 -4
  111. package/build/ota-transport/index.js.map +1 -1
  112. package/build/react/useGlassesConnection.d.ts +1 -1
  113. package/build/react/useGlassesConnection.d.ts.map +1 -1
  114. package/build/react/useGlassesConnection.js +3 -3
  115. package/build/react/useGlassesConnection.js.map +1 -1
  116. package/build/react/useMentraBluetooth.d.ts +1 -1
  117. package/build/react/useMentraBluetooth.d.ts.map +1 -1
  118. package/build/react/useMentraBluetooth.js +1 -1
  119. package/build/react/useMentraBluetooth.js.map +1 -1
  120. package/ios/BluetoothSdkModule.swift +73 -22
  121. package/ios/LocalIPv4.swift +0 -61
  122. package/ios/MentraBluetoothSDK.podspec +7 -1
  123. package/ios/MentraOtaServerModule.swift +0 -16
  124. package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
  125. package/ios/Resources/NimoFirmware/nimo-firmware-0.1.1.1-537cf1.bin +0 -0
  126. package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
  127. package/ios/Source/BesCrashReportWaiters.swift +64 -0
  128. package/ios/Source/BluetoothSdkDefaults.swift +4 -4
  129. package/ios/Source/Bridge.swift +14 -0
  130. package/ios/Source/DeviceManager.swift +43 -22
  131. package/ios/Source/GeneratedChangelogCatalog.swift +2 -2
  132. package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
  133. package/ios/Source/MentraBluetoothSDK.swift +35 -16
  134. package/ios/Source/OtaManifest.swift +1 -17
  135. package/ios/Source/audio/PcmStreamPlayer.swift +290 -57
  136. package/ios/Source/audio/PcmUrlPlayback.swift +231 -0
  137. package/ios/Source/audio/SpeechActivity.swift +277 -0
  138. package/ios/Source/events/BluetoothEvents.swift +41 -0
  139. package/ios/Source/internal/BleTraceLogger.swift +14 -1
  140. package/ios/Source/internal/BluetoothAvailability.swift +15 -5
  141. package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +5 -0
  142. package/ios/Source/sgcs/MentraLive.swift +195 -66
  143. package/ios/Source/sgcs/Nimo.swift +249 -276
  144. package/ios/Source/sgcs/NimoCanvasCoordinator.swift +9 -38
  145. package/ios/Source/sgcs/NimoCanvasSession.swift +0 -1
  146. package/ios/Source/sgcs/NimoFirmwareUpdater.swift +260 -0
  147. package/ios/Source/sgcs/NimoOtaProtocol.swift +159 -0
  148. package/ios/Source/sgcs/SGCManager.swift +6 -0
  149. package/ios/Source/streaming/StreamModels.swift +15 -6
  150. package/ios/Source/stt/STTTools.swift +13 -31
  151. package/ios/Source/stt/SherpaOnnxTranscriber.swift +204 -162
  152. package/ios/Source/stt/SileroSpeechActivity.swift +87 -0
  153. package/ios/Source/stt/WakeWordDetector.swift +145 -0
  154. package/ios/Source/utils/BoundedWait.swift +44 -0
  155. package/ios/Source/utils/DemandDrivenAudioWorker.swift +79 -0
  156. package/ios/Source/utils/SttModelTraits.swift +62 -0
  157. package/ios/Tests/BesCrashReportTests.swift +142 -0
  158. package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
  159. package/ios/Tests/DeviceManagerReconnectTests.swift +0 -71
  160. package/ios/Tests/GlassesAudioSetupPolicyTests.swift +9 -3
  161. package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
  162. package/ios/Tests/MentraLiveAudioSetupTests.swift +6 -12
  163. package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
  164. package/ios/Tests/MentraLiveSessionReadinessTests.swift +179 -10
  165. package/ios/Tests/NimoCanvasTransportTests.swift +0 -89
  166. package/ios/Tests/NimoOtaProtocolTests.swift +78 -0
  167. package/ios/Tests/PcmStreamTests.swift +299 -0
  168. package/ios/Tests/SpeechActivityTests.swift +238 -0
  169. package/ios/Tests/StreamRequestTests.swift +18 -0
  170. package/ios/Tests/SttModelTraitsTests.swift +62 -0
  171. package/package.json +2 -2
  172. package/plugin/build/withAndroid.js +9 -11
  173. package/plugin/build/withKotlinVersion.d.ts +2 -0
  174. package/plugin/build/withKotlinVersion.js +46 -0
  175. package/src/BluetoothSdk.types.ts +107 -5
  176. package/src/_private/BluetoothSdkModule.ts +45 -8
  177. package/src/_private/MentraLocalNetworkModule.ts +5 -1
  178. package/src/generated/changelogCatalog.ts +2 -2
  179. package/src/generated/releaseMetadata.ts +5 -5
  180. package/src/index.ts +13 -1
  181. package/src/ota-server/MentraOtaServerModule.ts +0 -2
  182. package/src/ota-server/MentraOtaServerModule.web.ts +0 -4
  183. package/src/ota-transport/index.ts +4 -5
  184. package/src/react/useGlassesConnection.ts +4 -4
  185. package/src/react/useMentraBluetooth.ts +2 -2
  186. package/android/silero/LICENSE.md +0 -17
  187. package/android/silero/build.gradle +0 -50
  188. package/android/silero/proguard-rules.pro +0 -24
  189. package/android/silero/src/androidTest/assets/hello.wav +0 -0
  190. package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +0 -79
  191. package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +0 -160
  192. package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +0 -449
  193. package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +0 -15
  194. package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +0 -14
  195. package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +0 -12
  196. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +0 -47
  197. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +0 -41
  198. package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +0 -44
  199. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -368
  200. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +0 -156
  201. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -274
  202. package/android/src/main/java/com/mentra/bluetoothsdk/ScopedNetworkReadiness.kt +0 -17
  203. package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +0 -229
  204. package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -20
  205. package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -16
  206. package/android/src/test/java/com/mentra/bluetoothsdk/ScopedNetworkReadinessTest.kt +0 -39
  207. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +0 -287
  208. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +0 -127
  209. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +0 -851
  210. package/ios/Source/sgcs/NimoMacResourceTransport.swift +0 -217
  211. package/ios/Source/sgcs/NimoResourceFixture.swift +0 -384
  212. package/ios/Source/sgcs/NimoResourceSession.swift +0 -406
  213. package/ios/Tests/NimoResourceSessionTests.swift +0 -476
  214. /package/android/{silero/src/main/assets/LICENSE → src/main/assets/vad/LICENSE.silero_vad} +0 -0
  215. /package/android/{silero/src/main/assets → src/main/assets/vad}/silero_vad.onnx +0 -0
@@ -1,274 +0,0 @@
1
- package com.mentra.bluetoothsdk.sgcs
2
-
3
- import android.content.BroadcastReceiver
4
- import android.content.Context
5
- import android.content.Intent
6
- import android.content.IntentFilter
7
- import android.os.Build
8
- import android.os.Handler
9
- import android.os.Looper
10
- import android.os.Process
11
- import android.os.SystemClock
12
- import com.mentra.bluetoothsdk.BuildConfig
13
- import com.mentra.bluetoothsdk.DeviceManager
14
- import org.json.JSONObject
15
- import java.io.File
16
- import java.lang.ref.WeakReference
17
- import java.util.UUID
18
-
19
- /** Fixed, DUMP-protected debug commands. Expected address is comparison-only, never a connection target.
20
- * No packet, device-command, caller path, reset, bond or radio inputs are accepted. */
21
- internal object NimoResourceDiagnostics {
22
- const val CLOCK_PROTOCOL = "nimo-monotonic-receipt-v1"
23
- const val ACTION = "com.mentra.bluetoothsdk.NIMO_RESOURCE_LIFECYCLE"
24
- private val main = Handler(Looper.getMainLooper())
25
- private val processInstanceId = UUID.randomUUID().toString()
26
- private data class Observed(val instance: WeakReference<Nimo>, var tombstone: JSONObject)
27
- private val sessions = linkedMapOf<String, Observed>()
28
- private var registered = false
29
- private var application: Context? = null
30
- private val requests = linkedSetOf<String>()
31
- private data class Capture(val nonce: String, val name: String, val address: String,
32
- var instance: Nimo? = null, var cancelled: Boolean = false, var connectStarted: Boolean = false,
33
- var transportStarted: Boolean = false, val armedElapsedMs: Long,
34
- var admittedElapsedMs: Long? = null)
35
- // One diagnostic attempt per app process. Cancellation is a process-lifetime fence.
36
- @Volatile private var capture: Capture? = null
37
- internal fun preArmCaptureRequired(buildType: String = BuildConfig.BUILD_TYPE): Boolean = buildType == "nimoDiagnostic"
38
- internal fun allowUnarmedWearable(buildType: String, wearable: String): Boolean =
39
- !preArmCaptureRequired(buildType) || !wearable.contains("NIMO", ignoreCase = true)
40
-
41
-
42
- /** Debug entries share the main admission queue even before arm, so a call that
43
- * starts just before arm cannot resume effects past it. Release builds are no-op.
44
- * Queued calls re-enter current capture guards before any connection effect. */
45
- fun dispatchCapturedEntry(entry: () -> Unit): Boolean {
46
- if (!preArmCaptureRequired() && capture == null) return false
47
- if (Looper.myLooper() == main.looper) return false
48
- val task = java.util.concurrent.FutureTask<Unit> { entry() }
49
- main.post(task)
50
- try {
51
- task.get()
52
- } catch (error: java.util.concurrent.ExecutionException) {
53
- throw (error.cause ?: error)
54
- } catch (error: InterruptedException) {
55
- // A queued entry must not run later after its original caller abandoned it.
56
- task.cancel(false)
57
- Thread.currentThread().interrupt()
58
- throw error
59
- }
60
- return true
61
- }
62
-
63
- @Synchronized
64
- fun allowManagerConnect(wearable: String, name: String? = null): Boolean {
65
- val owned = capture ?: return allowUnarmedWearable(BuildConfig.BUILD_TYPE, wearable)
66
- if (Looper.myLooper() != main.looper) return false
67
- if (!wearable.contains("NIMO", ignoreCase = true)) return true
68
- val current = DeviceManager.getInstance().sgc
69
- return !owned.cancelled && (name == null || !owned.connectStarted && name == owned.name) &&
70
- (current == null || current is Nimo && (owned.instance === current ||
71
- owned.instance == null && current.resourceCaptureEligible()))
72
- }
73
-
74
- /** Scan-to-connect is one captured attempt: never destroy or transfer its instance. */
75
- @Synchronized
76
- fun preserveCapturedScan(wearable: String, name: String): Boolean {
77
- val owned = capture ?: return false
78
- if (Looper.myLooper() != main.looper || !wearable.contains("NIMO", ignoreCase = true) ||
79
- owned.cancelled || owned.connectStarted || name != owned.name) return false
80
- val original = owned.instance ?: return false
81
- return DeviceManager.getInstance().sgc === original &&
82
- original.resourceSnapshot().getLong("sessionGeneration") == 0L
83
- }
84
-
85
- @Synchronized
86
- fun admit(instance: Nimo, name: String?, connect: Boolean): Boolean {
87
- val owned = capture ?: return !preArmCaptureRequired()
88
- if (Looper.myLooper() != main.looper) return false
89
- if (!allowManagerConnect("NIMO", name) || DeviceManager.getInstance().sgc !== instance ||
90
- owned.instance != null && owned.instance !== instance || owned.connectStarted) return false
91
- if (owned.instance == null) {
92
- if (!instance.resourceCaptureEligible()) return false
93
- val candidateAdmittedElapsedMs = SystemClock.elapsedRealtime()
94
- owned.instance = instance
95
- // Immutable admission survives a setup timeout before any GATT session exists.
96
- val app = application ?: run { owned.cancelled = true; return false }
97
- val root = File(app.filesDir, "nimo-lifecycle")
98
- val target = File(root, "${owned.nonce}.admission.json")
99
- if (target.exists()) { owned.cancelled = true; return false }
100
- val pending = File(root, "${owned.nonce}.admission.tmp")
101
- try {
102
- pending.outputStream().use { it.write(captureSnapshot(owned, candidateAdmittedElapsedMs).toString().toByteArray(Charsets.UTF_8)); it.flush() }
103
- check(pending.renameTo(target))
104
- // Durable admission is authoritative; no live clock may claim it
105
- // before the original immutable receipt is safely committed.
106
- instance.resourceCaptureAdmission(owned.nonce, owned.armedElapsedMs, candidateAdmittedElapsedMs)
107
- owned.admittedElapsedMs = candidateAdmittedElapsedMs
108
- } catch (_: Exception) {
109
- owned.cancelled = true
110
- return false
111
- } finally { pending.delete() }
112
- }
113
- if (connect) owned.connectStarted = true
114
- return true
115
- }
116
-
117
- @Synchronized
118
- fun allowPeer(instance: Nimo, address: String, bonded: Boolean): Boolean {
119
- val owned = capture ?: return !preArmCaptureRequired()
120
- if (Looper.myLooper() != main.looper) return false
121
- return !owned.cancelled && owned.instance === instance && address == owned.address && bonded &&
122
- DeviceManager.getInstance().sgc === instance
123
- }
124
-
125
- @Synchronized
126
- fun beginTransport(instance: Nimo, address: String, bonded: Boolean): Boolean {
127
- val owned = capture ?: return !preArmCaptureRequired()
128
- if (Looper.myLooper() != main.looper) return false
129
- if (!allowPeer(instance, address, bonded) || owned.transportStarted) return false
130
- owned.transportStarted = true
131
- return true
132
- }
133
-
134
- @Synchronized
135
- private fun captureSnapshot(owned: Capture, admittedElapsedMs: Long? = owned.admittedElapsedMs): JSONObject = JSONObject()
136
- .put("clockProtocol", CLOCK_PROTOCOL)
137
- .put("clock", JSONObject().put("kind", "android-elapsed-realtime-v1").put("armedElapsedMs", owned.armedElapsedMs)
138
- .put("admittedElapsedMs", admittedElapsedMs ?: JSONObject.NULL).put("observedElapsedMs", SystemClock.elapsedRealtime()))
139
- .put("version", "nimo-preconnect-capture-v1").put("nonce", owned.nonce)
140
- .put("captureRequiredBeforeArm", preArmCaptureRequired())
141
- .put("expectedPair", JSONObject().put("name", owned.name).put("bluetoothAddress", owned.address))
142
- .put("instanceId", owned.instance?.resourceInstanceId ?: JSONObject.NULL)
143
- .put("sessionGeneration", owned.instance?.resourceSnapshot()?.getLong("sessionGeneration") ?: JSONObject.NULL)
144
- .put("observedPair", if (owned.transportStarted) owned.instance?.resourceSnapshot()?.getJSONObject("pair") ?: JSONObject.NULL else JSONObject.NULL)
145
- .put("cancelled", owned.cancelled).put("connectStarted", owned.connectStarted)
146
- .put("transportStarted", owned.transportStarted)
147
- .put("appPid", Process.myPid()).put("processInstanceId", processInstanceId)
148
- .put("observedAtEpochMs", System.currentTimeMillis())
149
-
150
-
151
- fun start(context: Context) {
152
- if (Looper.myLooper() != main.looper) { main.post { start(context) }; return }
153
- if (registered) return
154
- val app = context.applicationContext
155
- val filter = IntentFilter(ACTION)
156
- if (Build.VERSION.SDK_INT >= 33) app.registerReceiver(receiver, filter, "android.permission.DUMP", main, Context.RECEIVER_EXPORTED)
157
- else { @Suppress("DEPRECATION") app.registerReceiver(receiver, filter, "android.permission.DUMP", main) }
158
- application = app
159
- registered = true
160
- }
161
-
162
- fun track(instance: Nimo) {
163
- check(Looper.myLooper() == main.looper)
164
- val snapshot = instance.resourceSnapshot()
165
- sessions["${instance.resourceInstanceId}:${snapshot.getLong("sessionGeneration")}"] = Observed(WeakReference(instance), snapshot)
166
- while (sessions.size > 8) sessions.remove(sessions.keys.first())
167
- }
168
-
169
- private val receiver = object : BroadcastReceiver() {
170
- override fun onReceive(context: Context?, intent: Intent?) {
171
- if (intent?.action != ACTION) return
172
- try { execute(intent) } catch (_: Exception) { /* No receipt means unknown; never crash the product app. */ }
173
- }
174
- }
175
-
176
- /** Separate from BroadcastReceiver for source tests; no exported unrestricted app API. */
177
- @Synchronized
178
- internal fun execute(intent: Intent) {
179
- check(Looper.myLooper() == main.looper)
180
- val requestReceivedElapsedMs = SystemClock.elapsedRealtime()
181
- val nonce = intent.getStringExtra("nonce") ?: return
182
- if (!uuid(nonce) || nonce in requests) return
183
- val app = application ?: return
184
- val root = File(app.filesDir, "nimo-lifecycle")
185
- if ((!root.isDirectory && !root.mkdir()) || File(root, "$nonce.json").exists()) return
186
- requests.add(nonce)
187
- while (requests.size > 128) requests.remove(requests.first())
188
- val mode = intent.getStringExtra("mode") ?: "status"
189
- val address = intent.getStringExtra("expectedAddress") ?: ""
190
- val instanceId = intent.getStringExtra("instanceId")
191
- val generation = intent.getLongExtra("sessionGeneration", -1)
192
- val request = JSONObject().put("nonce", nonce).put("mode", mode).put("expectedAddress", address)
193
- .put("instanceId", instanceId ?: JSONObject.NULL).put("sessionGeneration", if (generation >= 0) generation else JSONObject.NULL)
194
- fun save(session: JSONObject?, error: String? = null): Boolean {
195
- val current = DeviceManager.getInstance().sgc
196
- val receipt = JSONObject().put("clockProtocol", CLOCK_PROTOCOL)
197
- .put("clock", JSONObject().put("kind", "android-elapsed-realtime-v1").put("requestReceivedElapsedMs", requestReceivedElapsedMs).put("observedElapsedMs", SystemClock.elapsedRealtime()))
198
- .put("schemaVersion", 1).put("request", request).put("observedAtEpochMs", System.currentTimeMillis())
199
- .put("appPid", Process.myPid()).put("processInstanceId", processInstanceId)
200
- .put("currentManager", JSONObject().put("type", current?.type ?: JSONObject.NULL)
201
- .put("instanceId", (current as? Nimo)?.resourceInstanceId ?: JSONObject.NULL))
202
- .put("session", session ?: JSONObject.NULL).put("error", error ?: JSONObject.NULL)
203
- val pending = File(root, "$nonce.tmp")
204
- try {
205
- pending.outputStream().use { it.write(receipt.toString().toByteArray(Charsets.UTF_8)); it.flush() }
206
- check(pending.renameTo(File(root, "$nonce.json")))
207
- return true
208
- } catch (_: Exception) { return false /* Absent receipt is unknown. */ } finally { pending.delete() }
209
- }
210
- if (mode in listOf("arm-capture", "capture-status", "cancel-capture")) {
211
- val expectedName = intent.getStringExtra("expectedName")
212
- val captureNonce = intent.getStringExtra("captureNonce")
213
- request.remove("instanceId"); request.remove("sessionGeneration")
214
- request.put("expectedName", expectedName ?: JSONObject.NULL).put("captureNonce", captureNonce ?: JSONObject.NULL)
215
- if (!Regex("^[0-9A-F]{2}(:[0-9A-F]{2}){5}$").matches(address) ||
216
- intent.extras?.keySet()?.any { it !in setOf("nonce", "mode", "expectedAddress", "expectedName", "captureNonce") } == true ||
217
- expectedName == null || !Regex("^Nimo-[A-Za-z0-9]{1,32}$").matches(expectedName) ||
218
- captureNonce == null || !uuid(captureNonce)) { save(null, "invalid-fixed-capture-request"); return }
219
- if (mode == "arm-capture") {
220
- val manager = DeviceManager.getInstance().sgc
221
- if (capture != null || captureNonce != nonce || manager != null) {
222
- save(null, "capture-arm-refused-existing-owner"); return
223
- }
224
- capture = Capture(captureNonce, expectedName, address, armedElapsedMs = requestReceivedElapsedMs)
225
- }
226
- val owned = capture
227
- if (owned == null || owned.nonce != captureNonce || owned.name != expectedName || owned.address != address) {
228
- save(null, "capture-not-original"); return
229
- }
230
- fun captureReceipt(session: JSONObject? = null, error: String? = null): Boolean {
231
- return save(JSONObject().put("capture", captureSnapshot(owned)).put("originalSession", session ?: JSONObject.NULL), error)
232
- }
233
- if (mode != "cancel-capture") {
234
- if (!captureReceipt(owned.instance?.resourceSnapshot()) && mode == "arm-capture") owned.cancelled = true
235
- return
236
- }
237
- owned.cancelled = true // fence before draining or emitting a no-admission receipt
238
- val original = owned.instance
239
- if (original == null) { captureReceipt(); return }
240
- if (DeviceManager.getInstance().sgc !== original) { captureReceipt(original.resourceSnapshot(), "capture-cancel-refused-replacement"); return }
241
- original.releaseCapturedResource({ DeviceManager.getInstance().sgc === original }, { result -> captureReceipt(result) }, nonce, requestReceivedElapsedMs)
242
- return
243
- }
244
- if (mode !in listOf("status", "release") || !Regex("^[0-9A-F]{2}(:[0-9A-F]{2}){5}$").matches(address) ||
245
- instanceId != null && !uuid(instanceId) || intent.extras?.keySet()?.any { it !in setOf("nonce", "mode", "expectedAddress", "instanceId", "sessionGeneration") } == true) {
246
- save(null, "invalid-fixed-request"); return
247
- }
248
- val current = DeviceManager.getInstance().sgc as? Nimo
249
- current?.let { track(it) }
250
- val selected = if (instanceId != null) sessions["$instanceId:$generation"] else sessions.values.lastOrNull {
251
- it.tombstone.getJSONObject("pair").optString("bluetoothAddress") == address
252
- }
253
- val candidate = selected?.instance?.get()
254
- val live = candidate?.resourceSnapshot()
255
- val instance = candidate?.takeIf { live?.optLong("sessionGeneration") == selected?.tombstone?.optLong("sessionGeneration") }
256
- val snapshot = if (instance != null) live else selected?.tombstone
257
- if (snapshot == null || snapshot.getJSONObject("pair").optString("bluetoothAddress") != address ||
258
- generation >= 0 && snapshot.optLong("sessionGeneration", -1) != generation) {
259
- save(null, "target-not-observed-or-generation-mismatch"); return
260
- }
261
- if (mode == "status") {
262
- save(JSONObject(snapshot.toString()).put("sessionObservationCurrent", instance != null).put("source", if (instance != null) "live-original-instance" else "retained-tombstone")); return
263
- }
264
- if (instanceId == null || generation < 1 || instance == null || instance !== current) {
265
- save(snapshot, "release-refused-replaced-or-unowned-target"); return
266
- }
267
- instance.releaseResource(generation, { DeviceManager.getInstance().sgc === instance }, { result ->
268
- track(instance)
269
- if (result.has("error")) save(instance.resourceSnapshot(), result.getString("error")) else save(result)
270
- }, nonce, requestReceivedElapsedMs)
271
- }
272
-
273
- private fun uuid(value: String): Boolean = try { UUID.fromString(value).toString() == value } catch (_: IllegalArgumentException) { false }
274
- }
@@ -1,17 +0,0 @@
1
- package com.mentra.bluetoothsdk
2
-
3
- internal class ScopedNetworkReadiness<T> {
4
- private var candidate: T? = null
5
-
6
- fun onAvailable(network: T) {
7
- candidate = network
8
- }
9
-
10
- fun isReady(network: T, isForeground: Boolean): Boolean = candidate == network && isForeground
11
-
12
- fun contains(network: T): Boolean = candidate == network
13
-
14
- fun clear() {
15
- candidate = null
16
- }
17
- }
@@ -1,229 +0,0 @@
1
- package com.mentra.bluetoothsdk.stt
2
-
3
- import android.content.Context
4
- import com.mentra.bluetoothsdk.utils.NativeLog as Log
5
- import com.konovalov.vad.silero.Vad
6
- import com.konovalov.vad.silero.VadSilero
7
- import com.konovalov.vad.silero.config.FrameSize
8
- import com.konovalov.vad.silero.config.Mode
9
- import com.konovalov.vad.silero.config.SampleRate
10
- import java.nio.ByteBuffer
11
- import java.nio.ByteOrder
12
-
13
- /**
14
- * VadGateSpeechPolicy handles Voice Activity Detection using Silero VAD.
15
- *
16
- * Features:
17
- * - Dynamic VAD check throttling (adjusts frequency based on silence duration)
18
- * - 8-second silence timeout before declaring "not speaking"
19
- * - Bypass modes for debugging and PCM streaming
20
- * - 512-sample frame size (matches Sherpa-ONNX requirements)
21
- *
22
- * Ported from android_core VadGateSpeechPolicy.java
23
- */
24
- class VadGateSpeechPolicy(private val context: Context) {
25
- companion object {
26
- private const val TAG = "VadGateSpeechPolicy"
27
-
28
- // Total required silence duration
29
- private const val REQUIRED_SILENCE_DURATION_MS = 8000L
30
-
31
- // Dynamic VAD check intervals
32
- private const val INITIAL_SILENCE_VAD_INTERVAL_MS = 50L // Check frequently at first
33
- private const val MEDIUM_SILENCE_VAD_INTERVAL_MS = 100L // Medium frequency after some time
34
- private const val LONG_SILENCE_VAD_INTERVAL_MS =
35
- 200L // Less frequent after extended silence
36
-
37
- // Thresholds for switching intervals
38
- private const val MEDIUM_SILENCE_THRESHOLD_MS =
39
- 20000L // Switch to medium interval after 20s
40
- private const val LONG_SILENCE_THRESHOLD_MS = 60000L // Switch to long interval after 60s
41
-
42
- private const val FRAME_SIZE = 512
43
- }
44
-
45
- private var vad: VadSilero? = null
46
- private var isCurrentlySpeech = false
47
- private var bypassVadForDebugging = false
48
- private var bypassVadForPCM = false
49
-
50
- /** Notified whenever the speech/silence state actually flips. */
51
- var onSpeechStateChanged: ((Boolean) -> Unit)? = null
52
-
53
- // Timestamp of the last detected speech
54
- private var lastSpeechDetectedTime = 0L
55
- // Throttle timer for silence VAD checks
56
- private var lastVadCheckTime = 0L
57
-
58
- /** Initialize the Silero VAD model */
59
- fun init(blockSizeSamples: Int) {
60
- startVad()
61
- }
62
-
63
- private fun startVad() {
64
- try {
65
- // Set internal silence duration very low; external logic manages the full required
66
- // silence duration
67
- vad =
68
- Vad.builder()
69
- .setContext(context)
70
- .setSampleRate(SampleRate.SAMPLE_RATE_16K)
71
- .setFrameSize(FrameSize.FRAME_SIZE_512)
72
- .setMode(Mode.NORMAL)
73
- .setSilenceDurationMs(50)
74
- .setSpeechDurationMs(50)
75
- .build()
76
-
77
- Log.d(TAG, "VAD initialized successfully")
78
- } catch (e: Exception) {
79
- Log.e(TAG, "Failed to initialize VAD", e)
80
- vad = null
81
- }
82
- }
83
-
84
- /** Check if audio should be passed to the recognizer based on VAD state */
85
- fun shouldPassAudioToRecognizer(): Boolean {
86
- // CRITICAL: Handle VAD null case
87
- if (vad == null) {
88
- return bypassVadForDebugging || bypassVadForPCM || true
89
- }
90
-
91
- return bypassVadForDebugging || bypassVadForPCM || isCurrentlySpeech
92
- }
93
-
94
- /** Process audio bytes through VAD to detect speech */
95
- fun processAudioBytes(bytes: ByteArray, offset: Int, length: Int) {
96
- val now = System.currentTimeMillis()
97
-
98
- // If in speech state and it hasn't been 8 seconds since the last speech was detected, skip
99
- // processing
100
- if (isCurrentlySpeech && (now - lastSpeechDetectedTime < REQUIRED_SILENCE_DURATION_MS)) {
101
- return
102
- }
103
-
104
- // Calculate silence duration
105
- val silenceDuration = now - lastSpeechDetectedTime
106
-
107
- // Determine which VAD interval to use based on silence duration
108
- val currentVadInterval =
109
- when {
110
- silenceDuration < MEDIUM_SILENCE_THRESHOLD_MS -> INITIAL_SILENCE_VAD_INTERVAL_MS
111
- silenceDuration < LONG_SILENCE_THRESHOLD_MS -> MEDIUM_SILENCE_VAD_INTERVAL_MS
112
- else -> LONG_SILENCE_VAD_INTERVAL_MS
113
- }
114
-
115
- // During silence, throttle VAD checks based on the dynamic interval
116
- if (!isCurrentlySpeech && (now - lastVadCheckTime < currentVadInterval)) {
117
- return
118
- }
119
- lastVadCheckTime = now
120
-
121
- val audioBytesFull = bytesToShort(bytes)
122
- val totalSamples = audioBytesFull.size
123
-
124
- if (totalSamples % FRAME_SIZE != 0) {
125
- Log.e(
126
- TAG,
127
- "Invalid audio frame size: $totalSamples samples. Needs to be multiple of $FRAME_SIZE."
128
- )
129
- return
130
- }
131
-
132
- val currentVad =
133
- vad
134
- ?: run {
135
- Log.w(TAG, "VAD not initialized, skipping audio processing")
136
- return
137
- }
138
-
139
- var previousSpeechState = isCurrentlySpeech
140
-
141
- // Process each 512-sample frame
142
- val numFrames = totalSamples / FRAME_SIZE
143
- for (i in 0 until numFrames) {
144
- val currentTime = System.currentTimeMillis()
145
- val startIdx = i * FRAME_SIZE
146
- val audioFrame = audioBytesFull.copyOfRange(startIdx, startIdx + FRAME_SIZE)
147
- val detectedSpeech = currentVad.isSpeech(audioFrame)
148
-
149
- if (detectedSpeech) {
150
- isCurrentlySpeech = true
151
- // Update the last speech detection timestamp
152
- lastSpeechDetectedTime = currentTime
153
- } else {
154
- // If no speech detected, and 8 seconds have elapsed since the last speech, mark as
155
- // silence
156
- if (currentTime - lastSpeechDetectedTime >= REQUIRED_SILENCE_DURATION_MS) {
157
- isCurrentlySpeech = false
158
- }
159
- }
160
-
161
- if (isCurrentlySpeech != previousSpeechState) {
162
- Log.d(
163
- TAG,
164
- "Speech detection changed to: ${if (isCurrentlySpeech) "SPEECH" else "SILENCE"}"
165
- )
166
- previousSpeechState = isCurrentlySpeech
167
- onSpeechStateChanged?.invoke(isCurrentlySpeech)
168
- }
169
- }
170
- }
171
-
172
- /** Convert byte array (PCM16LE) to short array */
173
- private fun bytesToShort(bytes: ByteArray): ShortArray {
174
- val shorts = ShortArray(bytes.size / 2)
175
- ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts)
176
- return shorts
177
- }
178
-
179
- /** Stop VAD and release resources */
180
- fun stop() {
181
- try {
182
- vad?.close()
183
- vad = null
184
- Log.d(TAG, "VAD stopped and resources released")
185
- } catch (e: Exception) {
186
- Log.e(TAG, "Error stopping VAD", e)
187
- }
188
- }
189
-
190
- /** Reset VAD state */
191
- fun reset() {
192
- val wasSpeaking = isCurrentlySpeech
193
- isCurrentlySpeech = false
194
- lastSpeechDetectedTime = 0
195
- lastVadCheckTime = 0
196
- if (wasSpeaking) onSpeechStateChanged?.invoke(false)
197
- }
198
-
199
- /** Change bypass VAD for debugging state */
200
- fun changeBypassVadForDebugging(bypass: Boolean) {
201
- bypassVadForDebugging = bypass
202
- Log.d(TAG, "Bypass VAD for debugging: $bypass")
203
- }
204
-
205
- /** Change bypass VAD for PCM streaming state */
206
- fun changeBypassVadForPCM(bypass: Boolean) {
207
- Log.d(TAG, "VAD PCM Bypass State Change: $bypassVadForPCM -> $bypass")
208
- bypassVadForPCM = bypass
209
- }
210
-
211
- /** Handle microphone state changes */
212
- fun microphoneStateChanged(state: Boolean) {
213
- if (!state) {
214
- // Microphone turned off: force immediate silence
215
- val wasSpeaking = isCurrentlySpeech
216
- isCurrentlySpeech = false
217
- lastSpeechDetectedTime = 0
218
- lastVadCheckTime = 0
219
-
220
- // Optionally flush the VAD's internal state by processing a silent frame
221
- vad?.let { vadInstance ->
222
- val silentFrame = ShortArray(FRAME_SIZE)
223
- vadInstance.isSpeech(silentFrame)
224
- }
225
- Log.d(TAG, "Microphone turned off; forced state to SILENCE.")
226
- if (wasSpeaking) onSpeechStateChanged?.invoke(false)
227
- }
228
- }
229
- }
@@ -1,20 +0,0 @@
1
- package com.mentra.bluetoothsdk.sgcs
2
-
3
- import android.content.Context
4
- import android.os.Handler
5
-
6
- /** No diagnostic receiver, commands, or screen capture in release builds. */
7
- @Suppress("UNUSED_PARAMETER")
8
- internal class NimoDiagnostics(
9
- context: Context,
10
- handler: Handler,
11
- send: (ByteArray, () -> Unit) -> Boolean,
12
- requestCanvasHold: ((() -> Unit) -> Unit) = { _ -> },
13
- releaseCanvasHold: (resume: Boolean) -> Unit = { _ -> },
14
- ) {
15
- fun connected(maxWriteBytes: Int) {}
16
- fun disconnected() {}
17
- fun close() {}
18
- fun onPacket(packet: ByteArray): Boolean = false
19
- fun cancelHeldCapture(reason: String, resumeCanvas: Boolean = false) {}
20
- }
@@ -1,16 +0,0 @@
1
- package com.mentra.bluetoothsdk.sgcs
2
-
3
- import android.content.Context
4
-
5
- /** Release builds register no receiver and expose no lifecycle control surface. */
6
- @Suppress("UNUSED_PARAMETER")
7
- internal object NimoResourceDiagnostics {
8
- fun start(context: Context) {}
9
- fun track(instance: Nimo) {}
10
- fun dispatchCapturedEntry(entry: () -> Unit) = false
11
- fun allowManagerConnect(wearable: String, name: String? = null) = true
12
- fun preserveCapturedScan(wearable: String, name: String) = false
13
- fun admit(instance: Nimo, name: String?, connect: Boolean) = true
14
- fun allowPeer(instance: Nimo, address: String, bonded: Boolean) = true
15
- fun beginTransport(instance: Nimo, address: String, bonded: Boolean) = true
16
- }
@@ -1,39 +0,0 @@
1
- package com.mentra.bluetoothsdk
2
-
3
- import org.junit.Assert.assertFalse
4
- import org.junit.Assert.assertTrue
5
- import org.junit.Test
6
-
7
- class ScopedNetworkReadinessTest {
8
- @Test
9
- fun `waits for the available network to become foreground`() {
10
- val readiness = ScopedNetworkReadiness<String>()
11
-
12
- readiness.onAvailable("glasses")
13
-
14
- assertFalse(readiness.isReady("glasses", isForeground = false))
15
- assertTrue(readiness.isReady("glasses", isForeground = true))
16
- }
17
-
18
- @Test
19
- fun `rejects capabilities from a stale network`() {
20
- val readiness = ScopedNetworkReadiness<String>()
21
-
22
- readiness.onAvailable("old")
23
- readiness.onAvailable("current")
24
-
25
- assertFalse(readiness.isReady("old", isForeground = true))
26
- assertTrue(readiness.isReady("current", isForeground = true))
27
- }
28
-
29
- @Test
30
- fun `clears the candidate when the request ends`() {
31
- val readiness = ScopedNetworkReadiness<String>()
32
- readiness.onAvailable("glasses")
33
-
34
- readiness.clear()
35
-
36
- assertFalse(readiness.contains("glasses"))
37
- assertFalse(readiness.isReady("glasses", isForeground = true))
38
- }
39
- }