@mentra/bluetooth-sdk 3.4.0-dev.957 → 3.4.0-dev.965

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.
@@ -0,0 +1,260 @@
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 com.mentra.bluetoothsdk.BuildConfig
12
+ import com.mentra.bluetoothsdk.DeviceManager
13
+ import org.json.JSONObject
14
+ import java.io.File
15
+ import java.lang.ref.WeakReference
16
+ import java.util.UUID
17
+
18
+ /** Fixed, DUMP-protected debug commands. Expected address is comparison-only, never a connection target.
19
+ * No packet, device-command, caller path, reset, bond or radio inputs are accepted. */
20
+ internal object NimoResourceDiagnostics {
21
+ const val ACTION = "com.mentra.bluetoothsdk.NIMO_RESOURCE_LIFECYCLE"
22
+ private val main = Handler(Looper.getMainLooper())
23
+ private val processInstanceId = UUID.randomUUID().toString()
24
+ private data class Observed(val instance: WeakReference<Nimo>, var tombstone: JSONObject)
25
+ private val sessions = linkedMapOf<String, Observed>()
26
+ private var registered = false
27
+ private var application: Context? = null
28
+ private val requests = linkedSetOf<String>()
29
+ private data class Capture(val nonce: String, val name: String, val address: String,
30
+ var instance: Nimo? = null, var cancelled: Boolean = false, var connectStarted: Boolean = false,
31
+ var transportStarted: Boolean = false)
32
+ // One diagnostic attempt per app process. Cancellation is a process-lifetime fence.
33
+ @Volatile private var capture: Capture? = null
34
+ internal fun preArmCaptureRequired(buildType: String = BuildConfig.BUILD_TYPE): Boolean = buildType == "nimoDiagnostic"
35
+ internal fun allowUnarmedWearable(buildType: String, wearable: String): Boolean =
36
+ !preArmCaptureRequired(buildType) || !wearable.contains("NIMO", ignoreCase = true)
37
+
38
+
39
+ /** Debug entries share the main admission queue even before arm, so a call that
40
+ * starts just before arm cannot resume effects past it. Release builds are no-op.
41
+ * Queued calls re-enter current capture guards before any connection effect. */
42
+ fun dispatchCapturedEntry(entry: () -> Unit): Boolean {
43
+ if (!preArmCaptureRequired() && capture == null) return false
44
+ if (Looper.myLooper() == main.looper) return false
45
+ val task = java.util.concurrent.FutureTask<Unit> { entry() }
46
+ main.post(task)
47
+ try {
48
+ task.get()
49
+ } catch (error: java.util.concurrent.ExecutionException) {
50
+ throw (error.cause ?: error)
51
+ } catch (error: InterruptedException) {
52
+ // A queued entry must not run later after its original caller abandoned it.
53
+ task.cancel(false)
54
+ Thread.currentThread().interrupt()
55
+ throw error
56
+ }
57
+ return true
58
+ }
59
+
60
+ @Synchronized
61
+ fun allowManagerConnect(wearable: String, name: String? = null): Boolean {
62
+ val owned = capture ?: return allowUnarmedWearable(BuildConfig.BUILD_TYPE, wearable)
63
+ if (Looper.myLooper() != main.looper) return false
64
+ if (!wearable.contains("NIMO", ignoreCase = true)) return true
65
+ val current = DeviceManager.getInstance().sgc
66
+ return !owned.cancelled && (name == null || !owned.connectStarted && name == owned.name) &&
67
+ (current == null || current is Nimo && (owned.instance === current ||
68
+ owned.instance == null && current.resourceCaptureEligible()))
69
+ }
70
+
71
+ /** Scan-to-connect is one captured attempt: never destroy or transfer its instance. */
72
+ @Synchronized
73
+ fun preserveCapturedScan(wearable: String, name: String): Boolean {
74
+ val owned = capture ?: return false
75
+ if (Looper.myLooper() != main.looper || !wearable.contains("NIMO", ignoreCase = true) ||
76
+ owned.cancelled || owned.connectStarted || name != owned.name) return false
77
+ val original = owned.instance ?: return false
78
+ return DeviceManager.getInstance().sgc === original &&
79
+ original.resourceSnapshot().getLong("sessionGeneration") == 0L
80
+ }
81
+
82
+ @Synchronized
83
+ fun admit(instance: Nimo, name: String?, connect: Boolean): Boolean {
84
+ val owned = capture ?: return !preArmCaptureRequired()
85
+ if (Looper.myLooper() != main.looper) return false
86
+ if (!allowManagerConnect("NIMO", name) || DeviceManager.getInstance().sgc !== instance ||
87
+ owned.instance != null && owned.instance !== instance || owned.connectStarted) return false
88
+ if (owned.instance == null) {
89
+ if (!instance.resourceCaptureEligible()) return false
90
+ owned.instance = instance
91
+ // Immutable admission survives a setup timeout before any GATT session exists.
92
+ val app = application ?: return false
93
+ val root = File(app.filesDir, "nimo-lifecycle")
94
+ val target = File(root, "${owned.nonce}.admission.json")
95
+ if (target.exists()) { owned.cancelled = true; return false }
96
+ val pending = File(root, "${owned.nonce}.admission.tmp")
97
+ try {
98
+ pending.outputStream().use { it.write(captureSnapshot(owned).toString().toByteArray(Charsets.UTF_8)); it.flush() }
99
+ check(pending.renameTo(target))
100
+ } catch (_: Exception) {
101
+ owned.cancelled = true
102
+ return false
103
+ } finally { pending.delete() }
104
+ }
105
+ if (connect) owned.connectStarted = true
106
+ return true
107
+ }
108
+
109
+ @Synchronized
110
+ fun allowPeer(instance: Nimo, address: String, bonded: Boolean): Boolean {
111
+ val owned = capture ?: return !preArmCaptureRequired()
112
+ if (Looper.myLooper() != main.looper) return false
113
+ return !owned.cancelled && owned.instance === instance && address == owned.address && bonded &&
114
+ DeviceManager.getInstance().sgc === instance
115
+ }
116
+
117
+ @Synchronized
118
+ fun beginTransport(instance: Nimo, address: String, bonded: Boolean): Boolean {
119
+ val owned = capture ?: return !preArmCaptureRequired()
120
+ if (Looper.myLooper() != main.looper) return false
121
+ if (!allowPeer(instance, address, bonded) || owned.transportStarted) return false
122
+ owned.transportStarted = true
123
+ return true
124
+ }
125
+
126
+ @Synchronized
127
+ private fun captureSnapshot(owned: Capture): JSONObject = JSONObject()
128
+ .put("version", "nimo-preconnect-capture-v1").put("nonce", owned.nonce)
129
+ .put("captureRequiredBeforeArm", preArmCaptureRequired())
130
+ .put("expectedPair", JSONObject().put("name", owned.name).put("bluetoothAddress", owned.address))
131
+ .put("instanceId", owned.instance?.resourceInstanceId ?: JSONObject.NULL)
132
+ .put("sessionGeneration", owned.instance?.resourceSnapshot()?.getLong("sessionGeneration") ?: JSONObject.NULL)
133
+ .put("observedPair", if (owned.transportStarted) owned.instance?.resourceSnapshot()?.getJSONObject("pair") ?: JSONObject.NULL else JSONObject.NULL)
134
+ .put("cancelled", owned.cancelled).put("connectStarted", owned.connectStarted)
135
+ .put("transportStarted", owned.transportStarted)
136
+ .put("appPid", Process.myPid()).put("processInstanceId", processInstanceId)
137
+ .put("observedAtEpochMs", System.currentTimeMillis())
138
+
139
+
140
+ fun start(context: Context) {
141
+ if (Looper.myLooper() != main.looper) { main.post { start(context) }; return }
142
+ if (registered) return
143
+ val app = context.applicationContext
144
+ val filter = IntentFilter(ACTION)
145
+ if (Build.VERSION.SDK_INT >= 33) app.registerReceiver(receiver, filter, "android.permission.DUMP", main, Context.RECEIVER_EXPORTED)
146
+ else { @Suppress("DEPRECATION") app.registerReceiver(receiver, filter, "android.permission.DUMP", main) }
147
+ application = app
148
+ registered = true
149
+ }
150
+
151
+ fun track(instance: Nimo) {
152
+ check(Looper.myLooper() == main.looper)
153
+ val snapshot = instance.resourceSnapshot()
154
+ sessions["${instance.resourceInstanceId}:${snapshot.getLong("sessionGeneration")}"] = Observed(WeakReference(instance), snapshot)
155
+ while (sessions.size > 8) sessions.remove(sessions.keys.first())
156
+ }
157
+
158
+ private val receiver = object : BroadcastReceiver() {
159
+ override fun onReceive(context: Context?, intent: Intent?) {
160
+ if (intent?.action != ACTION) return
161
+ try { execute(intent) } catch (_: Exception) { /* No receipt means unknown; never crash the product app. */ }
162
+ }
163
+ }
164
+
165
+ /** Separate from BroadcastReceiver for source tests; no exported unrestricted app API. */
166
+ @Synchronized
167
+ internal fun execute(intent: Intent) {
168
+ check(Looper.myLooper() == main.looper)
169
+ val nonce = intent.getStringExtra("nonce") ?: return
170
+ if (!uuid(nonce) || nonce in requests) return
171
+ val app = application ?: return
172
+ val root = File(app.filesDir, "nimo-lifecycle")
173
+ if ((!root.isDirectory && !root.mkdir()) || File(root, "$nonce.json").exists()) return
174
+ requests.add(nonce)
175
+ while (requests.size > 128) requests.remove(requests.first())
176
+ val mode = intent.getStringExtra("mode") ?: "status"
177
+ val address = intent.getStringExtra("expectedAddress") ?: ""
178
+ val instanceId = intent.getStringExtra("instanceId")
179
+ val generation = intent.getLongExtra("sessionGeneration", -1)
180
+ val request = JSONObject().put("nonce", nonce).put("mode", mode).put("expectedAddress", address)
181
+ .put("instanceId", instanceId ?: JSONObject.NULL).put("sessionGeneration", if (generation >= 0) generation else JSONObject.NULL)
182
+ fun save(session: JSONObject?, error: String? = null): Boolean {
183
+ val current = DeviceManager.getInstance().sgc
184
+ val receipt = JSONObject().put("schemaVersion", 1).put("request", request).put("observedAtEpochMs", System.currentTimeMillis())
185
+ .put("appPid", Process.myPid()).put("processInstanceId", processInstanceId)
186
+ .put("currentManager", JSONObject().put("type", current?.type ?: JSONObject.NULL)
187
+ .put("instanceId", (current as? Nimo)?.resourceInstanceId ?: JSONObject.NULL))
188
+ .put("session", session ?: JSONObject.NULL).put("error", error ?: JSONObject.NULL)
189
+ val pending = File(root, "$nonce.tmp")
190
+ try {
191
+ pending.outputStream().use { it.write(receipt.toString().toByteArray(Charsets.UTF_8)); it.flush() }
192
+ check(pending.renameTo(File(root, "$nonce.json")))
193
+ return true
194
+ } catch (_: Exception) { return false /* Absent receipt is unknown. */ } finally { pending.delete() }
195
+ }
196
+ if (mode in listOf("arm-capture", "capture-status", "cancel-capture")) {
197
+ val expectedName = intent.getStringExtra("expectedName")
198
+ val captureNonce = intent.getStringExtra("captureNonce")
199
+ request.remove("instanceId"); request.remove("sessionGeneration")
200
+ request.put("expectedName", expectedName ?: JSONObject.NULL).put("captureNonce", captureNonce ?: JSONObject.NULL)
201
+ if (!Regex("^[0-9A-F]{2}(:[0-9A-F]{2}){5}$").matches(address) ||
202
+ intent.extras?.keySet()?.any { it !in setOf("nonce", "mode", "expectedAddress", "expectedName", "captureNonce") } == true ||
203
+ expectedName == null || !Regex("^Nimo-[A-Za-z0-9]{1,32}$").matches(expectedName) ||
204
+ captureNonce == null || !uuid(captureNonce)) { save(null, "invalid-fixed-capture-request"); return }
205
+ if (mode == "arm-capture") {
206
+ val manager = DeviceManager.getInstance().sgc
207
+ if (capture != null || captureNonce != nonce || manager != null) {
208
+ save(null, "capture-arm-refused-existing-owner"); return
209
+ }
210
+ capture = Capture(captureNonce, expectedName, address)
211
+ }
212
+ val owned = capture
213
+ if (owned == null || owned.nonce != captureNonce || owned.name != expectedName || owned.address != address) {
214
+ save(null, "capture-not-original"); return
215
+ }
216
+ fun captureReceipt(session: JSONObject? = null, error: String? = null): Boolean {
217
+ return save(JSONObject().put("capture", captureSnapshot(owned)).put("originalSession", session ?: JSONObject.NULL), error)
218
+ }
219
+ if (mode != "cancel-capture") {
220
+ if (!captureReceipt(owned.instance?.resourceSnapshot()) && mode == "arm-capture") owned.cancelled = true
221
+ return
222
+ }
223
+ owned.cancelled = true // fence before draining or emitting a no-admission receipt
224
+ val original = owned.instance
225
+ if (original == null) { captureReceipt(); return }
226
+ if (DeviceManager.getInstance().sgc !== original) { captureReceipt(original.resourceSnapshot(), "capture-cancel-refused-replacement"); return }
227
+ original.releaseCapturedResource({ DeviceManager.getInstance().sgc === original }) { result -> captureReceipt(result) }
228
+ return
229
+ }
230
+ if (mode !in listOf("status", "release") || !Regex("^[0-9A-F]{2}(:[0-9A-F]{2}){5}$").matches(address) ||
231
+ instanceId != null && !uuid(instanceId) || intent.extras?.keySet()?.any { it !in setOf("nonce", "mode", "expectedAddress", "instanceId", "sessionGeneration") } == true) {
232
+ save(null, "invalid-fixed-request"); return
233
+ }
234
+ val current = DeviceManager.getInstance().sgc as? Nimo
235
+ current?.let { track(it) }
236
+ val selected = if (instanceId != null) sessions["$instanceId:$generation"] else sessions.values.lastOrNull {
237
+ it.tombstone.getJSONObject("pair").optString("bluetoothAddress") == address
238
+ }
239
+ val candidate = selected?.instance?.get()
240
+ val live = candidate?.resourceSnapshot()
241
+ val instance = candidate?.takeIf { live?.optLong("sessionGeneration") == selected?.tombstone?.optLong("sessionGeneration") }
242
+ val snapshot = if (instance != null) live else selected?.tombstone
243
+ if (snapshot == null || snapshot.getJSONObject("pair").optString("bluetoothAddress") != address ||
244
+ generation >= 0 && snapshot.optLong("sessionGeneration", -1) != generation) {
245
+ save(null, "target-not-observed-or-generation-mismatch"); return
246
+ }
247
+ if (mode == "status") {
248
+ save(JSONObject(snapshot.toString()).put("sessionObservationCurrent", instance != null).put("source", if (instance != null) "live-original-instance" else "retained-tombstone")); return
249
+ }
250
+ if (instanceId == null || generation < 1 || instance == null || instance !== current) {
251
+ save(snapshot, "release-refused-replaced-or-unowned-target"); return
252
+ }
253
+ instance.releaseResource(generation, { DeviceManager.getInstance().sgc === instance }) { result ->
254
+ track(instance)
255
+ if (result.has("error")) save(instance.resourceSnapshot(), result.getString("error")) else save(result)
256
+ }
257
+ }
258
+
259
+ private fun uuid(value: String): Boolean = try { UUID.fromString(value).toString() == value } catch (_: IllegalArgumentException) { false }
260
+ }
@@ -25,6 +25,7 @@ import com.mentra.bluetoothsdk.sgcs.Mach1
25
25
  import com.mentra.bluetoothsdk.sgcs.MentraLive
26
26
  import com.mentra.bluetoothsdk.sgcs.MentraNex
27
27
  import com.mentra.bluetoothsdk.sgcs.Nimo
28
+ import com.mentra.bluetoothsdk.sgcs.NimoResourceDiagnostics
28
29
  import com.mentra.bluetoothsdk.sgcs.SGCManager
29
30
  import com.mentra.bluetoothsdk.sgcs.Simulated
30
31
  import com.mentra.bluetoothsdk.utils.ControllerTypes
@@ -305,7 +306,10 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
305
306
  }
306
307
  }
307
308
  initializeViewStates()
308
- if (initializeHardware) initializeHardwareServices()
309
+ if (initializeHardware) {
310
+ initializeHardwareServices()
311
+ NimoResourceDiagnostics.start(Bridge.getContext())
312
+ }
309
313
  }
310
314
 
311
315
  // Keep host routing usable without starting audio codecs, receivers or services.
@@ -1375,6 +1379,7 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
1375
1379
  // MARK: - Auxiliary Commands
1376
1380
 
1377
1381
  fun initSGC(wearable: String) {
1382
+ if (!NimoResourceDiagnostics.allowManagerConnect(wearable)) return
1378
1383
  Bridge.log("Initializing manager for wearable: $wearable")
1379
1384
  if (sgc != null && sgc?.type != wearable) {
1380
1385
  Bridge.log("MAN: Manager already initialized, cleaning up previous sgc")
@@ -2346,6 +2351,7 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2346
2351
  }
2347
2352
 
2348
2353
  fun connectDefault() {
2354
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { connectDefault() }) return
2349
2355
  if (defaultWearable.isEmpty()) {
2350
2356
  Bridge.log("MAN: No default wearable, returning")
2351
2357
  return
@@ -2367,6 +2373,7 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2367
2373
  Bridge.log("MAN: connectDefault skipped — bluetooth runtime permissions not granted")
2368
2374
  return
2369
2375
  }
2376
+ if (!NimoResourceDiagnostics.allowManagerConnect(defaultWearable, reconnectTarget)) return
2370
2377
  initSGC(defaultWearable)
2371
2378
  val live = sgc as? MentraLive
2372
2379
  if (live?.isPairingYieldActive() == true) {
@@ -2397,6 +2404,7 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2397
2404
  }
2398
2405
 
2399
2406
  fun connectByName(dName: String) {
2407
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { connectByName(dName) }) return
2400
2408
  Bridge.log("MAN: Connecting to wearable: $dName")
2401
2409
 
2402
2410
  var name = dName
@@ -2411,6 +2419,7 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2411
2419
  return
2412
2420
  }
2413
2421
 
2422
+ if (!NimoResourceDiagnostics.allowManagerConnect(pendingWearable.ifEmpty { defaultWearable }, name)) return
2414
2423
  if (pendingWearable.isEmpty() && !defaultWearable.isEmpty()) {
2415
2424
  Bridge.log("MAN: No pending wearable, using default wearable")
2416
2425
  pendingWearable = defaultWearable
@@ -2425,8 +2434,11 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2425
2434
  return
2426
2435
  }
2427
2436
 
2428
- disconnect(clearPendingIdentity = false)
2429
- Thread.sleep(100)
2437
+ if (!NimoResourceDiagnostics.allowManagerConnect(pendingWearable, name)) return
2438
+ if (!NimoResourceDiagnostics.preserveCapturedScan(pendingWearable, name)) {
2439
+ disconnect(clearPendingIdentity = false)
2440
+ Thread.sleep(100)
2441
+ }
2430
2442
  searching = true
2431
2443
  pendingDeviceName = name
2432
2444
 
@@ -2435,8 +2447,10 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2435
2447
  }
2436
2448
 
2437
2449
  fun connectDevice(deviceModel: String, deviceName: String) {
2450
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { connectDevice(deviceModel, deviceName) }) return
2438
2451
  Bridge.log("MAN: Connecting to device: $deviceModel $deviceName")
2439
2452
  if (DeviceTypes.ALL.contains(deviceModel)) {
2453
+ if (!NimoResourceDiagnostics.allowManagerConnect(deviceModel, deviceName)) return
2440
2454
  pendingWearable = deviceModel
2441
2455
  initSGC(pendingWearable)
2442
2456
  sgc?.connectById(deviceName)
@@ -2640,6 +2654,8 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2640
2654
  }
2641
2655
 
2642
2656
  fun findCompatibleDevices(deviceModel: String) {
2657
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { findCompatibleDevices(deviceModel) }) return
2658
+ if (!NimoResourceDiagnostics.allowManagerConnect(deviceModel)) return
2643
2659
  Bridge.log("MAN: Searching for compatible device names for: $deviceModel")
2644
2660
 
2645
2661
  // reset the search results:
@@ -3,9 +3,9 @@ package com.mentra.bluetoothsdk
3
3
  /** Generated by release CI. Do not edit in a release checkout. */
4
4
  internal object GeneratedReleaseMetadata {
5
5
  const val FAMILY_BASE_VERSION: String = "3.4.0"
6
- const val RELEASE_IDENTITY: String = "3.4.0-dev.957"
7
- const val RELEASE_SET_ID: String = "mentra-3.4.0-dev.957"
8
- const val SOURCE_COMMIT: String = "e3c9413a4ce6f14d8697074474bb717336dcee80"
9
- const val OTA_MANIFEST_URL: String = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.957.json"
10
- const val OTA_MANIFEST_SHA256: String = "75b864b765ff692c46f53b024bfa4972e1d6ccf43af0d46550ab0cfc494a7ddf"
6
+ const val RELEASE_IDENTITY: String = "3.4.0-dev.965"
7
+ const val RELEASE_SET_ID: String = "mentra-3.4.0-dev.965"
8
+ const val SOURCE_COMMIT: String = "7909ffb46c61953874fffacdc737f8070be28f06"
9
+ const val OTA_MANIFEST_URL: String = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.965.json"
10
+ const val OTA_MANIFEST_SHA256: String = "798e597eba66ca395abd7a77cffdb86e9f6ffa7702625361b52aba8ba434f594"
11
11
  }
@@ -9,6 +9,7 @@ import android.os.Bundle
9
9
  import android.os.Handler
10
10
  import android.os.Looper
11
11
  import android.util.Log
12
+ import com.mentra.bluetoothsdk.sgcs.NimoResourceDiagnostics
12
13
  import com.mentra.bluetoothsdk.streaming.StreamSessionState
13
14
  import com.mentra.bluetoothsdk.utils.ControllerTypes
14
15
  import com.mentra.bluetoothsdk.utils.PhoneAudioMonitor
@@ -364,6 +365,8 @@ class MentraBluetoothSdk private constructor(
364
365
  }
365
366
 
366
367
  fun startScan(model: DeviceModel) {
368
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { startScan(model) }) return
369
+ if (!NimoResourceDiagnostics.allowManagerConnect(model.deviceType)) return
367
370
  if (model != DeviceModel.SIMULATED) {
368
371
  requireBluetoothReady("scan for glasses")
369
372
  }
@@ -470,11 +473,13 @@ class MentraBluetoothSdk private constructor(
470
473
 
471
474
  @JvmOverloads
472
475
  fun connect(device: Device, options: ConnectOptions = ConnectOptions()) {
476
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { connect(device, options) }) return
477
+ if (!NimoResourceDiagnostics.allowManagerConnect(device.model.deviceType, device.name)) return
473
478
  if (device.model != DeviceModel.SIMULATED) {
474
479
  requireBluetoothReady("connect to glasses")
475
480
  }
476
481
  val isController = ControllerTypes.ALL.contains(device.model.deviceType)
477
- if (options.cancelExistingConnectionAttempt) {
482
+ if (options.cancelExistingConnectionAttempt && !NimoResourceDiagnostics.preserveCapturedScan(device.model.deviceType, device.name)) {
478
483
  if (isController) {
479
484
  deviceManager.disconnectController()
480
485
  } else {
@@ -511,16 +516,18 @@ class MentraBluetoothSdk private constructor(
511
516
 
512
517
  @JvmOverloads
513
518
  fun connectDefault(options: ConnectOptions = ConnectOptions()) {
519
+ if (NimoResourceDiagnostics.dispatchCapturedEntry { connectDefault(options) }) return
514
520
  val defaultDevice =
515
521
  currentDefaultDevice()
516
522
  ?: throw BluetoothSdkException(
517
523
  "default_device_missing",
518
524
  "Set a default glasses device before calling connectDefault.",
519
525
  )
526
+ if (!NimoResourceDiagnostics.allowManagerConnect(defaultDevice.model.deviceType, defaultDevice.name)) return
520
527
  if (defaultDevice.model != DeviceModel.SIMULATED) {
521
528
  requireBluetoothReady("connect to glasses")
522
529
  }
523
- if (options.cancelExistingConnectionAttempt) {
530
+ if (options.cancelExistingConnectionAttempt && !NimoResourceDiagnostics.preserveCapturedScan(defaultDevice.model.deviceType, defaultDevice.name)) {
524
531
  cancelConnectionAttempt()
525
532
  }
526
533
  deviceManager.connectDefault()