#17 removed the `setSessionExpiry` and `isVpnRuntimeAlive` MethodChannel handlers from MainActivity, and #18 removed their last callers. The Dart wrappers stayed behind. Both swallow their errors, so a future caller would not fail loudly — it would get a silent no-op from `setSessionExpiry` and a permanent `processAlive: false` from `runtimeState()`, which previously read as "the tunnel is dead". Deleting them keeps that trap out of the codebase. `VpnRuntimeState` goes with them; runtime liveness now arrives through the native status stream, which is generation-scoped. The battery-optimisation methods are untouched and still used by background_reliability.dart. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019HT2x2JvJNg7XNsJubfHFf
45 lines
1.4 KiB
Dart
45 lines
1.4 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
/// Background-survival controls.
|
|
///
|
|
/// Android stops background services of apps that are not exempt from Doze and
|
|
/// App Standby, and it tears down the whole process group when a task is swiped
|
|
/// away. Those are OS behaviours, not app bugs; the battery-optimisation
|
|
/// exemption is the one sanctioned way an app can ask for around them, and it
|
|
/// still needs one user tap.
|
|
abstract final class PowerSettings {
|
|
PowerSettings._();
|
|
|
|
static const MethodChannel _channel = MethodChannel(
|
|
'com.revoltvpn.app/power',
|
|
);
|
|
|
|
/// Whether the OS has exempted this app from Doze / App Standby.
|
|
static Future<bool> isBatteryOptimisationDisabled() async {
|
|
if (kIsWeb) return true;
|
|
try {
|
|
return await _channel.invokeMethod<bool>(
|
|
'isIgnoringBatteryOptimizations',
|
|
) ??
|
|
false;
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// Shows the system exemption dialog. Returns false only when no system UI
|
|
/// could be opened at all — a user declining still returns true.
|
|
static Future<bool> requestDisableBatteryOptimisation() async {
|
|
if (kIsWeb) return true;
|
|
try {
|
|
return await _channel.invokeMethod<bool>(
|
|
'requestIgnoreBatteryOptimizations',
|
|
) ??
|
|
false;
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|