@mentra/bluetooth-sdk 3.5.0-dev.1503 → 3.5.0-dev.1504

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.
@@ -23,6 +23,11 @@
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"/>
26
31
 
27
32
  <!-- Foreground service permissions (must match foregroundServiceType bits on the service) -->
28
33
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
@@ -363,6 +363,7 @@ class BluetoothSdkModule : Module() {
363
363
  "saved_wifi_networks",
364
364
  "hotspot_status_change",
365
365
  "hotspot_error",
366
+ "fast_link_status",
366
367
  "photo_response",
367
368
  "photo_status",
368
369
  "camera_status",
@@ -668,6 +669,12 @@ class BluetoothSdkModule : Module() {
668
669
  requireSdk().forgetWifiNetwork(ssid).toMap()
669
670
  }
670
671
 
672
+ Function("openFastLink") { requireSdk().openFastLink() }
673
+
674
+ Function("closeFastLink") { requireSdk().closeFastLink() }
675
+
676
+ Function("getFastLinkStatus") { requireSdk().getFastLinkStatus() }
677
+
671
678
  SdkCoroutineFunction("setHotspotState") { enabled: Boolean ->
672
679
  requireSdk().setHotspotState(enabled).values
673
680
  }
@@ -2022,6 +2022,27 @@ 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
+
2025
2046
  fun setWifiAdbState(enabled: Boolean, expectedBluetoothMac: String? = null) {
2026
2047
  if (expectedBluetoothMac != null) {
2027
2048
  val current = sgc as? MentraLive ?: throw BluetoothSdkException(
@@ -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.1503"
7
- const val RELEASE_SET_ID: String = "mentra-3.5.0-dev.1503"
8
- const val SOURCE_COMMIT: String = "a4f32ad528757b20a19b001039a6790f2c055961"
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.1503.json"
10
- const val OTA_MANIFEST_SHA256: String = "a89a829632d8ebd9f211989ff9332d619031ccc1dcfc36738012b9105f691d86"
6
+ const val RELEASE_IDENTITY: String = "3.5.0-dev.1504"
7
+ const val RELEASE_SET_ID: String = "mentra-3.5.0-dev.1504"
8
+ const val SOURCE_COMMIT: String = "01d8beea33cfb777a24014e8855bba6504e04a7a"
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.1504.json"
10
+ const val OTA_MANIFEST_SHA256: String = "e6e0ff0a2c99f5671f7b7b81a340a6ef7ce7a0422d9c4eb31b62815b8cd28db4"
11
11
  }
@@ -1099,6 +1099,19 @@ 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
+
1102
1115
  suspend fun setHotspotState(enabled: Boolean): HotspotStatusEvent {
1103
1116
  // SoftAP teardown disables from the transport and again from the host
1104
1117
  // barrier. Throwing request_in_flight on the second disable recorded a
@@ -426,6 +426,12 @@ sealed interface PhotoResponse {
426
426
  val contentType: String?,
427
427
  val fileSizeBytes: Long?,
428
428
  override val timestamp: Long,
429
+ /** How a local photo reached the phone: "ble", "wifi_direct" or "hotspot". */
430
+ val transport: String? = null,
431
+ /** Its last hop: the fetch over a fast link, or the Bluetooth packets. */
432
+ val transferMs: Long? = null,
433
+ /** From the phone's request to the saved file. */
434
+ val totalMs: Long? = null,
429
435
  ) : PhotoResponse {
430
436
  override val state: String = "success"
431
437
  }
@@ -458,6 +464,9 @@ sealed interface PhotoResponse {
458
464
  ?: longValue(values, "bytes")
459
465
  ?: longValue(values, "size"),
460
466
  timestamp = timestamp,
467
+ transport = stringValue(values, "transport"),
468
+ transferMs = longValue(values, "transferMs"),
469
+ totalMs = longValue(values, "totalMs"),
461
470
  )
462
471
  } else {
463
472
  Error(
@@ -480,6 +489,9 @@ private fun Map<String, Any>.withOptionalPhotoMetadata(
480
489
  success.statusUrl?.takeIf { it.isNotBlank() }?.let { this["statusUrl"] = it }
481
490
  success.contentType?.takeIf { it.isNotBlank() }?.let { this["contentType"] = it }
482
491
  success.fileSizeBytes?.let { this["fileSizeBytes"] = it }
492
+ success.transport?.takeIf { it.isNotBlank() }?.let { this["transport"] = it }
493
+ success.transferMs?.let { this["transferMs"] = it }
494
+ success.totalMs?.let { this["totalMs"] = it }
483
495
  }
484
496
 
485
497
  data class PhotoResponseEvent(
@@ -881,6 +881,10 @@ class MentraLive : SGCManager() {
881
881
  var phoneStartTime: Long = System.currentTimeMillis() // When phone received the request
882
882
  var bleTransferStartTime: Long = 0 // When BLE transfer actually started
883
883
  var glassesCompressionDurationMs: Long = 0 // How long glasses took to compress
884
+ /** How the photo reached the phone: "ble", "wifi_direct" or "hotspot". */
885
+ var transport: String = "ble"
886
+ /** How long its last hop took (fetch over a fast link, or Bluetooth packets). */
887
+ var transferMs: Long = 0
884
888
  }
885
889
 
886
890
  private enum class BleIncidentLogKind {
@@ -1158,6 +1162,25 @@ class MentraLive : SGCManager() {
1158
1162
  private val lc3TimestampFormat = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US)
1159
1163
  private val lc3PacketTimestampFormat = SimpleDateFormat("HH:mm:ss.SSS", Locale.US)
1160
1164
 
1165
+ /** The Wi-Fi Direct photo link; Bluetooth stays its control channel. */
1166
+ val wifiDirectLink: WifiDirectLink by lazy {
1167
+ WifiDirectLink(
1168
+ Bridge.getContext(),
1169
+ sendToGlasses = { json ->
1170
+ if (connectionState == ConnTypes.CONNECTED) {
1171
+ sendJson(json, true)
1172
+ true
1173
+ } else {
1174
+ false
1175
+ }
1176
+ },
1177
+ onStatus = { status -> Bridge.sendTypedMessage("fast_link_status", status) },
1178
+ )
1179
+ }
1180
+
1181
+ /** Fetches photos announced on a fast link, one at a time, off the BLE threads. */
1182
+ private val fastPhotoExecutor = Executors.newSingleThreadExecutor()
1183
+
1161
1184
  init {
1162
1185
  this.type = DeviceTypes.LIVE
1163
1186
  this.hasMic = true
@@ -1320,6 +1343,8 @@ class MentraLive : SGCManager() {
1320
1343
  if (state == ConnTypes.DISCONNECTED) {
1321
1344
  wifiAdbPeerIdentity = null
1322
1345
  DeviceStore.apply("glasses", "hotspotOtaVersion", 0)
1346
+ wifiDirectLink.glassesVersion = 0
1347
+ wifiDirectLink.onGlassesDisconnected()
1323
1348
  }
1324
1349
  val isEqual = state == connectionState
1325
1350
  if (isEqual) {
@@ -4732,6 +4757,8 @@ class MentraLive : SGCManager() {
4732
4757
 
4733
4758
  updateHotspotStatus(hotspotEnabled, hotspotSsid, hotspotPassword, hotspotGatewayIp)
4734
4759
  }
4760
+ "wifi_direct_status" -> wifiDirectLink.onGlassesStatus(json)
4761
+ "fast_photo_ready" -> handleFastPhotoReady(json)
4735
4762
  "hotspot_error" -> {
4736
4763
  // Process hotspot error
4737
4764
  val errorMessage = json.optString("error_message", "Unknown hotspot error")
@@ -5660,6 +5687,11 @@ class MentraLive : SGCManager() {
5660
5687
  DeviceStore.apply("glasses", "systemTimeMs", v.toLong())
5661
5688
  }
5662
5689
  }
5690
+ if (fields.containsKey("wifi_direct_version")) {
5691
+ (fields["wifi_direct_version"] as? Number)?.let {
5692
+ wifiDirectLink.glassesVersion = it.toInt()
5693
+ }
5694
+ }
5663
5695
  if (fields.containsKey("hotspot_ota_version")) {
5664
5696
  val version = fields["hotspot_ota_version"]
5665
5697
  if (version is Number) {
@@ -7583,6 +7615,12 @@ class MentraLive : SGCManager() {
7583
7615
  // phone-relayed BLE path. Auto remains the default.
7584
7616
  json.put("transferMethod", transferMethod)
7585
7617
 
7618
+ // Photos ride any open fast link: the Wi-Fi Direct group, or a glasses hotspot the
7619
+ // phone joined for something else. The glasses fall back to Bluetooth by themselves,
7620
+ // and glasses without fast transfer ignore the flag.
7621
+ val fastLink = fastPhotoLink()
7622
+ if (fastLink != null) json.put("fastTransfer", true)
7623
+
7586
7624
  // Always prepare for potential BLE transfer
7587
7625
  if (localFile) {
7588
7626
  val transfer = BlePhotoTransfer(bleImgId, requestId, null)
@@ -7595,7 +7633,10 @@ class MentraLive : SGCManager() {
7595
7633
  blePhotoTransfers[bleImgId] = transfer
7596
7634
  }
7597
7635
 
7598
- Bridge.log("LIVE: Using " + transferMethod + " transfer mode with BLE fallback ID: " + bleImgId)
7636
+ Bridge.log(
7637
+ "LIVE: Using " + transferMethod + " transfer mode with BLE fallback ID: " + bleImgId +
7638
+ (if (fastLink != null) ", fast link: $fastLink" else "")
7639
+ )
7599
7640
  Bridge.log(
7600
7641
  "LIVE: PHOTO PIPELINE [5b/6] JSON ready mode=" +
7601
7642
  mode +
@@ -11388,6 +11429,7 @@ class MentraLive : SGCManager() {
11388
11429
  photoTransfer.glassesCompressionDurationMs +
11389
11430
  "ms"
11390
11431
  )
11432
+ photoTransfer.transferMs = bleTransferDuration
11391
11433
  if (bleTransferDuration > 0) {
11392
11434
  Bridge.log("LIVE: ⏱️ BLE transfer duration: " + bleTransferDuration + "ms")
11393
11435
  Bridge.log(
@@ -11987,6 +12029,65 @@ class MentraLive : SGCManager() {
11987
12029
  }
11988
12030
 
11989
12031
  /** Process and upload a BLE photo transfer */
12032
+ /** The fast link a photo requested now would use, or null for Bluetooth. */
12033
+ private fun fastPhotoLink(): String? =
12034
+ when {
12035
+ wifiDirectLink.isOpen() -> "wifi_direct"
12036
+ DeviceStore.get("glasses", "hotspotEnabled") == true &&
12037
+ wifiDirectLink.hotspotNetwork(DeviceStore.get("glasses", "hotspotGatewayIp") as? String) != null ->
12038
+ "hotspot"
12039
+ else -> null
12040
+ }
12041
+
12042
+ /**
12043
+ * The glasses hold a finished photo on a fast link instead of sending it over Bluetooth. Fetch
12044
+ * it and finish the request exactly as a Bluetooth photo would; if the fetch fails, ask the
12045
+ * glasses for Bluetooth, which the request's transfer entry still expects.
12046
+ */
12047
+ private fun handleFastPhotoReady(json: JSONObject) {
12048
+ val bleImgId = json.optString("bleImgId", "")
12049
+ val url = json.optString("url", "")
12050
+ val ackUrl = json.optString("ackUrl", "")
12051
+ val link = json.optString("link", "wifi_direct")
12052
+ val transfer = blePhotoTransfers[bleImgId]
12053
+ if (transfer == null || url.isEmpty()) {
12054
+ Log.w(TAG, "fast_photo_ready for an unknown photo: $bleImgId")
12055
+ return
12056
+ }
12057
+ transfer.bleTransferStartTime = System.currentTimeMillis()
12058
+ fastPhotoExecutor.execute {
12059
+ try {
12060
+ val photo = wifiDirectLink.fetchPhoto(url, ackUrl, link)
12061
+ if (blePhotoTransfers.remove(bleImgId) == null) return@execute
12062
+ val total = System.currentTimeMillis() - transfer.phoneStartTime
12063
+ Bridge.log(
12064
+ "LIVE: ⏱️ Fast photo over $link: ${photo.bytes.size} bytes in ${photo.fetchMs} ms" +
12065
+ " (${if (photo.fetchMs > 0) photo.bytes.size / photo.fetchMs else 0} KB/s)," +
12066
+ " request→received $total ms, requestId=${transfer.requestId}"
12067
+ )
12068
+ transfer.transport = link
12069
+ transfer.transferMs = photo.fetchMs
12070
+ processAndUploadBlePhoto(transfer, photo.bytes)
12071
+ } catch (e: Exception) {
12072
+ // A host app that bound its process to another network (an old hotspot join) sends
12073
+ // even Wi-Fi Direct traffic there; say so, since it's the host's to undo.
12074
+ val bound = context?.getSystemService(android.net.ConnectivityManager::class.java)?.boundNetworkForProcess
12075
+ Log.w(
12076
+ TAG,
12077
+ "Fast photo fetch over $link failed, asking for Bluetooth: ${e.message}" +
12078
+ (if (bound != null) " (this process is bound to network $bound)" else "")
12079
+ )
12080
+ sendJson(
12081
+ JSONObject()
12082
+ .put("type", "fast_photo_failed")
12083
+ .put("bleImgId", bleImgId)
12084
+ .put("reason", e.javaClass.simpleName),
12085
+ true
12086
+ )
12087
+ }
12088
+ }
12089
+ }
12090
+
11990
12091
  private fun processAndUploadBlePhoto(transfer: BlePhotoTransfer, imageData: ByteArray) {
11991
12092
  if (transfer.isThumbnail) {
11992
12093
  Bridge.sendPhotoStatus(mapOf(
@@ -12098,6 +12199,9 @@ class MentraLive : SGCManager() {
12098
12199
  event["contentType"] = "image/jpeg"
12099
12200
  event["fileSizeBytes"] = file.length()
12100
12201
  event["timestamp"] = System.currentTimeMillis()
12202
+ event["transport"] = transfer.transport
12203
+ event["transferMs"] = transfer.transferMs
12204
+ event["totalMs"] = System.currentTimeMillis() - transfer.phoneStartTime
12101
12205
  Bridge.sendPhotoResponse(event)
12102
12206
  }
12103
12207