@mentra/bluetooth-sdk 3.5.0-dev.1507 → 3.5.0-dev.1509
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/AndroidManifest.xml +0 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +0 -21
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +0 -35
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +0 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +1 -64
- package/android/src/main/java/com/mentra/bluetoothsdk/camera/CameraModels.kt +0 -36
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +6 -190
- package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +0 -7
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveFileTransferSessionTest.kt +0 -16
- package/build/BluetoothSdk.types.d.ts +0 -75
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +1 -3
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +0 -14
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/_private/photoRequestPayload.d.ts.map +1 -1
- package/build/_private/photoRequestPayload.js +0 -3
- package/build/_private/photoRequestPayload.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 +0 -14
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +0 -15
- package/ios/Source/BluetoothSdkDefaults.swift +1 -1
- package/ios/Source/DeviceManager.swift +0 -10
- package/ios/Source/DeviceStore.swift +0 -1
- package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
- package/ios/Source/MentraBluetoothSDK.swift +2 -53
- package/ios/Source/camera/CameraModels.swift +8 -44
- package/ios/Source/sgcs/MentraLive.swift +6 -83
- package/ios/Source/sgcs/MentraLiveFileTransferSession.swift +0 -5
- package/ios/Source/status/DeviceStatus.swift +0 -9
- package/ios/Tests/PhotoRequestRoutingTests.swift +0 -31
- package/package.json +2 -2
- package/src/BluetoothSdk.types.ts +0 -80
- package/src/_private/BluetoothSdkModule.ts +0 -22
- package/src/_private/photoRequestPayload.ts +0 -3
- package/src/generated/releaseMetadata.ts +5 -5
- package/src/index.ts +0 -26
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/WifiDirectLink.kt +0 -488
|
@@ -23,11 +23,6 @@
|
|
|
23
23
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
|
24
24
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
|
25
25
|
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
|
|
26
|
-
<!-- Wi-Fi Direct photo link to Mentra Live (Android 13+); never used to derive location. -->
|
|
27
|
-
<uses-permission
|
|
28
|
-
android:name="android.permission.NEARBY_WIFI_DEVICES"
|
|
29
|
-
android:usesPermissionFlags="neverForLocation"
|
|
30
|
-
tools:targetApi="33"/>
|
|
31
26
|
|
|
32
27
|
<!-- Foreground service permissions (must match foregroundServiceType bits on the service) -->
|
|
33
28
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
|
@@ -363,7 +363,6 @@ class BluetoothSdkModule : Module() {
|
|
|
363
363
|
"saved_wifi_networks",
|
|
364
364
|
"hotspot_status_change",
|
|
365
365
|
"hotspot_error",
|
|
366
|
-
"fast_link_status",
|
|
367
366
|
"photo_response",
|
|
368
367
|
"photo_status",
|
|
369
368
|
"camera_status",
|
|
@@ -669,12 +668,6 @@ class BluetoothSdkModule : Module() {
|
|
|
669
668
|
requireSdk().forgetWifiNetwork(ssid).toMap()
|
|
670
669
|
}
|
|
671
670
|
|
|
672
|
-
Function("openFastLink") { requireSdk().openFastLink() }
|
|
673
|
-
|
|
674
|
-
Function("closeFastLink") { requireSdk().closeFastLink() }
|
|
675
|
-
|
|
676
|
-
Function("getFastLinkStatus") { requireSdk().getFastLinkStatus() }
|
|
677
|
-
|
|
678
671
|
SdkCoroutineFunction("setHotspotState") { enabled: Boolean ->
|
|
679
672
|
requireSdk().setHotspotState(enabled).values
|
|
680
673
|
}
|
|
@@ -796,20 +789,6 @@ class BluetoothSdkModule : Module() {
|
|
|
796
789
|
requireSdk().stopCameraWarmUp(requestId)
|
|
797
790
|
}
|
|
798
791
|
|
|
799
|
-
SdkCoroutineFunction("fetchHeldPhoto") { params: Map<String, Any?> ->
|
|
800
|
-
requireSdk()
|
|
801
|
-
.fetchHeldPhoto(
|
|
802
|
-
requestId = params["requestId"] as? String ?: "",
|
|
803
|
-
localFile = params["localFile"] as? Boolean ?: true,
|
|
804
|
-
webhookUrl = params["webhookUrl"] as? String,
|
|
805
|
-
authToken = params["authToken"] as? String,
|
|
806
|
-
).values
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
SdkAsyncFunction("releaseHeldPhotos") { requestIds: List<String>? ->
|
|
810
|
-
requireSdk().releaseHeldPhotos(requestIds)
|
|
811
|
-
}
|
|
812
|
-
|
|
813
792
|
// MARK: - OTA Commands
|
|
814
793
|
|
|
815
794
|
SdkFunction("setOtaVersionUrl") { otaVersionUrl: String ->
|
|
@@ -2022,27 +2022,6 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
|
|
|
2022
2022
|
sgc?.sendHotspotState(enabled)
|
|
2023
2023
|
}
|
|
2024
2024
|
|
|
2025
|
-
/** Opens the Wi-Fi Direct photo link to Mentra Live; the result comes as `fast_link_status`. */
|
|
2026
|
-
fun openFastLink(): Map<String, Any> {
|
|
2027
|
-
val live = sgc as? MentraLive
|
|
2028
|
-
?: return mapOf(
|
|
2029
|
-
"state" to "unavailable",
|
|
2030
|
-
"link" to "wifi_direct",
|
|
2031
|
-
"glassesSupported" to false,
|
|
2032
|
-
"reason" to "glasses_not_connected",
|
|
2033
|
-
)
|
|
2034
|
-
live.wifiDirectLink.open()
|
|
2035
|
-
return live.wifiDirectLink.status()
|
|
2036
|
-
}
|
|
2037
|
-
|
|
2038
|
-
fun closeFastLink() {
|
|
2039
|
-
(sgc as? MentraLive)?.wifiDirectLink?.close()
|
|
2040
|
-
}
|
|
2041
|
-
|
|
2042
|
-
fun fastLinkStatus(): Map<String, Any> =
|
|
2043
|
-
(sgc as? MentraLive)?.wifiDirectLink?.status()
|
|
2044
|
-
?: mapOf("state" to "closed", "link" to "wifi_direct", "glassesSupported" to false)
|
|
2045
|
-
|
|
2046
2025
|
fun setWifiAdbState(enabled: Boolean, expectedBluetoothMac: String? = null) {
|
|
2047
2026
|
if (expectedBluetoothMac != null) {
|
|
2048
2027
|
val current = sgc as? MentraLive ?: throw BluetoothSdkException(
|
|
@@ -2207,20 +2186,6 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
|
|
|
2207
2186
|
live.stopCameraWarmUp(requestId)
|
|
2208
2187
|
}
|
|
2209
2188
|
|
|
2210
|
-
fun fetchHeldPhoto(requestId: String, localFile: Boolean, webhookUrl: String?, authToken: String?) {
|
|
2211
|
-
val live =
|
|
2212
|
-
sgc as? MentraLive
|
|
2213
|
-
?: throw BluetoothSdkException("unsupported_device", "This command requires Mentra Live glasses.")
|
|
2214
|
-
live.fetchHeldPhoto(requestId, localFile, webhookUrl, authToken)
|
|
2215
|
-
}
|
|
2216
|
-
|
|
2217
|
-
fun releaseHeldPhotos(requestIds: List<String>?) {
|
|
2218
|
-
val live =
|
|
2219
|
-
sgc as? MentraLive
|
|
2220
|
-
?: throw BluetoothSdkException("unsupported_device", "This command requires Mentra Live glasses.")
|
|
2221
|
-
live.releaseHeldPhotos(requestIds)
|
|
2222
|
-
}
|
|
2223
|
-
|
|
2224
2189
|
/**
|
|
2225
2190
|
* Read glasses media step volume (0—5) via K900 on Mentra Live only. Blocks until response,
|
|
2226
2191
|
* error, or timeout (used from JS AsyncFunction on a worker thread).
|
|
@@ -77,7 +77,6 @@ object DeviceStore {
|
|
|
77
77
|
store.set("glasses", "deviceModel", "")
|
|
78
78
|
store.set("glasses", "firmwareVersion", "")
|
|
79
79
|
store.set("glasses", "hotspotOtaVersion", 0)
|
|
80
|
-
store.set("glasses", "heldPhotosVersion", 0)
|
|
81
80
|
store.set("glasses", "micEnabled", false)
|
|
82
81
|
store.set("glasses", "voiceActivityDetectionEnabled", BluetoothSdkDefaults.VOICE_ACTIVITY_DETECTION_ENABLED)
|
|
83
82
|
store.set("glasses", "bluetoothClassicConnected", false)
|
|
@@ -3,9 +3,9 @@ package com.mentra.bluetoothsdk
|
|
|
3
3
|
/** Generated by release CI. Do not edit in a release checkout. */
|
|
4
4
|
internal object GeneratedReleaseMetadata {
|
|
5
5
|
const val FAMILY_BASE_VERSION: String = "3.5.0"
|
|
6
|
-
const val RELEASE_IDENTITY: String = "3.5.0-dev.
|
|
7
|
-
const val RELEASE_SET_ID: String = "mentra-3.5.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.5.0/mentra-live-ota-3.5.0-dev.
|
|
10
|
-
const val OTA_MANIFEST_SHA256: String = "
|
|
6
|
+
const val RELEASE_IDENTITY: String = "3.5.0-dev.1509"
|
|
7
|
+
const val RELEASE_SET_ID: String = "mentra-3.5.0-dev.1509"
|
|
8
|
+
const val SOURCE_COMMIT: String = "c51ab169af7e451ae9b250bc7436421c43b1ed66"
|
|
9
|
+
const val OTA_MANIFEST_URL: String = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.5.0/mentra-live-ota-3.5.0-dev.1509.json"
|
|
10
|
+
const val OTA_MANIFEST_SHA256: String = "02523ef80ca019ca896cce503619f02ea8566c5df9652c29750bfbe8d639a875"
|
|
11
11
|
}
|
|
@@ -1099,19 +1099,6 @@ class MentraBluetoothSdk private constructor(
|
|
|
1099
1099
|
}
|
|
1100
1100
|
}
|
|
1101
1101
|
|
|
1102
|
-
/**
|
|
1103
|
-
* Opens the fast photo link (Wi-Fi Direct with Mentra Live on Android). Returns the state now;
|
|
1104
|
-
* changes arrive as `fast_link_status` events. While it is open, photos travel over it, and
|
|
1105
|
-
* over Bluetooth when it is not.
|
|
1106
|
-
*/
|
|
1107
|
-
fun openFastLink(): Map<String, Any> = deviceManager.openFastLink()
|
|
1108
|
-
|
|
1109
|
-
/** Closes the fast photo link. Photos go over Bluetooth again. */
|
|
1110
|
-
fun closeFastLink() = deviceManager.closeFastLink()
|
|
1111
|
-
|
|
1112
|
-
/** `closed`, `opening`, `open` or `unavailable`, with a `reason` for the last two. */
|
|
1113
|
-
fun getFastLinkStatus(): Map<String, Any> = deviceManager.fastLinkStatus()
|
|
1114
|
-
|
|
1115
1102
|
suspend fun setHotspotState(enabled: Boolean): HotspotStatusEvent {
|
|
1116
1103
|
// SoftAP teardown disables from the transport and again from the host
|
|
1117
1104
|
// barrier. Throwing request_in_flight on the second disable recorded a
|
|
@@ -1158,7 +1145,6 @@ class MentraBluetoothSdk private constructor(
|
|
|
1158
1145
|
Bridge.log(
|
|
1159
1146
|
"NATIVE: PHOTO PIPELINE [3b/6] MentraBluetoothSdk.requestPhoto requestId=${routedRequest.requestId}"
|
|
1160
1147
|
)
|
|
1161
|
-
if (routedRequest.holdsPhoto) requireHeldPhotos()
|
|
1162
1148
|
val pending = PendingResponse<PhotoResponseEvent>("photo request ${routedRequest.requestId}", "photo request")
|
|
1163
1149
|
pendingPhotoRequests[routedRequest.requestId] = pending
|
|
1164
1150
|
try {
|
|
@@ -1181,11 +1167,7 @@ class MentraBluetoothSdk private constructor(
|
|
|
1181
1167
|
) {
|
|
1182
1168
|
deviceManager.requestPhoto(routedRequest)
|
|
1183
1169
|
pending.await(
|
|
1184
|
-
if (routedRequest.presendThumbnail
|
|
1185
|
-
PHOTO_THUMBNAIL_REQUEST_TIMEOUT_MS
|
|
1186
|
-
} else {
|
|
1187
|
-
PHOTO_REQUEST_TIMEOUT_MS
|
|
1188
|
-
},
|
|
1170
|
+
if (routedRequest.presendThumbnail) PHOTO_THUMBNAIL_REQUEST_TIMEOUT_MS else PHOTO_REQUEST_TIMEOUT_MS,
|
|
1189
1171
|
)
|
|
1190
1172
|
}
|
|
1191
1173
|
} finally {
|
|
@@ -1220,51 +1202,6 @@ class MentraBluetoothSdk private constructor(
|
|
|
1220
1202
|
}
|
|
1221
1203
|
}
|
|
1222
1204
|
|
|
1223
|
-
private fun requireHeldPhotos() {
|
|
1224
|
-
if (getRawGlassesStatus().heldPhotosVersion <= 0) {
|
|
1225
|
-
throw BluetoothSdkException(
|
|
1226
|
-
"held_photos_unsupported",
|
|
1227
|
-
"These glasses can't hold photos. Update the glasses software, or request whole photos.",
|
|
1228
|
-
)
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
/**
|
|
1233
|
-
* Fetch the full size of a photo the glasses hold (a request with `deliver = "thumbnail"`),
|
|
1234
|
-
* over Bluetooth. Resolves like [requestPhoto]: with the file's URI as `photoUrl` when
|
|
1235
|
-
* [localFile], else once it is uploaded to [webhookUrl]. The glasses keep the photo until
|
|
1236
|
-
* [releaseHeldPhotos] or 30 minutes after capture, so a failed fetch can be retried.
|
|
1237
|
-
*/
|
|
1238
|
-
suspend fun fetchHeldPhoto(
|
|
1239
|
-
requestId: String,
|
|
1240
|
-
localFile: Boolean = true,
|
|
1241
|
-
webhookUrl: String? = null,
|
|
1242
|
-
authToken: String? = null,
|
|
1243
|
-
): PhotoResponseEvent {
|
|
1244
|
-
val id = nonBlankRequestId(requestId)
|
|
1245
|
-
?: throw BluetoothSdkException("invalid_request", "A photo request ID is required.")
|
|
1246
|
-
if (!localFile && webhookUrl.isNullOrBlank()) {
|
|
1247
|
-
throw BluetoothSdkException("invalid_request", "Fetch to a file, or give a webhookUrl.")
|
|
1248
|
-
}
|
|
1249
|
-
requireHeldPhotos()
|
|
1250
|
-
val pending = PendingResponse<PhotoResponseEvent>("held photo fetch $id", "held photo fetch")
|
|
1251
|
-
if (pendingPhotoRequests.putIfAbsent(id, pending) != null) {
|
|
1252
|
-
throw BluetoothSdkException("request_in_flight", "This photo is already being fetched.")
|
|
1253
|
-
}
|
|
1254
|
-
try {
|
|
1255
|
-
deviceManager.fetchHeldPhoto(id, localFile, webhookUrl, authToken)
|
|
1256
|
-
return pending.await(PHOTO_THUMBNAIL_REQUEST_TIMEOUT_MS)
|
|
1257
|
-
} finally {
|
|
1258
|
-
pendingPhotoRequests.remove(id, pending)
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
/** Delete held photos on the glasses: these request IDs, or every held photo when null. */
|
|
1263
|
-
fun releaseHeldPhotos(requestIds: List<String>? = null) {
|
|
1264
|
-
requireHeldPhotos()
|
|
1265
|
-
deviceManager.releaseHeldPhotos(requestIds)
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
1205
|
fun stopCameraWarmUp(requestId: String) {
|
|
1269
1206
|
val effectiveRequestId = nonBlankRequestId(requestId)
|
|
1270
1207
|
?: throw BluetoothSdkException("invalid_request", "A warm-up request ID is required.")
|
|
@@ -231,19 +231,8 @@ data class PhotoRequest @JvmOverloads constructor(
|
|
|
231
231
|
* `webhookUrl` and `transferMethod` are ignored.
|
|
232
232
|
*/
|
|
233
233
|
val localFile: Boolean = false,
|
|
234
|
-
/**
|
|
235
|
-
* `"thumbnail"`: the glasses hold the full photo and send only its preview; the response
|
|
236
|
-
* comes once the preview arrived, with `held` and `thumbnailUrl`. Fetch the full photo later
|
|
237
|
-
* with `fetchHeldPhoto`, and release the rest with `releaseHeldPhotos`. Needs glasses whose
|
|
238
|
-
* status has `heldPhotosVersion` > 0. `webhookUrl` and `transferMethod` are ignored.
|
|
239
|
-
*/
|
|
240
|
-
val deliver: String? = null,
|
|
241
234
|
) {
|
|
242
|
-
val holdsPhoto: Boolean get() = deliver == DELIVER_THUMBNAIL
|
|
243
|
-
|
|
244
235
|
companion object {
|
|
245
|
-
const val DELIVER_THUMBNAIL = "thumbnail"
|
|
246
|
-
|
|
247
236
|
private fun transferMethodFromValue(value: Any?): String {
|
|
248
237
|
if (value == null) return "auto"
|
|
249
238
|
val raw = value as? String
|
|
@@ -295,7 +284,6 @@ data class PhotoRequest @JvmOverloads constructor(
|
|
|
295
284
|
transferMethod = transferMethodFromValue(values["transferMethod"]),
|
|
296
285
|
presendThumbnail = boolValue(values, "presend_thumbnail") ?: false,
|
|
297
286
|
localFile = boolValue(values, "localFile") ?: false,
|
|
298
|
-
deliver = stringValue(values, "deliver")?.takeIf { it == DELIVER_THUMBNAIL },
|
|
299
287
|
exposureTimeNs = exposureTimeNs,
|
|
300
288
|
iso = iso,
|
|
301
289
|
aeExposureDivisor = aeDivisor,
|
|
@@ -438,18 +426,6 @@ sealed interface PhotoResponse {
|
|
|
438
426
|
val contentType: String?,
|
|
439
427
|
val fileSizeBytes: Long?,
|
|
440
428
|
override val timestamp: Long,
|
|
441
|
-
/** How a local photo reached the phone: "ble", "wifi_direct" or "hotspot". */
|
|
442
|
-
val transport: String? = null,
|
|
443
|
-
/** Its last hop: the fetch over a fast link, or the Bluetooth packets. */
|
|
444
|
-
val transferMs: Long? = null,
|
|
445
|
-
/** From the phone's request to the saved file. */
|
|
446
|
-
val totalMs: Long? = null,
|
|
447
|
-
/** The glasses hold the full photo (a `deliver = "thumbnail"` request). */
|
|
448
|
-
val held: Boolean = false,
|
|
449
|
-
/** The held photo's preview, as a `data:image/jpeg;base64,` URI. */
|
|
450
|
-
val thumbnailUrl: String? = null,
|
|
451
|
-
/** When the glasses captured the held photo (ms since the epoch). */
|
|
452
|
-
val capturedAt: Long? = null,
|
|
453
429
|
) : PhotoResponse {
|
|
454
430
|
override val state: String = "success"
|
|
455
431
|
}
|
|
@@ -482,12 +458,6 @@ sealed interface PhotoResponse {
|
|
|
482
458
|
?: longValue(values, "bytes")
|
|
483
459
|
?: longValue(values, "size"),
|
|
484
460
|
timestamp = timestamp,
|
|
485
|
-
transport = stringValue(values, "transport"),
|
|
486
|
-
transferMs = longValue(values, "transferMs"),
|
|
487
|
-
totalMs = longValue(values, "totalMs"),
|
|
488
|
-
held = boolValue(values, "held") == true,
|
|
489
|
-
thumbnailUrl = stringValue(values, "thumbnailUrl"),
|
|
490
|
-
capturedAt = longValue(values, "capturedAt"),
|
|
491
461
|
)
|
|
492
462
|
} else {
|
|
493
463
|
Error(
|
|
@@ -510,12 +480,6 @@ private fun Map<String, Any>.withOptionalPhotoMetadata(
|
|
|
510
480
|
success.statusUrl?.takeIf { it.isNotBlank() }?.let { this["statusUrl"] = it }
|
|
511
481
|
success.contentType?.takeIf { it.isNotBlank() }?.let { this["contentType"] = it }
|
|
512
482
|
success.fileSizeBytes?.let { this["fileSizeBytes"] = it }
|
|
513
|
-
success.transport?.takeIf { it.isNotBlank() }?.let { this["transport"] = it }
|
|
514
|
-
success.transferMs?.let { this["transferMs"] = it }
|
|
515
|
-
success.totalMs?.let { this["totalMs"] = it }
|
|
516
|
-
if (success.held) this["held"] = true
|
|
517
|
-
success.thumbnailUrl?.takeIf { it.isNotBlank() }?.let { this["thumbnailUrl"] = it }
|
|
518
|
-
success.capturedAt?.let { this["capturedAt"] = it }
|
|
519
483
|
}
|
|
520
484
|
|
|
521
485
|
data class PhotoResponseEvent(
|
|
@@ -836,19 +836,6 @@ class MentraLive : SGCManager() {
|
|
|
836
836
|
|
|
837
837
|
// BLE photo transfer tracking
|
|
838
838
|
private var blePhotoTransfers: MutableMap<String, BlePhotoTransfer> = ConcurrentHashMap()
|
|
839
|
-
private val lastBleImgNumber = java.util.concurrent.atomic.AtomicLong(0)
|
|
840
|
-
|
|
841
|
-
/**
|
|
842
|
-
* A Bluetooth image ID no other transfer of this process has: the clock's milliseconds, or one
|
|
843
|
-
* past the last ID when two requests fall in the same millisecond (a burst, concurrent fetches).
|
|
844
|
-
*/
|
|
845
|
-
private fun nextBleImgId(): String {
|
|
846
|
-
val number = lastBleImgNumber.updateAndGet { last -> maxOf(System.currentTimeMillis(), last + 1) }
|
|
847
|
-
return "I" + String.format("%09d", number % 1000000000)
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
/** Held photos' previews (data URIs) by requestId, until the request's terminal response. */
|
|
851
|
-
private val heldPreviews: MutableMap<String, String> = ConcurrentHashMap()
|
|
852
839
|
|
|
853
840
|
/** Expected incident log relay files from glasses (B… firmware, L… logcat). */
|
|
854
841
|
private val bleIncidentLogRelays = ConcurrentHashMap<String, BleIncidentLogRelay>()
|
|
@@ -887,8 +874,6 @@ class MentraLive : SGCManager() {
|
|
|
887
874
|
var webhookUrl: String?
|
|
888
875
|
) {
|
|
889
876
|
var isThumbnail: Boolean = false
|
|
890
|
-
/** A held-photo request (deliver "thumbnail"): no full photo follows its preview. */
|
|
891
|
-
var held: Boolean = false
|
|
892
877
|
/** The photo stays on the phone as a file instead of being uploaded. */
|
|
893
878
|
var localFile: Boolean = false
|
|
894
879
|
var authToken: String? = null
|
|
@@ -896,10 +881,6 @@ class MentraLive : SGCManager() {
|
|
|
896
881
|
var phoneStartTime: Long = System.currentTimeMillis() // When phone received the request
|
|
897
882
|
var bleTransferStartTime: Long = 0 // When BLE transfer actually started
|
|
898
883
|
var glassesCompressionDurationMs: Long = 0 // How long glasses took to compress
|
|
899
|
-
/** How the photo reached the phone: "ble", "wifi_direct" or "hotspot". */
|
|
900
|
-
var transport: String = "ble"
|
|
901
|
-
/** How long its last hop took (fetch over a fast link, or Bluetooth packets). */
|
|
902
|
-
var transferMs: Long = 0
|
|
903
884
|
}
|
|
904
885
|
|
|
905
886
|
private enum class BleIncidentLogKind {
|
|
@@ -1011,9 +992,6 @@ class MentraLive : SGCManager() {
|
|
|
1011
992
|
}
|
|
1012
993
|
|
|
1013
994
|
fun addPacket(index: Int, data: ByteArray): Boolean {
|
|
1014
|
-
// The first packet seen can be the file's short last one (the ones before it lost on a
|
|
1015
|
-
// link still settling after a reconnect): a larger packet gives the real pack size.
|
|
1016
|
-
if (actualPackSize in 1 until data.size) recalculateTotalPackets(data.size)
|
|
1017
995
|
if (dynamicPayload && (index < 0 || index >= totalPackets || actualPackSize <= 0 ||
|
|
1018
996
|
data.size != minOf(actualPackSize, fileSize - index * actualPackSize))) {
|
|
1019
997
|
return false
|
|
@@ -1180,25 +1158,6 @@ class MentraLive : SGCManager() {
|
|
|
1180
1158
|
private val lc3TimestampFormat = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US)
|
|
1181
1159
|
private val lc3PacketTimestampFormat = SimpleDateFormat("HH:mm:ss.SSS", Locale.US)
|
|
1182
1160
|
|
|
1183
|
-
/** The Wi-Fi Direct photo link; Bluetooth stays its control channel. */
|
|
1184
|
-
val wifiDirectLink: WifiDirectLink by lazy {
|
|
1185
|
-
WifiDirectLink(
|
|
1186
|
-
Bridge.getContext(),
|
|
1187
|
-
sendToGlasses = { json ->
|
|
1188
|
-
if (connectionState == ConnTypes.CONNECTED) {
|
|
1189
|
-
sendJson(json, true)
|
|
1190
|
-
true
|
|
1191
|
-
} else {
|
|
1192
|
-
false
|
|
1193
|
-
}
|
|
1194
|
-
},
|
|
1195
|
-
onStatus = { status -> Bridge.sendTypedMessage("fast_link_status", status) },
|
|
1196
|
-
)
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
/** Fetches photos announced on a fast link, one at a time, off the BLE threads. */
|
|
1200
|
-
private val fastPhotoExecutor = Executors.newSingleThreadExecutor()
|
|
1201
|
-
|
|
1202
1161
|
init {
|
|
1203
1162
|
this.type = DeviceTypes.LIVE
|
|
1204
1163
|
this.hasMic = true
|
|
@@ -1361,10 +1320,6 @@ class MentraLive : SGCManager() {
|
|
|
1361
1320
|
if (state == ConnTypes.DISCONNECTED) {
|
|
1362
1321
|
wifiAdbPeerIdentity = null
|
|
1363
1322
|
DeviceStore.apply("glasses", "hotspotOtaVersion", 0)
|
|
1364
|
-
wifiDirectLink.glassesVersion = 0
|
|
1365
|
-
wifiDirectLink.onGlassesDisconnected()
|
|
1366
|
-
DeviceStore.apply("glasses", "heldPhotosVersion", 0)
|
|
1367
|
-
heldPreviews.clear()
|
|
1368
1323
|
}
|
|
1369
1324
|
val isEqual = state == connectionState
|
|
1370
1325
|
if (isEqual) {
|
|
@@ -4777,8 +4732,6 @@ class MentraLive : SGCManager() {
|
|
|
4777
4732
|
|
|
4778
4733
|
updateHotspotStatus(hotspotEnabled, hotspotSsid, hotspotPassword, hotspotGatewayIp)
|
|
4779
4734
|
}
|
|
4780
|
-
"wifi_direct_status" -> wifiDirectLink.onGlassesStatus(json)
|
|
4781
|
-
"fast_photo_ready" -> handleFastPhotoReady(json)
|
|
4782
4735
|
"hotspot_error" -> {
|
|
4783
4736
|
// Process hotspot error
|
|
4784
4737
|
val errorMessage = json.optString("error_message", "Unknown hotspot error")
|
|
@@ -4793,13 +4746,6 @@ class MentraLive : SGCManager() {
|
|
|
4793
4746
|
val photoState = json.optString("state", "")
|
|
4794
4747
|
val photoSuccess = "success" == photoState || json.optBoolean("success", false)
|
|
4795
4748
|
|
|
4796
|
-
if (!json.optBoolean("fetch", false)) {
|
|
4797
|
-
// A held photo's request ended (or failed): no full photo follows its preview.
|
|
4798
|
-
blePhotoTransfers.entries.removeIf { it.value.held && it.value.requestId == requestId }
|
|
4799
|
-
val preview = heldPreviews.remove(requestId)
|
|
4800
|
-
if (photoSuccess && preview != null) json.put("thumbnailUrl", preview)
|
|
4801
|
-
}
|
|
4802
|
-
|
|
4803
4749
|
try {
|
|
4804
4750
|
Bridge.sendPhotoResponse(jsonObjectToMap(json))
|
|
4805
4751
|
} catch (e: JSONException) {
|
|
@@ -5714,14 +5660,6 @@ class MentraLive : SGCManager() {
|
|
|
5714
5660
|
DeviceStore.apply("glasses", "systemTimeMs", v.toLong())
|
|
5715
5661
|
}
|
|
5716
5662
|
}
|
|
5717
|
-
if (fields.containsKey("wifi_direct_version")) {
|
|
5718
|
-
(fields["wifi_direct_version"] as? Number)?.let {
|
|
5719
|
-
wifiDirectLink.glassesVersion = it.toInt()
|
|
5720
|
-
}
|
|
5721
|
-
}
|
|
5722
|
-
(fields["held_photos"] as? Number)?.let {
|
|
5723
|
-
DeviceStore.apply("glasses", "heldPhotosVersion", it.toInt())
|
|
5724
|
-
}
|
|
5725
5663
|
if (fields.containsKey("hotspot_ota_version")) {
|
|
5726
5664
|
val version = fields["hotspot_ota_version"]
|
|
5727
5665
|
if (version is Number) {
|
|
@@ -5882,18 +5820,13 @@ class MentraLive : SGCManager() {
|
|
|
5882
5820
|
!it.isThumbnail && it.requestId == requestId &&
|
|
5883
5821
|
bleImgId == "T" + it.bleImgId.drop(1)
|
|
5884
5822
|
}
|
|
5885
|
-
|
|
5886
|
-
val held = json.optBoolean("held", false) || parent?.held == true
|
|
5887
|
-
if (parent == null && !held) {
|
|
5823
|
+
if (parent == null) {
|
|
5888
5824
|
Log.w(TAG, "Ignoring thumbnail for an unknown photo request")
|
|
5889
5825
|
return
|
|
5890
5826
|
}
|
|
5891
5827
|
// Duplicate ready messages must not erase packets already received.
|
|
5892
5828
|
blePhotoTransfers.getOrPut(bleImgId) {
|
|
5893
|
-
BlePhotoTransfer(bleImgId, requestId, null).apply {
|
|
5894
|
-
isThumbnail = true
|
|
5895
|
-
this.held = held
|
|
5896
|
-
}
|
|
5829
|
+
BlePhotoTransfer(bleImgId, requestId, null).apply { isThumbnail = true }
|
|
5897
5830
|
}
|
|
5898
5831
|
}
|
|
5899
5832
|
|
|
@@ -7626,9 +7559,6 @@ class MentraLive : SGCManager() {
|
|
|
7626
7559
|
json.put("save", save)
|
|
7627
7560
|
json.put("sound", sound)
|
|
7628
7561
|
if (request.presendThumbnail) json.put("presend_thumbnail", true)
|
|
7629
|
-
if (request.holdsPhoto) {
|
|
7630
|
-
json.put("deliver", PhotoRequest.DELIVER_THUMBNAIL)
|
|
7631
|
-
}
|
|
7632
7562
|
if (exposureTimeNs != null && exposureTimeNs > 0L) {
|
|
7633
7563
|
Bridge.log(
|
|
7634
7564
|
"LIVE: Using manual exposure time for photo request " +
|
|
@@ -7646,24 +7576,15 @@ class MentraLive : SGCManager() {
|
|
|
7646
7576
|
PhotoRequest.appendScanFields(json, request)
|
|
7647
7577
|
|
|
7648
7578
|
// Always generate BLE ID for potential fallback
|
|
7649
|
-
val bleImgId =
|
|
7579
|
+
val bleImgId = "I" + String.format("%09d", System.currentTimeMillis() % 1000000000)
|
|
7650
7580
|
json.put("bleImgId", bleImgId)
|
|
7651
7581
|
|
|
7652
7582
|
// Miniapps may explicitly skip direct Wi-Fi upload and force the
|
|
7653
7583
|
// phone-relayed BLE path. Auto remains the default.
|
|
7654
7584
|
json.put("transferMethod", transferMethod)
|
|
7655
7585
|
|
|
7656
|
-
// Photos ride any open fast link: the Wi-Fi Direct group, or a glasses hotspot the
|
|
7657
|
-
// phone joined for something else. The glasses fall back to Bluetooth by themselves,
|
|
7658
|
-
// and glasses without fast transfer ignore the flag.
|
|
7659
|
-
val fastLink = fastPhotoLink()
|
|
7660
|
-
if (fastLink != null) json.put("fastTransfer", true)
|
|
7661
|
-
|
|
7662
7586
|
// Always prepare for potential BLE transfer
|
|
7663
|
-
if (
|
|
7664
|
-
// Only the preview crosses now; it finds this request by its "T" ID.
|
|
7665
|
-
blePhotoTransfers[bleImgId] = BlePhotoTransfer(bleImgId, requestId, null).apply { held = true }
|
|
7666
|
-
} else if (localFile) {
|
|
7587
|
+
if (localFile) {
|
|
7667
7588
|
val transfer = BlePhotoTransfer(bleImgId, requestId, null)
|
|
7668
7589
|
transfer.localFile = true
|
|
7669
7590
|
blePhotoTransfers[bleImgId] = transfer
|
|
@@ -7674,10 +7595,7 @@ class MentraLive : SGCManager() {
|
|
|
7674
7595
|
blePhotoTransfers[bleImgId] = transfer
|
|
7675
7596
|
}
|
|
7676
7597
|
|
|
7677
|
-
Bridge.log(
|
|
7678
|
-
"LIVE: Using " + transferMethod + " transfer mode with BLE fallback ID: " + bleImgId +
|
|
7679
|
-
(if (fastLink != null) ", fast link: $fastLink" else "")
|
|
7680
|
-
)
|
|
7598
|
+
Bridge.log("LIVE: Using " + transferMethod + " transfer mode with BLE fallback ID: " + bleImgId)
|
|
7681
7599
|
Bridge.log(
|
|
7682
7600
|
"LIVE: PHOTO PIPELINE [5b/6] JSON ready mode=" +
|
|
7683
7601
|
mode +
|
|
@@ -7693,42 +7611,6 @@ class MentraLive : SGCManager() {
|
|
|
7693
7611
|
}
|
|
7694
7612
|
}
|
|
7695
7613
|
|
|
7696
|
-
/**
|
|
7697
|
-
* Send a held photo's full size over Bluetooth, through the ordinary BLE photo transfer for
|
|
7698
|
-
* its request: saved on the phone (`localFile`) or uploaded to `webhookUrl`, then the usual
|
|
7699
|
-
* terminal `photo_response` for [requestId].
|
|
7700
|
-
*/
|
|
7701
|
-
fun fetchHeldPhoto(requestId: String, localFile: Boolean, webhookUrl: String?, authToken: String?) {
|
|
7702
|
-
val bleImgId = nextBleImgId()
|
|
7703
|
-
val transfer = BlePhotoTransfer(bleImgId, requestId, if (localFile) null else webhookUrl)
|
|
7704
|
-
transfer.localFile = localFile
|
|
7705
|
-
transfer.authToken = authToken
|
|
7706
|
-
blePhotoTransfers[bleImgId] = transfer
|
|
7707
|
-
try {
|
|
7708
|
-
val json = JSONObject()
|
|
7709
|
-
json.put("type", "fetch_photo")
|
|
7710
|
-
json.put("requestId", requestId)
|
|
7711
|
-
json.put("bleImgId", bleImgId)
|
|
7712
|
-
Bridge.log("LIVE: Fetching held photo " + requestId + " as " + bleImgId)
|
|
7713
|
-
sendJson(json, true)
|
|
7714
|
-
} catch (e: JSONException) {
|
|
7715
|
-
blePhotoTransfers.remove(bleImgId)
|
|
7716
|
-
Log.e(TAG, "Error creating fetch_photo JSON", e)
|
|
7717
|
-
}
|
|
7718
|
-
}
|
|
7719
|
-
|
|
7720
|
-
/** Delete held photos on the glasses: these, or all of them when [requestIds] is null. */
|
|
7721
|
-
fun releaseHeldPhotos(requestIds: List<String>?) {
|
|
7722
|
-
try {
|
|
7723
|
-
val json = JSONObject()
|
|
7724
|
-
json.put("type", "release_photos")
|
|
7725
|
-
if (requestIds == null) json.put("all", true) else json.put("requestIds", JSONArray(requestIds))
|
|
7726
|
-
sendJson(json, true)
|
|
7727
|
-
} catch (e: JSONException) {
|
|
7728
|
-
Log.e(TAG, "Error creating release_photos JSON", e)
|
|
7729
|
-
}
|
|
7730
|
-
}
|
|
7731
|
-
|
|
7732
7614
|
fun warmUpCamera(
|
|
7733
7615
|
requestId: String,
|
|
7734
7616
|
size: PhotoSize,
|
|
@@ -11506,7 +11388,6 @@ class MentraLive : SGCManager() {
|
|
|
11506
11388
|
photoTransfer.glassesCompressionDurationMs +
|
|
11507
11389
|
"ms"
|
|
11508
11390
|
)
|
|
11509
|
-
photoTransfer.transferMs = bleTransferDuration
|
|
11510
11391
|
if (bleTransferDuration > 0) {
|
|
11511
11392
|
Bridge.log("LIVE: ⏱️ BLE transfer duration: " + bleTransferDuration + "ms")
|
|
11512
11393
|
Bridge.log(
|
|
@@ -12106,76 +11987,14 @@ class MentraLive : SGCManager() {
|
|
|
12106
11987
|
}
|
|
12107
11988
|
|
|
12108
11989
|
/** Process and upload a BLE photo transfer */
|
|
12109
|
-
/** The fast link a photo requested now would use, or null for Bluetooth. */
|
|
12110
|
-
private fun fastPhotoLink(): String? =
|
|
12111
|
-
when {
|
|
12112
|
-
wifiDirectLink.isOpen() -> "wifi_direct"
|
|
12113
|
-
DeviceStore.get("glasses", "hotspotEnabled") == true &&
|
|
12114
|
-
wifiDirectLink.hotspotNetwork(DeviceStore.get("glasses", "hotspotGatewayIp") as? String) != null ->
|
|
12115
|
-
"hotspot"
|
|
12116
|
-
else -> null
|
|
12117
|
-
}
|
|
12118
|
-
|
|
12119
|
-
/**
|
|
12120
|
-
* The glasses hold a finished photo on a fast link instead of sending it over Bluetooth. Fetch
|
|
12121
|
-
* it and finish the request exactly as a Bluetooth photo would; if the fetch fails, ask the
|
|
12122
|
-
* glasses for Bluetooth, which the request's transfer entry still expects.
|
|
12123
|
-
*/
|
|
12124
|
-
private fun handleFastPhotoReady(json: JSONObject) {
|
|
12125
|
-
val bleImgId = json.optString("bleImgId", "")
|
|
12126
|
-
val url = json.optString("url", "")
|
|
12127
|
-
val ackUrl = json.optString("ackUrl", "")
|
|
12128
|
-
val link = json.optString("link", "wifi_direct")
|
|
12129
|
-
val transfer = blePhotoTransfers[bleImgId]
|
|
12130
|
-
if (transfer == null || url.isEmpty()) {
|
|
12131
|
-
Log.w(TAG, "fast_photo_ready for an unknown photo: $bleImgId")
|
|
12132
|
-
return
|
|
12133
|
-
}
|
|
12134
|
-
transfer.bleTransferStartTime = System.currentTimeMillis()
|
|
12135
|
-
fastPhotoExecutor.execute {
|
|
12136
|
-
try {
|
|
12137
|
-
val photo = wifiDirectLink.fetchPhoto(url, ackUrl, link)
|
|
12138
|
-
if (blePhotoTransfers.remove(bleImgId) == null) return@execute
|
|
12139
|
-
val total = System.currentTimeMillis() - transfer.phoneStartTime
|
|
12140
|
-
Bridge.log(
|
|
12141
|
-
"LIVE: ⏱️ Fast photo over $link: ${photo.bytes.size} bytes in ${photo.fetchMs} ms" +
|
|
12142
|
-
" (${if (photo.fetchMs > 0) photo.bytes.size / photo.fetchMs else 0} KB/s)," +
|
|
12143
|
-
" request→received $total ms, requestId=${transfer.requestId}"
|
|
12144
|
-
)
|
|
12145
|
-
transfer.transport = link
|
|
12146
|
-
transfer.transferMs = photo.fetchMs
|
|
12147
|
-
processAndUploadBlePhoto(transfer, photo.bytes)
|
|
12148
|
-
} catch (e: Exception) {
|
|
12149
|
-
// A host app that bound its process to another network (an old hotspot join) sends
|
|
12150
|
-
// even Wi-Fi Direct traffic there; say so, since it's the host's to undo.
|
|
12151
|
-
val bound = context?.getSystemService(android.net.ConnectivityManager::class.java)?.boundNetworkForProcess
|
|
12152
|
-
Log.w(
|
|
12153
|
-
TAG,
|
|
12154
|
-
"Fast photo fetch over $link failed, asking for Bluetooth: ${e.message}" +
|
|
12155
|
-
(if (bound != null) " (this process is bound to network $bound)" else "")
|
|
12156
|
-
)
|
|
12157
|
-
sendJson(
|
|
12158
|
-
JSONObject()
|
|
12159
|
-
.put("type", "fast_photo_failed")
|
|
12160
|
-
.put("bleImgId", bleImgId)
|
|
12161
|
-
.put("reason", e.javaClass.simpleName),
|
|
12162
|
-
true
|
|
12163
|
-
)
|
|
12164
|
-
}
|
|
12165
|
-
}
|
|
12166
|
-
}
|
|
12167
|
-
|
|
12168
11990
|
private fun processAndUploadBlePhoto(transfer: BlePhotoTransfer, imageData: ByteArray) {
|
|
12169
11991
|
if (transfer.isThumbnail) {
|
|
12170
|
-
val thumbnailUrl = "data:image/jpeg;base64," + android.util.Base64.encodeToString(imageData, android.util.Base64.NO_WRAP)
|
|
12171
|
-
// The held request's terminal response follows this preview's acknowledgement.
|
|
12172
|
-
if (transfer.held) heldPreviews[transfer.requestId] = thumbnailUrl
|
|
12173
11992
|
Bridge.sendPhotoStatus(mapOf(
|
|
12174
11993
|
"type" to "photo_status",
|
|
12175
11994
|
"requestId" to transfer.requestId,
|
|
12176
11995
|
"status" to "thumbnail_received",
|
|
12177
11996
|
"timestamp" to System.currentTimeMillis(),
|
|
12178
|
-
"thumbnailUrl" to
|
|
11997
|
+
"thumbnailUrl" to ("data:image/jpeg;base64," + android.util.Base64.encodeToString(imageData, android.util.Base64.NO_WRAP)),
|
|
12179
11998
|
"fileSizeBytes" to imageData.size,
|
|
12180
11999
|
))
|
|
12181
12000
|
return
|
|
@@ -12279,9 +12098,6 @@ class MentraLive : SGCManager() {
|
|
|
12279
12098
|
event["contentType"] = "image/jpeg"
|
|
12280
12099
|
event["fileSizeBytes"] = file.length()
|
|
12281
12100
|
event["timestamp"] = System.currentTimeMillis()
|
|
12282
|
-
event["transport"] = transfer.transport
|
|
12283
|
-
event["transferMs"] = transfer.transferMs
|
|
12284
|
-
event["totalMs"] = System.currentTimeMillis() - transfer.phoneStartTime
|
|
12285
12101
|
Bridge.sendPhotoResponse(event)
|
|
12286
12102
|
}
|
|
12287
12103
|
|