From dd6b3b67deddc9908bdefaefb15dc641ccffd294 Mon Sep 17 00:00:00 2001 From: Eldrinn-Elantey <46845681+Eldrinn-Elantey@users.noreply.github.com> Date: Mon, 5 Oct 2026 18:49:29 +0400 Subject: [PATCH] Fix battery drain from busy-polling the incoming packet queue --- .../src/main/java/io/openflux/app/OpenFluxTunnelService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/io/openflux/app/OpenFluxTunnelService.java b/android/app/src/main/java/io/openflux/app/OpenFluxTunnelService.java index 454fdf12..872b78bd 100644 --- a/android/app/src/main/java/io/openflux/app/OpenFluxTunnelService.java +++ b/android/app/src/main/java/io/openflux/app/OpenFluxTunnelService.java @@ -405,8 +405,11 @@ private void readOutgoingPackets(int session, FileInputStream input) { private void writeIncomingPackets(int session, FileOutputStream output) { try { while (isCurrent(session)) { - byte[] packet = Mobile.read(); + // Blocks until a packet arrives; polling read() with a 2ms sleep + // woke the CPU ~500 times a second and drained the battery. + byte[] packet = Mobile.readTimeout(1000); if (packet == null || packet.length == 0) { + // readTimeout returns at once before the core is started. Thread.sleep(2); continue; }