Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions asg_client/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application>
<!-- Allow adb shell am broadcast to reach BleTransferMode in debug builds. -->
<receiver
android:name="com.mentra.asg_client.io.bluetooth.managers.BleTransferModeReceiver"
android:exported="true"
tools:replace="android:exported" />
</application>
</manifest>
10 changes: 10 additions & 0 deletions asg_client/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@
</intent-filter>
</receiver>

<!-- Debug: exported via src/debug/AndroidManifest.xml for adb toggles -->
<receiver
android:name="com.mentra.asg_client.io.bluetooth.managers.BleTransferModeReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.mentra.BLE_TRANSFER_MODE" />
</intent-filter>
</receiver>

<!-- Intent IPC receiver for third-party app commands -->
<receiver
android:name="com.mentra.asg_client.receiver.IntentCommandReceiver"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.mentra.asg_client.io.bluetooth.managers;

import android.util.Log;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
* Synchronizes ASG {@code ble_photo_ready} transmission with phone {@code ble_ready_ack} so file
* packets start only after the JSON notification has reached the phone (Phase 2).
*/
public final class BlePhotoReadyAck {

private static final String TAG = "BlePhotoReadyAck";
private static final ConcurrentHashMap<String, CountDownLatch> LATCHES =
new ConcurrentHashMap<>();

private BlePhotoReadyAck() {}

public static void prepare(String requestId) {
if (requestId == null || requestId.isEmpty()) {
return;
}
LATCHES.put(requestId, new CountDownLatch(1));
}

public static boolean await(String requestId, long timeoutMs) {
if (requestId == null || requestId.isEmpty()) {
return false;
}
CountDownLatch latch = LATCHES.get(requestId);
if (latch == null) {
return false;
}
try {
boolean signaled = latch.await(timeoutMs, TimeUnit.MILLISECONDS);
if (!signaled) {
Log.w(TAG, "ble_ready_ack timeout for requestId=" + requestId);
}
return signaled;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Log.w(TAG, "ble_ready_ack wait interrupted for requestId=" + requestId);
return false;
} finally {
LATCHES.remove(requestId);
}
}

public static void signal(String requestId) {
if (requestId == null || requestId.isEmpty()) {
return;
}
CountDownLatch latch = LATCHES.remove(requestId);
if (latch != null) {
latch.countDown();
Log.i(TAG, "ble_ready_ack received for requestId=" + requestId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mentra.asg_client.io.bluetooth.managers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.mentra.asg_client.BuildConfig;

/**
* Manifest-registered receiver so {@code adb shell am broadcast} can toggle {@link
* BleTransferMode} in debug builds. No-op in release.
*/
public class BleTransferModeReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
if (!BuildConfig.DEBUG) {
return;
}
BleTransferMode.handleIntent(intent);
}
}
Loading
Loading