@mentra/bluetooth-sdk 3.3.0-dev.944 → 3.4.0-dev.1004
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/MIGRATION.md +61 -0
- package/README.md +78 -0
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +274 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +13 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +8 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +79 -8
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +21 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +1 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +22 -4
- package/android/src/main/java/com/mentra/bluetoothsdk/TouchGesture.kt +19 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/connection/ConnectionModels.kt +5 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicy.kt +64 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +832 -134
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +227 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +19 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicy.kt +94 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachine.kt +411 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateStore.kt +124 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +337 -39
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +8 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasEncoder.kt +8 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +1 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +50 -0
- package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +16 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/DeviceManagerOwnerLossTest.kt +146 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusAudioSetupTest.kt +51 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusClassicAudioTest.kt +2 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/TouchGestureCommandTest.kt +112 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/WifiAdbPeerIntentTest.kt +19 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicyTest.kt +65 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveAudioSetupReadinessTest.kt +231 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +368 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +20 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicyTest.kt +136 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachineTest.kt +346 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +564 -1
- package/build/BluetoothSdk.types.d.ts +110 -2
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +6 -2
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +1 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/generated/changelogCatalog.d.ts +3 -0
- package/build/generated/changelogCatalog.d.ts.map +1 -1
- package/build/generated/changelogCatalog.js +4 -0
- package/build/generated/changelogCatalog.js.map +1 -1
- package/build/generated/releaseMetadata.js +6 -6
- package/build/generated/releaseMetadata.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -0
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +24 -4
- package/ios/Source/BluetoothSdkDefaults.swift +1 -1
- package/ios/Source/Bridge.swift +11 -3
- package/ios/Source/DeviceManager.swift +103 -7
- package/ios/Source/DeviceStore.swift +27 -0
- package/ios/Source/GeneratedChangelogCatalog.swift +1 -0
- package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
- package/ios/Source/MentraBluetoothSDK.swift +41 -7
- package/ios/Source/TouchGesture.swift +13 -0
- package/ios/Source/errors/BluetoothSdkError.swift +5 -1
- package/ios/Source/events/BluetoothEvents.swift +4 -0
- package/ios/Source/internal/BleTraceLogger.swift +9 -6
- package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +181 -0
- package/ios/Source/sgcs/MentraLive.swift +1196 -173
- package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +260 -1
- package/ios/Source/sgcs/MentraLivePairingStateMachine.swift +385 -0
- package/ios/Source/sgcs/MentraLivePairingStateStore.swift +121 -0
- package/ios/Source/sgcs/Nimo.swift +278 -38
- package/ios/Source/sgcs/NimoCanvasCoordinator.swift +77 -18
- package/ios/Source/sgcs/NimoCanvasSession.swift +1 -0
- package/ios/Source/sgcs/NimoMacResourceTransport.swift +217 -0
- package/ios/Source/sgcs/NimoResourceFixture.swift +384 -0
- package/ios/Source/sgcs/NimoResourceSession.swift +406 -0
- package/ios/Source/sgcs/SGCManager.swift +7 -0
- package/ios/Source/sgcs/Simulated.swift +2 -0
- package/ios/Source/status/DeviceStatus.swift +35 -0
- package/ios/Source/types/DeviceModels.swift +8 -1
- package/ios/Source/utils/AudioSessionMonitor.swift +158 -5
- package/ios/Tests/BluetoothAudioRouteTests.swift +82 -0
- package/ios/Tests/DeviceManagerReconnectTests.swift +75 -2
- package/ios/Tests/GlassesAudioSetupPolicyTests.swift +191 -0
- package/ios/Tests/MentraLiveAudioSetupTests.swift +215 -0
- package/ios/Tests/MentraLiveConnectionOptionsTests.swift +55 -0
- package/ios/Tests/MentraLivePairingAdvertisementTests.swift +327 -0
- package/ios/Tests/MentraLivePairingStateMachineTests.swift +402 -0
- package/ios/Tests/MentraLiveSessionReadinessTests.swift +328 -26
- package/ios/Tests/NimoCanvasTransportTests.swift +147 -0
- package/ios/Tests/NimoResourceSessionTests.swift +476 -0
- package/ios/Tests/TouchGestureCommandTests.swift +87 -0
- package/ios/Tests/WifiAdbDispatchTests.swift +118 -0
- package/package.json +3 -2
- package/src/BluetoothSdk.types.ts +115 -1
- package/src/_private/BluetoothSdkModule.ts +7 -1
- package/src/generated/changelogCatalog.ts +4 -0
- package/src/generated/releaseMetadata.ts +6 -6
- package/src/index.ts +12 -0
package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicyTest.kt
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothDevice
|
|
4
|
+
import com.mentra.bluetoothsdk.sgcs.MentraLivePairingReadinessPolicy.Readiness
|
|
5
|
+
import org.junit.Assert.assertEquals
|
|
6
|
+
import org.junit.Assert.assertFalse
|
|
7
|
+
import org.junit.Assert.assertNotEquals
|
|
8
|
+
import org.junit.Assert.assertNull
|
|
9
|
+
import org.junit.Assert.assertTrue
|
|
10
|
+
import org.junit.Test
|
|
11
|
+
|
|
12
|
+
class MentraLivePairingReadinessPolicyTest {
|
|
13
|
+
private val bonded = BluetoothDevice.BOND_BONDED
|
|
14
|
+
private val unbonded = BluetoothDevice.BOND_NONE
|
|
15
|
+
|
|
16
|
+
@Test
|
|
17
|
+
fun `constants match the spec`() {
|
|
18
|
+
assertEquals(5_000L, MentraLivePairingReadinessPolicy.UNKNOWN_CAPABILITY_PAIRING_INFO_WAIT_MS)
|
|
19
|
+
assertEquals(15_000L, MentraLivePairingReadinessPolicy.SECURE_FIRMWARE_REFRESH_MS)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Test
|
|
23
|
+
fun `the selected row decides and session pairing_info only fills an unknown row`() {
|
|
24
|
+
val policy = MentraLivePairingReadinessPolicy
|
|
25
|
+
assertTrue(policy.isSecurePairingTarget(true, null))
|
|
26
|
+
assertTrue(policy.isSecurePairingTarget(true, false))
|
|
27
|
+
// A row listed as legacy stays legacy (a rolled-back unit is never re-read as secure).
|
|
28
|
+
assertFalse(policy.isSecurePairingTarget(false, true))
|
|
29
|
+
assertFalse(policy.isSecurePairingTarget(false, null))
|
|
30
|
+
assertTrue(policy.isSecurePairingTarget(null, true))
|
|
31
|
+
assertFalse(policy.isSecurePairingTarget(null, false))
|
|
32
|
+
assertFalse(policy.isSecurePairingTarget(null, null))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Test
|
|
36
|
+
fun `automatic reconnects are never gated`() {
|
|
37
|
+
for (selected in listOf(true, false, null)) for (session in listOf(true, false, null)) {
|
|
38
|
+
assertEquals(
|
|
39
|
+
Readiness.READY,
|
|
40
|
+
readiness(explicit = false, selected = selected, session = session, bond = unbonded),
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Test
|
|
46
|
+
fun `unknown capability waits for pairing_info, then is legacy and ready without one`() {
|
|
47
|
+
assertEquals(Readiness.AWAIT_PAIRING_INFO, readiness(selected = null, session = null))
|
|
48
|
+
assertEquals(Readiness.READY, readiness(selected = null, session = null, expired = true))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Test
|
|
52
|
+
fun `unknown capability with a secure pairing_info follows the secure rule`() {
|
|
53
|
+
assertEquals(Readiness.AWAIT_OWNER_COMMIT, readiness(selected = null, session = true, bond = unbonded))
|
|
54
|
+
assertEquals(
|
|
55
|
+
Readiness.AWAIT_OWNER_COMMIT,
|
|
56
|
+
readiness(selected = null, session = true, bond = bonded, committed = false),
|
|
57
|
+
)
|
|
58
|
+
assertEquals(Readiness.READY, readiness(selected = null, session = true, bond = bonded, committed = true))
|
|
59
|
+
// A late secure report after the wait expired still applies the secure rule.
|
|
60
|
+
assertEquals(
|
|
61
|
+
Readiness.AWAIT_OWNER_COMMIT,
|
|
62
|
+
readiness(selected = null, session = true, expired = true, bond = unbonded),
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@Test
|
|
67
|
+
fun `unknown capability with a legacy pairing_info is ready at once`() {
|
|
68
|
+
assertEquals(Readiness.READY, readiness(selected = null, session = false, bond = unbonded))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Test
|
|
72
|
+
fun `known rows never wait for pairing_info`() {
|
|
73
|
+
assertEquals(Readiness.AWAIT_OWNER_COMMIT, readiness(selected = true, session = null, bond = unbonded))
|
|
74
|
+
assertEquals(Readiness.READY, readiness(selected = true, session = null, bond = bonded, committed = true))
|
|
75
|
+
assertEquals(Readiness.READY, readiness(selected = false, session = null, bond = unbonded))
|
|
76
|
+
assertEquals(Readiness.READY, readiness(selected = false, session = true, bond = unbonded))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Test
|
|
80
|
+
fun `readiness never waits without a deadline`() {
|
|
81
|
+
for (explicit in listOf(true, false)) for (selected in listOf(true, false, null)) {
|
|
82
|
+
for (session in listOf(true, false, null)) for (expired in listOf(true, false)) {
|
|
83
|
+
for (bond in listOf(bonded, unbonded, BluetoothDevice.BOND_BONDING, null)) {
|
|
84
|
+
for (committed in listOf(true, false)) {
|
|
85
|
+
val result = readiness(explicit, selected, session, expired, bond, committed)
|
|
86
|
+
// The pairing_info wait is bounded: once it expired it never applies.
|
|
87
|
+
if (expired) assertNotEquals(Readiness.AWAIT_PAIRING_INFO, result)
|
|
88
|
+
// The owner-commit wait always runs the secure bond wait deadline.
|
|
89
|
+
if (result == Readiness.AWAIT_OWNER_COMMIT) {
|
|
90
|
+
assertTrue(
|
|
91
|
+
MentraLiveOwnerLossPolicy.shouldRunSecureBondWait(
|
|
92
|
+
explicit,
|
|
93
|
+
MentraLivePairingReadinessPolicy.isSecurePairingTarget(selected, session),
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@Test
|
|
104
|
+
fun `a ready session without pairing_info clears the secure firmware memory`() {
|
|
105
|
+
assertEquals(false, MentraLivePairingReadinessPolicy.secureFirmwareAfterReadySession(pairingInfoSeen = false))
|
|
106
|
+
assertNull(MentraLivePairingReadinessPolicy.secureFirmwareAfterReadySession(pairingInfoSeen = true))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Test
|
|
110
|
+
fun `secure trailer memory starts empty with each scan`() {
|
|
111
|
+
val memory = MentraLiveSecureTrailerScanMemory()
|
|
112
|
+
memory.noteSecureTrailer("AA:BB:CC:DD:EE:01")
|
|
113
|
+
assertTrue(memory.contains("AA:BB:CC:DD:EE:01"))
|
|
114
|
+
assertFalse(memory.contains("AA:BB:CC:DD:EE:02"))
|
|
115
|
+
assertFalse(memory.contains(null))
|
|
116
|
+
memory.onScanStart()
|
|
117
|
+
assertFalse(memory.contains("AA:BB:CC:DD:EE:01"))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private fun readiness(
|
|
121
|
+
explicit: Boolean = true,
|
|
122
|
+
selected: Boolean?,
|
|
123
|
+
session: Boolean?,
|
|
124
|
+
expired: Boolean = false,
|
|
125
|
+
bond: Int? = unbonded,
|
|
126
|
+
committed: Boolean = false,
|
|
127
|
+
): Readiness =
|
|
128
|
+
MentraLivePairingReadinessPolicy.readiness(
|
|
129
|
+
explicitPairing = explicit,
|
|
130
|
+
selectedCapability = selected,
|
|
131
|
+
sessionPairingInfoSecure = session,
|
|
132
|
+
unknownCapabilityWaitExpired = expired,
|
|
133
|
+
bondState = bond,
|
|
134
|
+
ownerCommitted = committed,
|
|
135
|
+
)
|
|
136
|
+
}
|
package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachineTest.kt
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Assert.assertFalse
|
|
5
|
+
import org.junit.Assert.assertNull
|
|
6
|
+
import org.junit.Assert.assertTrue
|
|
7
|
+
import org.junit.Test
|
|
8
|
+
|
|
9
|
+
class MentraLivePairingStateMachineTest {
|
|
10
|
+
private val t0 = 1_700_000_000_000L
|
|
11
|
+
private val device = "MENTRA_LIVE_BLE_ABCD"
|
|
12
|
+
|
|
13
|
+
private fun enter(
|
|
14
|
+
machine: MentraLivePairingStateMachine,
|
|
15
|
+
windowId: Int? = 7,
|
|
16
|
+
windowMs: Long? = 120_000L,
|
|
17
|
+
ownerRetained: Boolean = true,
|
|
18
|
+
explicit: Boolean = false,
|
|
19
|
+
now: Long = t0,
|
|
20
|
+
) = machine.onEnteringPairingMode(windowMs, windowId, ownerRetained, explicit, device, now)
|
|
21
|
+
|
|
22
|
+
private fun pausedMachine(windowId: Int = 7): MentraLivePairingStateMachine =
|
|
23
|
+
MentraLivePairingStateMachine().also { enter(it, windowId = windowId) }
|
|
24
|
+
|
|
25
|
+
private fun reject(machine: MentraLivePairingStateMachine, now: Long, explicit: Boolean = false) =
|
|
26
|
+
machine.onAuthRejection(secureFirmware = true, explicitAttempt = explicit, nowMs = now)
|
|
27
|
+
|
|
28
|
+
@Test
|
|
29
|
+
fun v4NoticePausesForTheWindowPlusMarginWithoutA300sClamp() {
|
|
30
|
+
val machine = MentraLivePairingStateMachine()
|
|
31
|
+
val transition = enter(machine)
|
|
32
|
+
assertEquals(MentraLivePairingEffect.PAUSE, transition.effect)
|
|
33
|
+
assertEquals(MentraLivePairingState.PairingMode(7, t0 + 150_000L), machine.state)
|
|
34
|
+
assertFalse(machine.allowsAutomaticReconnect)
|
|
35
|
+
assertEquals(150_000L, machine.remainingPauseMs(t0))
|
|
36
|
+
|
|
37
|
+
val long = MentraLivePairingStateMachine()
|
|
38
|
+
enter(long, windowMs = 900_000L)
|
|
39
|
+
assertEquals(MentraLivePairingState.PairingMode(7, t0 + 930_000L), long.state)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Test
|
|
43
|
+
fun publicStateMapsMatchTheTypeScriptContract() {
|
|
44
|
+
assertEquals(mapOf("state" to "normal"), MentraLivePairingState.Normal.toMap())
|
|
45
|
+
assertEquals(mapOf("state" to "pairing_rejected"), MentraLivePairingState.Rejected.toMap())
|
|
46
|
+
assertEquals(
|
|
47
|
+
mapOf("state" to "pairing_mode", "windowId" to 7, "endsAtMs" to t0),
|
|
48
|
+
MentraLivePairingState.PairingMode(7, t0).toMap(),
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Test
|
|
53
|
+
fun aDuplicateNoticeForTheSameWindowIsIgnored() {
|
|
54
|
+
val machine = pausedMachine()
|
|
55
|
+
val again = enter(machine, now = t0 + 5_000L)
|
|
56
|
+
assertEquals(MentraLivePairingEffect.NONE, again.effect)
|
|
57
|
+
assertEquals(MentraLivePairingState.PairingMode(7, t0 + 150_000L), machine.state)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@Test
|
|
61
|
+
fun anExplicitAttemptIsNeverPausedByTheNotice() {
|
|
62
|
+
val machine = MentraLivePairingStateMachine()
|
|
63
|
+
assertEquals(MentraLivePairingEffect.NONE, enter(machine, explicit = true).effect)
|
|
64
|
+
assertEquals(MentraLivePairingState.Normal, machine.state)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Test
|
|
68
|
+
fun flagOffFirmwareForgetsThisPhoneOnEntry() {
|
|
69
|
+
val machine = MentraLivePairingStateMachine()
|
|
70
|
+
val transition = enter(machine, windowId = null, ownerRetained = false)
|
|
71
|
+
assertEquals(MentraLivePairingEffect.REJECT, transition.effect)
|
|
72
|
+
assertEquals(MentraLivePairingState.Rejected, machine.state)
|
|
73
|
+
|
|
74
|
+
val pairing = MentraLivePairingStateMachine()
|
|
75
|
+
enter(pairing, windowId = null, ownerRetained = false, explicit = true)
|
|
76
|
+
assertEquals(MentraLivePairingState.Normal, pairing.state)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Test
|
|
80
|
+
fun pairingModeEndedResumesEarlyForTheMatchingWindowOnly() {
|
|
81
|
+
val machine = pausedMachine()
|
|
82
|
+
assertEquals(MentraLivePairingEffect.NONE, machine.onPairingModeEnded("timeout", 8).effect)
|
|
83
|
+
assertTrue(machine.isPaused)
|
|
84
|
+
val ended = machine.onPairingModeEnded("paired", 7)
|
|
85
|
+
assertEquals(MentraLivePairingEffect.RESUME, ended.effect)
|
|
86
|
+
assertEquals(MentraLivePairingState.Normal, machine.state)
|
|
87
|
+
// The connected phone was admitted, so there is nothing to verify.
|
|
88
|
+
assertNull(machine.endedWindowId)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Test
|
|
92
|
+
fun aClearedAdvertisementFlagResumesEarlyAfterTheGrace() {
|
|
93
|
+
val machine = pausedMachine()
|
|
94
|
+
// An advertisement from before the window opened can still be in flight.
|
|
95
|
+
val early = machine.onAdvertisement(false, false, 6, t0 + 1_000L)
|
|
96
|
+
assertEquals(MentraLivePairingEffect.NONE, early.effect)
|
|
97
|
+
assertTrue(machine.isPaused)
|
|
98
|
+
assertEquals(MentraLivePairingEffect.NONE, machine.onAdvertisement(true, false, 7, t0 + 20_000L).effect)
|
|
99
|
+
val cleared = machine.onAdvertisement(false, false, 7, t0 + 60_000L)
|
|
100
|
+
assertEquals(MentraLivePairingEffect.RESUME, cleared.effect)
|
|
101
|
+
assertEquals(MentraLivePairingState.Normal, machine.state)
|
|
102
|
+
assertEquals(7, machine.endedWindowId)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Test
|
|
106
|
+
fun theDeadlineResumes() {
|
|
107
|
+
val machine = pausedMachine()
|
|
108
|
+
assertEquals(MentraLivePairingEffect.NONE, machine.onTick(t0 + 149_999L).effect)
|
|
109
|
+
assertEquals(MentraLivePairingEffect.RESUME, machine.onTick(t0 + 150_000L).effect)
|
|
110
|
+
assertTrue(machine.allowsAutomaticReconnect)
|
|
111
|
+
assertTrue(machine.awaitingTakeoverCheck)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@Test
|
|
115
|
+
fun ownerChangedForTheEndedWindowRejectsOnTheFirstFailedVerification() {
|
|
116
|
+
val machine = pausedMachine()
|
|
117
|
+
machine.onTick(t0 + 150_000L)
|
|
118
|
+
machine.onAdvertisement(false, ownerChanged = true, generation = 7, nowMs = t0 + 151_000L)
|
|
119
|
+
assertTrue(machine.verificationArmed)
|
|
120
|
+
assertFalse(machine.awaitingTakeoverCheck)
|
|
121
|
+
val verdict = reject(machine, t0 + 152_000L)
|
|
122
|
+
assertEquals(MentraLivePairingEffect.REJECT, verdict.effect)
|
|
123
|
+
assertEquals(MentraLivePairingState.Rejected, machine.state)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Test
|
|
127
|
+
fun ownerChangedCarriedOnTheFlagClearingAdvertisementArmsTheVerification() {
|
|
128
|
+
val machine = pausedMachine()
|
|
129
|
+
val cleared = machine.onAdvertisement(false, ownerChanged = true, generation = 7, nowMs = t0 + 60_000L)
|
|
130
|
+
assertEquals(MentraLivePairingEffect.RESUME, cleared.effect)
|
|
131
|
+
assertTrue(machine.verificationArmed)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@Test
|
|
135
|
+
fun aSpoofedOwnerChangedBitFollowedByASuccessfulReconnectDoesNotStrandThePhone() {
|
|
136
|
+
val machine = pausedMachine()
|
|
137
|
+
machine.onTick(t0 + 150_000L)
|
|
138
|
+
machine.onAdvertisement(false, ownerChanged = true, generation = 7, nowMs = t0 + 151_000L)
|
|
139
|
+
assertTrue(machine.verificationArmed)
|
|
140
|
+
machine.onSessionReady(explicitAttempt = false)
|
|
141
|
+
assertEquals(MentraLivePairingState.Normal, machine.state)
|
|
142
|
+
assertFalse(machine.verificationArmed)
|
|
143
|
+
// The same bit again arms nothing: exactly one verification per window.
|
|
144
|
+
machine.onAdvertisement(false, ownerChanged = true, generation = 7, nowMs = t0 + 200_000L)
|
|
145
|
+
assertFalse(machine.verificationArmed)
|
|
146
|
+
assertEquals(MentraLivePairingEffect.NONE, reject(machine, t0 + 201_000L).effect)
|
|
147
|
+
assertEquals(MentraLivePairingState.Normal, machine.state)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@Test
|
|
151
|
+
fun ownerChangedForAnotherWindowOrStillInPairingModeArmsNothing() {
|
|
152
|
+
val other = pausedMachine()
|
|
153
|
+
other.onTick(t0 + 150_000L)
|
|
154
|
+
other.onAdvertisement(false, ownerChanged = true, generation = 9, nowMs = t0 + 151_000L)
|
|
155
|
+
assertFalse(other.verificationArmed)
|
|
156
|
+
|
|
157
|
+
val stillPairing = pausedMachine()
|
|
158
|
+
stillPairing.onAdvertisement(true, ownerChanged = true, generation = 7, nowMs = t0 + 60_000L)
|
|
159
|
+
assertFalse(stillPairing.verificationArmed)
|
|
160
|
+
|
|
161
|
+
// Without a window this phone paused for, the bit is not this phone's business.
|
|
162
|
+
val idle = MentraLivePairingStateMachine()
|
|
163
|
+
idle.onAdvertisement(false, ownerChanged = true, generation = 7, nowMs = t0)
|
|
164
|
+
assertFalse(idle.verificationArmed)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@Test
|
|
168
|
+
fun aVerificationThatFailsWithoutAnAuthVerdictFallsBackToTheStreak() {
|
|
169
|
+
val machine = pausedMachine()
|
|
170
|
+
machine.onTick(t0 + 150_000L)
|
|
171
|
+
machine.onAdvertisement(false, ownerChanged = true, generation = 7, nowMs = t0 + 151_000L)
|
|
172
|
+
machine.onConnectAttemptFailed()
|
|
173
|
+
assertFalse(machine.verificationArmed)
|
|
174
|
+
assertEquals(MentraLivePairingEffect.NONE, reject(machine, t0 + 160_000L).effect)
|
|
175
|
+
assertEquals(MentraLivePairingState.Normal, machine.state)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@Test
|
|
179
|
+
fun withoutTheBitThreeRejectionsSpanningTheMinimumReject() {
|
|
180
|
+
val machine = MentraLivePairingStateMachine()
|
|
181
|
+
assertEquals(MentraLivePairingEffect.NONE, reject(machine, t0).effect)
|
|
182
|
+
assertEquals(MentraLivePairingEffect.NONE, reject(machine, t0 + 20_000L).effect)
|
|
183
|
+
val third = reject(machine, t0 + MentraLiveOwnerLossPolicy.MIN_REJECTION_SPAN_MS)
|
|
184
|
+
assertEquals(MentraLivePairingEffect.REJECT, third.effect)
|
|
185
|
+
assertEquals(MentraLivePairingState.Rejected, machine.state)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@Test
|
|
189
|
+
fun rejectionsDuringThePauseOrWhileThePairingAdvertIsFreshNeverCount() {
|
|
190
|
+
val machine = pausedMachine()
|
|
191
|
+
// The intentional disconnect and every 0x14/auth refusal inside the window.
|
|
192
|
+
var now = t0
|
|
193
|
+
repeat(6) {
|
|
194
|
+
assertEquals(MentraLivePairingEffect.NONE, reject(machine, now).effect)
|
|
195
|
+
now += 20_000L
|
|
196
|
+
}
|
|
197
|
+
assertTrue(machine.isPaused)
|
|
198
|
+
|
|
199
|
+
val advertising = MentraLivePairingStateMachine()
|
|
200
|
+
repeat(6) { i ->
|
|
201
|
+
val at = t0 + i * 20_000L
|
|
202
|
+
advertising.onAdvertisement(true, false, 3, at)
|
|
203
|
+
assertEquals(MentraLivePairingEffect.NONE, reject(advertising, at + 1_000L).effect)
|
|
204
|
+
}
|
|
205
|
+
assertEquals(MentraLivePairingState.Normal, advertising.state)
|
|
206
|
+
// The streak starts fresh once pairing mode is no longer advertised.
|
|
207
|
+
advertising.onAdvertisement(false, false, 3, t0 + 200_000L)
|
|
208
|
+
assertEquals(MentraLivePairingEffect.NONE, reject(advertising, t0 + 200_500L).effect)
|
|
209
|
+
assertEquals(MentraLivePairingState.Normal, advertising.state)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@Test
|
|
213
|
+
fun legacyFirmwareAndExplicitAttemptsNeverCount() {
|
|
214
|
+
val machine = MentraLivePairingStateMachine()
|
|
215
|
+
var now = t0
|
|
216
|
+
repeat(6) {
|
|
217
|
+
machine.onAuthRejection(secureFirmware = false, explicitAttempt = false, nowMs = now)
|
|
218
|
+
reject(machine, now + 1, explicit = true)
|
|
219
|
+
now += 20_000L
|
|
220
|
+
}
|
|
221
|
+
assertEquals(MentraLivePairingState.Normal, machine.state)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
@Test
|
|
225
|
+
fun onlyAnExplicitPairOrAForgetClearsARejection() {
|
|
226
|
+
val machine = MentraLivePairingStateMachine()
|
|
227
|
+
enter(machine, windowId = null, ownerRetained = false)
|
|
228
|
+
machine.onSessionReady(explicitAttempt = false)
|
|
229
|
+
assertEquals(MentraLivePairingState.Rejected, machine.state)
|
|
230
|
+
machine.onPairingModeEnded("timeout", 1)
|
|
231
|
+
machine.onTick(t0 + 1_000_000L)
|
|
232
|
+
machine.onAdvertisement(false, false, 1, t0 + 1_000_000L)
|
|
233
|
+
assertEquals(MentraLivePairingState.Rejected, machine.state)
|
|
234
|
+
val paired = machine.onSessionReady(explicitAttempt = true)
|
|
235
|
+
assertTrue(paired.stateChanged)
|
|
236
|
+
assertEquals(MentraLivePairingState.Normal, machine.state)
|
|
237
|
+
|
|
238
|
+
val forgotten = MentraLivePairingStateMachine()
|
|
239
|
+
enter(forgotten, windowId = null, ownerRetained = false)
|
|
240
|
+
forgotten.onForget()
|
|
241
|
+
assertEquals(MentraLivePairingState.Normal, forgotten.state)
|
|
242
|
+
assertEquals("", forgotten.deviceId)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@Test
|
|
246
|
+
fun aPauseSurvivesARestartWithTheSameWindowId() {
|
|
247
|
+
val machine = pausedMachine(windowId = 42)
|
|
248
|
+
val persisted = machine.persisted()
|
|
249
|
+
val restored = MentraLivePairingStateMachine()
|
|
250
|
+
val transition = restored.restore(persisted, device, t0 + 30_000L)
|
|
251
|
+
assertEquals(MentraLivePairingEffect.PAUSE, transition.effect)
|
|
252
|
+
assertEquals(MentraLivePairingState.PairingMode(42, t0 + 150_000L), restored.state)
|
|
253
|
+
assertEquals(120_000L, restored.remainingPauseMs(t0 + 30_000L))
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
@Test
|
|
257
|
+
fun aPauseThatEndedWhileTheAppWasAwayStillVerifiesTheTakeover() {
|
|
258
|
+
val persisted = pausedMachine(windowId = 42).persisted()
|
|
259
|
+
val restored = MentraLivePairingStateMachine()
|
|
260
|
+
val transition = restored.restore(persisted, device, t0 + 400_000L)
|
|
261
|
+
assertEquals(MentraLivePairingEffect.NONE, transition.effect)
|
|
262
|
+
assertEquals(MentraLivePairingState.Normal, restored.state)
|
|
263
|
+
assertEquals(42, restored.endedWindowId)
|
|
264
|
+
restored.onAdvertisement(false, ownerChanged = true, generation = 42, nowMs = t0 + 401_000L)
|
|
265
|
+
assertTrue(restored.verificationArmed)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
@Test
|
|
269
|
+
fun anArmedVerificationIsReArmedAfterARestart() {
|
|
270
|
+
val machine = pausedMachine(windowId = 42)
|
|
271
|
+
machine.onTick(t0 + 150_000L)
|
|
272
|
+
machine.onAdvertisement(false, ownerChanged = true, generation = 42, nowMs = t0 + 151_000L)
|
|
273
|
+
assertTrue(machine.verificationArmed)
|
|
274
|
+
val restored = MentraLivePairingStateMachine()
|
|
275
|
+
restored.restore(machine.persisted(), device, t0 + 160_000L)
|
|
276
|
+
assertFalse(restored.verificationArmed)
|
|
277
|
+
restored.onAdvertisement(false, ownerChanged = true, generation = 42, nowMs = t0 + 161_000L)
|
|
278
|
+
assertTrue(restored.verificationArmed)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@Test
|
|
282
|
+
fun anImplausibleRestoredDeadlineDoesNotPause() {
|
|
283
|
+
val persisted = pausedMachine().persisted().toMutableMap()
|
|
284
|
+
persisted[MentraLivePairingStateMachine.KEY_ENDS_AT_MS] = t0 + 10_000_000L
|
|
285
|
+
val restored = MentraLivePairingStateMachine()
|
|
286
|
+
restored.restore(persisted, device, t0)
|
|
287
|
+
assertEquals(MentraLivePairingState.Normal, restored.state)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
@Test
|
|
291
|
+
fun aRejectionSurvivesARestart() {
|
|
292
|
+
val machine = MentraLivePairingStateMachine()
|
|
293
|
+
enter(machine, windowId = null, ownerRetained = false)
|
|
294
|
+
val restored = MentraLivePairingStateMachine()
|
|
295
|
+
val transition = restored.restore(machine.persisted(), device, t0 + 86_400_000L)
|
|
296
|
+
assertEquals(MentraLivePairingEffect.REJECT, transition.effect)
|
|
297
|
+
assertEquals(MentraLivePairingState.Rejected, restored.state)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
@Test
|
|
301
|
+
fun restoreIgnoresUnknownKeysAndMalformedValues() {
|
|
302
|
+
val values =
|
|
303
|
+
mapOf(
|
|
304
|
+
MentraLivePairingStateMachine.KEY_DEVICE_ID to device,
|
|
305
|
+
MentraLivePairingStateMachine.KEY_STATE to "pairing_mode",
|
|
306
|
+
MentraLivePairingStateMachine.KEY_WINDOW_ID to "not a number",
|
|
307
|
+
MentraLivePairingStateMachine.KEY_ENDS_AT_MS to t0 + 60_000L,
|
|
308
|
+
"pairing_v9_future_key" to "whatever",
|
|
309
|
+
"unrelated" to 12,
|
|
310
|
+
)
|
|
311
|
+
val restored = MentraLivePairingStateMachine()
|
|
312
|
+
restored.restore(values, device, t0)
|
|
313
|
+
assertEquals(MentraLivePairingState.Normal, restored.state)
|
|
314
|
+
|
|
315
|
+
val future = MentraLivePairingStateMachine()
|
|
316
|
+
future.restore(mapOf(MentraLivePairingStateMachine.KEY_STATE to "pairing_v9_state"), device, t0)
|
|
317
|
+
assertEquals(MentraLivePairingState.Normal, future.state)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
@Test
|
|
321
|
+
fun aRecordForOtherGlassesDoesNotApply() {
|
|
322
|
+
val persisted = pausedMachine().persisted()
|
|
323
|
+
val restored = MentraLivePairingStateMachine()
|
|
324
|
+
restored.restore(persisted, "MENTRA_LIVE_BLE_OTHER", t0 + 1_000L)
|
|
325
|
+
assertEquals(MentraLivePairingState.Normal, restored.state)
|
|
326
|
+
assertEquals("MENTRA_LIVE_BLE_OTHER", restored.deviceId)
|
|
327
|
+
|
|
328
|
+
val bound = MentraLivePairingStateMachine()
|
|
329
|
+
enter(bound, windowId = null, ownerRetained = false)
|
|
330
|
+
assertTrue(bound.bindDevice("MENTRA_LIVE_BLE_OTHER").stateChanged)
|
|
331
|
+
assertEquals(MentraLivePairingState.Normal, bound.state)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
@Test
|
|
335
|
+
fun theLegacyStandDownPhaseMigratesToRejected() {
|
|
336
|
+
val restored = MentraLivePairingStateMachine()
|
|
337
|
+
val transition =
|
|
338
|
+
restored.restore(
|
|
339
|
+
mapOf(MentraLivePairingStateMachine.LEGACY_REJECTION_PHASE_KEY to "waiting"),
|
|
340
|
+
device,
|
|
341
|
+
t0,
|
|
342
|
+
)
|
|
343
|
+
assertEquals(MentraLivePairingEffect.REJECT, transition.effect)
|
|
344
|
+
assertEquals(MentraLivePairingState.Rejected, restored.state)
|
|
345
|
+
}
|
|
346
|
+
}
|