@mentra/bluetooth-sdk 3.2.1-beta.373 → 3.2.1-beta.386
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.
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +7 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1.kt +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G2.kt +8 -7
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +12 -9
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraNex.kt +12 -8
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SelectedDeviceAddress.kt +17 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/DeviceIdentityPairingTest.kt +59 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G1PairingTest.kt +105 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G2PairingTargetTest.kt +90 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingTargetTest.kt +65 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraNexPairingTest.kt +151 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/SelectedDeviceAddressTest.kt +27 -0
- package/build/generated/releaseMetadata.js +5 -5
- package/build/generated/releaseMetadata.js.map +1 -1
- package/ios/Source/BluetoothSdkDefaults.swift +1 -1
- package/ios/Source/DeviceManager.swift +7 -3
- package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
- package/ios/Source/sgcs/G1.swift +21 -6
- package/ios/Source/sgcs/G1ConnectionTarget.swift +13 -0
- package/ios/Source/sgcs/Mach1.swift +19 -7
- package/ios/Source/sgcs/MentraLive.swift +2 -1
- package/ios/Source/sgcs/MentraNex.swift +8 -31
- package/ios/Source/sgcs/NexConnectionTarget.swift +15 -0
- package/ios/Source/sgcs/VuzixConnectionTarget.swift +15 -0
- package/ios/Tests/DeviceIdentityPairingTests.swift +49 -0
- package/ios/Tests/SGCConnectionTargetTests.swift +48 -0
- package/ios/Tests/VersionInfoCommandTests.swift +53 -0
- package/package.json +2 -2
- package/src/generated/releaseMetadata.ts +5 -5
|
@@ -1501,12 +1501,16 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
|
|
|
1501
1501
|
return
|
|
1502
1502
|
}
|
|
1503
1503
|
|
|
1504
|
+
// A new identity must never inherit the previous glasses' address when
|
|
1505
|
+
// pairing supplied only a name. Same-device reconnects retain their cache.
|
|
1506
|
+
val identityChanged = pendingDeviceName.isNotEmpty() &&
|
|
1507
|
+
(pendingDeviceName != deviceName || sgc?.type != defaultWearable)
|
|
1508
|
+
if (identityChanged || pendingDeviceAddress.isNotEmpty()) {
|
|
1509
|
+
deviceAddress = pendingDeviceAddress
|
|
1510
|
+
}
|
|
1504
1511
|
if (pendingDeviceName.isNotEmpty()) {
|
|
1505
1512
|
deviceName = pendingDeviceName
|
|
1506
1513
|
}
|
|
1507
|
-
if (pendingDeviceAddress.isNotEmpty()) {
|
|
1508
|
-
deviceAddress = pendingDeviceAddress
|
|
1509
|
-
}
|
|
1510
1514
|
clearPendingConnection()
|
|
1511
1515
|
|
|
1512
1516
|
val readyKey = "${sgc?.type}:${deviceName}"
|
|
@@ -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.2.1"
|
|
6
|
-
const val RELEASE_IDENTITY: String = "3.2.1-beta.
|
|
7
|
-
const val RELEASE_SET_ID: String = "mentra-3.2.1-beta.
|
|
8
|
-
const val SOURCE_COMMIT: String = "
|
|
9
|
-
const val OTA_MANIFEST_URL: String = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.2.1/mentra-live-ota-3.2.1-beta.
|
|
10
|
-
const val OTA_MANIFEST_SHA256: String = "
|
|
6
|
+
const val RELEASE_IDENTITY: String = "3.2.1-beta.386"
|
|
7
|
+
const val RELEASE_SET_ID: String = "mentra-3.2.1-beta.386"
|
|
8
|
+
const val SOURCE_COMMIT: String = "447155847a6e3f268b9f8dcfd664aee9b59cfb68"
|
|
9
|
+
const val OTA_MANIFEST_URL: String = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.2.1/mentra-live-ota-3.2.1-beta.386.json"
|
|
10
|
+
const val OTA_MANIFEST_SHA256: String = "33fba6c95820df3762605aabe9ae04d45268430e0938cf136ff4716b8bd2a64c"
|
|
11
11
|
}
|
|
@@ -1370,8 +1370,8 @@ class G1 : SGCManager() {
|
|
|
1370
1370
|
context!!.registerReceiver(bondingReceiver, filter)
|
|
1371
1371
|
isBondingReceiverRegistered = true
|
|
1372
1372
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1373
|
+
// Keep the target supplied by connectById. device_name still belongs to
|
|
1374
|
+
// the previous pairing until DeviceManager promotes the ready device.
|
|
1375
1375
|
if (!bluetoothAdapter!!.isEnabled()) {
|
|
1376
1376
|
return
|
|
1377
1377
|
}
|
|
@@ -1364,17 +1364,18 @@ class G2 : SGCManager() {
|
|
|
1364
1364
|
// Map device names to serial numbers (populated from manufacturer data during scan)
|
|
1365
1365
|
private val deviceNameToSerialNumber = mutableMapOf<String, String>()
|
|
1366
1366
|
|
|
1367
|
-
//
|
|
1367
|
+
// Scope each side's address to the selected serial. Legacy global addresses have
|
|
1368
|
+
// no trustworthy owner, so the first connection after upgrading learns them by scan.
|
|
1368
1369
|
private var leftGlassAddress: String?
|
|
1369
1370
|
get() =
|
|
1370
1371
|
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
1371
|
-
.getString(KEY_LEFT_ADDRESS, null)
|
|
1372
|
+
.getString("$KEY_LEFT_ADDRESS:$DEVICE_SEARCH_ID", null)
|
|
1372
1373
|
set(value) {
|
|
1373
1374
|
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
1374
1375
|
.edit()
|
|
1375
1376
|
.apply {
|
|
1376
|
-
if (value != null) putString(KEY_LEFT_ADDRESS, value)
|
|
1377
|
-
else remove(KEY_LEFT_ADDRESS)
|
|
1377
|
+
if (value != null) putString("$KEY_LEFT_ADDRESS:$DEVICE_SEARCH_ID", value)
|
|
1378
|
+
else remove("$KEY_LEFT_ADDRESS:$DEVICE_SEARCH_ID")
|
|
1378
1379
|
}
|
|
1379
1380
|
.apply()
|
|
1380
1381
|
}
|
|
@@ -1382,13 +1383,13 @@ class G2 : SGCManager() {
|
|
|
1382
1383
|
private var rightGlassAddress: String?
|
|
1383
1384
|
get() =
|
|
1384
1385
|
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
1385
|
-
.getString(KEY_RIGHT_ADDRESS, null)
|
|
1386
|
+
.getString("$KEY_RIGHT_ADDRESS:$DEVICE_SEARCH_ID", null)
|
|
1386
1387
|
set(value) {
|
|
1387
1388
|
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
1388
1389
|
.edit()
|
|
1389
1390
|
.apply {
|
|
1390
|
-
if (value != null) putString(KEY_RIGHT_ADDRESS, value)
|
|
1391
|
-
else remove(KEY_RIGHT_ADDRESS)
|
|
1391
|
+
if (value != null) putString("$KEY_RIGHT_ADDRESS:$DEVICE_SEARCH_ID", value)
|
|
1392
|
+
else remove("$KEY_RIGHT_ADDRESS:$DEVICE_SEARCH_ID")
|
|
1392
1393
|
}
|
|
1393
1394
|
.apply()
|
|
1394
1395
|
}
|
|
@@ -2148,7 +2148,7 @@ class MentraLive : SGCManager() {
|
|
|
2148
2148
|
// than scanning).
|
|
2149
2149
|
// Falls back to name-based scan if no address is saved.
|
|
2150
2150
|
val lastDeviceAddress =
|
|
2151
|
-
|
|
2151
|
+
selectedConnectionAddress()
|
|
2152
2152
|
if (lastDeviceAddress != null &&
|
|
2153
2153
|
!lastDeviceAddress.isEmpty() &&
|
|
2154
2154
|
bluetoothAdapter != null
|
|
@@ -6163,7 +6163,8 @@ class MentraLive : SGCManager() {
|
|
|
6163
6163
|
val json = JSONObject()
|
|
6164
6164
|
json.put("type", "request_version")
|
|
6165
6165
|
requestId?.let { json.put("request_id", it) }
|
|
6166
|
-
|
|
6166
|
+
// Wake ASG so the version request and its response can finish after idle.
|
|
6167
|
+
sendJson(json, true)
|
|
6167
6168
|
Bridge.log("LIVE: 📱 Requesting version info from glasses")
|
|
6168
6169
|
} catch (e: JSONException) {
|
|
6169
6170
|
Log.e(TAG, "📱 Error creating request_version command", e)
|
|
@@ -6625,6 +6626,14 @@ class MentraLive : SGCManager() {
|
|
|
6625
6626
|
return false
|
|
6626
6627
|
}
|
|
6627
6628
|
|
|
6629
|
+
private fun selectedConnectionAddress(): String? = SelectedDeviceAddress.resolve(
|
|
6630
|
+
savedDeviceName,
|
|
6631
|
+
DeviceStore.get("bluetooth", "pending_device_name") as? String,
|
|
6632
|
+
DeviceStore.get("bluetooth", "pending_device_address") as? String,
|
|
6633
|
+
DeviceStore.get("bluetooth", "device_name") as? String,
|
|
6634
|
+
DeviceStore.get("bluetooth", "device_address") as? String,
|
|
6635
|
+
)
|
|
6636
|
+
|
|
6628
6637
|
fun connectToSmartGlasses() {
|
|
6629
6638
|
if (postGattLifecycle { connectToSmartGlasses() }) return
|
|
6630
6639
|
if (pairingYieldActive) {
|
|
@@ -6659,13 +6668,7 @@ class MentraLive : SGCManager() {
|
|
|
6659
6668
|
// var context = Bridge.getContext();
|
|
6660
6669
|
// SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
6661
6670
|
// String lastDeviceAddress = prefs.getString(PREF_DEVICE_NAME, null);
|
|
6662
|
-
val
|
|
6663
|
-
(DeviceStore.get("bluetooth", "pending_device_address") as String?)?.takeIf {
|
|
6664
|
-
it.isNotEmpty()
|
|
6665
|
-
}
|
|
6666
|
-
val lastDeviceAddress =
|
|
6667
|
-
pendingAddress
|
|
6668
|
-
?: (DeviceStore.get("bluetooth", "device_address") as String?)
|
|
6671
|
+
val lastDeviceAddress = selectedConnectionAddress()
|
|
6669
6672
|
|
|
6670
6673
|
if (lastDeviceAddress != null && lastDeviceAddress.length > 0) {
|
|
6671
6674
|
// Connect to last known device if available
|
|
@@ -208,7 +208,7 @@ class MentraNex : SGCManager() {
|
|
|
208
208
|
|
|
209
209
|
// If we already have saved device names for main...
|
|
210
210
|
if (name != null && preferredMainDeviceId != null) {
|
|
211
|
-
if (
|
|
211
|
+
if (name != preferredMainDeviceId) {
|
|
212
212
|
return // Not a matching device
|
|
213
213
|
}
|
|
214
214
|
}
|
|
@@ -230,7 +230,6 @@ class MentraNex : SGCManager() {
|
|
|
230
230
|
type = DeviceTypes.NEX
|
|
231
231
|
hasMic = true
|
|
232
232
|
DeviceStore.apply("glasses", "micEnabled", false)
|
|
233
|
-
preferredMainDeviceId = DeviceManager.getInstance().deviceName
|
|
234
233
|
|
|
235
234
|
// Initialize LC3 audio player
|
|
236
235
|
lc3AudioPlayer = Lc3Player(context)
|
|
@@ -1315,23 +1314,28 @@ class MentraNex : SGCManager() {
|
|
|
1315
1314
|
}
|
|
1316
1315
|
|
|
1317
1316
|
private fun connectToSmartGlasses() {
|
|
1318
|
-
val
|
|
1319
|
-
val deviceAddress =
|
|
1317
|
+
val target = preferredMainDeviceId?.takeIf { it.isNotBlank() } ?: return
|
|
1318
|
+
val deviceAddress = SelectedDeviceAddress.resolve(
|
|
1319
|
+
target,
|
|
1320
|
+
DeviceStore.get("bluetooth", "pending_device_name") as? String,
|
|
1321
|
+
DeviceStore.get("bluetooth", "pending_device_address") as? String,
|
|
1322
|
+
DeviceStore.get("bluetooth", "device_name") as? String,
|
|
1323
|
+
DeviceStore.get("bluetooth", "device_address") as? String,
|
|
1324
|
+
)
|
|
1320
1325
|
|
|
1321
1326
|
// Register bonding receiver
|
|
1322
1327
|
Bridge.log("connectToSmartGlasses start")
|
|
1323
|
-
Bridge.log("
|
|
1324
|
-
preferredMainDeviceId = DeviceManager.getInstance().deviceName
|
|
1328
|
+
Bridge.log("Connecting to selected Nex: $target address: $deviceAddress")
|
|
1325
1329
|
if (!bluetoothAdapter.isEnabled) {
|
|
1326
1330
|
return
|
|
1327
1331
|
}
|
|
1328
1332
|
when {
|
|
1329
|
-
|
|
1333
|
+
deviceAddress != null -> {
|
|
1330
1334
|
stopScan()
|
|
1331
1335
|
mainDevice = bluetoothAdapter.getRemoteDevice(deviceAddress)
|
|
1332
1336
|
mainTaskHandler?.sendEmptyMessageDelayed(MAIN_TASK_HANDLER_CODE_RECONNECT_DEVICE, 0)
|
|
1333
1337
|
}
|
|
1334
|
-
savedNexMainAddress != null -> {
|
|
1338
|
+
savedNexMainName == target && savedNexMainAddress != null -> {
|
|
1335
1339
|
mainDevice = bluetoothAdapter.getRemoteDevice(savedNexMainAddress)
|
|
1336
1340
|
mainTaskHandler?.sendEmptyMessageDelayed(MAIN_TASK_HANDLER_CODE_RECONNECT_DEVICE, 0)
|
|
1337
1341
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
/** An address is usable only when its accompanying name identifies the requested device. */
|
|
4
|
+
internal object SelectedDeviceAddress {
|
|
5
|
+
fun resolve(
|
|
6
|
+
target: String,
|
|
7
|
+
pendingName: String?,
|
|
8
|
+
pendingAddress: String?,
|
|
9
|
+
savedName: String?,
|
|
10
|
+
savedAddress: String?,
|
|
11
|
+
): String? {
|
|
12
|
+
if (target.isBlank()) return null
|
|
13
|
+
if (pendingName == target && !pendingAddress.isNullOrBlank()) return pendingAddress
|
|
14
|
+
if (savedName == target && !savedAddress.isNullOrBlank()) return savedAddress
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk
|
|
2
|
+
|
|
3
|
+
import androidx.test.core.app.ApplicationProvider
|
|
4
|
+
import com.mentra.bluetoothsdk.sgcs.Simulated
|
|
5
|
+
import org.junit.Assert.assertEquals
|
|
6
|
+
import org.junit.Test
|
|
7
|
+
import org.junit.runner.RunWith
|
|
8
|
+
import org.robolectric.RobolectricTestRunner
|
|
9
|
+
import org.robolectric.annotation.Config
|
|
10
|
+
import org.robolectric.annotation.LooperMode
|
|
11
|
+
|
|
12
|
+
@RunWith(RobolectricTestRunner::class)
|
|
13
|
+
@Config(sdk = [33])
|
|
14
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
15
|
+
class DeviceIdentityPairingTest {
|
|
16
|
+
@Test fun `readiness promotes a coherent name and address while preserving same-device reconnects`() {
|
|
17
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
18
|
+
val saved = listOf("bluetooth", "glasses").associateWith { DeviceStore.store.getCategory(it) }
|
|
19
|
+
val singleton = DeviceManager::class.java.getDeclaredField("_instance").apply { isAccessible = true }
|
|
20
|
+
val previous = singleton.get(null)
|
|
21
|
+
val cases = listOf(
|
|
22
|
+
// pending name, pending address, saved model, expected address
|
|
23
|
+
listOf("new", "", "test", ""),
|
|
24
|
+
listOf("new", "new-address", "test", "new-address"),
|
|
25
|
+
listOf("old", "", "test", "old-address"),
|
|
26
|
+
listOf("", "", "test", "old-address"),
|
|
27
|
+
listOf("old", "", "other-model", ""),
|
|
28
|
+
)
|
|
29
|
+
try {
|
|
30
|
+
for ((pendingName, pendingAddress, savedModel, expectedAddress) in cases) {
|
|
31
|
+
val manager = DeviceManager(initializeHardware = false)
|
|
32
|
+
singleton.set(null, manager)
|
|
33
|
+
manager.sgc = Simulated().apply { type = "test" }
|
|
34
|
+
DeviceStore.set("bluetooth", "default_wearable", savedModel)
|
|
35
|
+
DeviceStore.set("bluetooth", "device_name", "old")
|
|
36
|
+
DeviceStore.set("bluetooth", "device_address", "old-address")
|
|
37
|
+
DeviceStore.set("bluetooth", "pending_device_name", pendingName)
|
|
38
|
+
DeviceStore.set("bluetooth", "pending_device_address", pendingAddress)
|
|
39
|
+
DeviceStore.set("bluetooth", "shouldSendBootingMessage", false)
|
|
40
|
+
try {
|
|
41
|
+
manager.handleDeviceReady()
|
|
42
|
+
assertEquals(pendingName.ifEmpty { "old" }, DeviceStore.get("bluetooth", "device_name"))
|
|
43
|
+
assertEquals(expectedAddress, DeviceStore.get("bluetooth", "device_address"))
|
|
44
|
+
assertEquals("", DeviceStore.get("bluetooth", "pending_device_name"))
|
|
45
|
+
assertEquals("", DeviceStore.get("bluetooth", "pending_device_address"))
|
|
46
|
+
} finally {
|
|
47
|
+
manager.disconnect()
|
|
48
|
+
manager.cleanup()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} finally {
|
|
52
|
+
singleton.set(null, previous)
|
|
53
|
+
saved.forEach { (category, values) ->
|
|
54
|
+
(DeviceStore.store.getCategory(category).keys - values.keys).forEach { DeviceStore.store.remove(category, it) }
|
|
55
|
+
values.forEach { (key, value) -> DeviceStore.set(category, key, value) }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothAdapter
|
|
4
|
+
import android.bluetooth.BluetoothDevice
|
|
5
|
+
import android.bluetooth.BluetoothGatt
|
|
6
|
+
import android.bluetooth.BluetoothProfile
|
|
7
|
+
import android.bluetooth.le.ScanResult
|
|
8
|
+
import android.bluetooth.le.ScanSettings
|
|
9
|
+
import android.os.Looper
|
|
10
|
+
import androidx.test.core.app.ApplicationProvider
|
|
11
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
12
|
+
import com.mentra.bluetoothsdk.DeviceStore
|
|
13
|
+
import com.mentra.lc3Lib.Lc3Cpp
|
|
14
|
+
import org.junit.Assert.assertEquals
|
|
15
|
+
import org.junit.Assert.assertTrue
|
|
16
|
+
import org.junit.Before
|
|
17
|
+
import org.junit.Test
|
|
18
|
+
import org.junit.runner.RunWith
|
|
19
|
+
import org.robolectric.RobolectricTestRunner
|
|
20
|
+
import org.robolectric.Shadows.shadowOf
|
|
21
|
+
import org.robolectric.annotation.Config
|
|
22
|
+
import org.robolectric.annotation.Implementation
|
|
23
|
+
import org.robolectric.annotation.Implements
|
|
24
|
+
import org.robolectric.annotation.LooperMode
|
|
25
|
+
import java.util.concurrent.TimeUnit
|
|
26
|
+
|
|
27
|
+
@RunWith(RobolectricTestRunner::class)
|
|
28
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
29
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
30
|
+
class G1PairingTest {
|
|
31
|
+
@Before
|
|
32
|
+
fun setup() {
|
|
33
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
34
|
+
shadowOf(BluetoothAdapter.getDefaultAdapter()).setState(BluetoothAdapter.STATE_ON)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test
|
|
38
|
+
fun `fresh pairing connects the selected G1 without a saved identity`() {
|
|
39
|
+
assertSelectedGlassesConnect("")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Test
|
|
43
|
+
fun `pairing from simulated glasses connects the selected G1`() {
|
|
44
|
+
assertSelectedGlassesConnect("Simulated Glasses")
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Test
|
|
48
|
+
fun `switching G1 pairs ignores the previously saved pair`() {
|
|
49
|
+
assertSelectedGlassesConnect("12")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Test
|
|
53
|
+
fun `reconnecting the saved G1 still connects both halves`() {
|
|
54
|
+
assertSelectedGlassesConnect("47")
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private fun assertSelectedGlassesConnect(savedName: String) {
|
|
58
|
+
DeviceStore.set("bluetooth", "device_name", savedName)
|
|
59
|
+
DeviceStore.set("bluetooth", "pending_device_name", "47")
|
|
60
|
+
val adapter = BluetoothAdapter.getDefaultAdapter()
|
|
61
|
+
val scanner = shadowOf(adapter.bluetoothLeScanner)
|
|
62
|
+
val glasses = G1()
|
|
63
|
+
try {
|
|
64
|
+
glasses.connectById("47")
|
|
65
|
+
val callback = scanner.scanCallbacks.single()
|
|
66
|
+
val unrelated = device("00:00:00:00:12:01", "Even G1_12_L_000001")
|
|
67
|
+
val left = device("00:00:00:00:47:01", "Even G1_47_L_000001")
|
|
68
|
+
val right = device("00:00:00:00:47:02", "Even G1_47_R_000002")
|
|
69
|
+
|
|
70
|
+
for (device in listOf(unrelated, left, right)) {
|
|
71
|
+
callback.onScanResult(
|
|
72
|
+
ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
|
|
73
|
+
ScanResult(device, null, -50, 0),
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
77
|
+
assertTrue("The previously saved pair must not receive a GATT connection", shadowOf(unrelated).bluetoothGatts.isEmpty())
|
|
78
|
+
assertEquals("Connect the selected left half", 1, shadowOf(left).bluetoothGatts.size)
|
|
79
|
+
shadowOf(left).simulateGattConnectionChange(BluetoothGatt.GATT_SUCCESS, BluetoothProfile.STATE_CONNECTED)
|
|
80
|
+
shadowOf(Looper.getMainLooper()).idleFor(2, TimeUnit.SECONDS)
|
|
81
|
+
assertEquals("Connect the selected right half", 1, shadowOf(right).bluetoothGatts.size)
|
|
82
|
+
assertTrue("Stop scanning once both selected halves are found", scanner.scanCallbacks.isEmpty())
|
|
83
|
+
assertEquals("Scanning must not promote an unready pairing", savedName, DeviceStore.get("bluetooth", "device_name"))
|
|
84
|
+
} finally {
|
|
85
|
+
glasses.disconnect()
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private fun device(address: String, name: String): BluetoothDevice =
|
|
90
|
+
BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address).also {
|
|
91
|
+
shadowOf(it).setName(name)
|
|
92
|
+
shadowOf(it).setAlias(name)
|
|
93
|
+
shadowOf(it).setBondState(BluetoothDevice.BOND_BONDED)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Pairing tests exercise the real G1 driver; only its unrelated native audio codec is stubbed.
|
|
97
|
+
@Implements(Lc3Cpp::class)
|
|
98
|
+
class ShadowLc3Cpp {
|
|
99
|
+
companion object {
|
|
100
|
+
@JvmStatic @Implementation fun __staticInitializer__() {}
|
|
101
|
+
@JvmStatic @Implementation fun initDecoder(): Long = 1L
|
|
102
|
+
@JvmStatic @Implementation fun freeDecoder(decoderPtr: Long) {}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothAdapter
|
|
4
|
+
import android.bluetooth.BluetoothGatt
|
|
5
|
+
import android.bluetooth.BluetoothProfile
|
|
6
|
+
import android.bluetooth.le.ScanRecord
|
|
7
|
+
import android.bluetooth.le.ScanResult
|
|
8
|
+
import android.bluetooth.le.ScanSettings
|
|
9
|
+
import android.content.Context
|
|
10
|
+
import android.os.Looper
|
|
11
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
12
|
+
import org.junit.Assert.assertEquals
|
|
13
|
+
import org.junit.Assert.assertTrue
|
|
14
|
+
import org.junit.Before
|
|
15
|
+
import org.junit.Test
|
|
16
|
+
import org.junit.runner.RunWith
|
|
17
|
+
import org.robolectric.RobolectricTestRunner
|
|
18
|
+
import org.robolectric.RuntimeEnvironment
|
|
19
|
+
import org.robolectric.Shadows.shadowOf
|
|
20
|
+
import org.robolectric.annotation.Config
|
|
21
|
+
import org.robolectric.annotation.LooperMode
|
|
22
|
+
import org.robolectric.util.ReflectionHelpers
|
|
23
|
+
import org.robolectric.util.ReflectionHelpers.ClassParameter
|
|
24
|
+
|
|
25
|
+
@RunWith(RobolectricTestRunner::class)
|
|
26
|
+
@Config(sdk = [33])
|
|
27
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
28
|
+
class G2PairingTargetTest {
|
|
29
|
+
@Before fun setup() {
|
|
30
|
+
Bridge.initialize(RuntimeEnvironment.getApplication())
|
|
31
|
+
shadowOf(BluetoothAdapter.getDefaultAdapter()).setState(BluetoothAdapter.STATE_ON)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Test fun `unscoped legacy addresses cannot connect a different G2 pair`() {
|
|
35
|
+
RuntimeEnvironment.getApplication().getSharedPreferences("G2Prefs", Context.MODE_PRIVATE).edit()
|
|
36
|
+
.putString("g2_leftGlassAddress", "00:00:00:00:01:01")
|
|
37
|
+
.putString("g2_rightGlassAddress", "00:00:00:00:01:02").apply()
|
|
38
|
+
val g2 = G2()
|
|
39
|
+
try {
|
|
40
|
+
g2.connectById("S2NEW000000001")
|
|
41
|
+
val adapter = BluetoothAdapter.getDefaultAdapter()
|
|
42
|
+
assertTrue(shadowOf(adapter.getRemoteDevice("00:00:00:00:01:01")).bluetoothGatts.isEmpty())
|
|
43
|
+
assertTrue(shadowOf(adapter.getRemoteDevice("00:00:00:00:01:02")).bluetoothGatts.isEmpty())
|
|
44
|
+
assertEquals(1, shadowOf(adapter.bluetoothLeScanner).scanCallbacks.size)
|
|
45
|
+
} finally { g2.disconnect() }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Test fun `learned addresses reconnect only their own serial across driver recreation`() {
|
|
49
|
+
val serial = "S2NEW000000001"
|
|
50
|
+
val adapter = BluetoothAdapter.getDefaultAdapter()
|
|
51
|
+
val left = adapter.getRemoteDevice("00:00:00:00:02:01")
|
|
52
|
+
val right = adapter.getRemoteDevice("00:00:00:00:02:02")
|
|
53
|
+
shadowOf(left).setName("Even G2_47_L_000001")
|
|
54
|
+
shadowOf(right).setName("Even G2_47_R_000002")
|
|
55
|
+
var g2 = G2()
|
|
56
|
+
try {
|
|
57
|
+
g2.connectById(serial)
|
|
58
|
+
val callback = shadowOf(adapter.bluetoothLeScanner).scanCallbacks.single()
|
|
59
|
+
// Manufacturer record: company ID 0x4552, followed by the advertised serial.
|
|
60
|
+
val payload = byteArrayOf(0x52, 0x45) + serial.toByteArray(Charsets.US_ASCII)
|
|
61
|
+
val record = ReflectionHelpers.callStaticMethod<ScanRecord>(
|
|
62
|
+
ScanRecord::class.java, "parseFromBytes",
|
|
63
|
+
ClassParameter.from(ByteArray::class.java, byteArrayOf((payload.size + 1).toByte(), 0xff.toByte()) + payload + byteArrayOf(0)),
|
|
64
|
+
)
|
|
65
|
+
for (device in listOf(left, right)) {
|
|
66
|
+
callback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES, ScanResult(device, record, -50, 0))
|
|
67
|
+
}
|
|
68
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
69
|
+
for (device in listOf(left, right)) {
|
|
70
|
+
assertEquals(1, shadowOf(device).bluetoothGatts.size)
|
|
71
|
+
shadowOf(device).simulateGattConnectionChange(BluetoothGatt.GATT_SUCCESS, BluetoothProfile.STATE_CONNECTED)
|
|
72
|
+
}
|
|
73
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
74
|
+
g2.disconnect()
|
|
75
|
+
|
|
76
|
+
g2 = G2()
|
|
77
|
+
g2.connectById("S2OTHER0000001")
|
|
78
|
+
assertEquals(1, shadowOf(left).bluetoothGatts.size)
|
|
79
|
+
assertEquals(1, shadowOf(right).bluetoothGatts.size)
|
|
80
|
+
assertEquals(1, shadowOf(adapter.bluetoothLeScanner).scanCallbacks.size)
|
|
81
|
+
g2.disconnect()
|
|
82
|
+
|
|
83
|
+
g2 = G2()
|
|
84
|
+
g2.connectById(serial)
|
|
85
|
+
assertEquals(2, shadowOf(left).bluetoothGatts.size)
|
|
86
|
+
assertEquals(2, shadowOf(right).bluetoothGatts.size)
|
|
87
|
+
assertTrue(shadowOf(adapter.bluetoothLeScanner).scanCallbacks.isEmpty())
|
|
88
|
+
} finally { g2.disconnect() }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothAdapter
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import androidx.test.core.app.ApplicationProvider
|
|
6
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
7
|
+
import com.mentra.bluetoothsdk.DeviceStore
|
|
8
|
+
import java.time.Duration
|
|
9
|
+
import org.junit.Assert.assertEquals
|
|
10
|
+
import org.junit.Assert.assertTrue
|
|
11
|
+
import org.junit.Before
|
|
12
|
+
import org.junit.Test
|
|
13
|
+
import org.junit.runner.RunWith
|
|
14
|
+
import org.robolectric.RobolectricTestRunner
|
|
15
|
+
import org.robolectric.Shadows.shadowOf
|
|
16
|
+
import org.robolectric.annotation.Config
|
|
17
|
+
import org.robolectric.annotation.LooperMode
|
|
18
|
+
|
|
19
|
+
@RunWith(RobolectricTestRunner::class)
|
|
20
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
21
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
22
|
+
class MentraLivePairingTargetTest {
|
|
23
|
+
@Before fun setup() {
|
|
24
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
25
|
+
shadowOf(BluetoothAdapter.getDefaultAdapter()).setState(BluetoothAdapter.STATE_ON)
|
|
26
|
+
DeviceStore.set("bluetooth", "pending_device_name", "MENTRA_LIVE_NEW")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Test fun `name-only selection scans instead of connecting the previous Live`() {
|
|
30
|
+
assertTarget("MENTRA_LIVE_OLD", "00:00:00:00:00:01", "", scanExpected = true)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Test fun `normal pairing connects the pending Live address`() {
|
|
34
|
+
assertTarget("MENTRA_LIVE_OLD", "00:00:00:00:00:01", "00:00:00:00:00:02")
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test fun `normal saved Live reconnect keeps the matching address`() {
|
|
38
|
+
assertTarget("MENTRA_LIVE_NEW", "00:00:00:00:00:02", "")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private fun assertTarget(savedName: String, savedAddress: String, pendingAddress: String, scanExpected: Boolean = false) {
|
|
42
|
+
DeviceStore.set("bluetooth", "device_name", savedName)
|
|
43
|
+
DeviceStore.set("bluetooth", "device_address", savedAddress)
|
|
44
|
+
DeviceStore.set("bluetooth", "pending_device_address", pendingAddress)
|
|
45
|
+
val adapter = BluetoothAdapter.getDefaultAdapter()
|
|
46
|
+
val old = adapter.getRemoteDevice("00:00:00:00:00:01")
|
|
47
|
+
val selected = adapter.getRemoteDevice("00:00:00:00:00:02")
|
|
48
|
+
shadowOf(old).setName("MENTRA_LIVE_OLD")
|
|
49
|
+
shadowOf(selected).setName("MENTRA_LIVE_NEW")
|
|
50
|
+
val live = MentraLive()
|
|
51
|
+
try {
|
|
52
|
+
live.connectById("MENTRA_LIVE_NEW")
|
|
53
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
54
|
+
assertTrue(shadowOf(old).bluetoothGatts.isEmpty())
|
|
55
|
+
assertEquals(if (scanExpected) 0 else 1, shadowOf(selected).bluetoothGatts.size)
|
|
56
|
+
assertEquals(if (scanExpected) 1 else 0, shadowOf(adapter.bluetoothLeScanner).scanCallbacks.size)
|
|
57
|
+
assertEquals(savedName, DeviceStore.get("bluetooth", "device_name"))
|
|
58
|
+
} finally {
|
|
59
|
+
live.destroy()
|
|
60
|
+
// Robolectric does not deliver the disconnect callback automatically.
|
|
61
|
+
// Complete the production teardown timeout before another test connects.
|
|
62
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(2))
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothAdapter
|
|
4
|
+
import android.bluetooth.BluetoothDevice
|
|
5
|
+
import android.bluetooth.BluetoothGatt
|
|
6
|
+
import android.bluetooth.BluetoothProfile
|
|
7
|
+
import android.bluetooth.le.ScanResult
|
|
8
|
+
import android.bluetooth.le.ScanSettings
|
|
9
|
+
import android.os.Looper
|
|
10
|
+
import androidx.test.core.app.ApplicationProvider
|
|
11
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
12
|
+
import com.mentra.bluetoothsdk.DeviceManager
|
|
13
|
+
import com.mentra.bluetoothsdk.DeviceStore
|
|
14
|
+
import com.mentra.bluetoothsdk.utils.DeviceTypes
|
|
15
|
+
import org.junit.Assert.assertEquals
|
|
16
|
+
import org.junit.Assert.assertTrue
|
|
17
|
+
import org.junit.Before
|
|
18
|
+
import org.junit.Test
|
|
19
|
+
import org.junit.runner.RunWith
|
|
20
|
+
import org.robolectric.RobolectricTestRunner
|
|
21
|
+
import org.robolectric.Shadows.shadowOf
|
|
22
|
+
import org.robolectric.annotation.Config
|
|
23
|
+
import org.robolectric.annotation.Implementation
|
|
24
|
+
import org.robolectric.annotation.Implements
|
|
25
|
+
import org.robolectric.annotation.LooperMode
|
|
26
|
+
import org.robolectric.shadows.ShadowBluetoothGatt
|
|
27
|
+
|
|
28
|
+
@RunWith(RobolectricTestRunner::class)
|
|
29
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class, MentraNexPairingTest.ShadowNexGatt::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
30
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
31
|
+
class MentraNexPairingTest {
|
|
32
|
+
// Robolectric implements connection callbacks but not the PHY binder request.
|
|
33
|
+
@Implements(BluetoothGatt::class)
|
|
34
|
+
class ShadowNexGatt : ShadowBluetoothGatt() {
|
|
35
|
+
@Implementation fun setPreferredPhy(txPhy: Int, rxPhy: Int, phyOptions: Int) {}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Before fun setup() {
|
|
39
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
40
|
+
shadowOf(BluetoothAdapter.getDefaultAdapter()).setState(BluetoothAdapter.STATE_ON)
|
|
41
|
+
DeviceStore.set("bluetooth", "pending_device_name", "Nex1-2")
|
|
42
|
+
DeviceStore.set("bluetooth", "pending_device_address", "")
|
|
43
|
+
DeviceStore.set("bluetooth", "device_address", "")
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Test fun `fresh pairing selects only the requested Nex`() {
|
|
47
|
+
assertScansSelectedTarget("", "")
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Test fun `simulated pairing selects only the requested Nex`() {
|
|
51
|
+
assertScansSelectedTarget("Simulated Glasses", "")
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Test fun `a different saved Nex name and address cannot redirect selection`() {
|
|
55
|
+
assertScansSelectedTarget("Nex1-1", "00:00:00:00:00:01")
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Test fun `pending address targets the new Nex instead of the saved pair`() {
|
|
59
|
+
assertDirectTarget("Nex1-1", "00:00:00:00:00:01", "00:00:00:00:00:02")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Test fun `saved Nex reconnect retains its address`() {
|
|
63
|
+
assertDirectTarget("Nex1-2", "00:00:00:00:00:02", "")
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@Test fun `name-only pairing readiness cannot associate the old MAC with the new Nex`() {
|
|
67
|
+
DeviceStore.set("bluetooth", "default_wearable", DeviceTypes.NEX)
|
|
68
|
+
DeviceStore.set("bluetooth", "pending_wearable", DeviceTypes.NEX)
|
|
69
|
+
DeviceStore.set("bluetooth", "device_name", "Nex1-1")
|
|
70
|
+
DeviceStore.set("bluetooth", "device_address", "00:00:00:00:00:01")
|
|
71
|
+
DeviceStore.set("bluetooth", "shouldSendBootingMessage", false)
|
|
72
|
+
DeviceStore.set("glasses", "fullyBooted", false)
|
|
73
|
+
val old = device("00:00:00:00:00:01", "Nex1-1")
|
|
74
|
+
val selected = device("00:00:00:00:00:02", "Nex1-2")
|
|
75
|
+
val singleton = DeviceManager::class.java.getDeclaredField("_instance").apply { isAccessible = true }
|
|
76
|
+
val previous = singleton.get(null)
|
|
77
|
+
val manager = DeviceManager(initializeHardware = false)
|
|
78
|
+
singleton.set(null, manager)
|
|
79
|
+
try {
|
|
80
|
+
var nex = MentraNex()
|
|
81
|
+
manager.sgc = nex
|
|
82
|
+
nex.connectById("Nex1-2")
|
|
83
|
+
val scanner = shadowOf(BluetoothAdapter.getDefaultAdapter().bluetoothLeScanner)
|
|
84
|
+
scanner.scanCallbacks.single().onScanResult(
|
|
85
|
+
ScanSettings.CALLBACK_TYPE_ALL_MATCHES, ScanResult(selected, null, -50, 0),
|
|
86
|
+
)
|
|
87
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
88
|
+
// Drive the actual ready callback and DeviceManager's identity promotion.
|
|
89
|
+
shadowOf(selected).simulateGattConnectionChange(BluetoothGatt.GATT_SUCCESS, BluetoothProfile.STATE_CONNECTED)
|
|
90
|
+
assertEquals("Nex1-2", DeviceStore.get("bluetooth", "device_name"))
|
|
91
|
+
assertEquals("", DeviceStore.get("bluetooth", "device_address"))
|
|
92
|
+
assertEquals("", DeviceStore.get("bluetooth", "pending_device_name"))
|
|
93
|
+
manager.disconnect()
|
|
94
|
+
|
|
95
|
+
nex = MentraNex()
|
|
96
|
+
manager.sgc = nex
|
|
97
|
+
nex.connectById(DeviceStore.get("bluetooth", "device_name") as String)
|
|
98
|
+
assertTrue(shadowOf(old).bluetoothGatts.isEmpty())
|
|
99
|
+
scanner.scanCallbacks.single().onScanResult(
|
|
100
|
+
ScanSettings.CALLBACK_TYPE_ALL_MATCHES, ScanResult(selected, null, -50, 0),
|
|
101
|
+
)
|
|
102
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
103
|
+
assertEquals(2, shadowOf(selected).bluetoothGatts.size)
|
|
104
|
+
} finally {
|
|
105
|
+
manager.disconnect()
|
|
106
|
+
manager.cleanup()
|
|
107
|
+
singleton.set(null, previous)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private fun assertScansSelectedTarget(savedName: String, savedAddress: String) {
|
|
112
|
+
DeviceStore.set("bluetooth", "device_name", savedName)
|
|
113
|
+
DeviceStore.set("bluetooth", "device_address", savedAddress)
|
|
114
|
+
val old = device("00:00:00:00:00:01", "Nex1-1")
|
|
115
|
+
val prefixCollision = device("00:00:00:00:00:03", "Nex1-23")
|
|
116
|
+
val selected = device("00:00:00:00:00:02", "Nex1-2")
|
|
117
|
+
val nex = MentraNex()
|
|
118
|
+
try {
|
|
119
|
+
nex.connectById("Nex1-2")
|
|
120
|
+
val scanner = shadowOf(BluetoothAdapter.getDefaultAdapter().bluetoothLeScanner)
|
|
121
|
+
val callback = scanner.scanCallbacks.single()
|
|
122
|
+
for (found in listOf(old, prefixCollision, selected)) {
|
|
123
|
+
callback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES, ScanResult(found, null, -50, 0))
|
|
124
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
125
|
+
}
|
|
126
|
+
assertTrue(shadowOf(old).bluetoothGatts.isEmpty())
|
|
127
|
+
assertTrue(shadowOf(prefixCollision).bluetoothGatts.isEmpty())
|
|
128
|
+
assertEquals(1, shadowOf(selected).bluetoothGatts.size)
|
|
129
|
+
assertEquals(savedName, DeviceStore.get("bluetooth", "device_name"))
|
|
130
|
+
} finally { nex.disconnect() }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private fun assertDirectTarget(savedName: String, savedAddress: String, pendingAddress: String) {
|
|
134
|
+
DeviceStore.set("bluetooth", "device_name", savedName)
|
|
135
|
+
DeviceStore.set("bluetooth", "device_address", savedAddress)
|
|
136
|
+
DeviceStore.set("bluetooth", "pending_device_address", pendingAddress)
|
|
137
|
+
val old = device("00:00:00:00:00:01", "Nex1-1")
|
|
138
|
+
val selected = device("00:00:00:00:00:02", "Nex1-2")
|
|
139
|
+
val nex = MentraNex()
|
|
140
|
+
try {
|
|
141
|
+
nex.connectById("Nex1-2")
|
|
142
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
143
|
+
assertTrue(shadowOf(old).bluetoothGatts.isEmpty())
|
|
144
|
+
assertEquals(1, shadowOf(selected).bluetoothGatts.size)
|
|
145
|
+
assertEquals(savedName, DeviceStore.get("bluetooth", "device_name"))
|
|
146
|
+
} finally { nex.disconnect() }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private fun device(address: String, name: String): BluetoothDevice =
|
|
150
|
+
BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address).also { shadowOf(it).setName(name) }
|
|
151
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Assert.assertNull
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class SelectedDeviceAddressTest {
|
|
8
|
+
@Test fun `selected pending address wins over saved address`() {
|
|
9
|
+
assertEquals("new", SelectedDeviceAddress.resolve("LIVE_2", "LIVE_2", "new", "LIVE_1", "old"))
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@Test fun `a name-only selection cannot use another device's saved address`() {
|
|
13
|
+
assertNull(SelectedDeviceAddress.resolve("LIVE_2", "LIVE_2", "", "LIVE_1", "old"))
|
|
14
|
+
assertNull(SelectedDeviceAddress.resolve("Nex1-2", "Nex1-2", null, "Nex1-1", "old"))
|
|
15
|
+
assertNull(SelectedDeviceAddress.resolve("Nex1-2", null, null, "Simulated Glasses", ""))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Test fun `saved reconnect keeps its address even with an unrelated pending selection`() {
|
|
19
|
+
assertEquals("old", SelectedDeviceAddress.resolve("LIVE_1", "LIVE_2", "new", "LIVE_1", "old"))
|
|
20
|
+
assertEquals("old", SelectedDeviceAddress.resolve("Nex1-1", null, null, "Nex1-1", "old"))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Test fun `empty or mismatched identities never supply an address`() {
|
|
24
|
+
assertNull(SelectedDeviceAddress.resolve("", "", "new", "", "old"))
|
|
25
|
+
assertNull(SelectedDeviceAddress.resolve("LIVE_2", "LIVE_1", "new", "LIVE_1", "old"))
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export const BLUETOOTH_SDK_RELEASE_METADATA = Object.freeze({
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"familyBaseVersion": "3.2.1",
|
|
4
|
-
"releaseIdentity": "3.2.1-beta.
|
|
5
|
-
"releaseSetId": "mentra-3.2.1-beta.
|
|
6
|
-
"sourceCommit": "
|
|
7
|
-
"otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.2.1/mentra-live-ota-3.2.1-beta.
|
|
8
|
-
"otaManifestSha256": "
|
|
4
|
+
"releaseIdentity": "3.2.1-beta.386",
|
|
5
|
+
"releaseSetId": "mentra-3.2.1-beta.386",
|
|
6
|
+
"sourceCommit": "447155847a6e3f268b9f8dcfd664aee9b59cfb68",
|
|
7
|
+
"otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.2.1/mentra-live-ota-3.2.1-beta.386.json",
|
|
8
|
+
"otaManifestSha256": "33fba6c95820df3762605aabe9ae04d45268430e0938cf136ff4716b8bd2a64c"
|
|
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,gBAAgB;IACnC,cAAc,EAAE,uBAAuB;IACvC,cAAc,EAAE,0CAA0C;IAC1D,gBAAgB,EAAE,kIAAkI;IACpJ,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.2.1\",\n \"releaseIdentity\": \"3.2.1-beta.
|
|
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,gBAAgB;IACnC,cAAc,EAAE,uBAAuB;IACvC,cAAc,EAAE,0CAA0C;IAC1D,gBAAgB,EAAE,kIAAkI;IACpJ,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.2.1\",\n \"releaseIdentity\": \"3.2.1-beta.386\",\n \"releaseSetId\": \"mentra-3.2.1-beta.386\",\n \"sourceCommit\": \"447155847a6e3f268b9f8dcfd664aee9b59cfb68\",\n \"otaManifestUrl\": \"https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.2.1/mentra-live-ota-3.2.1-beta.386.json\",\n \"otaManifestSha256\": \"33fba6c95820df3762605aabe9ae04d45268430e0938cf136ff4716b8bd2a64c\"\n})\n"]}
|
|
@@ -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.2.1-beta.
|
|
19
|
+
private static let swiftPackageSdkVersion = "3.2.1-beta.386"
|
|
20
20
|
private static let swiftPackageSdkVersionPlaceholder = "__MENTRA" + "_BLUETOOTH_SDK_VERSION__"
|
|
21
21
|
|
|
22
22
|
private static func normalizedSdkVersion(_ value: String?) -> String? {
|
|
@@ -998,12 +998,16 @@ struct ViewState {
|
|
|
998
998
|
Bridge.log("MAN: handleDeviceReady(): \(sgc.type)")
|
|
999
999
|
resetMicHealth()
|
|
1000
1000
|
|
|
1001
|
+
// A new identity must never inherit the previous glasses' address when
|
|
1002
|
+
// pairing supplied only a name. Same-device reconnects retain their cache.
|
|
1003
|
+
let identityChanged = !pendingDeviceName.isEmpty &&
|
|
1004
|
+
(pendingDeviceName != deviceName || sgc.type != defaultWearable)
|
|
1005
|
+
if identityChanged || !pendingDeviceAddress.isEmpty {
|
|
1006
|
+
deviceAddress = pendingDeviceAddress
|
|
1007
|
+
}
|
|
1001
1008
|
if !pendingDeviceName.isEmpty {
|
|
1002
1009
|
deviceName = pendingDeviceName
|
|
1003
1010
|
}
|
|
1004
|
-
if !pendingDeviceAddress.isEmpty {
|
|
1005
|
-
deviceAddress = pendingDeviceAddress
|
|
1006
|
-
}
|
|
1007
1011
|
clearPendingConnection()
|
|
1008
1012
|
defaultWearable = sgc.type
|
|
1009
1013
|
searching = false
|
|
@@ -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.2.1"
|
|
6
|
-
static let releaseIdentity = "3.2.1-beta.
|
|
7
|
-
static let releaseSetId = "mentra-3.2.1-beta.
|
|
8
|
-
static let sourceCommit = "
|
|
9
|
-
static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.2.1/mentra-live-ota-3.2.1-beta.
|
|
10
|
-
static let otaManifestSha256 = "
|
|
6
|
+
static let releaseIdentity = "3.2.1-beta.386"
|
|
7
|
+
static let releaseSetId = "mentra-3.2.1-beta.386"
|
|
8
|
+
static let sourceCommit = "447155847a6e3f268b9f8dcfd664aee9b59cfb68"
|
|
9
|
+
static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.2.1/mentra-live-ota-3.2.1-beta.386.json"
|
|
10
|
+
static let otaManifestSha256 = "33fba6c95820df3762605aabe9ae04d45268430e0938cf136ff4716b8bd2a64c"
|
|
11
11
|
}
|
package/ios/Source/sgcs/G1.swift
CHANGED
|
@@ -468,8 +468,10 @@ class G1: NSObject, SGCManager {
|
|
|
468
468
|
set {
|
|
469
469
|
if let newValue = newValue {
|
|
470
470
|
UserDefaults.standard.set(newValue.uuidString, forKey: "leftGlassUUID")
|
|
471
|
+
UserDefaults.standard.set(DEVICE_SEARCH_ID, forKey: "leftGlassSearchID")
|
|
471
472
|
} else {
|
|
472
473
|
UserDefaults.standard.removeObject(forKey: "leftGlassUUID")
|
|
474
|
+
UserDefaults.standard.removeObject(forKey: "leftGlassSearchID")
|
|
473
475
|
}
|
|
474
476
|
}
|
|
475
477
|
}
|
|
@@ -484,8 +486,10 @@ class G1: NSObject, SGCManager {
|
|
|
484
486
|
set {
|
|
485
487
|
if let newValue = newValue {
|
|
486
488
|
UserDefaults.standard.set(newValue.uuidString, forKey: "rightGlassUUID")
|
|
489
|
+
UserDefaults.standard.set(DEVICE_SEARCH_ID, forKey: "rightGlassSearchID")
|
|
487
490
|
} else {
|
|
488
491
|
UserDefaults.standard.removeObject(forKey: "rightGlassUUID")
|
|
492
|
+
UserDefaults.standard.removeObject(forKey: "rightGlassSearchID")
|
|
489
493
|
}
|
|
490
494
|
}
|
|
491
495
|
}
|
|
@@ -2401,17 +2405,22 @@ extension G1: CBCentralManagerDelegate, CBPeripheralDelegate {
|
|
|
2401
2405
|
}
|
|
2402
2406
|
|
|
2403
2407
|
Bridge.log("G1: 🔵 Attempting to connect by UUID")
|
|
2404
|
-
var
|
|
2408
|
+
var foundSides = 0
|
|
2405
2409
|
|
|
2406
2410
|
if let leftUUID = leftGlassUUID {
|
|
2407
2411
|
Bridge.log("G1: 🔵 Found stored left glass UUID: \(leftUUID.uuidString)")
|
|
2408
2412
|
let leftDevices = centralManager!.retrievePeripherals(withIdentifiers: [leftUUID])
|
|
2409
2413
|
|
|
2410
|
-
if let leftDevice = leftDevices.first
|
|
2414
|
+
if let leftDevice = leftDevices.first,
|
|
2415
|
+
G1ConnectionTarget.matchesCachedPeripheral(
|
|
2416
|
+
name: leftDevice.name, searchID: DEVICE_SEARCH_ID,
|
|
2417
|
+
cachedSearchID: UserDefaults.standard.string(forKey: "leftGlassSearchID")
|
|
2418
|
+
)
|
|
2419
|
+
{
|
|
2411
2420
|
Bridge.log(
|
|
2412
2421
|
"G1: 🔵 Successfully retrieved left glass: \(leftDevice.name ?? "Unknown")"
|
|
2413
2422
|
)
|
|
2414
|
-
|
|
2423
|
+
foundSides += 1
|
|
2415
2424
|
leftPeripheral = leftDevice
|
|
2416
2425
|
leftDevice.delegate = self
|
|
2417
2426
|
centralManager!.connect(
|
|
@@ -2428,11 +2437,16 @@ extension G1: CBCentralManagerDelegate, CBPeripheralDelegate {
|
|
|
2428
2437
|
Bridge.log("G1: 🔵 Found stored right glass UUID: \(rightUUID.uuidString)")
|
|
2429
2438
|
let rightDevices = centralManager!.retrievePeripherals(withIdentifiers: [rightUUID])
|
|
2430
2439
|
|
|
2431
|
-
if let rightDevice = rightDevices.first
|
|
2440
|
+
if let rightDevice = rightDevices.first,
|
|
2441
|
+
G1ConnectionTarget.matchesCachedPeripheral(
|
|
2442
|
+
name: rightDevice.name, searchID: DEVICE_SEARCH_ID,
|
|
2443
|
+
cachedSearchID: UserDefaults.standard.string(forKey: "rightGlassSearchID")
|
|
2444
|
+
)
|
|
2445
|
+
{
|
|
2432
2446
|
Bridge.log(
|
|
2433
2447
|
"G1: 🔵 Successfully retrieved right glass: \(rightDevice.name ?? "Unknown")"
|
|
2434
2448
|
)
|
|
2435
|
-
|
|
2449
|
+
foundSides += 1
|
|
2436
2450
|
rightPeripheral = rightDevice
|
|
2437
2451
|
rightDevice.delegate = self
|
|
2438
2452
|
centralManager!.connect(
|
|
@@ -2445,7 +2459,8 @@ extension G1: CBCentralManagerDelegate, CBPeripheralDelegate {
|
|
|
2445
2459
|
}
|
|
2446
2460
|
}
|
|
2447
2461
|
|
|
2448
|
-
|
|
2462
|
+
// Continue scanning if only one matching cached half was available.
|
|
2463
|
+
return foundSides == 2
|
|
2449
2464
|
}
|
|
2450
2465
|
|
|
2451
2466
|
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices _: Error?) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
enum G1ConnectionTarget {
|
|
4
|
+
/// A legacy UUID needs a matching peripheral name; newly recorded UUIDs can
|
|
5
|
+
/// also reconnect without a name because their search ID was saved with them.
|
|
6
|
+
static func matchesCachedPeripheral(name: String?, searchID: String, cachedSearchID: String?) -> Bool {
|
|
7
|
+
guard searchID != "NOT_SET", searchID.count > 2 else { return false }
|
|
8
|
+
if let name, !name.isEmpty {
|
|
9
|
+
return name.contains("G1" + searchID)
|
|
10
|
+
}
|
|
11
|
+
return cachedSearchID == searchID
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -133,6 +133,15 @@ class Mach1: UltraliteBaseViewController, SGCManager {
|
|
|
133
133
|
|
|
134
134
|
/// Store discovered peripherals by their identifier
|
|
135
135
|
private var discoveredPeripherals: [String: CBPeripheral] = [:]
|
|
136
|
+
private var selectedPeripheralID: String?
|
|
137
|
+
|
|
138
|
+
private var currentDeviceMatchesSelection: Bool {
|
|
139
|
+
guard let selectedPeripheralID else { return true }
|
|
140
|
+
let currentDevice = UltraliteManager.shared.currentDevice
|
|
141
|
+
return VuzixConnectionTarget.matches(
|
|
142
|
+
name: currentDevice?.peripheral?.name ?? currentDevice?.getName(), target: selectedPeripheralID
|
|
143
|
+
)
|
|
144
|
+
}
|
|
136
145
|
|
|
137
146
|
private var textHandle: Int?
|
|
138
147
|
private var tapTextHandle: Int?
|
|
@@ -146,6 +155,7 @@ class Mach1: UltraliteBaseViewController, SGCManager {
|
|
|
146
155
|
if setupDone { return }
|
|
147
156
|
isConnectedListener = BondListener(listener: { [weak self] value in
|
|
148
157
|
guard let self else { return }
|
|
158
|
+
guard !value || self.currentDeviceMatchesSelection else { return }
|
|
149
159
|
Bridge.log("MACH1: isConnectedListener: \(value)")
|
|
150
160
|
|
|
151
161
|
if value {
|
|
@@ -171,6 +181,7 @@ class Mach1: UltraliteBaseViewController, SGCManager {
|
|
|
171
181
|
|
|
172
182
|
batteryLevelListener = BondListener(listener: { [weak self] value in
|
|
173
183
|
guard let self else { return }
|
|
184
|
+
guard self.currentDeviceMatchesSelection else { return }
|
|
174
185
|
Bridge.log("MACH1: batteryLevelListener: \(value)")
|
|
175
186
|
batteryLevel = value
|
|
176
187
|
DeviceStore.shared.apply("glasses", "batteryLevel", value)
|
|
@@ -238,23 +249,22 @@ class Mach1: UltraliteBaseViewController, SGCManager {
|
|
|
238
249
|
|
|
239
250
|
// Extract the ID from the device name if it contains brackets
|
|
240
251
|
// e.g., "Vuzix Z100 [f1b87c]" -> "f1b87c"
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
peripheralId = String(deviceId)
|
|
244
|
-
}
|
|
252
|
+
let peripheralId = VuzixConnectionTarget.identifier(id)
|
|
253
|
+
selectedPeripheralID = peripheralId
|
|
245
254
|
|
|
246
255
|
let isLinked = UltraliteManager.shared.isLinked.value
|
|
247
256
|
let currentDevice = UltraliteManager.shared.currentDevice
|
|
248
257
|
let isConnected =
|
|
249
258
|
isLinked && currentDevice != nil && currentDevice!.isPaired
|
|
250
259
|
&& currentDevice!.isConnected.value
|
|
251
|
-
let
|
|
260
|
+
let matchesSelection = currentDeviceMatchesSelection
|
|
261
|
+
let peripheral = discoveredPeripherals[peripheralId] ?? (matchesSelection ? currentDevice?.peripheral : nil)
|
|
252
262
|
|
|
253
263
|
// Bind listeners to get notified when device connects
|
|
254
264
|
UltraliteManager.shared.currentDevice?.isConnected.bind(listener: isConnectedListener!)
|
|
255
265
|
UltraliteManager.shared.currentDevice?.batteryLevel.bind(listener: batteryLevelListener!)
|
|
256
266
|
|
|
257
|
-
if isConnected {
|
|
267
|
+
if isConnected && matchesSelection {
|
|
258
268
|
// Already connected, request control now
|
|
259
269
|
let gotControl = currentDevice?.requestControl(
|
|
260
270
|
layout: UltraliteSDK.Ultralite.Layout.textBottomLeftAlign, timeout: 0,
|
|
@@ -266,7 +276,7 @@ class Mach1: UltraliteBaseViewController, SGCManager {
|
|
|
266
276
|
return
|
|
267
277
|
}
|
|
268
278
|
|
|
269
|
-
if !isLinked {
|
|
279
|
+
if !isLinked || !matchesSelection {
|
|
270
280
|
if peripheral == nil {
|
|
271
281
|
Bridge.log("Mach1Manager: No peripheral found or stored with ID: \(peripheralId)")
|
|
272
282
|
CONNECTING_DEVICE = peripheralId
|
|
@@ -279,6 +289,8 @@ class Mach1: UltraliteBaseViewController, SGCManager {
|
|
|
279
289
|
UltraliteManager.shared.stopScan()
|
|
280
290
|
CONNECTING_DEVICE = ""
|
|
281
291
|
|
|
292
|
+
// Replace the SDK link only after finding the explicitly selected device.
|
|
293
|
+
if isLinked { UltraliteManager.shared.unlink() }
|
|
282
294
|
UltraliteManager.shared.link(device: peripheral!, callback: linked)
|
|
283
295
|
UltraliteManager.shared.currentDevice?.isConnected.bind(listener: isConnectedListener!)
|
|
284
296
|
UltraliteManager.shared.currentDevice?.batteryLevel.bind(
|
|
@@ -5286,7 +5286,8 @@ class MentraLive: NSObject, SGCManager {
|
|
|
5286
5286
|
if let requestId {
|
|
5287
5287
|
json["request_id"] = requestId
|
|
5288
5288
|
}
|
|
5289
|
-
|
|
5289
|
+
// Wake ASG so the version request and its response can finish after idle.
|
|
5290
|
+
sendJson(json, wakeUp: true)
|
|
5290
5291
|
}
|
|
5291
5292
|
|
|
5292
5293
|
private func sendCoreTokenToAsgClient() {
|
|
@@ -994,7 +994,7 @@ class MentraNexSGC: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate, SG
|
|
|
994
994
|
// global "last" one. peripheralToConnectName == nil means an auto-reconnect with no
|
|
995
995
|
// specific target, so the cached device is exactly what we want — keep using it.)
|
|
996
996
|
if let targetName = peripheralToConnectName,
|
|
997
|
-
|
|
997
|
+
peripheralToConnect.name != targetName
|
|
998
998
|
{
|
|
999
999
|
Bridge.log(
|
|
1000
1000
|
"NEX-CONN: 🔵 Stored UUID is '\(peripheralToConnect.name ?? "unnamed")' but target is '\(targetName)'. Skipping UUID fast-path; will scan for the target."
|
|
@@ -1088,7 +1088,7 @@ class MentraNexSGC: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate, SG
|
|
|
1088
1088
|
])
|
|
1089
1089
|
if let targetName = peripheralToConnectName,
|
|
1090
1090
|
let existingPeripheral = connectedPeripherals.first(where: {
|
|
1091
|
-
$0.name
|
|
1091
|
+
$0.name == targetName
|
|
1092
1092
|
})
|
|
1093
1093
|
{
|
|
1094
1094
|
Bridge.log(
|
|
@@ -2724,35 +2724,12 @@ class MentraNexSGC: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate, SG
|
|
|
2724
2724
|
// Always emit the discovered device for the UI list
|
|
2725
2725
|
emitDiscoveredDevice(deviceName)
|
|
2726
2726
|
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
shouldConnect = true
|
|
2734
|
-
connectionReason = "Target device name match: \(targetName)"
|
|
2735
|
-
}
|
|
2736
|
-
// During a user-initiated discovery scan, only list devices — never auto-connect a
|
|
2737
|
-
// saved/preferred device, so the user can pick a different one.
|
|
2738
|
-
else if isDiscoveryScan {
|
|
2739
|
-
shouldConnect = false
|
|
2740
|
-
}
|
|
2741
|
-
// Check if this matches our saved device for reconnection
|
|
2742
|
-
else if let savedName = savedDeviceName, deviceName == savedName {
|
|
2743
|
-
shouldConnect = true
|
|
2744
|
-
connectionReason = "Saved device reconnection: \(savedName)"
|
|
2745
|
-
}
|
|
2746
|
-
// Check if this matches preferred device ID
|
|
2747
|
-
else if let preferredId = preferredDeviceId {
|
|
2748
|
-
if let extractedId = extractDeviceId(from: deviceName), extractedId == preferredId {
|
|
2749
|
-
shouldConnect = true
|
|
2750
|
-
connectionReason = "Preferred device ID match: \(preferredId)"
|
|
2751
|
-
}
|
|
2752
|
-
}
|
|
2753
|
-
|
|
2754
|
-
if shouldConnect {
|
|
2755
|
-
connectToFoundDevice(peripheral, reason: connectionReason)
|
|
2727
|
+
if NexConnectionTarget.shouldConnect(
|
|
2728
|
+
name: deviceName, target: peripheralToConnectName, discoveryOnly: isDiscoveryScan,
|
|
2729
|
+
savedName: savedDeviceName, preferredID: preferredDeviceId,
|
|
2730
|
+
discoveredID: extractDeviceId(from: deviceName)
|
|
2731
|
+
) {
|
|
2732
|
+
connectToFoundDevice(peripheral, reason: "Selected target or saved reconnect identity")
|
|
2756
2733
|
}
|
|
2757
2734
|
}
|
|
2758
2735
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
enum NexConnectionTarget {
|
|
4
|
+
static func shouldConnect(
|
|
5
|
+
name: String, target: String?, discoveryOnly: Bool,
|
|
6
|
+
savedName: String?, preferredID: String?, discoveredID: String?
|
|
7
|
+
) -> Bool {
|
|
8
|
+
guard !discoveryOnly else { return false }
|
|
9
|
+
// An explicit selection is authoritative even when it does not match.
|
|
10
|
+
// Saved-device fallbacks are only for reconnecting without a selection.
|
|
11
|
+
if let target { return !target.isEmpty && name == target }
|
|
12
|
+
if let savedName, !savedName.isEmpty, name == savedName { return true }
|
|
13
|
+
return preferredID != nil && preferredID == discoveredID
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
enum VuzixConnectionTarget {
|
|
4
|
+
static func identifier(_ name: String) -> String {
|
|
5
|
+
guard let start = name.lastIndex(of: "["),
|
|
6
|
+
let end = name[start...].firstIndex(of: "]")
|
|
7
|
+
else { return name }
|
|
8
|
+
return String(name[name.index(after: start) ..< end])
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static func matches(name: String?, target: String) -> Bool {
|
|
12
|
+
guard let name, !target.isEmpty else { return false }
|
|
13
|
+
return identifier(name) == identifier(target)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
@testable import MentraBluetoothSDK
|
|
2
|
+
import XCTest
|
|
3
|
+
|
|
4
|
+
@MainActor
|
|
5
|
+
final class DeviceIdentityPairingTests: XCTestCase {
|
|
6
|
+
func testReadinessPromotesCoherentIdentityAndPreservesSameDeviceReconnects() {
|
|
7
|
+
let store = DeviceStore.shared.store
|
|
8
|
+
let saved = ["bluetooth", "glasses"].map { ($0, store.getCategory($0)) }
|
|
9
|
+
defer {
|
|
10
|
+
for (category, values) in saved {
|
|
11
|
+
for key in store.getCategory(category).keys where values[key] == nil {
|
|
12
|
+
store.remove(category, key)
|
|
13
|
+
}
|
|
14
|
+
for (key, value) in values {
|
|
15
|
+
store.set(category, key, value)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let cases = [
|
|
20
|
+
// pending name, pending address, saved model, expected address
|
|
21
|
+
("new", "", "test", ""),
|
|
22
|
+
("new", "new-address", "test", "new-address"),
|
|
23
|
+
("old", "", "test", "old-address"),
|
|
24
|
+
("", "", "test", "old-address"),
|
|
25
|
+
("old", "", "other-model", ""),
|
|
26
|
+
]
|
|
27
|
+
for (pendingName, pendingAddress, savedModel, expectedAddress) in cases {
|
|
28
|
+
let manager = DeviceManager()
|
|
29
|
+
let device = Simulated()
|
|
30
|
+
device.type = "test"
|
|
31
|
+
manager.sgc = device
|
|
32
|
+
defer {
|
|
33
|
+
manager.disconnect()
|
|
34
|
+
manager.cleanup()
|
|
35
|
+
}
|
|
36
|
+
store.set("bluetooth", "default_wearable", savedModel)
|
|
37
|
+
store.set("bluetooth", "device_name", "old")
|
|
38
|
+
store.set("bluetooth", "device_address", "old-address")
|
|
39
|
+
store.set("bluetooth", "pending_device_name", pendingName)
|
|
40
|
+
store.set("bluetooth", "pending_device_address", pendingAddress)
|
|
41
|
+
store.set("bluetooth", "shouldSendBootingMessage", false)
|
|
42
|
+
manager.handleDeviceReady()
|
|
43
|
+
XCTAssertEqual(DeviceStore.shared.get("bluetooth", "device_name") as? String, pendingName.isEmpty ? "old" : pendingName)
|
|
44
|
+
XCTAssertEqual(DeviceStore.shared.get("bluetooth", "device_address") as? String, expectedAddress)
|
|
45
|
+
XCTAssertEqual(DeviceStore.shared.get("bluetooth", "pending_device_name") as? String, "")
|
|
46
|
+
XCTAssertEqual(DeviceStore.shared.get("bluetooth", "pending_device_address") as? String, "")
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
@testable import MentraBluetoothSDK
|
|
2
|
+
import XCTest
|
|
3
|
+
|
|
4
|
+
final class SGCConnectionTargetTests: XCTestCase {
|
|
5
|
+
func testG1RejectsAnotherPairsLegacyUUID() {
|
|
6
|
+
XCTAssertFalse(G1ConnectionTarget.matchesCachedPeripheral(name: "Even G1_12_L_123456", searchID: "_47_", cachedSearchID: nil))
|
|
7
|
+
XCTAssertTrue(G1ConnectionTarget.matchesCachedPeripheral(name: "Even G1_47_L_123456", searchID: "_47_", cachedSearchID: nil))
|
|
8
|
+
XCTAssertFalse(G1ConnectionTarget.matchesCachedPeripheral(name: "Even G1_470_R_123456", searchID: "_47_", cachedSearchID: nil))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
func testG1NamelessBackgroundReconnectRequiresRecordedTarget() {
|
|
12
|
+
XCTAssertTrue(G1ConnectionTarget.matchesCachedPeripheral(name: nil, searchID: "_47_", cachedSearchID: "_47_"))
|
|
13
|
+
XCTAssertFalse(G1ConnectionTarget.matchesCachedPeripheral(name: nil, searchID: "_47_", cachedSearchID: "_12_"))
|
|
14
|
+
XCTAssertFalse(G1ConnectionTarget.matchesCachedPeripheral(name: nil, searchID: "_47_", cachedSearchID: nil))
|
|
15
|
+
XCTAssertFalse(G1ConnectionTarget.matchesCachedPeripheral(name: "Even G1_12_L_123456", searchID: "_47_", cachedSearchID: "_47_"))
|
|
16
|
+
XCTAssertFalse(G1ConnectionTarget.matchesCachedPeripheral(name: nil, searchID: "NOT_SET", cachedSearchID: "NOT_SET"))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func testNexExplicitSelectionExcludesSavedAndPreferredFallbacks() {
|
|
20
|
+
XCTAssertFalse(nex(name: "Nex1-old", target: "Nex1-new"))
|
|
21
|
+
XCTAssertFalse(nex(name: "Nex1-new-extra", target: "Nex1-new"))
|
|
22
|
+
XCTAssertTrue(nex(name: "Nex1-new", target: "Nex1-new"))
|
|
23
|
+
XCTAssertFalse(nex(name: "Nex1-old", target: ""))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
func testNexDiscoveryNeverConnectsAndSavedReconnectStillWorks() {
|
|
27
|
+
XCTAssertFalse(nex(name: "Nex1-old", target: nil, discovery: true))
|
|
28
|
+
XCTAssertFalse(nex(name: "Nex1-new", target: "Nex1-new", discovery: true))
|
|
29
|
+
XCTAssertTrue(nex(name: "Nex1-old", target: nil))
|
|
30
|
+
XCTAssertTrue(nex(name: "Nex1-renamed", target: nil))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
func testVuzixCurrentLinkMustMatchTheSelectedBracketedID() {
|
|
34
|
+
XCTAssertTrue(VuzixConnectionTarget.matches(name: "Vuzix Z100 [abc123]", target: "abc123"))
|
|
35
|
+
XCTAssertTrue(VuzixConnectionTarget.matches(name: "Vuzix Z100 [abc123]", target: "Vuzix Z100 [abc123]"))
|
|
36
|
+
XCTAssertFalse(VuzixConnectionTarget.matches(name: "Vuzix Z100 [old123]", target: "abc123"))
|
|
37
|
+
XCTAssertFalse(VuzixConnectionTarget.matches(name: nil, target: "abc123"))
|
|
38
|
+
XCTAssertFalse(VuzixConnectionTarget.matches(name: "", target: ""))
|
|
39
|
+
XCTAssertEqual(VuzixConnectionTarget.identifier("abc123"), "abc123")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private func nex(name: String, target: String?, discovery: Bool = false) -> Bool {
|
|
43
|
+
NexConnectionTarget.shouldConnect(
|
|
44
|
+
name: name, target: target, discoveryOnly: discovery,
|
|
45
|
+
savedName: "Nex1-old", preferredID: "old", discoveredID: "old"
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
@testable import MentraBluetoothSDK
|
|
2
|
+
import XCTest
|
|
3
|
+
|
|
4
|
+
@MainActor
|
|
5
|
+
private final class VersionInfoCommandTransport: MentraLive {
|
|
6
|
+
var requestId: String?
|
|
7
|
+
|
|
8
|
+
override func sendJson(_ jsonOriginal: [String: Any], wakeUp: Bool, requireAck: Bool) {
|
|
9
|
+
XCTAssertEqual(jsonOriginal["type"] as? String, "request_version")
|
|
10
|
+
XCTAssertTrue(wakeUp, "An idle ASG must wake to finish its version response")
|
|
11
|
+
XCTAssertTrue(requireAck)
|
|
12
|
+
do {
|
|
13
|
+
let bytes = try JSONSerialization.data(withJSONObject: jsonOriginal)
|
|
14
|
+
let command = try XCTUnwrap(JSONSerialization.jsonObject(with: bytes) as? [String: Any])
|
|
15
|
+
let id = try XCTUnwrap(command["request_id"] as? String)
|
|
16
|
+
requestId = id
|
|
17
|
+
let common: [String: Any] = ["request_id": id, "sid": "asg-1", "chunkCount": 2]
|
|
18
|
+
for chunk: [String: Any] in [
|
|
19
|
+
["type": "version_info_1", "chunkIndex": 1, "final": false,
|
|
20
|
+
"build_number": "303000008", "app_version": "3.3.0"],
|
|
21
|
+
["type": "version_info_3", "chunkIndex": 2, "final": true,
|
|
22
|
+
"bes_fw_version": "26.9.23.0", "mtk_fw_version": "MentraLive_20260921.0"],
|
|
23
|
+
] {
|
|
24
|
+
let response = common.merging(chunk) { _, value in value }
|
|
25
|
+
try processReceivedData(JSONSerialization.data(withJSONObject: response))
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
XCTFail("Could not replay version request: \(error)")
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@MainActor
|
|
34
|
+
final class VersionInfoCommandTests: XCTestCase {
|
|
35
|
+
func testPublicVersionRequestWakesGlassesAndCombinesBothResponseChunks() async throws {
|
|
36
|
+
let previous = DeviceManager.shared.sgc
|
|
37
|
+
let transport = VersionInfoCommandTransport()
|
|
38
|
+
DeviceManager.shared.sgc = transport
|
|
39
|
+
let sdk = MentraBluetoothSDK()
|
|
40
|
+
defer {
|
|
41
|
+
sdk.invalidate()
|
|
42
|
+
DeviceManager.shared.sgc = previous
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let result = try await sdk.requestVersionInfo()
|
|
46
|
+
|
|
47
|
+
XCTAssertNotNil(transport.requestId)
|
|
48
|
+
XCTAssertEqual(result.buildNumber, "303000008")
|
|
49
|
+
XCTAssertEqual(result.appVersion, "3.3.0")
|
|
50
|
+
XCTAssertEqual(result.besFirmwareVersion, "26.9.23.0")
|
|
51
|
+
XCTAssertEqual(result.mtkFirmwareVersion, "MentraLive_20260921.0")
|
|
52
|
+
}
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentra/bluetooth-sdk",
|
|
3
|
-
"version": "3.2.1-beta.
|
|
3
|
+
"version": "3.2.1-beta.386",
|
|
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.2.1-beta.
|
|
117
|
+
"@mentra/cloud-protocol": "3.2.1-beta.386"
|
|
118
118
|
},
|
|
119
119
|
"devDependencies": {
|
|
120
120
|
"@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.2.1",
|
|
15
|
-
"releaseIdentity": "3.2.1-beta.
|
|
16
|
-
"releaseSetId": "mentra-3.2.1-beta.
|
|
17
|
-
"sourceCommit": "
|
|
18
|
-
"otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.2.1/mentra-live-ota-3.2.1-beta.
|
|
19
|
-
"otaManifestSha256": "
|
|
15
|
+
"releaseIdentity": "3.2.1-beta.386",
|
|
16
|
+
"releaseSetId": "mentra-3.2.1-beta.386",
|
|
17
|
+
"sourceCommit": "447155847a6e3f268b9f8dcfd664aee9b59cfb68",
|
|
18
|
+
"otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.2.1/mentra-live-ota-3.2.1-beta.386.json",
|
|
19
|
+
"otaManifestSha256": "33fba6c95820df3762605aabe9ae04d45268430e0938cf136ff4716b8bd2a64c"
|
|
20
20
|
})
|