Add "Show BLE bandwidth usage" option to developer settings

This commit is contained in:
James Babcock committed 2026-09-01 00:33:07 -07:00
1 parent 641e8e322e
commit 85508b87ca
10 files changed
+153 -2

No files matched your search

@@ -2243,6 +2243,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
return;
}
long ackedAtMs = SystemClock.elapsedRealtime();
FaceclawBleManager.recordDisplayFrameSent();
BleImageOptimizer.ImageUpdateStats stats = imageUpdateStats.remove(message.imageUpdateId);
if (stats != null && stats.firstWriteStartedAtMs > 0) {
emitFrameMetrics(stats.paintMs, (int) Math.max(0, ackedAtMs - stats.firstWriteStartedAtMs), stats.tileCount);
@@ -21,6 +21,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
@SuppressLint("MissingPermission")
public class FaceclawBleManager {
@@ -51,6 +52,23 @@ public class FaceclawBleManager {
private volatile FaceclawBleListener listener;
// Process-wide outbound-traffic totals, sampled by the phone UI's BLE
// bandwidth indicator. Static so counts from every manager instance and
// isolate land in the same totals.
private static final AtomicLong outboundMessages = new AtomicLong();
private static final AtomicLong outboundBytes = new AtomicLong();
private static final AtomicLong displayFramesSent = new AtomicLong();
/** Called by the communicator when a display frame's last message is acked. */
public static void recordDisplayFrameSent() {
displayFramesSent.incrementAndGet();
}
/** Running totals of outbound BLE traffic since process start: [messages, bytes, display frames]. */
public static long[] sampleOutboundTraffic() {
return new long[] { outboundMessages.get(), outboundBytes.get(), displayFramesSent.get() };
}
public FaceclawBleManager(Context context) {
this.context = context.getApplicationContext();
BluetoothManager bluetoothManager = (BluetoothManager) this.context.getSystemService(Context.BLUETOOTH_SERVICE);
@@ -250,8 +268,10 @@ public class FaceclawBleManager {
if (!startWrite(gatt, characteristic, address, frame, writeType, timeoutMs)) {
return false;
}
outboundBytes.addAndGet(frame != null ? frame.length : 0);
}
}
outboundMessages.incrementAndGet();
int totalSize = frames.stream().mapToInt(frame -> frame != null ? frame.length : 0).sum();
Log.i(TAG, "writeFrames wrote " + frames.size() + " frames totaling " + totalSize + " bytes in " + (System.currentTimeMillis() - startMs) + "ms");
return true;