@mentra/bluetooth-sdk 3.5.0-dev.1291 → 3.5.0-dev.1308

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 (44) hide show
  1. package/MIGRATION.md +15 -6
  2. package/README.md +1 -1
  3. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +4 -3
  4. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +1 -3
  5. package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +14 -0
  6. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +11 -0
  7. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
  8. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +7 -1
  9. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTracker.kt +15 -0
  10. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +78 -26
  11. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +5 -5
  12. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTrackerTest.kt +26 -0
  13. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +3 -3
  14. package/build/BluetoothSdk.types.d.ts +3 -1
  15. package/build/BluetoothSdk.types.d.ts.map +1 -1
  16. package/build/BluetoothSdk.types.js.map +1 -1
  17. package/build/_private/BluetoothSdkModule.d.ts +0 -1
  18. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  19. package/build/_private/BluetoothSdkModule.js.map +1 -1
  20. package/build/generated/releaseMetadata.js +5 -5
  21. package/build/generated/releaseMetadata.js.map +1 -1
  22. package/build/index.js +1 -1
  23. package/build/index.js.map +1 -1
  24. package/build/react/useGlassesConnection.d.ts +1 -1
  25. package/build/react/useGlassesConnection.d.ts.map +1 -1
  26. package/build/react/useGlassesConnection.js +3 -3
  27. package/build/react/useGlassesConnection.js.map +1 -1
  28. package/build/react/useMentraBluetooth.d.ts +1 -1
  29. package/build/react/useMentraBluetooth.d.ts.map +1 -1
  30. package/build/react/useMentraBluetooth.js +1 -1
  31. package/build/react/useMentraBluetooth.js.map +1 -1
  32. package/ios/BluetoothSdkModule.swift +1 -7
  33. package/ios/Source/BluetoothSdkDefaults.swift +5 -5
  34. package/ios/Source/Bridge.swift +14 -0
  35. package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
  36. package/ios/Source/MentraBluetoothSDK.swift +8 -1
  37. package/ios/Source/sgcs/MentraLive.swift +15 -23
  38. package/package.json +2 -2
  39. package/src/BluetoothSdk.types.ts +3 -1
  40. package/src/_private/BluetoothSdkModule.ts +0 -1
  41. package/src/generated/releaseMetadata.ts +5 -5
  42. package/src/index.ts +1 -1
  43. package/src/react/useGlassesConnection.ts +4 -4
  44. package/src/react/useMentraBluetooth.ts +2 -2
package/MIGRATION.md CHANGED
@@ -1,21 +1,30 @@
1
- # Bluetooth SDK migration: Mentra Live pairing state
1
+ # Bluetooth SDK migration
2
2
 
3
- This note covers the public pairing API change in `@mentra/bluetooth-sdk` `3.3.0`, for apps upgrading from `3.2`.
3
+ Public API changes in `@mentra/bluetooth-sdk`, for apps upgrading from an earlier release.
4
4
 
5
- ## Version
5
+ ## `3.4.0`: `unpair()` replaces `clearDefaultDevice()`
6
+
7
+ - `clearDefaultDevice()` is removed, in TypeScript, Kotlin and Swift. It forgot the saved default device but left the phone bonded with the glasses, so the next pairing skipped pairing mode.
8
+ - Use `unpair()`: it disconnects, forgets the default device and, on Mentra Live, removes the phone's Bluetooth bond, so pairing again starts from pairing mode. `forget()` is unchanged.
9
+
10
+ ## `3.3.0`: Mentra Live pairing state
11
+
12
+ This covers the public pairing API change in `3.3.0`, for apps upgrading from `3.2`.
13
+
14
+ ### Version
6
15
 
7
16
  The SDK version is `package.json` `"version"`. The iOS podspec (`ios/MentraBluetoothSDK.podspec`) and the Android Gradle module (`android/build.gradle`) read that same value. Swift package metadata is injected from it at pack time.
8
17
 
9
18
  This repository keeps the Bluetooth SDK version aligned with the matching Mentra Live software release. It does not cut an independent major for a breaking SDK change. The break below shipped in `3.3.0`. Apps on `3.2.1` pick it up by moving to `3.3.0` or later.
10
19
 
11
- ## Removed
20
+ ### Removed
12
21
 
13
22
  - `confirmReplaceOwner()` is removed.
14
23
  - The `confirm_replace_owner_result` event and its types are removed.
15
24
  - `owner_replaced` is deprecated and is never emitted. Remove listeners. Use `pairing_state_changed` or `GlassesStatus.pairingState`.
16
25
  - `pairing_info` no longer includes `awaiting_confirm` or `retained_owner_link`.
17
26
 
18
- ## Added
27
+ ### Added
19
28
 
20
29
  `GlassesStatus.pairingState` (absent on models other than Mentra Live):
21
30
 
@@ -54,7 +63,7 @@ Other additions:
54
63
  - `pairing_info.auto_audio` is true when the glasses derive Classic audio from the LE pair (CTKD). The SDK already uses it for `audioSetup`.
55
64
  - `pair_failure.code` may be `"ios_forget_pairing"`: iOS holds a stale Bluetooth pairing for these glasses during an explicit attempt. The user must open Settings > Bluetooth, choose Forget This Device, then pair again. On Android and iOS native apps this arrives as the pairing-failure error's `failureCode`.
56
65
 
57
- ## Behavior
66
+ ### Behavior
58
67
 
59
68
  On supported Mentra Live firmware, three presses of the power button open one 120-second pairing window. The glasses speak a 4-character code. Three presses again cancel the window. After a timeout or a cancel, the phone that was already paired reconnects automatically. If another phone pairs, that previous phone gets `pairing_rejected`. Pairing readiness needs no app-side `pairing_info` wait: the SDK reports the glasses ready only after secure firmware commits the bond, and treats glasses that send no `pairing_info` within 5 seconds as older firmware.
60
69
 
package/README.md CHANGED
@@ -446,7 +446,7 @@ const discoveredDevice = await scanAndChooseDevice()
446
446
  await BluetoothSdk.connect(discoveredDevice)
447
447
  await saveDeviceToYourAppStorage(discoveredDevice)
448
448
 
449
- await BluetoothSdk.clearDefaultDevice()
449
+ await BluetoothSdk.unpair()
450
450
  await saveDeviceToYourAppStorage(null)
451
451
  ```
452
452
 
@@ -6,8 +6,9 @@ object BluetoothSdkDefaults {
6
6
  const val LOUDNESS_GATE_ENABLED = true
7
7
 
8
8
  /**
9
- * Must match the firmware default (on). Re-pushed on connect, so a false
10
- * value here would silently turn it off on every pair the app touches.
9
+ * Must match the firmware and Mentra App default (off). Re-pushed on
10
+ * connect, so a true value here turns on the 20-minute unworn power-off on
11
+ * every pair the app touches.
11
12
  */
12
- const val AUTO_POWER_OFF_ENABLED = true
13
+ const val AUTO_POWER_OFF_ENABLED = false
13
14
  }
@@ -546,8 +546,6 @@ class BluetoothSdkModule : Module() {
546
546
  sdk?.setDefaultDevice(device.toMentraDevice())
547
547
  }
548
548
 
549
- SdkAsyncFunction("clearDefaultDevice") { -> sdk?.clearDefaultDevice() }
550
-
551
549
  SdkAsyncFunction("connectWithOptions") { device: Map<String, Any>, options: Map<String, Any> ->
552
550
  sdk?.connect(
553
551
  device.toMentraDevice()
@@ -562,7 +560,7 @@ class BluetoothSdkModule : Module() {
562
560
 
563
561
  SdkAsyncFunction("forget") { -> sdk?.forget() }
564
562
 
565
- SdkCoroutineFunction("unpair") { -> deviceManager?.unpair() }
563
+ SdkCoroutineFunction("unpair") { -> sdk?.unpair() }
566
564
 
567
565
  AsyncFunction("connectDefaultController") { deviceManager?.connectDefaultController() }
568
566
 
@@ -336,6 +336,20 @@ public class Bridge private constructor() {
336
336
  DeviceStore.set("bluetooth", "searchResults", uniqueResults)
337
337
  }
338
338
 
339
+ /** Drop glasses from the search results, for example when their pairing window closed. */
340
+ @JvmStatic
341
+ fun removeDiscoveredDevice(deviceModel: String, deviceName: String) {
342
+ val searchResults =
343
+ DeviceStore.store.getCategory("bluetooth")["searchResults"] as? List<*> ?: return
344
+ val remaining =
345
+ searchResults.filterNot { result ->
346
+ val values = result as? Map<*, *>
347
+ values?.get("model") == deviceModel && values["name"] == deviceName
348
+ }
349
+ if (remaining.size == searchResults.size) return
350
+ DeviceStore.set("bluetooth", "searchResults", remaining)
351
+ }
352
+
339
353
  private fun mergeStableSearchResults(
340
354
  currentResults: List<Map<String, Any>>,
341
355
  newResult: Map<String, Any>,
@@ -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.5.0"
6
- const val RELEASE_IDENTITY: String = "3.5.0-dev.1291"
7
- const val RELEASE_SET_ID: String = "mentra-3.5.0-dev.1291"
8
- const val SOURCE_COMMIT: String = "2ffa7667c0552de5c1c45df3f4465652abf4893c"
9
- const val OTA_MANIFEST_URL: String = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.5.0/mentra-live-ota-3.5.0-dev.1291.json"
10
- const val OTA_MANIFEST_SHA256: String = "88d0da6e0ae867d5f4df3ae914008c3913a2d0e1bac7b676a8ce4c42bab119dc"
6
+ const val RELEASE_IDENTITY: String = "3.5.0-dev.1308"
7
+ const val RELEASE_SET_ID: String = "mentra-3.5.0-dev.1308"
8
+ const val SOURCE_COMMIT: String = "6ad1a1d1cf362452478d58eb15db3293cdc760f3"
9
+ const val OTA_MANIFEST_URL: String = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.5.0/mentra-live-ota-3.5.0-dev.1308.json"
10
+ const val OTA_MANIFEST_SHA256: String = "abfc780248a6b1257a92eb978d3631a8c8d64837511c1da9216afdeca35e922b"
11
11
  }
@@ -350,7 +350,7 @@ class MentraBluetoothSdk private constructor(
350
350
  dispatchDefaultDeviceChanged()
351
351
  }
352
352
 
353
- fun clearDefaultDevice() {
353
+ private fun clearDefaultDevice() {
354
354
  suppressDefaultDeviceEvents = true
355
355
  try {
356
356
  DeviceStore.apply(ObservableStore.BLUETOOTH_CATEGORY, "default_wearable", "")
@@ -554,6 +554,12 @@ class MentraBluetoothSdk private constructor(
554
554
  deviceManager.forget()
555
555
  }
556
556
 
557
+ /** Unpair the glasses: disconnect, forget the default device and, on Mentra Live, remove the phone's Bluetooth bond. */
558
+ suspend fun unpair() {
559
+ analytics.noteDisconnectRequested(BluetoothSdkAnalyticsTracker.DISCONNECT_FORGET)
560
+ deviceManager.unpair()
561
+ }
562
+
557
563
  @JvmOverloads
558
564
  fun displayText(text: String, x: Int = 0, y: Int = 0, size: Int = 24) {
559
565
  displayText(DisplayTextRequest(text = text, x = x, y = y, size = size))
@@ -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
@@ -157,6 +157,12 @@ class MentraLive : SGCManager() {
157
157
  private const val A2DP_CONNECT_MAX_ATTEMPTS = 5
158
158
  private const val A2DP_CONNECT_RETRY_MS = 800L
159
159
  private const val UNPAIR_FLUSH_MS = 400L
160
+ /** Classic profile disconnects this soon after the app's own teardown are the app's. */
161
+ private const val OWN_CLASSIC_TEARDOWN_MS = 10_000L
162
+ /** Classic profiles going down this close together are one disconnect of the whole device. */
163
+ private const val CLASSIC_DISCONNECT_PAIR_MS = 3_000L
164
+ /** How long after the Classic drop the glasses must still be answering over BLE. */
165
+ private const val CLASSIC_DISCONNECT_CONFIRM_MS = 2_000L
160
166
  // Longer than the glasses' bounded relay of one report (BES logs, two file transfers,
161
167
  // the phone POST), so an unreleased name cannot be reused while its report is in flight.
162
168
  internal const val INCIDENT_RELAY_OWNERSHIP_MS = 10 * 60_000L
@@ -706,6 +712,13 @@ class MentraLive : SGCManager() {
706
712
  private var secureFirmwareRefreshRunnable: Runnable? = null
707
713
  /** elapsedRealtime of the last GATT link that was not an explicit pairing attempt. */
708
714
  private var lastAutoReconnectLinkAt: Long? = null
715
+ /** elapsedRealtime of the app's last own A2DP/HFP teardown. */
716
+ private var lastOwnClassicTeardownAt: Long? = null
717
+ /** elapsedRealtime when Android started disconnecting each Classic profile. */
718
+ private val classicDisconnectingAt = mutableMapOf<ClassicAudioProfile, Long>()
719
+ private var classicDisconnectCheck: Runnable? = null
720
+ /** elapsedRealtime of the last message from the glasses. */
721
+ private var lastInboundAt = 0L
709
722
  /** Hold GATT teardown until the unpair write can leave the phone. */
710
723
  private var unpairFlushPending = false
711
724
  private var unpairFlushRunnable: Runnable? = null
@@ -1670,29 +1683,17 @@ class MentraLive : SGCManager() {
1670
1683
  )
1671
1684
  val isNamedConnectTarget =
1672
1685
  isSavedGlasses && (isReconnecting || explicitConnectByName)
1673
- if (MentraLiveOwnerLossPolicy.shouldExposeAsNonPairable(
1686
+ if (MentraLiveOwnerLossPolicy.shouldIgnoreNotPairable(
1674
1687
  savedGlasses = isSavedGlasses,
1675
1688
  reconnectScan = isReconnecting,
1676
1689
  secureTrailer = advertisesPairingFlag(result),
1677
1690
  pairingDiscoverable = isPairingDiscoverable(result),
1678
1691
  )
1679
1692
  ) {
1680
- // Other secure units stay visible with pairing-mode guidance, and
1681
- // the scan screen blocks the connection until they are pairable.
1693
+ // Only glasses that can pair now are listed; a closed window drops them.
1682
1694
  // The saved glasses fall through so the pause watch scan can see
1683
1695
  // the pairing flag clear and reconnect.
1684
- Bridge.log(
1685
- "LIVE: Nearby $deviceName is secure firmware not in pairing mode — exposing as non-pairable"
1686
- )
1687
- Bridge.sendDiscoveredDevice(
1688
- DeviceTypes.LIVE,
1689
- deviceName,
1690
- deviceAddress,
1691
- result.rssi,
1692
- pairingMode = false,
1693
- pairingCode = null,
1694
- securePairingCapable = true,
1695
- )
1696
+ Bridge.removeDiscoveredDevice(DeviceTypes.LIVE, deviceName)
1696
1697
  return
1697
1698
  }
1698
1699
  val glassType = if (deviceName == "Xy_A") "Standard" else "Mentra Live"
@@ -1705,17 +1706,21 @@ class MentraLive : SGCManager() {
1705
1706
  if (secureCapable) " (pairingMode=$pairingMode)"
1706
1707
  else " (legacy firmware, pairable)"
1707
1708
  )
1708
- Bridge.sendDiscoveredDevice(
1709
- DeviceTypes.LIVE,
1710
- deviceName,
1711
- deviceAddress,
1712
- result.rssi,
1713
- // Field firmware has no pairing flag. Treat it as pairable so the
1714
- // new Mentra App can still find old glasses.
1715
- pairingMode = if (secureCapable) pairingMode else true,
1716
- pairingCode = pairingCode,
1717
- securePairingCapable = secureCapable,
1718
- )
1709
+ // Field firmware has no pairing flag. Treat it as pairable so the new
1710
+ // Mentra App can still find old glasses.
1711
+ if (secureCapable && !pairingMode) {
1712
+ Bridge.removeDiscoveredDevice(DeviceTypes.LIVE, deviceName)
1713
+ } else {
1714
+ Bridge.sendDiscoveredDevice(
1715
+ DeviceTypes.LIVE,
1716
+ deviceName,
1717
+ deviceAddress,
1718
+ result.rssi,
1719
+ pairingMode = true,
1720
+ pairingCode = pairingCode,
1721
+ securePairingCapable = secureCapable,
1722
+ )
1723
+ }
1719
1724
 
1720
1725
  if (ConnectedDeviceMatcher.sameSavedName(
1721
1726
  DeviceModel.MENTRA_LIVE,
@@ -4393,6 +4398,7 @@ class MentraLive : SGCManager() {
4393
4398
  }
4394
4399
  BleTraceLogger.logJson("glasses_to_phone", "sdk_ble_event", json, null)
4395
4400
  GlassesLinkDiagnostics.recordInbound()
4401
+ lastInboundAt = SystemClock.elapsedRealtime()
4396
4402
 
4397
4403
  if (MessageChunker.isChunkedMessage(json)) {
4398
4404
  processChunkedJsonMessage(json)
@@ -8074,11 +8080,56 @@ class MentraLive : SGCManager() {
8074
8080
  if (intent?.action != BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED &&
8075
8081
  intent?.action != BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED) return
8076
8082
  val device = intent.bluetoothDeviceExtra() ?: return
8083
+ noteClassicDisconnecting(device, intent)
8077
8084
  refreshClassicAudioConnectionState(device)
8078
8085
  }
8079
8086
  }
8080
8087
  }
8081
8088
 
8089
+ /**
8090
+ * Android's Bluetooth settings Disconnect drops every Classic profile of the glasses (A2DP,
8091
+ * and HFP unless the unworn glasses closed it) and leaves the app's BLE link up, so Home went
8092
+ * on showing them connected. When all the connected profiles start disconnecting within
8093
+ * [CLASSIC_DISCONNECT_PAIR_MS] while the app neither asked nor lost BLE, and the glasses
8094
+ * answer over BLE within [CLASSIC_DISCONNECT_CONFIRM_MS], the person disconnected them: it
8095
+ * lasts like the app's Disconnect, even if the glasses paged their audio back meanwhile. A
8096
+ * restart, power off, pairing window or range loss takes BLE down too; turning off Media or
8097
+ * Call audio leaves the other profile up.
8098
+ */
8099
+ private fun noteClassicDisconnecting(device: BluetoothDevice, intent: Intent) {
8100
+ if (intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1) != BluetoothProfile.STATE_CONNECTED ||
8101
+ intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1) != BluetoothProfile.STATE_DISCONNECTING
8102
+ ) {
8103
+ return
8104
+ }
8105
+ if (isKilled || !isConnected || connectedDevice?.address != device.address) return
8106
+ if (bluetoothAdapter?.state != BluetoothAdapter.STATE_ON) return
8107
+ val now = SystemClock.elapsedRealtime()
8108
+ val ownTeardownAt = lastOwnClassicTeardownAt
8109
+ if (ownTeardownAt != null && now - ownTeardownAt < OWN_CLASSIC_TEARDOWN_MS) return
8110
+ val profile =
8111
+ if (intent.action == BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED) ClassicAudioProfile.A2DP
8112
+ else ClassicAudioProfile.HEADSET
8113
+ classicDisconnectingAt[profile] = now
8114
+ val wereUp = classicAudioConnectionTracker.connectedProfiles() + profile
8115
+ if (!wholeClassicDeviceDisconnecting(wereUp, classicDisconnectingAt, now, CLASSIC_DISCONNECT_PAIR_MS)) return
8116
+ if (classicDisconnectCheck != null) return
8117
+ Bridge.log("LIVE: Classic: Android is disconnecting the glasses' audio - checking the glasses stay up")
8118
+ val session = gattEpoch
8119
+ sendJsonWithoutAck(JSONObject().put("type", "ping"))
8120
+ val check =
8121
+ Runnable {
8122
+ classicDisconnectCheck = null
8123
+ if (isKilled || !isConnected || gattEpoch != session || lastInboundAt <= now) {
8124
+ return@Runnable
8125
+ }
8126
+ Bridge.log("LIVE: Classic: Android disconnected the glasses - staying disconnected")
8127
+ DeviceManager.getInstance().disconnectByUser()
8128
+ }
8129
+ classicDisconnectCheck = check
8130
+ handler.postDelayed(check, CLASSIC_DISCONNECT_CONFIRM_MS)
8131
+ }
8132
+
8082
8133
  private fun registerClassicAudioReceiver() {
8083
8134
  val ctx = context ?: return
8084
8135
  val receiver = classicAudioReceiver ?: return
@@ -8712,6 +8763,7 @@ class MentraLive : SGCManager() {
8712
8763
  // The BLE device reference may already be cleared after a GATT drop. The tracker owns the
8713
8764
  // authoritative target address, so let it decide whether this teardown belongs to the
8714
8765
  // active Classic session instead of consulting connectedDevice.
8766
+ lastOwnClassicTeardownAt = SystemClock.elapsedRealtime()
8715
8767
  if (classicAudioConnectionTracker.invalidate(device.address)) {
8716
8768
  audioConnected = false
8717
8769
  }
@@ -153,12 +153,12 @@ internal object MentraLiveOwnerLossPolicy {
153
153
  ): Boolean = pairingMode && savedGlasses && !explicitPairing
154
154
 
155
155
  /**
156
- * A discovery scan lists other secure glasses that are not in pairing mode as non-pairable
157
- * and does not connect to them. The saved glasses are the exception: the pause watch scan
158
- * has to read their trailer, so a cleared pairing flag ends the pause and reconnects.
159
- * Mirrors iOS, which skips this return when the advertisement is the saved device.
156
+ * A discovery scan neither lists nor connects to other secure glasses that are not in pairing
157
+ * mode. The saved glasses are the exception: the pause watch scan has to read their trailer,
158
+ * so a cleared pairing flag ends the pause and reconnects. Mirrors iOS, which skips this
159
+ * return when the advertisement is the saved device.
160
160
  */
161
- fun shouldExposeAsNonPairable(
161
+ fun shouldIgnoreNotPairable(
162
162
  savedGlasses: Boolean,
163
163
  reconnectScan: Boolean,
164
164
  secureTrailer: Boolean,
@@ -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) {
@@ -201,7 +201,7 @@ class MentraLiveOwnerLossPolicyTest {
201
201
  @Test
202
202
  fun aClearedPairingFlagOnTheSavedGlassesIsNotHiddenFromThePauseWatchScan() {
203
203
  assertFalse(
204
- MentraLiveOwnerLossPolicy.shouldExposeAsNonPairable(
204
+ MentraLiveOwnerLossPolicy.shouldIgnoreNotPairable(
205
205
  savedGlasses = true,
206
206
  reconnectScan = false,
207
207
  secureTrailer = true,
@@ -209,7 +209,7 @@ class MentraLiveOwnerLossPolicyTest {
209
209
  )
210
210
  )
211
211
  assertTrue(
212
- MentraLiveOwnerLossPolicy.shouldExposeAsNonPairable(
212
+ MentraLiveOwnerLossPolicy.shouldIgnoreNotPairable(
213
213
  savedGlasses = false,
214
214
  reconnectScan = false,
215
215
  secureTrailer = true,
@@ -217,7 +217,7 @@ class MentraLiveOwnerLossPolicyTest {
217
217
  )
218
218
  )
219
219
  assertFalse(
220
- MentraLiveOwnerLossPolicy.shouldExposeAsNonPairable(
220
+ MentraLiveOwnerLossPolicy.shouldIgnoreNotPairable(
221
221
  savedGlasses = false,
222
222
  reconnectScan = false,
223
223
  secureTrailer = true,
@@ -1334,7 +1334,6 @@ export interface BluetoothSdkPublicModule {
1334
1334
  subscribeBluetoothStatus(listener: (changed: Partial<PublicBluetoothStatus>) => void): () => void;
1335
1335
  getDefaultDevice(): Promise<Device | null>;
1336
1336
  setDefaultDevice(device: Device | null): Promise<void>;
1337
- clearDefaultDevice(): Promise<void>;
1338
1337
  startScan(model: DeviceModel): Promise<void>;
1339
1338
  stopScan(): Promise<void>;
1340
1339
  scan(options: ScanOptions): Promise<Device[]>;
@@ -1344,6 +1343,9 @@ export interface BluetoothSdkPublicModule {
1344
1343
  cancelConnectionAttempt(): Promise<void>;
1345
1344
  disconnect(): Promise<void>;
1346
1345
  forget(): Promise<void>;
1346
+ /** Unpair the glasses: disconnect, forget them as the default device and, on Mentra Live, remove the phone's Bluetooth
1347
+ * bond, so the next pairing starts from pairing mode. */
1348
+ unpair(): Promise<void>;
1347
1349
  displayText(text: string, x?: number, y?: number, size?: number): Promise<void>;
1348
1350
  clearDisplay(): Promise<void>;
1349
1351
  /** Set session-only content below the dashboard status header. Pass an empty string to reset it. */