@mentra/bluetooth-sdk 3.5.0-dev.1504 → 3.5.0-dev.1506
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/BluetoothSdkModule.kt +14 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +14 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +1 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +51 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/camera/CameraModels.kt +24 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +85 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +7 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveFileTransferSessionTest.kt +16 -0
- package/build/BluetoothSdk.types.d.ts +34 -0
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +3 -1
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +14 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/_private/photoRequestPayload.d.ts.map +1 -1
- package/build/_private/photoRequestPayload.js +3 -0
- 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 +2 -0
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +15 -0
- package/ios/Source/BluetoothSdkDefaults.swift +1 -1
- package/ios/Source/DeviceManager.swift +10 -0
- package/ios/Source/DeviceStore.swift +1 -0
- package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
- package/ios/Source/MentraBluetoothSDK.swift +53 -2
- package/ios/Source/camera/CameraModels.swift +44 -8
- package/ios/Source/sgcs/MentraLive.swift +83 -6
- package/ios/Source/sgcs/MentraLiveFileTransferSession.swift +5 -0
- package/ios/Source/status/DeviceStatus.swift +9 -0
- package/ios/Tests/PhotoRequestRoutingTests.swift +31 -0
- package/package.json +2 -2
- package/src/BluetoothSdk.types.ts +35 -0
- package/src/_private/BluetoothSdkModule.ts +22 -0
- package/src/_private/photoRequestPayload.ts +3 -0
- package/src/generated/releaseMetadata.ts +5 -5
- package/src/index.ts +3 -0
|
@@ -796,6 +796,20 @@ class BluetoothSdkModule : Module() {
|
|
|
796
796
|
requireSdk().stopCameraWarmUp(requestId)
|
|
797
797
|
}
|
|
798
798
|
|
|
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
|
+
|
|
799
813
|
// MARK: - OTA Commands
|
|
800
814
|
|
|
801
815
|
SdkFunction("setOtaVersionUrl") { otaVersionUrl: String ->
|
|
@@ -2207,6 +2207,20 @@ class DeviceManager internal constructor(initializeHardware: Boolean) {
|
|
|
2207
2207
|
live.stopCameraWarmUp(requestId)
|
|
2208
2208
|
}
|
|
2209
2209
|
|
|
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
|
+
|
|
2210
2224
|
/**
|
|
2211
2225
|
* Read glasses media step volume (0—5) via K900 on Mentra Live only. Blocks until response,
|
|
2212
2226
|
* error, or timeout (used from JS AsyncFunction on a worker thread).
|
|
@@ -77,6 +77,7 @@ 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)
|
|
80
81
|
store.set("glasses", "micEnabled", false)
|
|
81
82
|
store.set("glasses", "voiceActivityDetectionEnabled", BluetoothSdkDefaults.VOICE_ACTIVITY_DETECTION_ENABLED)
|
|
82
83
|
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.1506"
|
|
7
|
+
const val RELEASE_SET_ID: String = "mentra-3.5.0-dev.1506"
|
|
8
|
+
const val SOURCE_COMMIT: String = "f4fe4865c5938c216ffaf1d6291e6c924b6aacca"
|
|
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.1506.json"
|
|
10
|
+
const val OTA_MANIFEST_SHA256: String = "05db21c8a7e9c5ce6b7a4c1e7a1c4b23b675f4886f4d6291fc1a0e55c5d48e99"
|
|
11
11
|
}
|
|
@@ -1158,6 +1158,7 @@ class MentraBluetoothSdk private constructor(
|
|
|
1158
1158
|
Bridge.log(
|
|
1159
1159
|
"NATIVE: PHOTO PIPELINE [3b/6] MentraBluetoothSdk.requestPhoto requestId=${routedRequest.requestId}"
|
|
1160
1160
|
)
|
|
1161
|
+
if (routedRequest.holdsPhoto) requireHeldPhotos()
|
|
1161
1162
|
val pending = PendingResponse<PhotoResponseEvent>("photo request ${routedRequest.requestId}", "photo request")
|
|
1162
1163
|
pendingPhotoRequests[routedRequest.requestId] = pending
|
|
1163
1164
|
try {
|
|
@@ -1180,7 +1181,11 @@ class MentraBluetoothSdk private constructor(
|
|
|
1180
1181
|
) {
|
|
1181
1182
|
deviceManager.requestPhoto(routedRequest)
|
|
1182
1183
|
pending.await(
|
|
1183
|
-
if (routedRequest.presendThumbnail
|
|
1184
|
+
if (routedRequest.presendThumbnail || routedRequest.holdsPhoto) {
|
|
1185
|
+
PHOTO_THUMBNAIL_REQUEST_TIMEOUT_MS
|
|
1186
|
+
} else {
|
|
1187
|
+
PHOTO_REQUEST_TIMEOUT_MS
|
|
1188
|
+
},
|
|
1184
1189
|
)
|
|
1185
1190
|
}
|
|
1186
1191
|
} finally {
|
|
@@ -1215,6 +1220,51 @@ class MentraBluetoothSdk private constructor(
|
|
|
1215
1220
|
}
|
|
1216
1221
|
}
|
|
1217
1222
|
|
|
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
|
+
|
|
1218
1268
|
fun stopCameraWarmUp(requestId: String) {
|
|
1219
1269
|
val effectiveRequestId = nonBlankRequestId(requestId)
|
|
1220
1270
|
?: throw BluetoothSdkException("invalid_request", "A warm-up request ID is required.")
|
|
@@ -231,8 +231,19 @@ 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,
|
|
234
241
|
) {
|
|
242
|
+
val holdsPhoto: Boolean get() = deliver == DELIVER_THUMBNAIL
|
|
243
|
+
|
|
235
244
|
companion object {
|
|
245
|
+
const val DELIVER_THUMBNAIL = "thumbnail"
|
|
246
|
+
|
|
236
247
|
private fun transferMethodFromValue(value: Any?): String {
|
|
237
248
|
if (value == null) return "auto"
|
|
238
249
|
val raw = value as? String
|
|
@@ -284,6 +295,7 @@ data class PhotoRequest @JvmOverloads constructor(
|
|
|
284
295
|
transferMethod = transferMethodFromValue(values["transferMethod"]),
|
|
285
296
|
presendThumbnail = boolValue(values, "presend_thumbnail") ?: false,
|
|
286
297
|
localFile = boolValue(values, "localFile") ?: false,
|
|
298
|
+
deliver = stringValue(values, "deliver")?.takeIf { it == DELIVER_THUMBNAIL },
|
|
287
299
|
exposureTimeNs = exposureTimeNs,
|
|
288
300
|
iso = iso,
|
|
289
301
|
aeExposureDivisor = aeDivisor,
|
|
@@ -432,6 +444,12 @@ sealed interface PhotoResponse {
|
|
|
432
444
|
val transferMs: Long? = null,
|
|
433
445
|
/** From the phone's request to the saved file. */
|
|
434
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,
|
|
435
453
|
) : PhotoResponse {
|
|
436
454
|
override val state: String = "success"
|
|
437
455
|
}
|
|
@@ -467,6 +485,9 @@ sealed interface PhotoResponse {
|
|
|
467
485
|
transport = stringValue(values, "transport"),
|
|
468
486
|
transferMs = longValue(values, "transferMs"),
|
|
469
487
|
totalMs = longValue(values, "totalMs"),
|
|
488
|
+
held = boolValue(values, "held") == true,
|
|
489
|
+
thumbnailUrl = stringValue(values, "thumbnailUrl"),
|
|
490
|
+
capturedAt = longValue(values, "capturedAt"),
|
|
470
491
|
)
|
|
471
492
|
} else {
|
|
472
493
|
Error(
|
|
@@ -492,6 +513,9 @@ private fun Map<String, Any>.withOptionalPhotoMetadata(
|
|
|
492
513
|
success.transport?.takeIf { it.isNotBlank() }?.let { this["transport"] = it }
|
|
493
514
|
success.transferMs?.let { this["transferMs"] = it }
|
|
494
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 }
|
|
495
519
|
}
|
|
496
520
|
|
|
497
521
|
data class PhotoResponseEvent(
|
|
@@ -836,6 +836,19 @@ 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()
|
|
839
852
|
|
|
840
853
|
/** Expected incident log relay files from glasses (B… firmware, L… logcat). */
|
|
841
854
|
private val bleIncidentLogRelays = ConcurrentHashMap<String, BleIncidentLogRelay>()
|
|
@@ -874,6 +887,8 @@ class MentraLive : SGCManager() {
|
|
|
874
887
|
var webhookUrl: String?
|
|
875
888
|
) {
|
|
876
889
|
var isThumbnail: Boolean = false
|
|
890
|
+
/** A held-photo request (deliver "thumbnail"): no full photo follows its preview. */
|
|
891
|
+
var held: Boolean = false
|
|
877
892
|
/** The photo stays on the phone as a file instead of being uploaded. */
|
|
878
893
|
var localFile: Boolean = false
|
|
879
894
|
var authToken: String? = null
|
|
@@ -996,6 +1011,9 @@ class MentraLive : SGCManager() {
|
|
|
996
1011
|
}
|
|
997
1012
|
|
|
998
1013
|
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)
|
|
999
1017
|
if (dynamicPayload && (index < 0 || index >= totalPackets || actualPackSize <= 0 ||
|
|
1000
1018
|
data.size != minOf(actualPackSize, fileSize - index * actualPackSize))) {
|
|
1001
1019
|
return false
|
|
@@ -1345,6 +1363,8 @@ class MentraLive : SGCManager() {
|
|
|
1345
1363
|
DeviceStore.apply("glasses", "hotspotOtaVersion", 0)
|
|
1346
1364
|
wifiDirectLink.glassesVersion = 0
|
|
1347
1365
|
wifiDirectLink.onGlassesDisconnected()
|
|
1366
|
+
DeviceStore.apply("glasses", "heldPhotosVersion", 0)
|
|
1367
|
+
heldPreviews.clear()
|
|
1348
1368
|
}
|
|
1349
1369
|
val isEqual = state == connectionState
|
|
1350
1370
|
if (isEqual) {
|
|
@@ -4773,6 +4793,13 @@ class MentraLive : SGCManager() {
|
|
|
4773
4793
|
val photoState = json.optString("state", "")
|
|
4774
4794
|
val photoSuccess = "success" == photoState || json.optBoolean("success", false)
|
|
4775
4795
|
|
|
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
|
+
|
|
4776
4803
|
try {
|
|
4777
4804
|
Bridge.sendPhotoResponse(jsonObjectToMap(json))
|
|
4778
4805
|
} catch (e: JSONException) {
|
|
@@ -5692,6 +5719,9 @@ class MentraLive : SGCManager() {
|
|
|
5692
5719
|
wifiDirectLink.glassesVersion = it.toInt()
|
|
5693
5720
|
}
|
|
5694
5721
|
}
|
|
5722
|
+
(fields["held_photos"] as? Number)?.let {
|
|
5723
|
+
DeviceStore.apply("glasses", "heldPhotosVersion", it.toInt())
|
|
5724
|
+
}
|
|
5695
5725
|
if (fields.containsKey("hotspot_ota_version")) {
|
|
5696
5726
|
val version = fields["hotspot_ota_version"]
|
|
5697
5727
|
if (version is Number) {
|
|
@@ -5852,13 +5882,18 @@ class MentraLive : SGCManager() {
|
|
|
5852
5882
|
!it.isThumbnail && it.requestId == requestId &&
|
|
5853
5883
|
bleImgId == "T" + it.bleImgId.drop(1)
|
|
5854
5884
|
}
|
|
5855
|
-
|
|
5885
|
+
// A held preview names itself: after a reconnect this connection has no parent.
|
|
5886
|
+
val held = json.optBoolean("held", false) || parent?.held == true
|
|
5887
|
+
if (parent == null && !held) {
|
|
5856
5888
|
Log.w(TAG, "Ignoring thumbnail for an unknown photo request")
|
|
5857
5889
|
return
|
|
5858
5890
|
}
|
|
5859
5891
|
// Duplicate ready messages must not erase packets already received.
|
|
5860
5892
|
blePhotoTransfers.getOrPut(bleImgId) {
|
|
5861
|
-
BlePhotoTransfer(bleImgId, requestId, null).apply {
|
|
5893
|
+
BlePhotoTransfer(bleImgId, requestId, null).apply {
|
|
5894
|
+
isThumbnail = true
|
|
5895
|
+
this.held = held
|
|
5896
|
+
}
|
|
5862
5897
|
}
|
|
5863
5898
|
}
|
|
5864
5899
|
|
|
@@ -7591,6 +7626,9 @@ class MentraLive : SGCManager() {
|
|
|
7591
7626
|
json.put("save", save)
|
|
7592
7627
|
json.put("sound", sound)
|
|
7593
7628
|
if (request.presendThumbnail) json.put("presend_thumbnail", true)
|
|
7629
|
+
if (request.holdsPhoto) {
|
|
7630
|
+
json.put("deliver", PhotoRequest.DELIVER_THUMBNAIL)
|
|
7631
|
+
}
|
|
7594
7632
|
if (exposureTimeNs != null && exposureTimeNs > 0L) {
|
|
7595
7633
|
Bridge.log(
|
|
7596
7634
|
"LIVE: Using manual exposure time for photo request " +
|
|
@@ -7608,7 +7646,7 @@ class MentraLive : SGCManager() {
|
|
|
7608
7646
|
PhotoRequest.appendScanFields(json, request)
|
|
7609
7647
|
|
|
7610
7648
|
// Always generate BLE ID for potential fallback
|
|
7611
|
-
val bleImgId =
|
|
7649
|
+
val bleImgId = nextBleImgId()
|
|
7612
7650
|
json.put("bleImgId", bleImgId)
|
|
7613
7651
|
|
|
7614
7652
|
// Miniapps may explicitly skip direct Wi-Fi upload and force the
|
|
@@ -7622,7 +7660,10 @@ class MentraLive : SGCManager() {
|
|
|
7622
7660
|
if (fastLink != null) json.put("fastTransfer", true)
|
|
7623
7661
|
|
|
7624
7662
|
// Always prepare for potential BLE transfer
|
|
7625
|
-
if (
|
|
7663
|
+
if (request.holdsPhoto) {
|
|
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) {
|
|
7626
7667
|
val transfer = BlePhotoTransfer(bleImgId, requestId, null)
|
|
7627
7668
|
transfer.localFile = true
|
|
7628
7669
|
blePhotoTransfers[bleImgId] = transfer
|
|
@@ -7652,6 +7693,42 @@ class MentraLive : SGCManager() {
|
|
|
7652
7693
|
}
|
|
7653
7694
|
}
|
|
7654
7695
|
|
|
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
|
+
|
|
7655
7732
|
fun warmUpCamera(
|
|
7656
7733
|
requestId: String,
|
|
7657
7734
|
size: PhotoSize,
|
|
@@ -12090,12 +12167,15 @@ class MentraLive : SGCManager() {
|
|
|
12090
12167
|
|
|
12091
12168
|
private fun processAndUploadBlePhoto(transfer: BlePhotoTransfer, imageData: ByteArray) {
|
|
12092
12169
|
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
|
|
12093
12173
|
Bridge.sendPhotoStatus(mapOf(
|
|
12094
12174
|
"type" to "photo_status",
|
|
12095
12175
|
"requestId" to transfer.requestId,
|
|
12096
12176
|
"status" to "thumbnail_received",
|
|
12097
12177
|
"timestamp" to System.currentTimeMillis(),
|
|
12098
|
-
"thumbnailUrl" to
|
|
12178
|
+
"thumbnailUrl" to thumbnailUrl,
|
|
12099
12179
|
"fileSizeBytes" to imageData.size,
|
|
12100
12180
|
))
|
|
12101
12181
|
return
|
|
@@ -63,6 +63,8 @@ internal data class GlassesStatus(
|
|
|
63
63
|
*/
|
|
64
64
|
val packageName: String,
|
|
65
65
|
val hotspotOtaVersion: Int,
|
|
66
|
+
/** Held photos (take_photo deliver "thumbnail"): the glasses' version, 0 without. */
|
|
67
|
+
val heldPhotosVersion: Int = 0,
|
|
66
68
|
val bluetoothName: String,
|
|
67
69
|
val serialNumber: String,
|
|
68
70
|
val style: String,
|
|
@@ -117,6 +119,7 @@ internal data class GlassesStatus(
|
|
|
117
119
|
"appVersion" to appVersion,
|
|
118
120
|
"packageName" to packageName,
|
|
119
121
|
"hotspotOtaVersion" to hotspotOtaVersion,
|
|
122
|
+
"heldPhotosVersion" to heldPhotosVersion,
|
|
120
123
|
"bluetoothName" to bluetoothName,
|
|
121
124
|
"serialNumber" to serialNumber,
|
|
122
125
|
"style" to style,
|
|
@@ -175,6 +178,7 @@ internal data class GlassesStatus(
|
|
|
175
178
|
appVersion = stringValue(values, "appVersion") ?: "",
|
|
176
179
|
packageName = stringValue(values, "packageName") ?: "",
|
|
177
180
|
hotspotOtaVersion = numberValue(values, "hotspotOtaVersion") ?: 0,
|
|
181
|
+
heldPhotosVersion = numberValue(values, "heldPhotosVersion") ?: 0,
|
|
178
182
|
bluetoothName = stringValue(values, "bluetoothName") ?: "",
|
|
179
183
|
serialNumber = stringValue(values, "serialNumber") ?: "",
|
|
180
184
|
style = stringValue(values, "style") ?: "",
|
|
@@ -460,6 +464,7 @@ internal data class GlassesStatusUpdate(
|
|
|
460
464
|
val appVersion: String? = null,
|
|
461
465
|
val packageName: String? = null,
|
|
462
466
|
val hotspotOtaVersion: Int? = null,
|
|
467
|
+
val heldPhotosVersion: Int? = null,
|
|
463
468
|
val bluetoothName: String? = null,
|
|
464
469
|
val serialNumber: String? = null,
|
|
465
470
|
val style: String? = null,
|
|
@@ -517,6 +522,7 @@ internal data class GlassesStatusUpdate(
|
|
|
517
522
|
putIfNotNull("appVersion", appVersion)
|
|
518
523
|
putIfNotNull("packageName", packageName)
|
|
519
524
|
putIfNotNull("hotspotOtaVersion", hotspotOtaVersion)
|
|
525
|
+
putIfNotNull("heldPhotosVersion", heldPhotosVersion)
|
|
520
526
|
putIfNotNull("bluetoothName", bluetoothName)
|
|
521
527
|
putIfNotNull("serialNumber", serialNumber)
|
|
522
528
|
putIfNotNull("style", style)
|
|
@@ -574,6 +580,7 @@ internal data class GlassesStatusUpdate(
|
|
|
574
580
|
appVersion = optionalStringValue(values, "appVersion"),
|
|
575
581
|
packageName = optionalStringValue(values, "packageName"),
|
|
576
582
|
hotspotOtaVersion = optionalNumberValue(values, "hotspotOtaVersion"),
|
|
583
|
+
heldPhotosVersion = optionalNumberValue(values, "heldPhotosVersion"),
|
|
577
584
|
bluetoothName = optionalStringValue(values, "bluetoothName"),
|
|
578
585
|
serialNumber = optionalStringValue(values, "serialNumber"),
|
|
579
586
|
style = optionalStringValue(values, "style"),
|
package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveFileTransferSessionTest.kt
CHANGED
|
@@ -22,6 +22,22 @@ class MentraLiveFileTransferSessionTest {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
@Test fun shortLastPacketFirstThenFullPackets() {
|
|
26
|
+
// After a reconnect the first packet through can be the last, short one.
|
|
27
|
+
for (flags in listOf(0, 2)) {
|
|
28
|
+
val source = ByteArray(4611) { (it % 251).toByte() }
|
|
29
|
+
val session = MentraLive.FileTransferSession("T1", source.size, flags)
|
|
30
|
+
session.recalculateTotalPackets(211)
|
|
31
|
+
assertTrue(session.addPacket(11, source.copyOfRange(4400, 4611)))
|
|
32
|
+
for (index in 0 until 11) {
|
|
33
|
+
assertTrue(session.addPacket(index, source.copyOfRange(index * 400, index * 400 + 400)))
|
|
34
|
+
}
|
|
35
|
+
assertEquals(12, session.totalPackets)
|
|
36
|
+
assertTrue(session.isComplete)
|
|
37
|
+
assertArrayEquals(source, session.assembleFile())
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
25
41
|
@Test fun legacyInflatedSizeAndLargeUnflaggedPayloads() {
|
|
26
42
|
// Flag 1 enables batched ACKs but still uses legacy size semantics.
|
|
27
43
|
for ((pack, headerSize, actualSize, packets) in listOf(
|
|
@@ -271,6 +271,12 @@ export type PhotoResponseEvent = {
|
|
|
271
271
|
transferMs?: number;
|
|
272
272
|
/** From the phone's request to the saved file. */
|
|
273
273
|
totalMs?: number;
|
|
274
|
+
/** The glasses hold the full photo: a `deliver: "thumbnail"` request. */
|
|
275
|
+
held?: boolean;
|
|
276
|
+
/** A held photo's preview (≤500 px JPEG), as a `data:image/jpeg;base64,` URI. */
|
|
277
|
+
thumbnailUrl?: string;
|
|
278
|
+
/** When the glasses captured the held photo, in ms since the epoch. */
|
|
279
|
+
capturedAt?: number;
|
|
274
280
|
} | {
|
|
275
281
|
type: "photo_response";
|
|
276
282
|
state: "error";
|
|
@@ -675,7 +681,25 @@ type NativeCameraFovSetting = {
|
|
|
675
681
|
};
|
|
676
682
|
export type MicPreference = "auto" | "phone" | "glasses" | "bluetooth";
|
|
677
683
|
export type MicMode = "phone" | "glasses" | "bluetoothClassic" | "bluetooth";
|
|
684
|
+
/** Fetch a held photo's full size: see {@link BluetoothSdkPublicModule.fetchHeldPhoto}. */
|
|
685
|
+
export type FetchHeldPhotoParams = {
|
|
686
|
+
/** The `requestId` of the `deliver: "thumbnail"` request that took it. */
|
|
687
|
+
requestId: string;
|
|
688
|
+
/** Save it as a file on the phone (default true); otherwise upload it to `webhookUrl`. */
|
|
689
|
+
localFile?: boolean;
|
|
690
|
+
webhookUrl?: string;
|
|
691
|
+
authToken?: string;
|
|
692
|
+
};
|
|
678
693
|
export type PhotoRequestParams = {
|
|
694
|
+
/**
|
|
695
|
+
* `"thumbnail"`: the glasses hold the full photo and send only its preview, and the request
|
|
696
|
+
* resolves once the preview arrived, with `held: true` and `thumbnailUrl`. The camera is free
|
|
697
|
+
* for the next request as soon as the capture is written. Fetch the full photo with
|
|
698
|
+
* `fetchHeldPhoto` and delete the rest with `releaseHeldPhotos`; the glasses delete held photos
|
|
699
|
+
* 30 minutes after capture. Needs `heldPhotosVersion > 0` in the glasses status. A preview that
|
|
700
|
+
* fails rejects with `PREVIEW_FAILED`, and the photo is still held.
|
|
701
|
+
*/
|
|
702
|
+
deliver?: "thumbnail";
|
|
679
703
|
/**
|
|
680
704
|
* Send an oriented <=500px, quality-50 JPEG preview before the full photo. Default false.
|
|
681
705
|
* Enables a 110-second end-to-end native deadline (ordinary requests: 30 seconds).
|
|
@@ -1463,6 +1487,14 @@ export interface BluetoothSdkPublicModule {
|
|
|
1463
1487
|
setCameraTuningConfig(anrOn: boolean, gainOn: boolean): Promise<SettingsAckSuccessEvent>;
|
|
1464
1488
|
queryGalleryStatus(): Promise<GalleryStatusEvent>;
|
|
1465
1489
|
requestPhoto(params: PhotoRequestParams): Promise<PhotoSuccessResponseEvent>;
|
|
1490
|
+
/**
|
|
1491
|
+
* Fetch the full size of a photo the glasses hold (`deliver: "thumbnail"`), over Bluetooth.
|
|
1492
|
+
* Resolves like `requestPhoto`: with the file's `file://` URI as `photoUrl`, or once uploaded.
|
|
1493
|
+
* The glasses keep the photo, so a failed fetch can be retried.
|
|
1494
|
+
*/
|
|
1495
|
+
fetchHeldPhoto(params: FetchHeldPhotoParams): Promise<PhotoSuccessResponseEvent>;
|
|
1496
|
+
/** Delete held photos on the glasses: these request IDs, or all of them when omitted. */
|
|
1497
|
+
releaseHeldPhotos(requestIds?: string[] | null): Promise<void>;
|
|
1466
1498
|
warmUpCamera(params: WarmUpCameraParams): Promise<CameraStatusEvent>;
|
|
1467
1499
|
/** Release one request-owned warm-up. Opening requests reject with camera_warm_up_cancelled. */
|
|
1468
1500
|
stopCameraWarmUp(requestId: string): Promise<void>;
|
|
@@ -1626,6 +1658,8 @@ export interface GlassesStatus {
|
|
|
1626
1658
|
packageName: string;
|
|
1627
1659
|
/** Phone-served hotspot OTA protocol version; 0 means unsupported/legacy glasses. */
|
|
1628
1660
|
hotspotOtaVersion: number;
|
|
1661
|
+
/** Held photos (`requestPhoto` with `deliver: "thumbnail"`); 0 means the glasses can't hold photos. */
|
|
1662
|
+
heldPhotosVersion?: number;
|
|
1629
1663
|
bluetoothName: string;
|
|
1630
1664
|
serialNumber: string;
|
|
1631
1665
|
style: string;
|