@mentra/bluetooth-sdk 3.5.0-dev.1513 → 3.5.0-dev.1515
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/README.md +14 -30
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +28 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +27 -16
- 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 +69 -17
- package/android/src/main/java/com/mentra/bluetoothsdk/camera/CameraModels.kt +12 -12
- package/android/src/main/java/com/mentra/bluetoothsdk/camera/PhotoCapture.kt +115 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/controllers/ControllerManager.kt +1 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/controllers/R1.kt +1 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Ar99.java +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1.kt +1 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G2.kt +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Mach1.kt +1 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +83 -27
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraNex.kt +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +1 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Simulated.kt +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +7 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/DeviceManagerSceneHandoffTest.kt +1 -1
- package/android/src/test/java/com/mentra/bluetoothsdk/camera/PhotoCaptureTest.kt +53 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/camera/PhotoRequestTest.kt +0 -19
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveFileTransferSessionTest.kt +16 -0
- package/build/BluetoothSdk.types.d.ts +56 -25
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +5 -3
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +50 -4
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/_private/photoRequestPayload.d.ts +4 -2
- package/build/_private/photoRequestPayload.d.ts.map +1 -1
- package/build/_private/photoRequestPayload.js +11 -12
- 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 +4 -2
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +35 -3
- package/ios/Source/BluetoothSdkDefaults.swift +1 -1
- package/ios/Source/DeviceManager.swift +15 -3
- package/ios/Source/DeviceStore.swift +1 -0
- package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
- package/ios/Source/MentraBluetoothSDK.swift +60 -17
- package/ios/Source/camera/CameraModels.swift +17 -16
- package/ios/Source/camera/PhotoCapture.swift +118 -0
- package/ios/Source/controllers/ControllerManager.swift +1 -1
- package/ios/Source/controllers/R1.swift +1 -1
- package/ios/Source/sgcs/Ar99.swift +2 -2
- package/ios/Source/sgcs/Frame.swift +1 -1
- package/ios/Source/sgcs/G1.swift +1 -1
- package/ios/Source/sgcs/G2.swift +1 -1
- package/ios/Source/sgcs/Mach1.swift +1 -1
- package/ios/Source/sgcs/MentraLive.swift +84 -34
- package/ios/Source/sgcs/MentraLiveFileTransferSession.swift +5 -0
- package/ios/Source/sgcs/MentraNex.swift +1 -1
- package/ios/Source/sgcs/Nimo.swift +4 -4
- package/ios/Source/sgcs/SGCManager.swift +1 -1
- package/ios/Source/sgcs/Simulated.swift +2 -2
- package/ios/Source/status/DeviceStatus.swift +9 -0
- package/ios/Tests/DashboardRenderingTests.swift +1 -1
- package/ios/Tests/DeviceManagerReconnectTests.swift +1 -1
- package/ios/Tests/PhotoCaptureTests.swift +39 -0
- package/ios/Tests/PhotoLocalFileTests.swift +0 -7
- package/ios/Tests/PhotoRequestRoutingTests.swift +0 -14
- package/package.json +2 -2
- package/src/BluetoothSdk.types.ts +50 -25
- package/src/_private/BluetoothSdkModule.ts +68 -7
- package/src/_private/photoRequestPayload.ts +13 -13
- package/src/generated/releaseMetadata.ts +5 -5
- package/src/index.ts +9 -3
|
@@ -38,6 +38,7 @@ import com.mentra.bluetoothsdk.BluetoothSdkDefaults
|
|
|
38
38
|
import com.mentra.bluetoothsdk.BluetoothSdkException
|
|
39
39
|
import com.mentra.bluetoothsdk.Bridge
|
|
40
40
|
import com.mentra.bluetoothsdk.DeviceManager
|
|
41
|
+
import com.mentra.bluetoothsdk.PhotoPreview
|
|
41
42
|
import com.mentra.bluetoothsdk.PhotoRequest
|
|
42
43
|
import com.mentra.bluetoothsdk.PhotoSize
|
|
43
44
|
import com.mentra.bluetoothsdk.PhotoMode
|
|
@@ -546,7 +547,7 @@ class MentraLive : SGCManager() {
|
|
|
546
547
|
|
|
547
548
|
// File transfer management
|
|
548
549
|
private const val FILE_SAVE_DIR = "MentraLive_Images"
|
|
549
|
-
/** Cache folder for photos kept on the phone (`
|
|
550
|
+
/** Cache folder for photos kept on the phone (`capturePhoto`); the caller moves each file out. */
|
|
550
551
|
private const val LOCAL_PHOTO_DIR = "mentra_local_photos"
|
|
551
552
|
/** Stand-in upload target the glasses are given for a local photo. Never contacted. */
|
|
552
553
|
private const val LOCAL_PHOTO_TARGET = "phone://local-photo"
|
|
@@ -837,6 +838,16 @@ class MentraLive : SGCManager() {
|
|
|
837
838
|
|
|
838
839
|
// BLE photo transfer tracking
|
|
839
840
|
private var blePhotoTransfers: MutableMap<String, BlePhotoTransfer> = ConcurrentHashMap()
|
|
841
|
+
private val lastBleImgNumber = java.util.concurrent.atomic.AtomicLong(0)
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* A Bluetooth image ID no other transfer of this process has: the clock's milliseconds, or one
|
|
845
|
+
* past the last ID when two requests fall in the same millisecond (a burst, concurrent fetches).
|
|
846
|
+
*/
|
|
847
|
+
private fun nextBleImgId(): String {
|
|
848
|
+
val number = lastBleImgNumber.updateAndGet { last -> maxOf(System.currentTimeMillis(), last + 1) }
|
|
849
|
+
return "I" + String.format("%09d", number % 1000000000)
|
|
850
|
+
}
|
|
840
851
|
|
|
841
852
|
/** Expected incident log relay files from glasses (B… firmware, L… logcat). */
|
|
842
853
|
private val bleIncidentLogRelays = ConcurrentHashMap<String, BleIncidentLogRelay>()
|
|
@@ -874,7 +885,10 @@ class MentraLive : SGCManager() {
|
|
|
874
885
|
var requestId: String,
|
|
875
886
|
var webhookUrl: String?
|
|
876
887
|
) {
|
|
877
|
-
|
|
888
|
+
/** A deferred photo's preview, of this size. */
|
|
889
|
+
var preview: Boolean = false
|
|
890
|
+
var previewWidth: Int? = null
|
|
891
|
+
var previewHeight: Int? = null
|
|
878
892
|
/** The photo stays on the phone as a file instead of being uploaded. */
|
|
879
893
|
var localFile: Boolean = false
|
|
880
894
|
var authToken: String? = null
|
|
@@ -993,6 +1007,9 @@ class MentraLive : SGCManager() {
|
|
|
993
1007
|
}
|
|
994
1008
|
|
|
995
1009
|
fun addPacket(index: Int, data: ByteArray): Boolean {
|
|
1010
|
+
// The first packet seen can be the file's short last one (the ones before it lost on a
|
|
1011
|
+
// link still settling after a reconnect): a larger packet gives the real pack size.
|
|
1012
|
+
if (actualPackSize in 1 until data.size) recalculateTotalPackets(data.size)
|
|
996
1013
|
if (dynamicPayload && (index < 0 || index >= totalPackets || actualPackSize <= 0 ||
|
|
997
1014
|
data.size != minOf(actualPackSize, fileSize - index * actualPackSize))) {
|
|
998
1015
|
return false
|
|
@@ -1329,6 +1346,7 @@ class MentraLive : SGCManager() {
|
|
|
1329
1346
|
if (state == ConnTypes.DISCONNECTED) {
|
|
1330
1347
|
wifiAdbPeerIdentity = null
|
|
1331
1348
|
DeviceStore.apply("glasses", "hotspotOtaVersion", 0)
|
|
1349
|
+
DeviceStore.apply("glasses", "deferredPhotosVersion", 0)
|
|
1332
1350
|
GlassesWifiDirect.onGlassesDisconnected()
|
|
1333
1351
|
}
|
|
1334
1352
|
val isEqual = state == connectionState
|
|
@@ -5162,6 +5180,8 @@ class MentraLive : SGCManager() {
|
|
|
5162
5180
|
// Set the ready flag to stop any future readiness checks
|
|
5163
5181
|
glassesReady = true
|
|
5164
5182
|
glassesReadyReceived = true
|
|
5183
|
+
// Deferred photos still waited for are asked again: a restart loses what was queued.
|
|
5184
|
+
Bridge.sendTypedMessage("glasses_ready", emptyMap<String, Any>())
|
|
5165
5185
|
armSecureFirmwareRefresh()
|
|
5166
5186
|
// Match iOS MentraLive.handleGlassesReady: BLE/SOC ready is enough for
|
|
5167
5187
|
// fullyBooted + CONNECTED. CTKD Classic bonding continues in the background
|
|
@@ -5674,6 +5694,9 @@ class MentraLive : SGCManager() {
|
|
|
5674
5694
|
DeviceStore.apply("glasses", "systemTimeMs", v.toLong())
|
|
5675
5695
|
}
|
|
5676
5696
|
}
|
|
5697
|
+
(fields["deferred_photos"] as? Number)?.let {
|
|
5698
|
+
DeviceStore.apply("glasses", "deferredPhotosVersion", it.toInt())
|
|
5699
|
+
}
|
|
5677
5700
|
(fields["wifi_direct_version"] as? Number)?.let { GlassesWifiDirect.version = it.toInt() }
|
|
5678
5701
|
if (fields.containsKey("hotspot_ota_version")) {
|
|
5679
5702
|
val version = fields["hotspot_ota_version"]
|
|
@@ -5830,18 +5853,17 @@ class MentraLive : SGCManager() {
|
|
|
5830
5853
|
val bleImgId = json.optString("bleImgId", "")
|
|
5831
5854
|
val requestId = json.optString("requestId", "")
|
|
5832
5855
|
val compressionDurationMs = json.optLong("compressionDurationMs", 0)
|
|
5833
|
-
if (json.optBoolean("
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
}
|
|
5838
|
-
if (parent == null) {
|
|
5839
|
-
Log.w(TAG, "Ignoring thumbnail for an unknown photo request")
|
|
5840
|
-
return
|
|
5841
|
-
}
|
|
5842
|
-
// Duplicate ready messages must not erase packets already received.
|
|
5856
|
+
if (json.optBoolean("deferred", false) && bleImgId.isNotEmpty() && requestId.isNotEmpty()) {
|
|
5857
|
+
// A deferred photo's preview or full photo: the glasses name the file, and a
|
|
5858
|
+
// restart or reconnect since the request doesn't matter. Duplicate ready messages
|
|
5859
|
+
// must not erase packets already received.
|
|
5843
5860
|
blePhotoTransfers.getOrPut(bleImgId) {
|
|
5844
|
-
BlePhotoTransfer(bleImgId, requestId, null).apply {
|
|
5861
|
+
BlePhotoTransfer(bleImgId, requestId, null).apply {
|
|
5862
|
+
preview = json.optBoolean("preview", false)
|
|
5863
|
+
localFile = !preview
|
|
5864
|
+
previewWidth = json.optInt("width", 0).takeIf { it > 0 }
|
|
5865
|
+
previewHeight = json.optInt("height", 0).takeIf { it > 0 }
|
|
5866
|
+
}
|
|
5845
5867
|
}
|
|
5846
5868
|
}
|
|
5847
5869
|
|
|
@@ -7507,11 +7529,30 @@ class MentraLive : SGCManager() {
|
|
|
7507
7529
|
}
|
|
7508
7530
|
}
|
|
7509
7531
|
|
|
7510
|
-
override fun
|
|
7532
|
+
override fun uploadPhoto(request: PhotoRequest) = sendTakePhoto(request, localFile = false, deferred = false)
|
|
7533
|
+
|
|
7534
|
+
/**
|
|
7535
|
+
* A photo kept on the phone. On glasses with deferred photos ([deferred]) the glasses keep it
|
|
7536
|
+
* and send only its preview, then the full photo on [fetchPhoto]; on older glasses it comes
|
|
7537
|
+
* whole now, as a file.
|
|
7538
|
+
*/
|
|
7539
|
+
fun capturePhoto(request: PhotoRequest, deferred: Boolean) = sendTakePhoto(request, localFile = !deferred, deferred)
|
|
7540
|
+
|
|
7541
|
+
/** Ask the glasses for a deferred photo's full size, or ([preview]) its preview again. */
|
|
7542
|
+
fun fetchPhoto(request: PhotoRequest, preview: Boolean) {
|
|
7543
|
+
val json = JSONObject()
|
|
7544
|
+
json.put("type", "fetch_photo")
|
|
7545
|
+
json.put("requestId", request.requestId)
|
|
7546
|
+
json.put("size", request.size.value)
|
|
7547
|
+
json.put("compress", request.compress.value)
|
|
7548
|
+
if (preview) json.put("preview", true)
|
|
7549
|
+
sendJson(json, true)
|
|
7550
|
+
}
|
|
7551
|
+
|
|
7552
|
+
private fun sendTakePhoto(request: PhotoRequest, localFile: Boolean, deferred: Boolean) {
|
|
7511
7553
|
val requestId = request.requestId
|
|
7512
7554
|
val size = request.size.value
|
|
7513
7555
|
val mode = request.mode.value
|
|
7514
|
-
val localFile = request.localFile
|
|
7515
7556
|
// A local photo has no upload target, but the glasses expect one: without it they
|
|
7516
7557
|
// route a save-to-gallery request to their gallery and transfer nothing, and reject
|
|
7517
7558
|
// a thumbnail request. So it names a stand-in, which the BLE transfer method never
|
|
@@ -7552,7 +7593,7 @@ class MentraLive : SGCManager() {
|
|
|
7552
7593
|
request.isoCap
|
|
7553
7594
|
)
|
|
7554
7595
|
Bridge.log(
|
|
7555
|
-
"LIVE: PHOTO PIPELINE [5/6]
|
|
7596
|
+
"LIVE: PHOTO PIPELINE [5/6] uploadPhoto() entry — requestId=" +
|
|
7556
7597
|
requestId
|
|
7557
7598
|
)
|
|
7558
7599
|
|
|
@@ -7573,7 +7614,6 @@ class MentraLive : SGCManager() {
|
|
|
7573
7614
|
json.put("compress", compress)
|
|
7574
7615
|
json.put("save", save)
|
|
7575
7616
|
json.put("sound", sound)
|
|
7576
|
-
if (request.presendThumbnail) json.put("presend_thumbnail", true)
|
|
7577
7617
|
if (exposureTimeNs != null && exposureTimeNs > 0L) {
|
|
7578
7618
|
Bridge.log(
|
|
7579
7619
|
"LIVE: Using manual exposure time for photo request " +
|
|
@@ -7589,9 +7629,15 @@ class MentraLive : SGCManager() {
|
|
|
7589
7629
|
json.put("iso", iso)
|
|
7590
7630
|
}
|
|
7591
7631
|
PhotoRequest.appendScanFields(json, request)
|
|
7632
|
+
if (deferred) {
|
|
7633
|
+
// The glasses keep it and name the files they send (preview, then full photo).
|
|
7634
|
+
Bridge.log("LIVE: PHOTO PIPELINE [6/6] Dispatching deferred take_photo " + requestId)
|
|
7635
|
+
sendJson(json, true)
|
|
7636
|
+
return
|
|
7637
|
+
}
|
|
7592
7638
|
|
|
7593
7639
|
// Always generate BLE ID for potential fallback
|
|
7594
|
-
val bleImgId =
|
|
7640
|
+
val bleImgId = nextBleImgId()
|
|
7595
7641
|
json.put("bleImgId", bleImgId)
|
|
7596
7642
|
|
|
7597
7643
|
// Miniapps may explicitly skip direct Wi-Fi upload and force the
|
|
@@ -7626,6 +7672,18 @@ class MentraLive : SGCManager() {
|
|
|
7626
7672
|
}
|
|
7627
7673
|
}
|
|
7628
7674
|
|
|
7675
|
+
/** Delete deferred photos on the glasses: these, or all of them when [requestIds] is null. */
|
|
7676
|
+
fun releasePhotos(requestIds: List<String>?) {
|
|
7677
|
+
try {
|
|
7678
|
+
val json = JSONObject()
|
|
7679
|
+
json.put("type", "release_photos")
|
|
7680
|
+
if (requestIds == null) json.put("all", true) else json.put("requestIds", JSONArray(requestIds))
|
|
7681
|
+
sendJson(json, true)
|
|
7682
|
+
} catch (e: JSONException) {
|
|
7683
|
+
Log.e(TAG, "Error creating release_photos JSON", e)
|
|
7684
|
+
}
|
|
7685
|
+
}
|
|
7686
|
+
|
|
7629
7687
|
fun warmUpCamera(
|
|
7630
7688
|
requestId: String,
|
|
7631
7689
|
size: PhotoSize,
|
|
@@ -12030,15 +12088,13 @@ class MentraLive : SGCManager() {
|
|
|
12030
12088
|
|
|
12031
12089
|
/** Process and upload a BLE photo transfer */
|
|
12032
12090
|
private fun processAndUploadBlePhoto(transfer: BlePhotoTransfer, imageData: ByteArray) {
|
|
12033
|
-
if (transfer.
|
|
12034
|
-
|
|
12035
|
-
"
|
|
12036
|
-
|
|
12037
|
-
|
|
12038
|
-
|
|
12039
|
-
|
|
12040
|
-
"fileSizeBytes" to imageData.size,
|
|
12041
|
-
))
|
|
12091
|
+
if (transfer.preview) {
|
|
12092
|
+
val preview = PhotoPreview(
|
|
12093
|
+
"data:image/jpeg;base64," + android.util.Base64.encodeToString(imageData, android.util.Base64.NO_WRAP),
|
|
12094
|
+
transfer.previewWidth,
|
|
12095
|
+
transfer.previewHeight,
|
|
12096
|
+
)
|
|
12097
|
+
Bridge.sendTypedMessage("photo_preview", preview.values + ("requestId" to transfer.requestId))
|
|
12042
12098
|
return
|
|
12043
12099
|
}
|
|
12044
12100
|
if (transfer.localFile) {
|
|
@@ -362,8 +362,8 @@ class MentraNex : SGCManager() {
|
|
|
362
362
|
override fun requestVersionInfo() { Bridge.log("Nex: requestVersionInfo operation not supported") }
|
|
363
363
|
|
|
364
364
|
// Camera & Media: Not supported on Nex (No camera)
|
|
365
|
-
override fun
|
|
366
|
-
Bridge.log("Nex:
|
|
365
|
+
override fun uploadPhoto(request: PhotoRequest) {
|
|
366
|
+
Bridge.log("Nex: uploadPhoto operation not supported")
|
|
367
367
|
}
|
|
368
368
|
override fun startStream(message: MutableMap<String, Any>) { Bridge.log("Nex: startStream operation not supported") }
|
|
369
369
|
override fun stopStream() { Bridge.log("Nex: stopStream operation not supported") }
|
|
@@ -1493,8 +1493,8 @@ class Nimo : SGCManager() {
|
|
|
1493
1493
|
|
|
1494
1494
|
// ---------- SGCManager: Camera & Media (no camera) ----------
|
|
1495
1495
|
|
|
1496
|
-
override fun
|
|
1497
|
-
Bridge.log("NIMO:
|
|
1496
|
+
override fun uploadPhoto(request: PhotoRequest) {
|
|
1497
|
+
Bridge.log("NIMO: uploadPhoto - not supported (no camera)")
|
|
1498
1498
|
}
|
|
1499
1499
|
|
|
1500
1500
|
override fun startStream(message: MutableMap<String, Any>) {
|
|
@@ -52,7 +52,7 @@ abstract class SGCManager {
|
|
|
52
52
|
abstract fun sortMicRanking(list: MutableList<String>): MutableList<String>
|
|
53
53
|
|
|
54
54
|
// Camera & Media
|
|
55
|
-
abstract fun
|
|
55
|
+
abstract fun uploadPhoto(request: PhotoRequest)
|
|
56
56
|
abstract fun startStream(message: MutableMap<String, Any>)
|
|
57
57
|
abstract fun stopStream()
|
|
58
58
|
/**
|
|
@@ -33,8 +33,8 @@ class Simulated : SGCManager() {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Camera & Media
|
|
36
|
-
override fun
|
|
37
|
-
Bridge.log("
|
|
36
|
+
override fun uploadPhoto(request: PhotoRequest) {
|
|
37
|
+
Bridge.log("uploadPhoto save=${request.save}, sound=${request.sound}")
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
override fun startStream(message: MutableMap<String, Any>) {
|
|
@@ -63,6 +63,8 @@ internal data class GlassesStatus(
|
|
|
63
63
|
*/
|
|
64
64
|
val packageName: String,
|
|
65
65
|
val hotspotOtaVersion: Int,
|
|
66
|
+
/** Deferred photos (capturePhoto): the glasses' version, 0 without. */
|
|
67
|
+
val deferredPhotosVersion: 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
|
+
"deferredPhotosVersion" to deferredPhotosVersion,
|
|
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
|
+
deferredPhotosVersion = numberValue(values, "deferredPhotosVersion") ?: 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 deferredPhotosVersion: 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("deferredPhotosVersion", deferredPhotosVersion)
|
|
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
|
+
deferredPhotosVersion = optionalNumberValue(values, "deferredPhotosVersion"),
|
|
577
584
|
bluetoothName = optionalStringValue(values, "bluetoothName"),
|
|
578
585
|
serialNumber = optionalStringValue(values, "serialNumber"),
|
|
579
586
|
style = optionalStringValue(values, "style"),
|
|
@@ -622,7 +622,7 @@ class DeviceManagerSceneHandoffTest {
|
|
|
622
622
|
DeviceStore.set("glasses", "micEnabled", enabled)
|
|
623
623
|
}
|
|
624
624
|
override fun sortMicRanking(list: MutableList<String>) = list
|
|
625
|
-
override fun
|
|
625
|
+
override fun uploadPhoto(request: PhotoRequest) {}
|
|
626
626
|
override fun startStream(message: MutableMap<String, Any>) {}
|
|
627
627
|
override fun stopStream() {}
|
|
628
628
|
override fun sendStreamKeepAlive(message: MutableMap<String, Any>) {}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk
|
|
2
|
+
|
|
3
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
4
|
+
import kotlinx.coroutines.runBlocking
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class PhotoCaptureTest {
|
|
8
|
+
private val calls = mutableListOf<String>()
|
|
9
|
+
private val glasses =
|
|
10
|
+
object : PhotoCapture.Glasses {
|
|
11
|
+
override fun fetch(request: PhotoRequest, preview: Boolean) {
|
|
12
|
+
calls += if (preview) "preview" else "fetch"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override fun release(requestId: String) {
|
|
16
|
+
calls += "release"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override fun forget(requestId: String) {
|
|
20
|
+
calls += "forget"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private fun saved(requestId: String) =
|
|
25
|
+
PhotoResponseEvent(
|
|
26
|
+
mapOf(
|
|
27
|
+
"requestId" to requestId,
|
|
28
|
+
"state" to "success",
|
|
29
|
+
"photoUrl" to "file:///cache/photo.jpg",
|
|
30
|
+
"timestamp" to 1L,
|
|
31
|
+
),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
@Test
|
|
35
|
+
fun `a fetched photo is still deleted from the glasses on release`(): Unit = runBlocking {
|
|
36
|
+
val capture = PhotoCapture(PhotoRequest(requestId = "p1", size = PhotoSize.MEDIUM), deferred = true, glasses)
|
|
37
|
+
capture.onStatus(PhotoStatusEvent(mapOf("requestId" to "p1", "status" to "captured")))
|
|
38
|
+
capture.onResponse(saved("p1"))
|
|
39
|
+
assertThat(capture.photo().requestId).isEqualTo("p1")
|
|
40
|
+
capture.release()
|
|
41
|
+
assertThat(calls).containsExactly("fetch", "forget", "release")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Test
|
|
45
|
+
fun `after a reconnect only what is still awaited is asked again`() {
|
|
46
|
+
val capture = PhotoCapture(PhotoRequest(requestId = "p1", size = PhotoSize.MEDIUM), deferred = true, glasses)
|
|
47
|
+
capture.onStatus(PhotoStatusEvent(mapOf("requestId" to "p1", "status" to "captured")))
|
|
48
|
+
capture.resume()
|
|
49
|
+
capture.onPreview(PhotoPreview("data:image/jpeg;base64,AA==", 500, 375))
|
|
50
|
+
capture.resume()
|
|
51
|
+
assertThat(calls).containsExactly("preview")
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -32,25 +32,6 @@ class PhotoRequestTest {
|
|
|
32
32
|
assertThat(PhotoRequest.fromMap(mapOf("authToken" to null)).compress).isEqualTo(PhotoCompression.NONE)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
@Test
|
|
36
|
-
fun `thumbnail is opt in and survives request routing copies`() {
|
|
37
|
-
val fields = mapOf("size" to "medium", "webhookUrl" to "https://example.com/upload")
|
|
38
|
-
assertThat(PhotoRequest.fromMap(fields).presendThumbnail).isFalse()
|
|
39
|
-
assertThat(PhotoRequest.fromMap(fields + ("presend_thumbnail" to false)).presendThumbnail).isFalse()
|
|
40
|
-
val request = PhotoRequest.fromMap(fields + ("presend_thumbnail" to true))
|
|
41
|
-
assertThat(request.copy(requestId = "routed").presendThumbnail).isTrue()
|
|
42
|
-
assertThat(request.transferMethod).isEqualTo("auto")
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Test
|
|
46
|
-
fun `local file delivery is opt in and survives request routing copies`() {
|
|
47
|
-
val fields = mapOf("size" to "low")
|
|
48
|
-
assertThat(PhotoRequest.fromMap(fields).localFile).isFalse()
|
|
49
|
-
val request = PhotoRequest.fromMap(fields + ("localFile" to true))
|
|
50
|
-
assertThat(request.copy(requestId = "routed").localFile).isTrue()
|
|
51
|
-
assertThat(request.webhookUrl).isEmpty()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
35
|
@Test
|
|
55
36
|
fun `constructor generates requestId when omitted`() {
|
|
56
37
|
val request =
|
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(
|
|
@@ -233,9 +233,9 @@ export type PhotoResponseEvent = {
|
|
|
233
233
|
type: "photo_response";
|
|
234
234
|
state: "success";
|
|
235
235
|
requestId: string;
|
|
236
|
-
/** Where the photo was uploaded
|
|
236
|
+
/** Where the photo was uploaded. */
|
|
237
237
|
uploadUrl: string;
|
|
238
|
-
/** The upload target's own URL for the photo
|
|
238
|
+
/** The upload target's own URL for the photo. */
|
|
239
239
|
photoUrl?: string;
|
|
240
240
|
statusUrl?: string;
|
|
241
241
|
contentType?: string;
|
|
@@ -252,7 +252,7 @@ export type PhotoResponseEvent = {
|
|
|
252
252
|
export type PhotoSuccessResponseEvent = Extract<PhotoResponseEvent, {
|
|
253
253
|
state: "success";
|
|
254
254
|
}>;
|
|
255
|
-
export type PhotoStatusState = "accepted" | "queued" | "configuring" | "capturing" | "captured" | "compressing" | "ble_fallback_compression" | "uploading" | "uploaded" | "ready_for_transfer" | "transferring" | "
|
|
255
|
+
export type PhotoStatusState = "accepted" | "queued" | "configuring" | "capturing" | "captured" | "compressing" | "ble_fallback_compression" | "uploading" | "uploaded" | "ready_for_transfer" | "transferring" | "failed";
|
|
256
256
|
export type PhotoResolvedConfig = {
|
|
257
257
|
format?: "jpeg" | string;
|
|
258
258
|
width?: number;
|
|
@@ -322,8 +322,6 @@ export type PhotoStatusEvent = {
|
|
|
322
322
|
captureMetadata?: PhotoCaptureMetadata;
|
|
323
323
|
errorCode?: string;
|
|
324
324
|
errorMessage?: string;
|
|
325
|
-
/** Present on thumbnail_received: a JPEG data URI, not the final photo. */
|
|
326
|
-
thumbnailUrl?: string;
|
|
327
325
|
fileSizeBytes?: number;
|
|
328
326
|
};
|
|
329
327
|
export type CameraStatusEvent = {
|
|
@@ -549,7 +547,7 @@ export type PhotoTransferMethod = "auto" | "direct" | "ble";
|
|
|
549
547
|
export type ButtonPhotoSize = "low" | "medium" | "high" | "max";
|
|
550
548
|
/**
|
|
551
549
|
* @deprecated Sticky action-button photo presets via {@link BluetoothSdkPublicModule.setPhotoCaptureDefaults}
|
|
552
|
-
* are deprecated. Prefer per-request {@link BluetoothSdkPublicModule.
|
|
550
|
+
* are deprecated. Prefer per-request {@link BluetoothSdkPublicModule.uploadPhoto} options
|
|
553
551
|
* (e.g. `mode: "text"` for text sensor size/crop, or explicit `aeExposureDivisor`) instead of
|
|
554
552
|
* persisting button-photo tuning on the glasses.
|
|
555
553
|
*/
|
|
@@ -645,27 +643,12 @@ type NativeCameraFovSetting = {
|
|
|
645
643
|
};
|
|
646
644
|
export type MicPreference = "auto" | "phone" | "glasses" | "bluetooth";
|
|
647
645
|
export type MicMode = "phone" | "glasses" | "bluetoothClassic" | "bluetooth";
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
* Send an oriented <=500px, quality-50 JPEG preview before the full photo. Default false.
|
|
651
|
-
* Enables a 110-second end-to-end native deadline (ordinary requests: 30 seconds).
|
|
652
|
-
*/
|
|
653
|
-
presend_thumbnail?: boolean;
|
|
646
|
+
/** The settings of one capture, shared by `capturePhoto` and `uploadPhoto`. */
|
|
647
|
+
export type PhotoCaptureParams = {
|
|
654
648
|
requestId?: string;
|
|
655
649
|
appId?: string;
|
|
656
650
|
size: PhotoSize;
|
|
657
651
|
mode?: PhotoMode;
|
|
658
|
-
/** `direct` disables BLE fallback; `ble` skips direct upload and forces phone-relayed transfer. */
|
|
659
|
-
transferMethod?: PhotoTransferMethod;
|
|
660
|
-
webhookUrl: string | null;
|
|
661
|
-
authToken: string | null;
|
|
662
|
-
/**
|
|
663
|
-
* Keep the photo on the phone: it comes over BLE, is saved as a JPEG file, and the success
|
|
664
|
-
* response carries that file's `file://` URI as `photoUrl`, with `fileSizeBytes`. Nothing is
|
|
665
|
-
* uploaded, and `webhookUrl`, `authToken` and `transferMethod` are ignored. The file is in the
|
|
666
|
-
* app's cache folder and is the caller's to move or delete. Default false.
|
|
667
|
-
*/
|
|
668
|
-
localFile?: boolean;
|
|
669
652
|
compress?: PhotoCompression;
|
|
670
653
|
save?: boolean;
|
|
671
654
|
sound: boolean;
|
|
@@ -686,6 +669,44 @@ export type PhotoRequestParams = {
|
|
|
686
669
|
ispDigitalGain?: number;
|
|
687
670
|
ispAnalogGain?: string;
|
|
688
671
|
};
|
|
672
|
+
/** A photo uploaded where `webhookUrl` says, by the glasses over Wi-Fi or by the phone over Bluetooth. */
|
|
673
|
+
export type PhotoUploadParams = PhotoCaptureParams & {
|
|
674
|
+
/** `direct` disables BLE fallback; `ble` skips direct upload and forces phone-relayed transfer. */
|
|
675
|
+
transferMethod?: PhotoTransferMethod;
|
|
676
|
+
webhookUrl: string | null;
|
|
677
|
+
authToken: string | null;
|
|
678
|
+
};
|
|
679
|
+
/** A photo's preview: the glasses' at most 500 px JPEG, as a `data:image/jpeg;base64,` URL. */
|
|
680
|
+
export type PhotoPreview = {
|
|
681
|
+
url: string;
|
|
682
|
+
width?: number;
|
|
683
|
+
height?: number;
|
|
684
|
+
};
|
|
685
|
+
/** A full photo kept on the phone: a JPEG in the app's cache folder, the caller's to move or delete. */
|
|
686
|
+
export type PhotoTaken = {
|
|
687
|
+
requestId: string;
|
|
688
|
+
fileUri: string;
|
|
689
|
+
mimeType: string;
|
|
690
|
+
size: number;
|
|
691
|
+
};
|
|
692
|
+
/**
|
|
693
|
+
* One photo kept on the phone, in stages. Any number can be in flight: the glasses refuse a capture
|
|
694
|
+
* only while another one is being taken (`CAMERA_BUSY`), never because photos are being sent.
|
|
695
|
+
*/
|
|
696
|
+
export interface PhotoCapture {
|
|
697
|
+
readonly requestId: string;
|
|
698
|
+
/** Resolves once the glasses wrote the photo: the camera takes the next one. */
|
|
699
|
+
readonly captured: Promise<void>;
|
|
700
|
+
/** The glasses' preview, which comes for every photo before its full size. */
|
|
701
|
+
readonly preview: Promise<PhotoPreview>;
|
|
702
|
+
/**
|
|
703
|
+
* The full photo. The first call asks the glasses to send it; until then it waits on the
|
|
704
|
+
* glasses (deferred delivery), for 30 minutes at most. Later calls return the same photo.
|
|
705
|
+
*/
|
|
706
|
+
photo(): Promise<PhotoTaken>;
|
|
707
|
+
/** The full photo isn't needed: the glasses delete it. Stages not reached yet reject. */
|
|
708
|
+
release(): Promise<void>;
|
|
709
|
+
}
|
|
689
710
|
export type WarmUpCameraParams = {
|
|
690
711
|
/** Supply this when the owner needs to call stopCameraWarmUp during teardown. */
|
|
691
712
|
requestId?: string;
|
|
@@ -1395,7 +1416,7 @@ export interface BluetoothSdkPublicModule {
|
|
|
1395
1416
|
setAutoPowerOffEnabled(enabled: boolean): Promise<void>;
|
|
1396
1417
|
/**
|
|
1397
1418
|
* @deprecated Sticky action-button photo presets are deprecated. Prefer per-request
|
|
1398
|
-
* `
|
|
1419
|
+
* `uploadPhoto(...)` options (e.g. `mode: "text"` for text sensor size/crop, or explicit per-shot
|
|
1399
1420
|
* fields). Still functional until removed in a future release.
|
|
1400
1421
|
*/
|
|
1401
1422
|
setPhotoCaptureDefaults(settings: PhotoCaptureDefaults): Promise<SettingsAckSuccessEvent>;
|
|
@@ -1421,7 +1442,15 @@ export interface BluetoothSdkPublicModule {
|
|
|
1421
1442
|
*/
|
|
1422
1443
|
setCameraTuningConfig(anrOn: boolean, gainOn: boolean): Promise<SettingsAckSuccessEvent>;
|
|
1423
1444
|
queryGalleryStatus(): Promise<GalleryStatusEvent>;
|
|
1424
|
-
|
|
1445
|
+
/**
|
|
1446
|
+
* A photo sent to `webhookUrl`: uploaded by the glasses over their own Wi-Fi, or relayed by the
|
|
1447
|
+
* phone over Bluetooth. Resolves once it is there. A photo kept on the phone is `takePhoto`.
|
|
1448
|
+
*/
|
|
1449
|
+
uploadPhoto(params: PhotoUploadParams): Promise<PhotoSuccessResponseEvent>;
|
|
1450
|
+
/** A photo kept on the phone, in stages: see {@link PhotoCapture}. */
|
|
1451
|
+
capturePhoto(params: PhotoCaptureParams): PhotoCapture;
|
|
1452
|
+
/** A photo kept on the phone, whole: `capturePhoto(params).photo()`, then its release. */
|
|
1453
|
+
takePhoto(params: PhotoCaptureParams): Promise<PhotoTaken>;
|
|
1425
1454
|
warmUpCamera(params: WarmUpCameraParams): Promise<CameraStatusEvent>;
|
|
1426
1455
|
/** Release one request-owned warm-up. Opening requests reject with camera_warm_up_cancelled. */
|
|
1427
1456
|
stopCameraWarmUp(requestId: string): Promise<void>;
|
|
@@ -1585,6 +1614,8 @@ export interface GlassesStatus {
|
|
|
1585
1614
|
packageName: string;
|
|
1586
1615
|
/** Phone-served hotspot OTA protocol version; 0 means unsupported/legacy glasses. */
|
|
1587
1616
|
hotspotOtaVersion: number;
|
|
1617
|
+
/** Deferred photos (`capturePhoto` keeps the full photo on the glasses until asked); 0 without. */
|
|
1618
|
+
deferredPhotosVersion?: number;
|
|
1588
1619
|
bluetoothName: string;
|
|
1589
1620
|
serialNumber: string;
|
|
1590
1621
|
style: string;
|