@mentra/bluetooth-sdk 3.4.0-dev.1059 → 3.4.0-dev.1061
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/BesCrashReportWaiters.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +9 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +7 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +22 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +85 -7
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +11 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/BesCrashReportWaitersTest.kt +112 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +175 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNamingTest.kt +23 -0
- package/build/BluetoothSdk.types.d.ts +47 -0
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +6 -0
- 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/releaseMetadata.js +5 -5
- 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 +1 -0
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +8 -0
- package/ios/Source/BesCrashReportWaiters.swift +64 -0
- package/ios/Source/BluetoothSdkDefaults.swift +1 -1
- package/ios/Source/DeviceManager.swift +7 -0
- package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
- package/ios/Source/MentraBluetoothSDK.swift +25 -0
- package/ios/Source/events/BluetoothEvents.swift +41 -0
- package/ios/Source/sgcs/MentraLive.swift +88 -12
- package/ios/Source/sgcs/SGCManager.swift +6 -0
- package/ios/Tests/BesCrashReportTests.swift +142 -0
- package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
- package/package.json +2 -2
- package/src/BluetoothSdk.types.ts +51 -0
- package/src/_private/BluetoothSdkModule.ts +10 -0
- package/src/generated/releaseMetadata.ts +5 -5
- package/src/index.ts +5 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk
|
|
2
|
+
|
|
3
|
+
import kotlinx.coroutines.CompletableDeferred
|
|
4
|
+
import kotlinx.coroutines.withTimeoutOrNull
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Correlates `bes_crash_reported` commands with the glasses' `bes_crash_reported_ack`.
|
|
8
|
+
*
|
|
9
|
+
* Each call owns one waiter keyed by (incidentKey, reportId), so concurrent reports for
|
|
10
|
+
* different incidents, or a stale ack for an earlier reportId, never settle each other.
|
|
11
|
+
*/
|
|
12
|
+
internal class BesCrashReportWaiters {
|
|
13
|
+
private class Waiter(val incidentKey: String, val reportId: String) {
|
|
14
|
+
val result = CompletableDeferred<Unit>()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private val waiters = mutableListOf<Waiter>()
|
|
18
|
+
|
|
19
|
+
/** Registers before [send] so an immediate ack cannot be missed. */
|
|
20
|
+
suspend fun await(incidentKey: String, reportId: String, timeoutMs: Long, send: () -> Unit) {
|
|
21
|
+
val waiter = Waiter(incidentKey, reportId)
|
|
22
|
+
synchronized(waiters) { waiters.add(waiter) }
|
|
23
|
+
try {
|
|
24
|
+
send()
|
|
25
|
+
withTimeoutOrNull(timeoutMs) { waiter.result.await() }
|
|
26
|
+
?: throw BluetoothSdkException(
|
|
27
|
+
"request_timeout",
|
|
28
|
+
"bes_crash_reported for $incidentKey timed out waiting for the glasses ack.",
|
|
29
|
+
)
|
|
30
|
+
} finally {
|
|
31
|
+
synchronized(waiters) { waiters.remove(waiter) }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Settles the waiters this ack answers. `ok:true` must echo the reportId; an `ok:false`
|
|
37
|
+
* without a reportId rejects every waiter for that incidentKey. Returns the number settled.
|
|
38
|
+
*/
|
|
39
|
+
fun onAck(values: Map<String, Any>): Int {
|
|
40
|
+
val incidentKey = values["incidentKey"] as? String ?: return 0
|
|
41
|
+
val reportId = (values["reportId"] as? String)?.takeIf { it.isNotEmpty() }
|
|
42
|
+
val ok = values["ok"] == true
|
|
43
|
+
val matched = synchronized(waiters) {
|
|
44
|
+
waiters.filter {
|
|
45
|
+
it.incidentKey == incidentKey && (it.reportId == reportId || (!ok && reportId == null))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (ok) {
|
|
49
|
+
matched.forEach { it.result.complete(Unit) }
|
|
50
|
+
} else {
|
|
51
|
+
val error = (values["error"] as? String)?.takeIf { it.isNotEmpty() } ?: "unknown_error"
|
|
52
|
+
matched.forEach {
|
|
53
|
+
it.result.completeExceptionally(
|
|
54
|
+
BluetoothSdkException(
|
|
55
|
+
"bes_crash_report_rejected",
|
|
56
|
+
"Glasses rejected bes_crash_reported for $incidentKey: $error",
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return matched.size
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fun rejectAll(error: Throwable) {
|
|
65
|
+
val snapshot = synchronized(waiters) { waiters.toList() }
|
|
66
|
+
snapshot.forEach { it.result.completeExceptionally(error) }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -271,6 +271,10 @@ class BluetoothSdkModule : Module() {
|
|
|
271
271
|
sendEvent("ota_status", event.values)
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
+
override fun onBesCrashDetected(event: BesCrashDetectedEvent) {
|
|
275
|
+
sendEvent("bes_crash_detected", event.toEventMap())
|
|
276
|
+
}
|
|
277
|
+
|
|
274
278
|
override fun onSettingsAck(event: SettingsAckEvent) {
|
|
275
279
|
sendEvent("settings_ack", event.values)
|
|
276
280
|
}
|
|
@@ -406,6 +410,7 @@ class BluetoothSdkModule : Module() {
|
|
|
406
410
|
"ota_start_ack",
|
|
407
411
|
"ota_status",
|
|
408
412
|
"ar99_ota_status",
|
|
413
|
+
"bes_crash_detected",
|
|
409
414
|
// Nex / BLE debug (NexEventUtils —Bridge.sendTypedMessage)
|
|
410
415
|
"send_command_to_ble",
|
|
411
416
|
"receive_command_from_ble",
|
|
@@ -626,6 +631,10 @@ class BluetoothSdkModule : Module() {
|
|
|
626
631
|
requireSdk().sendIncidentId(incidentId, apiBaseUrl)
|
|
627
632
|
}
|
|
628
633
|
|
|
634
|
+
SdkCoroutineFunction("sendBesCrashReported") { incidentKey: String, reportId: String ->
|
|
635
|
+
requireSdk().sendBesCrashReported(incidentKey, reportId)
|
|
636
|
+
}
|
|
637
|
+
|
|
629
638
|
// MARK: - Native Notification Centre
|
|
630
639
|
|
|
631
640
|
// Public controls use the SDK facade; phone payload delivery uses DeviceManager.
|
|
@@ -2006,6 +2006,13 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
|
|
|
2006
2006
|
driver.sendIncidentId(incidentId, apiBaseUrl)
|
|
2007
2007
|
}
|
|
2008
2008
|
|
|
2009
|
+
fun sendBesCrashReported(incidentKey: String, reportId: String) {
|
|
2010
|
+
val driver = sgc ?: throw BluetoothSdkException(
|
|
2011
|
+
"glasses_not_connected", "Cannot report the BES crash because glasses are not connected.",
|
|
2012
|
+
)
|
|
2013
|
+
driver.sendBesCrashReported(incidentKey, reportId)
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2009
2016
|
/** Push a notification into the glasses' own notification centre; rejects unsupported or disconnected devices. */
|
|
2010
2017
|
fun sendPhoneNotification(notification: Map<String, Any>) {
|
|
2011
2018
|
// Package only - never the notification text.
|
|
@@ -3,9 +3,9 @@ package com.mentra.bluetoothsdk
|
|
|
3
3
|
/** Generated by release CI. Do not edit in a release checkout. */
|
|
4
4
|
internal object GeneratedReleaseMetadata {
|
|
5
5
|
const val FAMILY_BASE_VERSION: String = "3.4.0"
|
|
6
|
-
const val RELEASE_IDENTITY: String = "3.4.0-dev.
|
|
7
|
-
const val RELEASE_SET_ID: String = "mentra-3.4.0-dev.
|
|
8
|
-
const val SOURCE_COMMIT: String = "
|
|
9
|
-
const val OTA_MANIFEST_URL: String = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.
|
|
10
|
-
const val OTA_MANIFEST_SHA256: String = "
|
|
6
|
+
const val RELEASE_IDENTITY: String = "3.4.0-dev.1061"
|
|
7
|
+
const val RELEASE_SET_ID: String = "mentra-3.4.0-dev.1061"
|
|
8
|
+
const val SOURCE_COMMIT: String = "ffb4056fe13e60f511a1d92ea69cb9ba0ad89e93"
|
|
9
|
+
const val OTA_MANIFEST_URL: String = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.1061.json"
|
|
10
|
+
const val OTA_MANIFEST_SHA256: String = "1353d6d9742eea3aa81f27518e3580bbd1a9ba8f1928a52f4310c0bc87114645"
|
|
11
11
|
}
|
|
@@ -95,6 +95,7 @@ class MentraBluetoothSdk private constructor(
|
|
|
95
95
|
private var pendingHotspotStatus: PendingHotspotStatusRequest? = null
|
|
96
96
|
private val hotspotMutex = Mutex()
|
|
97
97
|
private var pendingVersionInfo: PendingVersionInfoRequest? = null
|
|
98
|
+
private val besCrashReports = BesCrashReportWaiters()
|
|
98
99
|
private val wifiSessionCapabilities = WifiSessionCapabilities()
|
|
99
100
|
@Volatile private var configuredOtaVersionUrl: String? = null
|
|
100
101
|
|
|
@@ -149,6 +150,7 @@ class MentraBluetoothSdk private constructor(
|
|
|
149
150
|
private const val VIDEO_UPLOAD_STOP_TIMEOUT_MS = 10 * 60 * 1000L
|
|
150
151
|
private const val STREAM_START_TIMEOUT_MS = 30_000L
|
|
151
152
|
private const val STREAM_STOP_TIMEOUT_MS = 15_000L
|
|
153
|
+
private const val BES_CRASH_REPORTED_TIMEOUT_MS = 10_000L
|
|
152
154
|
private const val OTA_BES_VERSION_WAIT_MS = 5_000L
|
|
153
155
|
private const val OTA_MTK_VERSION_WAIT_MS = 2_000L
|
|
154
156
|
private const val OTA_VERSION_POLL_MS = 100L
|
|
@@ -1684,6 +1686,14 @@ class MentraBluetoothSdk private constructor(
|
|
|
1684
1686
|
deviceManager.sendIncidentId(incidentId, apiBaseUrl)
|
|
1685
1687
|
}
|
|
1686
1688
|
|
|
1689
|
+
/** Resolves on the glasses' matching `ok:true` ack; throws on `ok:false`, disconnect or timeout. */
|
|
1690
|
+
internal suspend fun sendBesCrashReported(incidentKey: String, reportId: String) {
|
|
1691
|
+
requireGlassesConnected("report the BES crash")
|
|
1692
|
+
besCrashReports.await(incidentKey, reportId, BES_CRASH_REPORTED_TIMEOUT_MS) {
|
|
1693
|
+
deviceManager.sendBesCrashReported(incidentKey, reportId)
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1687
1697
|
override fun close() {
|
|
1688
1698
|
resetWifiProtocolSession("", "sdk_closed")
|
|
1689
1699
|
if (activityLifecycleCallbacksRegistered) {
|
|
@@ -1704,6 +1714,12 @@ class MentraBluetoothSdk private constructor(
|
|
|
1704
1714
|
"glasses" -> {
|
|
1705
1715
|
if (changes["connected"] == false) {
|
|
1706
1716
|
resetWifiProtocolSession("", "wifi_session_disconnected")
|
|
1717
|
+
besCrashReports.rejectAll(
|
|
1718
|
+
BluetoothSdkException(
|
|
1719
|
+
"glasses_not_connected",
|
|
1720
|
+
"Glasses disconnected before acknowledging bes_crash_reported.",
|
|
1721
|
+
)
|
|
1722
|
+
)
|
|
1707
1723
|
}
|
|
1708
1724
|
analytics.observeGlassesStatus(getRawGlassesStatus(), ::isPhoneBluetoothOff)
|
|
1709
1725
|
val state = getState()
|
|
@@ -2065,6 +2081,12 @@ class MentraBluetoothSdk private constructor(
|
|
|
2065
2081
|
}
|
|
2066
2082
|
dispatchToListeners { it.onOtaStatus(event) }
|
|
2067
2083
|
}
|
|
2084
|
+
"bes_crash_detected" -> {
|
|
2085
|
+
val event = BesCrashDetectedEvent(data + mapOf("type" to "bes_crash_detected"))
|
|
2086
|
+
dispatchToListeners { it.onBesCrashDetected(event) }
|
|
2087
|
+
}
|
|
2088
|
+
// Request-scoped: consumed by the waiting sendBesCrashReported call, never a listener event.
|
|
2089
|
+
"bes_crash_reported_ack" -> besCrashReports.onAck(data)
|
|
2068
2090
|
"mic_health" -> {
|
|
2069
2091
|
dispatchToListeners { it.onMicHealth(MicHealthEvent.fromMap(data)) }
|
|
2070
2092
|
}
|
|
@@ -106,6 +106,21 @@ data class OtaStatusEvent(
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/** Mentra Live stored a BES crash incident; [values] is the glasses message with JSON nulls omitted. */
|
|
110
|
+
data class BesCrashDetectedEvent(
|
|
111
|
+
val values: Map<String, Any>,
|
|
112
|
+
) {
|
|
113
|
+
val incidentKey: String get() = stringValue(values, "incidentKey").orEmpty()
|
|
114
|
+
val reason: String get() = stringValue(values, "reason").orEmpty()
|
|
115
|
+
val state: String get() = stringValue(values, "state").orEmpty()
|
|
116
|
+
val reportId: String? get() = stringValue(values, "reportId")?.takeIf { it.isNotEmpty() }
|
|
117
|
+
@Suppress("UNCHECKED_CAST")
|
|
118
|
+
val summary: Map<String, Any> get() = values["summary"] as? Map<String, Any> ?: emptyMap()
|
|
119
|
+
|
|
120
|
+
/** Event body for JavaScript; `reportId` is null rather than absent before a report exists. */
|
|
121
|
+
fun toEventMap(): Map<String, Any?> = values + ("reportId" to reportId)
|
|
122
|
+
}
|
|
123
|
+
|
|
109
124
|
data class OtaQueryResult(
|
|
110
125
|
val values: Map<String, Any>,
|
|
111
126
|
) {
|
|
@@ -170,6 +185,7 @@ interface MentraBluetoothSdkListener {
|
|
|
170
185
|
fun onKeepAliveAck(event: KeepAliveAckEvent) {}
|
|
171
186
|
fun onOtaStartAck(event: OtaStartAckEvent) {}
|
|
172
187
|
fun onOtaStatus(event: OtaStatusEvent) {}
|
|
188
|
+
fun onBesCrashDetected(event: BesCrashDetectedEvent) {}
|
|
173
189
|
fun onSettingsAck(event: SettingsAckEvent) {}
|
|
174
190
|
fun onVersionInfo(event: VersionInfoResult) {}
|
|
175
191
|
fun onMicPcm(event: MicPcmEvent) {}
|
|
@@ -155,6 +155,9 @@ class MentraLive : SGCManager() {
|
|
|
155
155
|
private const val A2DP_CONNECT_MAX_ATTEMPTS = 5
|
|
156
156
|
private const val A2DP_CONNECT_RETRY_MS = 800L
|
|
157
157
|
private const val UNPAIR_FLUSH_MS = 400L
|
|
158
|
+
// Longer than the glasses' bounded relay of one report (BES logs, two file transfers,
|
|
159
|
+
// the phone POST), so an unreleased name cannot be reused while its report is in flight.
|
|
160
|
+
internal const val INCIDENT_RELAY_OWNERSHIP_MS = 10 * 60_000L
|
|
158
161
|
private const val GATT_DISCONNECT_TIMEOUT_MS = 2_000L
|
|
159
162
|
private const val MTU_CALLBACK_TIMEOUT_MS = 3_000L
|
|
160
163
|
private val gattTeardownBarrier = MentraLiveGattTeardownBarrier()
|
|
@@ -830,6 +833,7 @@ class MentraLive : SGCManager() {
|
|
|
830
833
|
val apiBaseUrl: String,
|
|
831
834
|
val kind: BleIncidentLogKind
|
|
832
835
|
) {
|
|
836
|
+
val reservedAtMs: Long = SystemClock.elapsedRealtime()
|
|
833
837
|
var session: FileTransferSession? = null
|
|
834
838
|
}
|
|
835
839
|
|
|
@@ -4781,6 +4785,16 @@ class MentraLive : SGCManager() {
|
|
|
4781
4785
|
if (json.has("bytes_downloaded")) json.optLong("bytes_downloaded", 0) else null
|
|
4782
4786
|
)
|
|
4783
4787
|
}
|
|
4788
|
+
"bes_crash_detected", "bes_crash_reported_ack" ->
|
|
4789
|
+
try {
|
|
4790
|
+
Bridge.log(
|
|
4791
|
+
"LIVE: $type incidentKey=${json.optString("incidentKey")} " +
|
|
4792
|
+
"state=${json.optString("state")} ok=${json.opt("ok")}"
|
|
4793
|
+
)
|
|
4794
|
+
Bridge.sendTypedMessage(type, jsonObjectToMap(json))
|
|
4795
|
+
} catch (e: JSONException) {
|
|
4796
|
+
Log.e(TAG, "Error converting $type to Map", e)
|
|
4797
|
+
}
|
|
4784
4798
|
"ota_progress" -> {
|
|
4785
4799
|
// Legacy glasses firmware: map to unified ota_status so JS has a single path
|
|
4786
4800
|
// (Mantle / progress UI).
|
|
@@ -6502,6 +6516,30 @@ class MentraLive : SGCManager() {
|
|
|
6502
6516
|
}
|
|
6503
6517
|
}
|
|
6504
6518
|
|
|
6519
|
+
/**
|
|
6520
|
+
* The 16-character relay file names keep only 15 characters of the report id, so two reports
|
|
6521
|
+
* can share them. The phone routes a received file to the report registered under its name;
|
|
6522
|
+
* refuse a second report until the owner's Cloud POST is confirmed or its ownership expires.
|
|
6523
|
+
*/
|
|
6524
|
+
private fun reserveIncidentRelays(vararg relays: BleIncidentLogRelay) {
|
|
6525
|
+
synchronized(bleIncidentLogRelays) {
|
|
6526
|
+
val now = SystemClock.elapsedRealtime()
|
|
6527
|
+
for (relay in relays) {
|
|
6528
|
+
val owner = bleIncidentLogRelays[relay.fileBaseKey] ?: continue
|
|
6529
|
+
if (owner.incidentId != relay.incidentId &&
|
|
6530
|
+
now - owner.reservedAtMs < INCIDENT_RELAY_OWNERSHIP_MS) {
|
|
6531
|
+
throw BluetoothSdkException(
|
|
6532
|
+
"incident_relay_busy",
|
|
6533
|
+
"BLE relay ${relay.fileBaseKey} is still owned by report ${owner.incidentId}.",
|
|
6534
|
+
)
|
|
6535
|
+
}
|
|
6536
|
+
}
|
|
6537
|
+
for (relay in relays) {
|
|
6538
|
+
bleIncidentLogRelays[relay.fileBaseKey] = relay
|
|
6539
|
+
}
|
|
6540
|
+
}
|
|
6541
|
+
}
|
|
6542
|
+
|
|
6505
6543
|
override fun sendIncidentId(incidentId: String, apiBaseUrl: String?) {
|
|
6506
6544
|
if (!isConnected || bluetoothGatt == null || txCharacteristic == null) {
|
|
6507
6545
|
throw BluetoothSdkException(
|
|
@@ -6521,10 +6559,9 @@ class MentraLive : SGCManager() {
|
|
|
6521
6559
|
}
|
|
6522
6560
|
val bKey = IncidentLogBleRelayNaming.bleFileBaseName(incidentId, 'B')
|
|
6523
6561
|
val lKey = IncidentLogBleRelayNaming.bleFileBaseName(incidentId, 'L')
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
BleIncidentLogRelay(lKey, incidentId, base, BleIncidentLogKind.LOGCAT)
|
|
6562
|
+
val bRelay = BleIncidentLogRelay(bKey, incidentId, base, BleIncidentLogKind.FIRMWARE)
|
|
6563
|
+
val lRelay = BleIncidentLogRelay(lKey, incidentId, base, BleIncidentLogKind.LOGCAT)
|
|
6564
|
+
reserveIncidentRelays(bRelay, lRelay)
|
|
6528
6565
|
|
|
6529
6566
|
val auth = JSONObject()
|
|
6530
6567
|
auth.put("type", "auth_token")
|
|
@@ -6539,8 +6576,8 @@ class MentraLive : SGCManager() {
|
|
|
6539
6576
|
sessionGeneration != bleSessionGeneration.get() ||
|
|
6540
6577
|
!isConnected || bluetoothGatt == null || txCharacteristic == null ||
|
|
6541
6578
|
!sendJson(json, true, true, sessionGeneration) || sessionGeneration != bleSessionGeneration.get()) {
|
|
6542
|
-
bleIncidentLogRelays.remove(bKey)
|
|
6543
|
-
bleIncidentLogRelays.remove(lKey)
|
|
6579
|
+
bleIncidentLogRelays.remove(bKey, bRelay)
|
|
6580
|
+
bleIncidentLogRelays.remove(lKey, lRelay)
|
|
6544
6581
|
throw BluetoothSdkException("incident_dispatch_failed", "Could not queue the glasses incident-log request.")
|
|
6545
6582
|
}
|
|
6546
6583
|
Bridge.log(
|
|
@@ -6557,6 +6594,27 @@ class MentraLive : SGCManager() {
|
|
|
6557
6594
|
}
|
|
6558
6595
|
}
|
|
6559
6596
|
|
|
6597
|
+
override fun sendBesCrashReported(incidentKey: String, reportId: String) {
|
|
6598
|
+
if (!isConnected || bluetoothGatt == null || txCharacteristic == null) {
|
|
6599
|
+
throw BluetoothSdkException(
|
|
6600
|
+
"glasses_not_connected", "Cannot report the BES crash because the glasses BLE link is not ready.",
|
|
6601
|
+
)
|
|
6602
|
+
}
|
|
6603
|
+
val sessionGeneration = bleSessionGeneration.get()
|
|
6604
|
+
try {
|
|
6605
|
+
val json = JSONObject()
|
|
6606
|
+
json.put("type", "bes_crash_reported")
|
|
6607
|
+
json.put("incidentKey", incidentKey)
|
|
6608
|
+
json.put("reportId", reportId)
|
|
6609
|
+
if (!sendJson(json, true, true, sessionGeneration) || sessionGeneration != bleSessionGeneration.get()) {
|
|
6610
|
+
throw BluetoothSdkException("bes_crash_dispatch_failed", "Could not queue bes_crash_reported to the glasses.")
|
|
6611
|
+
}
|
|
6612
|
+
Bridge.log("LIVE: Queued bes_crash_reported incidentKey=$incidentKey reportId=$reportId")
|
|
6613
|
+
} catch (e: JSONException) {
|
|
6614
|
+
throw BluetoothSdkException("bes_crash_dispatch_failed", "Could not create bes_crash_reported.", e)
|
|
6615
|
+
}
|
|
6616
|
+
}
|
|
6617
|
+
|
|
6560
6618
|
/** Query gallery status from the glasses */
|
|
6561
6619
|
override fun queryGalleryStatus() {
|
|
6562
6620
|
try {
|
|
@@ -11214,6 +11272,15 @@ class MentraLive : SGCManager() {
|
|
|
11214
11272
|
// Transfer is complete - process successfully
|
|
11215
11273
|
Bridge.log("LIVE: 📦 File transfer complete: " + packetInfo.fileName)
|
|
11216
11274
|
|
|
11275
|
+
if (IncidentLogBleRelayNaming.isRelayFileName(packetInfo.fileName)) {
|
|
11276
|
+
// No relay registered (e.g. the app restarted mid-relay): nothing reached
|
|
11277
|
+
// Cloud, so success would make the glasses mark the incident uploaded.
|
|
11278
|
+
Log.w(TAG, "Incident log relay without a registered report: " + packetInfo.fileName)
|
|
11279
|
+
sendTransferCompleteConfirmation(packetInfo.fileName, false)
|
|
11280
|
+
activeFileTransfers.remove(packetInfo.fileName)
|
|
11281
|
+
return
|
|
11282
|
+
}
|
|
11283
|
+
|
|
11217
11284
|
// Assemble and save the file
|
|
11218
11285
|
val fileData = session.assembleFile()
|
|
11219
11286
|
if (fileData != null) {
|
|
@@ -11430,6 +11497,13 @@ class MentraLive : SGCManager() {
|
|
|
11430
11497
|
success,
|
|
11431
11498
|
message ->
|
|
11432
11499
|
Handler(Looper.getMainLooper()).post {
|
|
11500
|
+
// A different report now owns this name (it was admitted after our owner finished),
|
|
11501
|
+
// so a completion here would mark ITS file done. Drop the stale callback.
|
|
11502
|
+
val owner = bleIncidentLogRelays[relay.fileBaseKey]
|
|
11503
|
+
if (owner != null && owner.incidentId != relay.incidentId) {
|
|
11504
|
+
Log.w(TAG, "Dropping stale incident relay callback for " + relay.fileBaseKey)
|
|
11505
|
+
return@post
|
|
11506
|
+
}
|
|
11433
11507
|
if (success) {
|
|
11434
11508
|
Bridge.log(
|
|
11435
11509
|
"LIVE: ✅ Incident log BLE relay uploaded (" +
|
|
@@ -11437,7 +11511,6 @@ class MentraLive : SGCManager() {
|
|
|
11437
11511
|
"): " +
|
|
11438
11512
|
relay.incidentId
|
|
11439
11513
|
)
|
|
11440
|
-
bleIncidentLogRelays.remove(relay.fileBaseKey)
|
|
11441
11514
|
} else {
|
|
11442
11515
|
Log.e(
|
|
11443
11516
|
TAG,
|
|
@@ -11450,6 +11523,11 @@ class MentraLive : SGCManager() {
|
|
|
11450
11523
|
relay.session = null
|
|
11451
11524
|
}
|
|
11452
11525
|
sendTransferCompleteConfirmation(fileName, success)
|
|
11526
|
+
// Release only after the glasses' confirmation is queued, so a report that reuses
|
|
11527
|
+
// this name is ordered behind the owner's completion.
|
|
11528
|
+
if (success) {
|
|
11529
|
+
bleIncidentLogRelays.remove(relay.fileBaseKey, relay)
|
|
11530
|
+
}
|
|
11453
11531
|
}
|
|
11454
11532
|
}
|
|
11455
11533
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.mentra.bluetoothsdk.sgcs
|
|
2
2
|
|
|
3
3
|
import com.mentra.bluetoothsdk.BluetoothSdkDefaults
|
|
4
|
+
import com.mentra.bluetoothsdk.BluetoothSdkException
|
|
4
5
|
import com.mentra.bluetoothsdk.Bridge
|
|
5
6
|
import com.mentra.bluetoothsdk.DeviceStore
|
|
6
7
|
import com.mentra.bluetoothsdk.PhotoRequest
|
|
@@ -348,6 +349,11 @@ abstract class SGCManager {
|
|
|
348
349
|
// Incident Reporting
|
|
349
350
|
abstract fun sendIncidentId(incidentId: String, apiBaseUrl: String? = null)
|
|
350
351
|
|
|
352
|
+
/** Tell the glasses Cloud recorded [reportId] for a BES crash incident (Mentra Live only). */
|
|
353
|
+
open fun sendBesCrashReported(incidentKey: String, reportId: String) {
|
|
354
|
+
throw BluetoothSdkException("unsupported_device", "BES crash reporting is not supported on $type.")
|
|
355
|
+
}
|
|
356
|
+
|
|
351
357
|
// Gallery
|
|
352
358
|
abstract fun queryGalleryStatus()
|
|
353
359
|
abstract fun sendGalleryMode()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.mentra.bluetoothsdk.utils;
|
|
2
2
|
|
|
3
3
|
import java.util.Locale;
|
|
4
|
+
import java.util.regex.Pattern;
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* 16-byte K900 file name for incident log payloads relayed over BLE (must match ASG
|
|
@@ -9,9 +10,19 @@ import java.util.Locale;
|
|
|
9
10
|
public final class IncidentLogBleRelayNaming {
|
|
10
11
|
|
|
11
12
|
private static final int SUFFIX_LEN = 15;
|
|
13
|
+
private static final Pattern RELAY_FILE_NAME = Pattern.compile("^[BL][a-z0-9_]{15}$");
|
|
12
14
|
|
|
13
15
|
private IncidentLogBleRelayNaming() {}
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Whether a received K900 file has the shape of an incident log relay. Such a file is only
|
|
19
|
+
* uploaded through a relay registered by {@code sendIncidentId}; without one it must not be
|
|
20
|
+
* acknowledged as delivered.
|
|
21
|
+
*/
|
|
22
|
+
public static boolean isRelayFileName(String fileName) {
|
|
23
|
+
return fileName != null && RELAY_FILE_NAME.matcher(fileName).matches();
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
public static String bleFileBaseName(String incidentId, char prefix) {
|
|
16
27
|
if (incidentId == null || incidentId.isEmpty()) {
|
|
17
28
|
return prefix + "000000000000000";
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk
|
|
2
|
+
|
|
3
|
+
import kotlinx.coroutines.CompletableDeferred
|
|
4
|
+
import kotlinx.coroutines.async
|
|
5
|
+
import kotlinx.coroutines.runBlocking
|
|
6
|
+
import org.junit.Assert.assertEquals
|
|
7
|
+
import org.junit.Assert.assertTrue
|
|
8
|
+
import org.junit.Assert.fail
|
|
9
|
+
import org.junit.Test
|
|
10
|
+
|
|
11
|
+
class BesCrashReportWaitersTest {
|
|
12
|
+
private val keyA = "ML395018B-dump-0000002a-1f2e3d4c"
|
|
13
|
+
private val keyB = "ML395018B-reset-9f3a0c1b2d4e5f60"
|
|
14
|
+
|
|
15
|
+
private fun ack(key: String, reportId: String?, ok: Boolean, error: String? = null): Map<String, Any> =
|
|
16
|
+
buildMap {
|
|
17
|
+
put("type", "bes_crash_reported_ack")
|
|
18
|
+
put("incidentKey", key)
|
|
19
|
+
reportId?.let { put("reportId", it) }
|
|
20
|
+
put("ok", ok)
|
|
21
|
+
error?.let { put("error", it) }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private suspend fun expectCode(code: String, block: suspend () -> Unit): BluetoothSdkException {
|
|
25
|
+
try {
|
|
26
|
+
block()
|
|
27
|
+
} catch (error: BluetoothSdkException) {
|
|
28
|
+
assertEquals(code, error.code)
|
|
29
|
+
return error
|
|
30
|
+
}
|
|
31
|
+
fail("expected $code")
|
|
32
|
+
throw AssertionError()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Test fun `ack delivered during send resolves the call`() = runBlocking {
|
|
36
|
+
val waiters = BesCrashReportWaiters()
|
|
37
|
+
waiters.await(keyA, "rep_1", 1_000) { waiters.onAck(ack(keyA, "rep_1", ok = true)) }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Test fun `concurrent incidents settle only their own call`() = runBlocking {
|
|
41
|
+
val waiters = BesCrashReportWaiters()
|
|
42
|
+
val sentA = CompletableDeferred<Unit>()
|
|
43
|
+
val sentB = CompletableDeferred<Unit>()
|
|
44
|
+
val a = async { waiters.await(keyA, "rep_a", 2_000) { sentA.complete(Unit) } }
|
|
45
|
+
val b = async { runCatching { waiters.await(keyB, "rep_b", 300) { sentB.complete(Unit) } } }
|
|
46
|
+
sentA.await()
|
|
47
|
+
sentB.await()
|
|
48
|
+
assertEquals(1, waiters.onAck(ack(keyA, "rep_a", ok = true)))
|
|
49
|
+
a.await()
|
|
50
|
+
val bResult = b.await()
|
|
51
|
+
assertEquals("request_timeout", (bResult.exceptionOrNull() as BluetoothSdkException).code)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Test fun `ack for another reportId of the same incident is ignored`() = runBlocking {
|
|
55
|
+
val waiters = BesCrashReportWaiters()
|
|
56
|
+
expectCode("request_timeout") {
|
|
57
|
+
waiters.await(keyA, "rep_new", 200) {
|
|
58
|
+
assertEquals(0, waiters.onAck(ack(keyA, "rep_old", ok = true)))
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
Unit
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Test fun `ok false rejects with the glasses error`() = runBlocking {
|
|
65
|
+
val waiters = BesCrashReportWaiters()
|
|
66
|
+
val error = expectCode("bes_crash_report_rejected") {
|
|
67
|
+
waiters.await(keyA, "rep_1", 1_000) {
|
|
68
|
+
waiters.onAck(ack(keyA, "rep_1", ok = false, error = "unknown_incident"))
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
assertTrue(error.message!!.contains("unknown_incident"))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@Test fun `ok false without reportId rejects every call for that incident only`() = runBlocking {
|
|
75
|
+
val waiters = BesCrashReportWaiters()
|
|
76
|
+
val sent = CompletableDeferred<Unit>()
|
|
77
|
+
val other = async { runCatching { waiters.await(keyB, "rep_b", 300) { sent.complete(Unit) } } }
|
|
78
|
+
sent.await()
|
|
79
|
+
expectCode("bes_crash_report_rejected") {
|
|
80
|
+
waiters.await(keyA, "rep_1", 1_000) {
|
|
81
|
+
assertEquals(1, waiters.onAck(ack(keyA, null, ok = false, error = "unknown_incident")))
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
assertEquals("request_timeout", (other.await().exceptionOrNull() as BluetoothSdkException).code)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@Test fun `ok true without reportId does not resolve`() = runBlocking {
|
|
88
|
+
val waiters = BesCrashReportWaiters()
|
|
89
|
+
expectCode("request_timeout") {
|
|
90
|
+
waiters.await(keyA, "rep_1", 200) { assertEquals(0, waiters.onAck(ack(keyA, null, ok = true))) }
|
|
91
|
+
}
|
|
92
|
+
Unit
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@Test fun `disconnect rejects pending calls`() = runBlocking {
|
|
96
|
+
val waiters = BesCrashReportWaiters()
|
|
97
|
+
expectCode("glasses_not_connected") {
|
|
98
|
+
waiters.await(keyA, "rep_1", 5_000) {
|
|
99
|
+
waiters.rejectAll(BluetoothSdkException("glasses_not_connected", "disconnected"))
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
Unit
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Test fun `send failure propagates and leaves no waiter behind`() = runBlocking {
|
|
106
|
+
val waiters = BesCrashReportWaiters()
|
|
107
|
+
expectCode("glasses_not_connected") {
|
|
108
|
+
waiters.await(keyA, "rep_1", 1_000) { throw BluetoothSdkException("glasses_not_connected", "no link") }
|
|
109
|
+
}
|
|
110
|
+
assertEquals(0, waiters.onAck(ack(keyA, "rep_1", ok = true)))
|
|
111
|
+
}
|
|
112
|
+
}
|