@mentra/bluetooth-sdk 3.4.0-dev.949 → 3.4.0-dev.951

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.
@@ -1,10 +1,10 @@
1
1
  export const BLUETOOTH_SDK_RELEASE_METADATA = Object.freeze({
2
2
  "schemaVersion": 1,
3
3
  "familyBaseVersion": "3.4.0",
4
- "releaseIdentity": "3.4.0-dev.949",
5
- "releaseSetId": "mentra-3.4.0-dev.949",
6
- "sourceCommit": "db6b4cda6341549d79b0ca6321785c0ae3d480c3",
7
- "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.949.json",
8
- "otaManifestSha256": "bb0be7ec3410dd7e5db8a3777606e299aa8baea03c61275b8f3b1d0b4a5efb55"
4
+ "releaseIdentity": "3.4.0-dev.951",
5
+ "releaseSetId": "mentra-3.4.0-dev.951",
6
+ "sourceCommit": "f9be3585fd1da406b0884ed01cc8075157e5d3dd",
7
+ "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.951.json",
8
+ "otaManifestSha256": "a736a19a494f34b518f3e4d0468e85fdfd22c0032855636e1191e4a58b460fdb"
9
9
  });
10
10
  //# sourceMappingURL=releaseMetadata.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"releaseMetadata.js","sourceRoot":"","sources":["../../src/generated/releaseMetadata.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,8BAA8B,GAA0C,MAAM,CAAC,MAAM,CAAC;IACjG,eAAe,EAAE,CAAC;IAClB,mBAAmB,EAAE,OAAO;IAC5B,iBAAiB,EAAE,eAAe;IAClC,cAAc,EAAE,sBAAsB;IACtC,cAAc,EAAE,0CAA0C;IAC1D,gBAAgB,EAAE,iIAAiI;IACnJ,mBAAmB,EAAE,kEAAkE;CACxF,CAAC,CAAA","sourcesContent":["/** Generated by release CI. Do not edit in a release checkout. */\nexport interface BluetoothSdkReleaseMetadata {\n schemaVersion: 1\n familyBaseVersion: string | null\n releaseIdentity: string | null\n releaseSetId: string | null\n sourceCommit: string | null\n otaManifestUrl: string | null\n otaManifestSha256: string | null\n}\n\nexport const BLUETOOTH_SDK_RELEASE_METADATA: Readonly<BluetoothSdkReleaseMetadata> = Object.freeze({\n \"schemaVersion\": 1,\n \"familyBaseVersion\": \"3.4.0\",\n \"releaseIdentity\": \"3.4.0-dev.949\",\n \"releaseSetId\": \"mentra-3.4.0-dev.949\",\n \"sourceCommit\": \"db6b4cda6341549d79b0ca6321785c0ae3d480c3\",\n \"otaManifestUrl\": \"https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.949.json\",\n \"otaManifestSha256\": \"bb0be7ec3410dd7e5db8a3777606e299aa8baea03c61275b8f3b1d0b4a5efb55\"\n})\n"]}
1
+ {"version":3,"file":"releaseMetadata.js","sourceRoot":"","sources":["../../src/generated/releaseMetadata.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,8BAA8B,GAA0C,MAAM,CAAC,MAAM,CAAC;IACjG,eAAe,EAAE,CAAC;IAClB,mBAAmB,EAAE,OAAO;IAC5B,iBAAiB,EAAE,eAAe;IAClC,cAAc,EAAE,sBAAsB;IACtC,cAAc,EAAE,0CAA0C;IAC1D,gBAAgB,EAAE,iIAAiI;IACnJ,mBAAmB,EAAE,kEAAkE;CACxF,CAAC,CAAA","sourcesContent":["/** Generated by release CI. Do not edit in a release checkout. */\nexport interface BluetoothSdkReleaseMetadata {\n schemaVersion: 1\n familyBaseVersion: string | null\n releaseIdentity: string | null\n releaseSetId: string | null\n sourceCommit: string | null\n otaManifestUrl: string | null\n otaManifestSha256: string | null\n}\n\nexport const BLUETOOTH_SDK_RELEASE_METADATA: Readonly<BluetoothSdkReleaseMetadata> = Object.freeze({\n \"schemaVersion\": 1,\n \"familyBaseVersion\": \"3.4.0\",\n \"releaseIdentity\": \"3.4.0-dev.951\",\n \"releaseSetId\": \"mentra-3.4.0-dev.951\",\n \"sourceCommit\": \"f9be3585fd1da406b0884ed01cc8075157e5d3dd\",\n \"otaManifestUrl\": \"https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.951.json\",\n \"otaManifestSha256\": \"a736a19a494f34b518f3e4d0468e85fdfd22c0032855636e1191e4a58b460fdb\"\n})\n"]}
@@ -429,9 +429,9 @@ public class BluetoothSdkModule: Module, MentraBluetoothSDKDelegate {
429
429
  }
430
430
  }
431
431
 
432
- AsyncFunction("setWifiAdbState") { (enabled: Bool) in
432
+ AsyncFunction("setWifiAdbState") { (enabled: Bool, expectedBluetoothMac: String?) in
433
433
  let sdk = await MainActor.run { self.bluetoothSdk() }
434
- try await sdk.setWifiAdbState(enabled: enabled)
434
+ try await sdk.setWifiAdbState(enabled: enabled, expectedBluetoothMac: expectedBluetoothMac)
435
435
  }
436
436
 
437
437
  AsyncFunction("setSystemTime") { (timestampMs: Double) in
@@ -16,7 +16,7 @@ enum BluetoothSdkDefaults {
16
16
  /// silently disable it on every pair the app touches.
17
17
  static let autoPowerOffEnabled = false
18
18
  private static let infoSdkVersionKey = "MentraBluetoothSdkVersion"
19
- private static let swiftPackageSdkVersion = "3.4.0-dev.949"
19
+ private static let swiftPackageSdkVersion = "3.4.0-dev.951"
20
20
  private static let swiftPackageSdkVersionPlaceholder = "__MENTRA" + "_BLUETOOTH_SDK_VERSION__"
21
21
 
22
22
  private static func normalizedSdkVersion(_ value: String?) -> String? {
@@ -1540,6 +1540,15 @@ struct ViewState {
1540
1540
  sgc?.sendHotspotState(enabled)
1541
1541
  }
1542
1542
 
1543
+ func setWifiAdbState(_ enabled: Bool, expectedBluetoothMac: String?) throws {
1544
+ guard let expectedBluetoothMac else { setWifiAdbState(enabled); return }
1545
+ guard let live = sgc as? MentraLive else {
1546
+ throw BluetoothSdkError(code: "glasses_not_connected", message: "Mentra Live glasses are not connected.")
1547
+ }
1548
+ // Capture one driver; its own session identity guards the actual queue insertion.
1549
+ try live.sendWifiAdbState(enabled, expectedBluetoothMac: expectedBluetoothMac)
1550
+ }
1551
+
1543
1552
  func setWifiAdbState(_ enabled: Bool) {
1544
1553
  Bridge.log("MAN: 🔧 Setting glasses Wi-Fi ADB state: \(enabled)")
1545
1554
  sgc?.sendWifiAdbState(enabled)
@@ -3,9 +3,9 @@ import Foundation
3
3
  /// Generated by release CI. Do not edit in a release checkout.
4
4
  enum GeneratedReleaseMetadata {
5
5
  static let familyBaseVersion = "3.4.0"
6
- static let releaseIdentity = "3.4.0-dev.949"
7
- static let releaseSetId = "mentra-3.4.0-dev.949"
8
- static let sourceCommit = "db6b4cda6341549d79b0ca6321785c0ae3d480c3"
9
- static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.949.json"
10
- static let otaManifestSha256 = "bb0be7ec3410dd7e5db8a3777606e299aa8baea03c61275b8f3b1d0b4a5efb55"
6
+ static let releaseIdentity = "3.4.0-dev.951"
7
+ static let releaseSetId = "mentra-3.4.0-dev.951"
8
+ static let sourceCommit = "f9be3585fd1da406b0884ed01cc8075157e5d3dd"
9
+ static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.951.json"
10
+ static let otaManifestSha256 = "a736a19a494f34b518f3e4d0468e85fdfd22c0032855636e1191e4a58b460fdb"
11
11
  }
@@ -1185,8 +1185,12 @@ public final class MentraBluetoothSDK {
1185
1185
  /// Fire-and-forget Mentra Live Wi-Fi ADB toggle. Glasses do not ack this
1186
1186
  /// command, so there is no pending-response wait (unlike hotspot / Wi-Fi forget).
1187
1187
  public func setWifiAdbState(enabled: Bool) async throws {
1188
+ try await setWifiAdbState(enabled: enabled, expectedBluetoothMac: nil)
1189
+ }
1190
+
1191
+ public func setWifiAdbState(enabled: Bool, expectedBluetoothMac: String?) async throws {
1188
1192
  try requireGlassesConnected(operation: "toggle Wi-Fi ADB")
1189
- DeviceManager.shared.setWifiAdbState(enabled)
1193
+ try DeviceManager.shared.setWifiAdbState(enabled, expectedBluetoothMac: expectedBluetoothMac)
1190
1194
  }
1191
1195
 
1192
1196
  func setSystemTime(timestampMs: Int64) {
@@ -17,7 +17,8 @@ enum BleTraceLogger {
17
17
  bytes: Int? = nil,
18
18
  sourceFile: String = #fileID,
19
19
  sourceFunction: String = #function,
20
- sourceLine: Int = #line
20
+ sourceLine: Int = #line,
21
+ forwardToBridge: Bool = true
21
22
  ) {
22
23
  guard let payload else {
23
24
  emit(format(
@@ -27,7 +28,7 @@ enum BleTraceLogger {
27
28
  type: "null",
28
29
  bytes: bytes,
29
30
  payload: "null"
30
- ))
31
+ ), forwardToBridge: forwardToBridge)
31
32
  return
32
33
  }
33
34
 
@@ -39,7 +40,7 @@ enum BleTraceLogger {
39
40
  type: extractType(from: payload),
40
41
  bytes: bytes,
41
42
  payload: jsonString(sanitized)
42
- ))
43
+ ), forwardToBridge: forwardToBridge)
43
44
  }
44
45
 
45
46
  static func logMap(
@@ -50,7 +51,8 @@ enum BleTraceLogger {
50
51
  bytes: Int? = nil,
51
52
  sourceFile: String = #fileID,
52
53
  sourceFunction: String = #function,
53
- sourceLine: Int = #line
54
+ sourceLine: Int = #line,
55
+ forwardToBridge: Bool = true
54
56
  ) {
55
57
  let sanitized = sanitizeDictionary(payload)
56
58
  emit(format(
@@ -60,7 +62,7 @@ enum BleTraceLogger {
60
62
  type: type ?? extractType(from: sanitized),
61
63
  bytes: bytes,
62
64
  payload: jsonString(sanitized)
63
- ))
65
+ ), forwardToBridge: forwardToBridge)
64
66
  }
65
67
 
66
68
  static func logLifecycle(component: String, event: String, extra: [String: Any] = [:]) {
@@ -82,8 +84,9 @@ enum BleTraceLogger {
82
84
  logMap(direction: "phone_app", layer: "app_lifecycle", type: event, payload: payload)
83
85
  }
84
86
 
85
- private static func emit(_ line: String) {
87
+ private static func emit(_ line: String, forwardToBridge: Bool = true) {
86
88
  os_log("%{public}@", log: log, type: .info, line)
89
+ guard forwardToBridge else { return }
87
90
  // Log events are excluded from tracing in Bridge, so forwarding a trace
88
91
  // cannot recursively generate another trace.
89
92
  Bridge.sendTypedMessage("log", body: ["message": line])
@@ -1152,13 +1152,14 @@ extension MentraLive: CBPeripheralDelegate {
1152
1152
  }
1153
1153
 
1154
1154
  nonisolated func peripheral(
1155
- _: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?
1155
+ _ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?
1156
1156
  ) {
1157
+ guard let token = notificationIngress.capture(peripheral) else { return }
1157
1158
  let uuid = characteristic.uuid
1158
1159
  let data = characteristic.value
1159
1160
  let errorDescription = error?.localizedDescription
1160
1161
  DispatchQueue.main.async { [weak self] in
1161
- guard let self else { return }
1162
+ guard let self, self.connectedPeripheral === peripheral, self.notificationIngress.current(token) else { return }
1162
1163
  // Bridge.log("LIVE: DEBUG: didUpdateValueFor CALLED - characteristic: \(uuid), dataSize: \(data?.count ?? 0)")
1163
1164
  // Log raw hex for debugging glasses_ready issue
1164
1165
  if let data {
@@ -1195,7 +1196,7 @@ extension MentraLive: CBPeripheralDelegate {
1195
1196
  }
1196
1197
 
1197
1198
  // Handle regular data (JSON messages, file transfers, etc.)
1198
- self.processReceivedData(data)
1199
+ self.receiveBleNotification(data, token: token)
1199
1200
  }
1200
1201
  }
1201
1202
 
@@ -1278,6 +1279,29 @@ typealias JSONObject = [String: Any]
1278
1279
 
1279
1280
  // MARK: - Main Manager Class
1280
1281
 
1282
+ /// Captures CoreBluetooth callback provenance before its MainActor hop.
1283
+ final class MentraLiveNotificationIngress: @unchecked Sendable {
1284
+ struct Token: Equatable, Sendable { let source: ObjectIdentifier; let epoch: UInt64 }
1285
+ private let lock = NSLock()
1286
+ private var epoch: UInt64 = 0
1287
+ private var source: ObjectIdentifier?
1288
+ func begin(_ peer: AnyObject?) -> Token? {
1289
+ lock.lock(); defer { lock.unlock() }
1290
+ epoch &+= 1
1291
+ source = peer.map(ObjectIdentifier.init)
1292
+ return source.map { Token(source: $0, epoch: epoch) }
1293
+ }
1294
+ func capture(_ peer: AnyObject) -> Token? {
1295
+ lock.lock(); defer { lock.unlock() }
1296
+ guard source == ObjectIdentifier(peer) else { return nil }
1297
+ return Token(source: ObjectIdentifier(peer), epoch: epoch)
1298
+ }
1299
+ func current(_ token: Token) -> Bool {
1300
+ lock.lock(); defer { lock.unlock() }
1301
+ return source == token.source && epoch == token.epoch
1302
+ }
1303
+ }
1304
+
1281
1305
  @MainActor
1282
1306
  class MentraLive: NSObject, SGCManager {
1283
1307
  // Feature Flags
@@ -1321,11 +1345,25 @@ class MentraLive: NSObject, SGCManager {
1321
1345
  pairingAdvertisement(advertisementData) != nil
1322
1346
  }
1323
1347
 
1348
+ private nonisolated let notificationIngress = MentraLiveNotificationIngress()
1349
+ private var receivingNotification: MentraLiveNotificationIngress.Token?
1350
+ private var wifiAdbPeerIdentity: (mac: String, token: MentraLiveNotificationIngress.Token)?
1351
+ private final class WifiAdbAdmission {
1352
+ let identity: (mac: String, token: MentraLiveNotificationIngress.Token)
1353
+ let wireEpoch: Int
1354
+ var queued = 0
1355
+ var refused = false
1356
+ init(identity: (mac: String, token: MentraLiveNotificationIngress.Token), wireEpoch: Int) {
1357
+ self.identity = identity; self.wireEpoch = wireEpoch
1358
+ }
1359
+ }
1360
+ private var wifiAdbAdmission: WifiAdbAdmission?
1324
1361
  var connectionState: String = ConnTypes.DISCONNECTED
1325
1362
 
1326
1363
  /// Mirrors Android `updateConnectionState` — RN home reads `glasses.connectionState` for reconnecting UI.
1327
1364
  private func updateConnectionState(_ state: String) {
1328
1365
  if state == ConnTypes.DISCONNECTED {
1366
+ endBleNotificationSession()
1329
1367
  // Device identity is session-bound. Clear it on disconnect so a previous pair's
1330
1368
  // identifiers cannot be associated with the next connection. Connect must NOT clear
1331
1369
  // them: DeviceManager.disconnect already wipes them before any new connection, and
@@ -1530,7 +1568,9 @@ class MentraLive: NSObject, SGCManager {
1530
1568
  /// BLE Properties
1531
1569
  private var centralManager: CBCentralManager?
1532
1570
 
1533
- private var connectedPeripheral: CBPeripheral?
1571
+ private var connectedPeripheral: CBPeripheral? {
1572
+ didSet { _ = beginBleNotificationSession(source: connectedPeripheral) }
1573
+ }
1534
1574
  /// Peripheral for the in-flight connect; used to ignore stale disconnect/fail callbacks.
1535
1575
  private var connectingPeripheral: CBPeripheral?
1536
1576
  private var txCharacteristic: CBCharacteristic?
@@ -2193,11 +2233,14 @@ class MentraLive: NSObject, SGCManager {
2193
2233
  return commands.removeFirst()
2194
2234
  }
2195
2235
 
2236
+ var count: Int { commands.count }
2196
2237
  func removeAll() {
2197
2238
  commands.removeAll()
2198
2239
  }
2199
2240
  }
2200
2241
 
2242
+ var pendingBleCommandCount: Int { commandQueue.count }
2243
+
2201
2244
  private func setupCommandQueue() {
2202
2245
  Task.detached { [weak self] in
2203
2246
  guard let self else { return }
@@ -2611,6 +2654,7 @@ class MentraLive: NSObject, SGCManager {
2611
2654
  private func attachL2capFileChannel(_ channel: CBL2CAPChannel) {
2612
2655
  closeL2capFileChannel()
2613
2656
 
2657
+ guard let peer = connectedPeripheral, let token = notificationIngress.capture(peer) else { return }
2614
2658
  let channelId = UUID()
2615
2659
  l2capFileChannelId = channelId
2616
2660
  let reader = MentraLiveL2capChannel(
@@ -2620,7 +2664,7 @@ class MentraLive: NSObject, SGCManager {
2620
2664
  // while the existing transfer state remains serialized on the main actor.
2621
2665
  DispatchQueue.main.async {
2622
2666
  guard let self, self.l2capFileChannelId == channelId else { return }
2623
- self.processReceivedData(frame)
2667
+ self.receiveBleNotification(frame, token: token)
2624
2668
  }
2625
2669
  },
2626
2670
  onClose: { [weak self] in
@@ -3204,6 +3248,7 @@ class MentraLive: NSObject, SGCManager {
3204
3248
  )
3205
3249
  }
3206
3250
  if let bluetoothMacAddress = nonEmptyStringValue(fields, "bt_mac_address") {
3251
+ recordWifiAdbPeerIdentity(bluetoothMacAddress)
3207
3252
  DeviceStore.shared.apply("glasses", "bluetoothMacAddress", bluetoothMacAddress)
3208
3253
  }
3209
3254
  if let wifiMacAddress = nonEmptyStringValue(fields, "wifi_mac_address") {
@@ -3690,6 +3735,66 @@ class MentraLive: NSObject, SGCManager {
3690
3735
  sendJson(json, wakeUp: true)
3691
3736
  }
3692
3737
 
3738
+ @discardableResult func beginBleNotificationSession(source: AnyObject?) -> MentraLiveNotificationIngress.Token? {
3739
+ wifiAdbPeerIdentity = nil
3740
+ incomingChunkReassembler.clear()
3741
+ resetWireNegotiationState()
3742
+ commandQueue.removeAll()
3743
+ return notificationIngress.begin(source)
3744
+ }
3745
+
3746
+ func endBleNotificationSession() {
3747
+ wifiAdbPeerIdentity = nil
3748
+ incomingChunkReassembler.clear()
3749
+ resetWireNegotiationState()
3750
+ commandQueue.removeAll()
3751
+ _ = notificationIngress.begin(nil)
3752
+ }
3753
+
3754
+ func receiveBleNotification(_ data: Data, token: MentraLiveNotificationIngress.Token) {
3755
+ guard notificationIngress.current(token) else { return }
3756
+ let previous = receivingNotification
3757
+ receivingNotification = token
3758
+ defer { receivingNotification = previous }
3759
+ processReceivedData(data)
3760
+ }
3761
+
3762
+ private func recordWifiAdbPeerIdentity(_ mac: String) {
3763
+ guard let token = receivingNotification, notificationIngress.current(token) else { return }
3764
+ wifiAdbPeerIdentity = (mac, token)
3765
+ }
3766
+
3767
+ private func currentWifiAdbAdmission(_ admission: WifiAdbAdmission) -> Bool {
3768
+ notificationIngress.current(admission.identity.token) && wireSessionGeneration == admission.wireEpoch &&
3769
+ wifiAdbPeerIdentity?.mac == admission.identity.mac && wifiAdbLinkReady
3770
+ }
3771
+
3772
+ var wifiAdbLinkReady: Bool {
3773
+ connectionState == ConnTypes.CONNECTED && connectedPeripheral?.state == .connected && txCharacteristic != nil
3774
+ }
3775
+
3776
+ func enqueueWifiAdbState(_ enabled: Bool) -> Bool {
3777
+ // Match Wi-Fi forget: public log delegates must not reenter between validation and enqueue.
3778
+ sendJson(["type": "set_wifi_adb_state", "enabled": enabled], wakeUp: true, requireAck: true, bridgeLogging: false)
3779
+ }
3780
+
3781
+ /// MainActor performs identity validation and queue insertion without suspension.
3782
+ func sendWifiAdbState(_ enabled: Bool, expectedBluetoothMac: String) throws {
3783
+ guard expectedBluetoothMac.range(of: "^(?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$", options: .regularExpression) != nil,
3784
+ let identity = wifiAdbPeerIdentity,
3785
+ identity.mac.caseInsensitiveCompare(expectedBluetoothMac) == .orderedSame,
3786
+ notificationIngress.current(identity.token), wifiAdbLinkReady else {
3787
+ throw BluetoothSdkError(code: "device_identity_changed", message: "The selected glasses identity or connection changed.")
3788
+ }
3789
+ let admission = WifiAdbAdmission(identity: identity, wireEpoch: wireSessionGeneration)
3790
+ wifiAdbAdmission = admission
3791
+ defer { wifiAdbAdmission = nil }
3792
+ guard enqueueWifiAdbState(enabled), !admission.refused, admission.queued > 0,
3793
+ currentWifiAdbAdmission(admission) else {
3794
+ throw BluetoothSdkError(code: "command_send_failed", message: "Could not queue Wi-Fi debugging for the selected glasses.")
3795
+ }
3796
+ }
3797
+
3693
3798
  func sendWifiAdbState(_ enabled: Bool) {
3694
3799
  Bridge.log("LIVE: 🔧 Sending Wi-Fi ADB state: \(enabled)")
3695
3800
 
@@ -4043,6 +4148,7 @@ class MentraLive: NSObject, SGCManager {
4043
4148
  DeviceStore.shared.apply("glasses", "otaVersionUrl", otaVersionUrl)
4044
4149
  DeviceStore.shared.apply("glasses", "firmwareVersion", firmwareVersion)
4045
4150
  if let bluetoothMacAddress {
4151
+ recordWifiAdbPeerIdentity(bluetoothMacAddress)
4046
4152
  DeviceStore.shared.apply("glasses", "bluetoothMacAddress", bluetoothMacAddress)
4047
4153
  }
4048
4154
  if let serialNumber {
@@ -4725,6 +4831,10 @@ class MentraLive: NSObject, SGCManager {
4725
4831
  }
4726
4832
 
4727
4833
  func queueSend(_ data: Data, id: String, trace: BleWriteTrace?) {
4834
+ if let admission = wifiAdbAdmission {
4835
+ guard currentWifiAdbAdmission(admission) else { admission.refused = true; return }
4836
+ admission.queued += 1
4837
+ }
4728
4838
  let significantQueueSize = SIGNIFICANT_BLE_TRACE_QUEUE_SIZE
4729
4839
  // Insert synchronously on MainActor so fragments and dependent commands retain call order.
4730
4840
  let generation = wireSessionGeneration
@@ -4829,7 +4939,8 @@ class MentraLive: NSObject, SGCManager {
4829
4939
  }
4830
4940
  }
4831
4941
 
4832
- BleTraceLogger.logMap(direction: "phone_to_glasses", layer: layer, type: trace.commandType, payload: payload)
4942
+ BleTraceLogger.logMap(direction: "phone_to_glasses", layer: layer, type: trace.commandType, payload: payload,
4943
+ forwardToBridge: wifiAdbAdmission == nil)
4833
4944
  }
4834
4945
 
4835
4946
  private func bleTraceWarningReason(stage: String, extra: [String: Any?]) -> String? {
@@ -5159,7 +5270,8 @@ class MentraLive: NSObject, SGCManager {
5159
5270
  direction: "phone_to_glasses",
5160
5271
  layer: "sdk_ble_command",
5161
5272
  payload: json,
5162
- bytes: jsonData.count
5273
+ bytes: jsonData.count,
5274
+ forwardToBridge: bridgeLogging
5163
5275
  )
5164
5276
 
5165
5277
  if useBinaryWireProtocol, isNewVersion {
@@ -0,0 +1,118 @@
1
+ @testable import MentraBluetoothSDK
2
+ import XCTest
3
+
4
+ @MainActor
5
+ private final class WifiAdbRecordingLive: MentraLive {
6
+ var ready = true
7
+ var accepts = true
8
+ var beforeEnqueue: (() -> Void)?
9
+ override var wifiAdbLinkReady: Bool { ready }
10
+ override func enqueueWifiAdbState(_ enabled: Bool) -> Bool {
11
+ guard accepts else { return false }
12
+ beforeEnqueue?()
13
+ return super.enqueueWifiAdbState(enabled)
14
+ }
15
+ }
16
+
17
+ @MainActor
18
+ final class WifiAdbDispatchTests: XCTestCase {
19
+ let first = "AA:BB:CC:DD:EE:01"
20
+ let second = "AA:BB:CC:DD:EE:02"
21
+
22
+ func frame(_ mac: String) throws -> Data {
23
+ try JSONSerialization.data(withJSONObject: ["type": "version_info", "bt_mac_address": mac, "build_number": "0"])
24
+ }
25
+ @discardableResult func receive(_ live: MentraLive, source: NSObject, mac: String) throws -> MentraLiveNotificationIngress.Token {
26
+ let token = try XCTUnwrap(live.beginBleNotificationSession(source: source))
27
+ live.receiveBleNotification(try frame(mac), token: token)
28
+ return token
29
+ }
30
+
31
+ func testRetargetBeforeNativeDispatchCannotQueueForTheOtherPair() throws {
32
+ let manager = DeviceManager()
33
+ let old = WifiAdbRecordingLive(), replacement = WifiAdbRecordingLive()
34
+ defer { manager.sgc = nil; manager.cleanup(); old.cleanup(); replacement.cleanup() }
35
+ try receive(old, source: NSObject(), mac: first)
36
+ try receive(replacement, source: NSObject(), mac: second)
37
+ manager.sgc = old
38
+ manager.sgc = replacement
39
+ XCTAssertThrowsError(try manager.setWifiAdbState(true, expectedBluetoothMac: first))
40
+ XCTAssertEqual(old.pendingBleCommandCount, 0)
41
+ XCTAssertEqual(replacement.pendingBleCommandCount, 0)
42
+ try manager.setWifiAdbState(false, expectedBluetoothMac: second)
43
+ XCTAssertEqual(replacement.pendingBleCommandCount, 1)
44
+ }
45
+
46
+ func testDelayedOldNotificationCannotRestoreIdentityAfterReconnectIncludingSamePeripheral() throws {
47
+ for samePeripheral in [false, true] {
48
+ let live = WifiAdbRecordingLive(), oldSource = NSObject()
49
+ defer { live.cleanup() }
50
+ let oldToken = try receive(live, source: oldSource, mac: first)
51
+ live.endBleNotificationSession()
52
+ let newSource = samePeripheral ? oldSource : NSObject()
53
+ let newToken = try XCTUnwrap(live.beginBleNotificationSession(source: newSource))
54
+ live.receiveBleNotification(try frame(first), token: oldToken)
55
+ XCTAssertThrowsError(try live.sendWifiAdbState(true, expectedBluetoothMac: first))
56
+ live.receiveBleNotification(try frame(second), token: newToken)
57
+ live.receiveBleNotification(try frame(first), token: oldToken)
58
+ XCTAssertThrowsError(try live.sendWifiAdbState(true, expectedBluetoothMac: first))
59
+ try live.sendWifiAdbState(false, expectedBluetoothMac: second)
60
+ XCTAssertEqual(live.pendingBleCommandCount, 1)
61
+ }
62
+ }
63
+
64
+ func testIngressCapturesSourceAndEpochBeforeTheActorHop() throws {
65
+ let ingress = MentraLiveNotificationIngress(), first = NSObject(), second = NSObject()
66
+ let old = try XCTUnwrap(ingress.begin(first))
67
+ XCTAssertEqual(ingress.capture(first), old)
68
+ _ = ingress.begin(second)
69
+ XCTAssertNil(ingress.capture(first))
70
+ XCTAssertFalse(ingress.current(old))
71
+ }
72
+
73
+ func testNativeOnlyLoggingAndActualQueueRejectSynchronousDelegateReset() throws {
74
+ let live = WifiAdbRecordingLive(), source = NSObject()
75
+ defer { live.cleanup() }
76
+ try receive(live, source: source, mac: first)
77
+ var logs = 0
78
+ let sink = Bridge.addEventSink { event, _ in
79
+ guard event == "log" else { return }
80
+ MainActor.assumeIsolated {
81
+ logs += 1
82
+ live.ready = false
83
+ live.endBleNotificationSession()
84
+ }
85
+ }
86
+ defer { Bridge.removeEventSink(sink) }
87
+ try live.sendWifiAdbState(true, expectedBluetoothMac: first)
88
+ XCTAssertEqual(logs, 0) // real framing/queue insertion never invokes the public log sink
89
+ XCTAssertEqual(live.pendingBleCommandCount, 1)
90
+ // Simulate reentry at the former public-log boundary, retaining real framing and enqueue.
91
+ live.beforeEnqueue = { Bridge.log("test synchronous reset") }
92
+ XCTAssertThrowsError(try live.sendWifiAdbState(false, expectedBluetoothMac: first))
93
+ XCTAssertEqual(logs, 1)
94
+ XCTAssertEqual(live.pendingBleCommandCount, 0) // no newly stamped command entered the reset epoch
95
+ }
96
+
97
+ func testMissingSessionIdentityDisconnectedAndSuffixInputsQueueNothing() throws {
98
+ let live = WifiAdbRecordingLive()
99
+ defer { live.cleanup() }
100
+ XCTAssertThrowsError(try live.sendWifiAdbState(true, expectedBluetoothMac: first))
101
+ try receive(live, source: NSObject(), mac: first)
102
+ for invalid in ["EE:01", first + ":00", " " + first, second] {
103
+ XCTAssertThrowsError(try live.sendWifiAdbState(true, expectedBluetoothMac: invalid))
104
+ }
105
+ live.ready = false
106
+ XCTAssertThrowsError(try live.sendWifiAdbState(true, expectedBluetoothMac: first))
107
+ XCTAssertEqual(live.pendingBleCommandCount, 0)
108
+ }
109
+
110
+ func testRejectedQueueDoesNotResolveAsSuccessfulDispatch() throws {
111
+ let live = WifiAdbRecordingLive()
112
+ defer { live.cleanup() }
113
+ try receive(live, source: NSObject(), mac: first)
114
+ live.accepts = false
115
+ XCTAssertThrowsError(try live.sendWifiAdbState(true, expectedBluetoothMac: first))
116
+ XCTAssertEqual(live.pendingBleCommandCount, 0)
117
+ }
118
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/bluetooth-sdk",
3
- "version": "3.4.0-dev.949",
3
+ "version": "3.4.0-dev.951",
4
4
  "description": "SDK for communicating with smart glasses",
5
5
  "main": "build/index.js",
6
6
  "react-native": "src/index.ts",
@@ -114,7 +114,7 @@
114
114
  "registry": "https://registry.npmjs.org/"
115
115
  },
116
116
  "dependencies": {
117
- "@mentra/cloud-protocol": "3.4.0-dev.949"
117
+ "@mentra/cloud-protocol": "3.4.0-dev.951"
118
118
  },
119
119
  "devDependencies": {
120
120
  "@types/node": "^25.9.3",
@@ -1430,7 +1430,9 @@ export interface BluetoothSdkPublicModule {
1430
1430
  /** Set the glasses clock from the phone after an OTA clock-skew failure. */
1431
1431
  setSystemTime(timestampMs: number): Promise<void>
1432
1432
  /** Enable or disable Wi-Fi ADB on Mentra Live (no-op on other devices). */
1433
- setWifiAdbState(enabled: boolean): Promise<void>
1433
+ /** When supplied, binds native admission to this full MAC observed in the current BLE session.
1434
+ * Resolves on queue admission, without confirming glasses-side state. */
1435
+ setWifiAdbState(enabled: boolean, expectedBluetoothMac?: string): Promise<void>
1434
1436
 
1435
1437
  /**
1436
1438
  * Persistently enable/disable unauthenticated HTTP gallery access on the glasses' Wi-Fi.
@@ -136,7 +136,7 @@ declare class BluetoothSdkNativeModule extends NativeModule<BluetoothSdkModuleEv
136
136
  forgetWifiNetwork(ssid: string): Promise<WifiForgetResult>
137
137
  setHotspotState(enabled: boolean): Promise<HotspotStatusChangeEvent>
138
138
  /** Enable or disable Wi-Fi ADB on Mentra Live (no-op on other devices). */
139
- setWifiAdbState(enabled: boolean): Promise<void>
139
+ setWifiAdbState(enabled: boolean, expectedBluetoothMac?: string): Promise<void>
140
140
  /** Set the glasses system clock when phone detects clock skew (Mentra Live and G2). */
141
141
  setSystemTime(timestampMs: number): Promise<void>
142
142
  /** Logs current WiFi frequency (MHz) and 5 GHz band to Android logcat. */
@@ -12,9 +12,9 @@ export interface BluetoothSdkReleaseMetadata {
12
12
  export const BLUETOOTH_SDK_RELEASE_METADATA: Readonly<BluetoothSdkReleaseMetadata> = Object.freeze({
13
13
  "schemaVersion": 1,
14
14
  "familyBaseVersion": "3.4.0",
15
- "releaseIdentity": "3.4.0-dev.949",
16
- "releaseSetId": "mentra-3.4.0-dev.949",
17
- "sourceCommit": "db6b4cda6341549d79b0ca6321785c0ae3d480c3",
18
- "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.949.json",
19
- "otaManifestSha256": "bb0be7ec3410dd7e5db8a3777606e299aa8baea03c61275b8f3b1d0b4a5efb55"
15
+ "releaseIdentity": "3.4.0-dev.951",
16
+ "releaseSetId": "mentra-3.4.0-dev.951",
17
+ "sourceCommit": "f9be3585fd1da406b0884ed01cc8075157e5d3dd",
18
+ "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.951.json",
19
+ "otaManifestSha256": "a736a19a494f34b518f3e4d0468e85fdfd22c0032855636e1191e4a58b460fdb"
20
20
  })