From e7a750dd7774493991e6fd82af9da7961c1ec384 Mon Sep 17 00:00:00 2001 From: ospab Date: Sat, 29 Aug 2026 00:36:20 +0300 Subject: [PATCH] fix(android): request battery-optimization exemption so Doze can't freeze the VPN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On phones the tunnel dropped quickly and never reconnected. Root cause: the app had a foreground service and a wake lock but never asked to be exempt from battery optimization, so Doze / App Standby froze the whole VPN process when the screen went off. A frozen process means not just a dead socket but that the in-process reconnect logic — wall-clock suspend detection, the NetworkChanged handler, keepalive — never runs at all, which is exactly "reconnect doesn't work." Adds the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission and, on VPN start, prompts for the exemption when it isn't already granted (checked via isIgnoringBatteryOptimizations, so it asks once). Fired after the VPN consent so the two system dialogs don't stack. Socket protection on reconnect was already correct (try_connect_transport protects every new socket), so this targets the process-freeze, which is the part that stopped recovery. --- .../android/app/src/main/AndroidManifest.xml | 4 ++++ .../com/ospab/ostp_client/MainActivity.kt | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ostp-flutter/android/app/src/main/AndroidManifest.xml b/ostp-flutter/android/app/src/main/AndroidManifest.xml index 54f4f4f..7008153 100644 --- a/ostp-flutter/android/app/src/main/AndroidManifest.xml +++ b/ostp-flutter/android/app/src/main/AndroidManifest.xml @@ -7,6 +7,10 @@ + +