3.3.1 could display "connected" against a tunnel that was no longer running, with a frozen countdown and no traffic. Three causes, and the fix for each removes more code than it adds. Liveness was read from getConnectedServerDelay(), which measures through AppConfigs.V2RAY_CONFIG?.LOCAL_SOCKS5_PORT ?: 10807. AppConfigs lives in the :RunSoLibXrayDaemon process, so from the UI process it is always null and the port always fell back to 10807 -- accidentally correct while the SOCKS port was fixed, permanently wrong once 3.3.1 made it ephemeral. Liveness now comes from the OS: is our service process running, and is a VPN transport actually present. The foreground notification (id 1) is owned by XrayVPNService via startForeground, but MainActivity was posting to the same id from the UI process. When that process died its notification stayed on screen with nothing left to update it. MainActivity now refuses to post for a dead runtime and clears the stale notification instead. Nothing ever asked Android for permission to stay alive. Adds the battery-optimisation exemption prompt and a deep link to Always-on VPN -- the two sanctioned mechanisms for background survival, each needing one user tap. Removes Standard/Extreme resilience and the runtime-restart machinery: recovery ran off a disconnect broadcast delivered to the app process, so it could never fire when Android killed that process. Removes startup restoration and the config-snapshot rebuild along with it; with the OS keeping the tunnel up there is nothing to restore. Version 3.3.2+28. Co-Authored-By: Claude Opus 5 <[email protected]>
41 lines
1.1 KiB
Dart
41 lines
1.1 KiB
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
enum ConnectionMode { tun, proxy }
|
|
|
|
abstract final class ConnectionSettings {
|
|
ConnectionSettings._();
|
|
|
|
static const String _modeKey = 'connection_mode';
|
|
|
|
static ConnectionMode _mode = ConnectionMode.tun;
|
|
static bool _initialized = false;
|
|
|
|
static ConnectionMode get mode => _mode;
|
|
|
|
static Future<void> initialize() async {
|
|
if (_initialized) return;
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final storedMode = prefs.getString(_modeKey);
|
|
|
|
// Legacy 'ass' was the pre-V3 SOCKS5 label; map it to proxy. Everything
|
|
// else (including the old 'auto') is TUN — there is no runtime auto mode.
|
|
_mode = storedMode == ConnectionMode.proxy.name || storedMode == 'ass'
|
|
? ConnectionMode.proxy
|
|
: ConnectionMode.tun;
|
|
|
|
if (storedMode != _mode.name) {
|
|
await prefs.setString(_modeKey, _mode.name);
|
|
}
|
|
|
|
_initialized = true;
|
|
}
|
|
|
|
static Future<void> setMode(ConnectionMode mode) async {
|
|
_mode = mode;
|
|
_initialized = true;
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString(_modeKey, mode.name);
|
|
}
|
|
}
|