@mentra/bluetooth-sdk 3.4.0-beta.1298 → 3.4.0-beta.1301

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.
@@ -2344,6 +2344,17 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
2344
2344
  sgc?.sendRgbLedControl(requestId, packageName, action, color, onDurationMs, offDurationMs, count)
2345
2345
  }
2346
2346
 
2347
+ /**
2348
+ * The person disconnected the glasses outside the app, in Android's Bluetooth settings. Like
2349
+ * the app's Disconnect, nothing reconnects them until the person connects again.
2350
+ */
2351
+ fun disconnectByUser() {
2352
+ Bridge.log("MAN: Glasses disconnected in Android's Bluetooth settings")
2353
+ DeviceStore.apply("bluetooth", "glasses_user_disconnected", true)
2354
+ Bridge.saveSetting("glasses_user_disconnected", true)
2355
+ disconnect()
2356
+ }
2357
+
2347
2358
  /** Glasses the person disconnected in the app stay disconnected. */
2348
2359
  internal fun shouldReconnectAfterBluetoothOn(): Boolean =
2349
2360
  defaultWearable.isNotEmpty() && deviceName.isNotEmpty() &&
@@ -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-beta.1298"
7
- const val RELEASE_SET_ID: String = "mentra-3.4.0-beta.1298"
8
- const val SOURCE_COMMIT: String = "da505cc7c363e458588c70353bf21667a2397803"
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-beta.1298.json"
10
- const val OTA_MANIFEST_SHA256: String = "f9987322fefc5896ce7e95778d1df190f15041a00aa6000d0dfcd97f20e8ed06"
6
+ const val RELEASE_IDENTITY: String = "3.4.0-beta.1301"
7
+ const val RELEASE_SET_ID: String = "mentra-3.4.0-beta.1301"
8
+ const val SOURCE_COMMIT: String = "4d2f7ba80d269bf2371c689f34eb379a47900877"
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-beta.1301.json"
10
+ const val OTA_MANIFEST_SHA256: String = "d69bcbf3e13f9451628aa0145ebfd9f597ed213aee5a0dc322700e82a343b80e"
11
11
  }
@@ -11,6 +11,18 @@ internal fun readyClassicAudioSnapshot(states: Map<ClassicAudioProfile, Boolean>
11
11
  return if (connected.isNotEmpty() || states.size == ClassicAudioProfile.entries.size) connected else null
12
12
  }
13
13
 
14
+ /**
15
+ * Android is disconnecting the whole device, not one profile: every profile that was connected
16
+ * started disconnecting within [windowMs] of [nowMs]. Turning off Media or Call audio leaves the
17
+ * other one up.
18
+ */
19
+ internal fun wholeClassicDeviceDisconnecting(
20
+ wereUp: Set<ClassicAudioProfile>,
21
+ disconnectingAt: Map<ClassicAudioProfile, Long>,
22
+ nowMs: Long,
23
+ windowMs: Long,
24
+ ): Boolean = wereUp.all { profile -> disconnectingAt[profile]?.let { nowMs - it <= windowMs } == true }
25
+
14
26
  /**
15
27
  * Tracks the Android Classic audio profiles for one dual-mode glasses device.
16
28
  *
@@ -29,6 +41,9 @@ internal class ClassicAudioConnectionTracker(
29
41
  val connected: Boolean
30
42
  get() = connectedProfiles.isNotEmpty()
31
43
 
44
+ @Synchronized
45
+ fun connectedProfiles(): Set<ClassicAudioProfile> = connectedProfiles.toSet()
46
+
32
47
  /** BLE may already be gone when the user explicitly disconnects Classic audio. */
33
48
  @Synchronized
34
49
  fun targetForDisconnect(): String? = targetAddress
@@ -155,6 +155,12 @@ class MentraLive : SGCManager() {
155
155
  private const val A2DP_CONNECT_MAX_ATTEMPTS = 5
156
156
  private const val A2DP_CONNECT_RETRY_MS = 800L
157
157
  private const val UNPAIR_FLUSH_MS = 400L
158
+ /** Classic profile disconnects this soon after the app's own teardown are the app's. */
159
+ private const val OWN_CLASSIC_TEARDOWN_MS = 10_000L
160
+ /** Classic profiles going down this close together are one disconnect of the whole device. */
161
+ private const val CLASSIC_DISCONNECT_PAIR_MS = 3_000L
162
+ /** How long after the Classic drop the glasses must still be answering over BLE. */
163
+ private const val CLASSIC_DISCONNECT_CONFIRM_MS = 2_000L
158
164
  // Longer than the glasses' bounded relay of one report (BES logs, two file transfers,
159
165
  // the phone POST), so an unreleased name cannot be reused while its report is in flight.
160
166
  internal const val INCIDENT_RELAY_OWNERSHIP_MS = 10 * 60_000L
@@ -692,6 +698,13 @@ class MentraLive : SGCManager() {
692
698
  private var secureFirmwareRefreshRunnable: Runnable? = null
693
699
  /** elapsedRealtime of the last GATT link that was not an explicit pairing attempt. */
694
700
  private var lastAutoReconnectLinkAt: Long? = null
701
+ /** elapsedRealtime of the app's last own A2DP/HFP teardown. */
702
+ private var lastOwnClassicTeardownAt: Long? = null
703
+ /** elapsedRealtime when Android started disconnecting each Classic profile. */
704
+ private val classicDisconnectingAt = mutableMapOf<ClassicAudioProfile, Long>()
705
+ private var classicDisconnectCheck: Runnable? = null
706
+ /** elapsedRealtime of the last message from the glasses. */
707
+ private var lastInboundAt = 0L
695
708
  /** Hold GATT teardown until the unpair write can leave the phone. */
696
709
  private var unpairFlushPending = false
697
710
  private var unpairFlushRunnable: Runnable? = null
@@ -4338,6 +4351,7 @@ class MentraLive : SGCManager() {
4338
4351
  }
4339
4352
  BleTraceLogger.logJson("glasses_to_phone", "sdk_ble_event", json, null)
4340
4353
  GlassesLinkDiagnostics.recordInbound()
4354
+ lastInboundAt = SystemClock.elapsedRealtime()
4341
4355
 
4342
4356
  if (MessageChunker.isChunkedMessage(json)) {
4343
4357
  processChunkedJsonMessage(json)
@@ -8010,11 +8024,56 @@ class MentraLive : SGCManager() {
8010
8024
  if (intent?.action != BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED &&
8011
8025
  intent?.action != BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED) return
8012
8026
  val device = intent.bluetoothDeviceExtra() ?: return
8027
+ noteClassicDisconnecting(device, intent)
8013
8028
  refreshClassicAudioConnectionState(device)
8014
8029
  }
8015
8030
  }
8016
8031
  }
8017
8032
 
8033
+ /**
8034
+ * Android's Bluetooth settings Disconnect drops every Classic profile of the glasses (A2DP,
8035
+ * and HFP unless the unworn glasses closed it) and leaves the app's BLE link up, so Home went
8036
+ * on showing them connected. When all the connected profiles start disconnecting within
8037
+ * [CLASSIC_DISCONNECT_PAIR_MS] while the app neither asked nor lost BLE, and the glasses
8038
+ * answer over BLE within [CLASSIC_DISCONNECT_CONFIRM_MS], the person disconnected them: it
8039
+ * lasts like the app's Disconnect, even if the glasses paged their audio back meanwhile. A
8040
+ * restart, power off, pairing window or range loss takes BLE down too; turning off Media or
8041
+ * Call audio leaves the other profile up.
8042
+ */
8043
+ private fun noteClassicDisconnecting(device: BluetoothDevice, intent: Intent) {
8044
+ if (intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1) != BluetoothProfile.STATE_CONNECTED ||
8045
+ intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1) != BluetoothProfile.STATE_DISCONNECTING
8046
+ ) {
8047
+ return
8048
+ }
8049
+ if (isKilled || !isConnected || connectedDevice?.address != device.address) return
8050
+ if (bluetoothAdapter?.state != BluetoothAdapter.STATE_ON) return
8051
+ val now = SystemClock.elapsedRealtime()
8052
+ val ownTeardownAt = lastOwnClassicTeardownAt
8053
+ if (ownTeardownAt != null && now - ownTeardownAt < OWN_CLASSIC_TEARDOWN_MS) return
8054
+ val profile =
8055
+ if (intent.action == BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED) ClassicAudioProfile.A2DP
8056
+ else ClassicAudioProfile.HEADSET
8057
+ classicDisconnectingAt[profile] = now
8058
+ val wereUp = classicAudioConnectionTracker.connectedProfiles() + profile
8059
+ if (!wholeClassicDeviceDisconnecting(wereUp, classicDisconnectingAt, now, CLASSIC_DISCONNECT_PAIR_MS)) return
8060
+ if (classicDisconnectCheck != null) return
8061
+ Bridge.log("LIVE: Classic: Android is disconnecting the glasses' audio - checking the glasses stay up")
8062
+ val session = gattEpoch
8063
+ sendJsonWithoutAck(JSONObject().put("type", "ping"))
8064
+ val check =
8065
+ Runnable {
8066
+ classicDisconnectCheck = null
8067
+ if (isKilled || !isConnected || gattEpoch != session || lastInboundAt <= now) {
8068
+ return@Runnable
8069
+ }
8070
+ Bridge.log("LIVE: Classic: Android disconnected the glasses - staying disconnected")
8071
+ DeviceManager.getInstance().disconnectByUser()
8072
+ }
8073
+ classicDisconnectCheck = check
8074
+ handler.postDelayed(check, CLASSIC_DISCONNECT_CONFIRM_MS)
8075
+ }
8076
+
8018
8077
  private fun registerClassicAudioReceiver() {
8019
8078
  val ctx = context ?: return
8020
8079
  val receiver = classicAudioReceiver ?: return
@@ -8648,6 +8707,7 @@ class MentraLive : SGCManager() {
8648
8707
  // The BLE device reference may already be cleared after a GATT drop. The tracker owns the
8649
8708
  // authoritative target address, so let it decide whether this teardown belongs to the
8650
8709
  // active Classic session instead of consulting connectedDevice.
8710
+ lastOwnClassicTeardownAt = SystemClock.elapsedRealtime()
8651
8711
  if (classicAudioConnectionTracker.invalidate(device.address)) {
8652
8712
  audioConnected = false
8653
8713
  }
@@ -19,6 +19,32 @@ class ClassicAudioConnectionTrackerTest {
19
19
  ClassicAudioProfile.HEADSET to false))).isEmpty()
20
20
  }
21
21
 
22
+ private val both = setOf(ClassicAudioProfile.A2DP, ClassicAudioProfile.HEADSET)
23
+
24
+ @Test
25
+ fun `android Disconnect drops every connected profile together`() {
26
+ val at = mapOf(ClassicAudioProfile.HEADSET to 1_000L, ClassicAudioProfile.A2DP to 1_001L)
27
+ assertThat(wholeClassicDeviceDisconnecting(both, at, 1_001L, 3_000L)).isTrue()
28
+ }
29
+
30
+ @Test
31
+ fun `turning off Media or Call audio is not a disconnect`() {
32
+ assertThat(wholeClassicDeviceDisconnecting(both, mapOf(ClassicAudioProfile.A2DP to 1_000L), 1_000L, 3_000L)).isFalse()
33
+ assertThat(wholeClassicDeviceDisconnecting(both, mapOf(ClassicAudioProfile.HEADSET to 1_000L), 1_000L, 3_000L)).isFalse()
34
+ }
35
+
36
+ @Test
37
+ fun `unworn glasses with only A2DP up are disconnected by that profile alone`() {
38
+ val a2dp = setOf(ClassicAudioProfile.A2DP)
39
+ assertThat(wholeClassicDeviceDisconnecting(a2dp, mapOf(ClassicAudioProfile.A2DP to 1_000L), 1_000L, 3_000L)).isTrue()
40
+ }
41
+
42
+ @Test
43
+ fun `two profile toggles far apart are not one disconnect`() {
44
+ val at = mapOf(ClassicAudioProfile.HEADSET to 1_000L, ClassicAudioProfile.A2DP to 10_000L)
45
+ assertThat(wholeClassicDeviceDisconnecting(both, at, 10_000L, 3_000L)).isFalse()
46
+ }
47
+
22
48
  private val address = "AA:BB:CC:DD:EE:FF"
23
49
 
24
50
  private fun snapshot(tracker: ClassicAudioConnectionTracker, vararg profiles: ClassicAudioProfile) {
@@ -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-beta.1298",
5
- "releaseSetId": "mentra-3.4.0-beta.1298",
6
- "sourceCommit": "da505cc7c363e458588c70353bf21667a2397803",
7
- "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-beta.1298.json",
8
- "otaManifestSha256": "f9987322fefc5896ce7e95778d1df190f15041a00aa6000d0dfcd97f20e8ed06"
4
+ "releaseIdentity": "3.4.0-beta.1301",
5
+ "releaseSetId": "mentra-3.4.0-beta.1301",
6
+ "sourceCommit": "4d2f7ba80d269bf2371c689f34eb379a47900877",
7
+ "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-beta.1301.json",
8
+ "otaManifestSha256": "d69bcbf3e13f9451628aa0145ebfd9f597ed213aee5a0dc322700e82a343b80e"
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,iBAAiB;IACpC,cAAc,EAAE,wBAAwB;IACxC,cAAc,EAAE,0CAA0C;IAC1D,gBAAgB,EAAE,mIAAmI;IACrJ,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-beta.1298\",\n \"releaseSetId\": \"mentra-3.4.0-beta.1298\",\n \"sourceCommit\": \"da505cc7c363e458588c70353bf21667a2397803\",\n \"otaManifestUrl\": \"https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-beta.1298.json\",\n \"otaManifestSha256\": \"f9987322fefc5896ce7e95778d1df190f15041a00aa6000d0dfcd97f20e8ed06\"\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,iBAAiB;IACpC,cAAc,EAAE,wBAAwB;IACxC,cAAc,EAAE,0CAA0C;IAC1D,gBAAgB,EAAE,mIAAmI;IACrJ,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-beta.1301\",\n \"releaseSetId\": \"mentra-3.4.0-beta.1301\",\n \"sourceCommit\": \"4d2f7ba80d269bf2371c689f34eb379a47900877\",\n \"otaManifestUrl\": \"https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-beta.1301.json\",\n \"otaManifestSha256\": \"d69bcbf3e13f9451628aa0145ebfd9f597ed213aee5a0dc322700e82a343b80e\"\n})\n"]}
@@ -16,7 +16,7 @@ enum BluetoothSdkDefaults {
16
16
  /// 20-minute unworn power-off 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-beta.1298"
19
+ private static let swiftPackageSdkVersion = "3.4.0-beta.1301"
20
20
  private static let swiftPackageSdkVersionPlaceholder = "__MENTRA" + "_BLUETOOTH_SDK_VERSION__"
21
21
 
22
22
  private static func normalizedSdkVersion(_ value: String?) -> String? {
@@ -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-beta.1298"
7
- static let releaseSetId = "mentra-3.4.0-beta.1298"
8
- static let sourceCommit = "da505cc7c363e458588c70353bf21667a2397803"
9
- static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-beta.1298.json"
10
- static let otaManifestSha256 = "f9987322fefc5896ce7e95778d1df190f15041a00aa6000d0dfcd97f20e8ed06"
6
+ static let releaseIdentity = "3.4.0-beta.1301"
7
+ static let releaseSetId = "mentra-3.4.0-beta.1301"
8
+ static let sourceCommit = "4d2f7ba80d269bf2371c689f34eb379a47900877"
9
+ static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-beta.1301.json"
10
+ static let otaManifestSha256 = "d69bcbf3e13f9451628aa0145ebfd9f597ed213aee5a0dc322700e82a343b80e"
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/bluetooth-sdk",
3
- "version": "3.4.0-beta.1298",
3
+ "version": "3.4.0-beta.1301",
4
4
  "description": "SDK for communicating with smart glasses",
5
5
  "main": "build/index.js",
6
6
  "react-native": "src/index.ts",
@@ -115,7 +115,7 @@
115
115
  "registry": "https://registry.npmjs.org/"
116
116
  },
117
117
  "dependencies": {
118
- "@mentra/cloud-protocol": "3.4.0-beta.1298"
118
+ "@mentra/cloud-protocol": "3.4.0-beta.1301"
119
119
  },
120
120
  "devDependencies": {
121
121
  "@types/node": "^25.9.3",
@@ -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-beta.1298",
16
- "releaseSetId": "mentra-3.4.0-beta.1298",
17
- "sourceCommit": "da505cc7c363e458588c70353bf21667a2397803",
18
- "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-beta.1298.json",
19
- "otaManifestSha256": "f9987322fefc5896ce7e95778d1df190f15041a00aa6000d0dfcd97f20e8ed06"
15
+ "releaseIdentity": "3.4.0-beta.1301",
16
+ "releaseSetId": "mentra-3.4.0-beta.1301",
17
+ "sourceCommit": "4d2f7ba80d269bf2371c689f34eb379a47900877",
18
+ "otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-beta.1301.json",
19
+ "otaManifestSha256": "d69bcbf3e13f9451628aa0145ebfd9f597ed213aee5a0dc322700e82a343b80e"
20
20
  })