android opt:add disable ignore_battery_optimizations
This commit is contained in:
parent
d3fc6ccd9c
commit
88fef77980
@ -192,7 +192,6 @@ class MainActivity : FlutterActivity() {
|
|||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
val inputPer = InputService.isOpen
|
val inputPer = InputService.isOpen
|
||||||
Log.d(logTag, "onResume inputPer:$inputPer")
|
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
flutterMethodChannel.invokeMethod(
|
flutterMethodChannel.invokeMethod(
|
||||||
"on_state_changed",
|
"on_state_changed",
|
||||||
|
@ -57,6 +57,18 @@ fun requestPermission(context: Context, type: String) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
"application_details_settings" -> {
|
||||||
|
try {
|
||||||
|
context.startActivity(Intent().apply {
|
||||||
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
action = "android.settings.APPLICATION_DETAILS_SETTINGS"
|
||||||
|
data = Uri.parse("package:" + context.packageName)
|
||||||
|
})
|
||||||
|
} catch (e:Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
"audio" -> {
|
"audio" -> {
|
||||||
Permission.RECORD_AUDIO
|
Permission.RECORD_AUDIO
|
||||||
}
|
}
|
||||||
|
@ -260,7 +260,12 @@ class PermissionManager {
|
|||||||
static Timer? _timer;
|
static Timer? _timer;
|
||||||
static var _current = "";
|
static var _current = "";
|
||||||
|
|
||||||
static final permissions = ["audio", "file", "ignore_battery_optimizations"];
|
static final permissions = [
|
||||||
|
"audio",
|
||||||
|
"file",
|
||||||
|
"ignore_battery_optimizations",
|
||||||
|
"application_details_settings"
|
||||||
|
];
|
||||||
|
|
||||||
static bool isWaitingFile() {
|
static bool isWaitingFile() {
|
||||||
if (_completer != null) {
|
if (_completer != null) {
|
||||||
|
@ -26,23 +26,42 @@ class SettingsPage extends StatefulWidget implements PageShape {
|
|||||||
_SettingsState createState() => _SettingsState();
|
_SettingsState createState() => _SettingsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SettingsState extends State<SettingsPage> {
|
class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
|
||||||
static const url = 'https://rustdesk.com/';
|
static const url = 'https://rustdesk.com/';
|
||||||
var _showIgnoreBattery = false;
|
final _hasIgnoreBattery = androidVersion >= 26;
|
||||||
|
var _ignoreBatteryOpt = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
if (androidVersion >= 26) {
|
WidgetsBinding.instance.addObserver(this);
|
||||||
() async {
|
if (_hasIgnoreBattery) {
|
||||||
final res =
|
updateIgnoreBatteryStatus();
|
||||||
await PermissionManager.check("ignore_battery_optimizations");
|
}
|
||||||
if (_showIgnoreBattery != !res) {
|
}
|
||||||
setState(() {
|
|
||||||
_showIgnoreBattery = !res;
|
@override
|
||||||
});
|
void dispose() {
|
||||||
}
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
}();
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
|
if (state == AppLifecycleState.resumed) {
|
||||||
|
updateIgnoreBatteryStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> updateIgnoreBatteryStatus() async {
|
||||||
|
final res = await PermissionManager.check("ignore_battery_optimizations");
|
||||||
|
if (_ignoreBatteryOpt != res) {
|
||||||
|
setState(() {
|
||||||
|
_ignoreBatteryOpt = res;
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +72,6 @@ class _SettingsState extends State<SettingsPage> {
|
|||||||
final enableAbr = FFI.getByName("option", "enable-abr") != 'N';
|
final enableAbr = FFI.getByName("option", "enable-abr") != 'N';
|
||||||
final enhancementsTiles = [
|
final enhancementsTiles = [
|
||||||
SettingsTile.switchTile(
|
SettingsTile.switchTile(
|
||||||
leading: Icon(Icons.more_horiz),
|
|
||||||
title: Text(translate('Adaptive Bitrate') + '(beta)'),
|
title: Text(translate('Adaptive Bitrate') + '(beta)'),
|
||||||
initialValue: enableAbr,
|
initialValue: enableAbr,
|
||||||
onToggle: (v) {
|
onToggle: (v) {
|
||||||
@ -68,32 +86,37 @@ class _SettingsState extends State<SettingsPage> {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
if (_showIgnoreBattery) {
|
if (_hasIgnoreBattery) {
|
||||||
enhancementsTiles.insert(
|
enhancementsTiles.insert(
|
||||||
0,
|
0,
|
||||||
SettingsTile.navigation(
|
SettingsTile.switchTile(
|
||||||
|
initialValue: _ignoreBatteryOpt,
|
||||||
title: Text(translate('Keep RustDesk background service')),
|
title: Text(translate('Keep RustDesk background service')),
|
||||||
description:
|
description:
|
||||||
Text('* ${translate('Ignore Battery Optimizations')}'),
|
Text('* ${translate('Ignore Battery Optimizations')}'),
|
||||||
leading: Icon(Icons.battery_saver),
|
onToggle: (v) async {
|
||||||
onPressed: (context) {
|
if (v) {
|
||||||
PermissionManager.request("ignore_battery_optimizations");
|
PermissionManager.request("ignore_battery_optimizations");
|
||||||
var count = 0;
|
} else {
|
||||||
Timer.periodic(Duration(seconds: 1), (timer) async {
|
final res = await DialogManager.show<bool>(
|
||||||
if (count > 5) {
|
(setState, close) => CustomAlertDialog(
|
||||||
count = 0;
|
title: Text(translate("Open System Setting")),
|
||||||
timer.cancel();
|
content: Text(translate(
|
||||||
|
"android_open_battery_optimizations_tip")),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => close(),
|
||||||
|
child: Text(translate("Cancel"))),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () => close(true),
|
||||||
|
child:
|
||||||
|
Text(translate("Open System Setting"))),
|
||||||
|
],
|
||||||
|
));
|
||||||
|
if (res == true) {
|
||||||
|
PermissionManager.request("application_details_settings");
|
||||||
}
|
}
|
||||||
if (await PermissionManager.check(
|
}
|
||||||
"ignore_battery_optimizations")) {
|
|
||||||
count = 0;
|
|
||||||
timer.cancel();
|
|
||||||
setState(() {
|
|
||||||
_showIgnoreBattery = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
count++;
|
|
||||||
});
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +146,13 @@ class _SettingsState extends State<SettingsPage> {
|
|||||||
leading: Icon(Icons.cloud),
|
leading: Icon(Icons.cloud),
|
||||||
onPressed: (context) {
|
onPressed: (context) {
|
||||||
showServerSettings();
|
showServerSettings();
|
||||||
})
|
}),
|
||||||
|
SettingsTile.navigation(
|
||||||
|
title: Text(translate('Language')),
|
||||||
|
leading: Icon(Icons.translate),
|
||||||
|
onPressed: (context) {
|
||||||
|
showLanguageSettings();
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
SettingsSection(
|
SettingsSection(
|
||||||
title: Text(translate("Enhancements")),
|
title: Text(translate("Enhancements")),
|
||||||
@ -162,6 +191,13 @@ void showServerSettings() {
|
|||||||
showServerSettingsWithValue(id, relay, key, api);
|
showServerSettingsWithValue(id, relay, key, api);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void showLanguageSettings() {
|
||||||
|
try {
|
||||||
|
final langs = json.decode(FFI.getByName('langs')) as Map<String, String>;
|
||||||
|
debugPrint("langs:$langs");
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
void showAbout() {
|
void showAbout() {
|
||||||
DialogManager.show((setState, close) {
|
DialogManager.show((setState, close) {
|
||||||
return CustomAlertDialog(
|
return CustomAlertDialog(
|
||||||
|
@ -286,5 +286,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
|||||||
("Language", "语言"),
|
("Language", "语言"),
|
||||||
("Keep RustDesk background service", "保持RustDesk后台服务"),
|
("Keep RustDesk background service", "保持RustDesk后台服务"),
|
||||||
("Ignore Battery Optimizations", "忽略电池优化"),
|
("Ignore Battery Optimizations", "忽略电池优化"),
|
||||||
|
("android_open_battery_optimizations_tip", "如需关闭此功能,请在接下来的RustDesk应用设置页面中,找到并进入 [电源] 页面,取消勾选 [不受限制]"),
|
||||||
].iter().cloned().collect();
|
].iter().cloned().collect();
|
||||||
}
|
}
|
||||||
|
@ -27,5 +27,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
|||||||
("doc_mac_permission", "https://rustdesk.com/docs/en/manual/mac/#enable-permissions"),
|
("doc_mac_permission", "https://rustdesk.com/docs/en/manual/mac/#enable-permissions"),
|
||||||
("doc_fix_wayland", "https://rustdesk.com/docs/en/manual/linux/#x11-required"),
|
("doc_fix_wayland", "https://rustdesk.com/docs/en/manual/linux/#x11-required"),
|
||||||
("server_not_support", "Not yet supported by the server"),
|
("server_not_support", "Not yet supported by the server"),
|
||||||
|
("android_open_battery_optimizations_tip", "If you want to disable this feature, please go to the next RustDesk application settings page, find and enter [Battery] ,Uncheck [Unrestricted]"),
|
||||||
].iter().cloned().collect();
|
].iter().cloned().collect();
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,9 @@ unsafe extern "C" fn get_by_name(name: *const c_char, arg: *const c_char) -> *co
|
|||||||
.clone()
|
.clone()
|
||||||
.to_string();
|
.to_string();
|
||||||
}
|
}
|
||||||
|
"langs" => {
|
||||||
|
res = crate::lang::LANGS.to_string();
|
||||||
|
}
|
||||||
// File Action
|
// File Action
|
||||||
"get_home_dir" => {
|
"get_home_dir" => {
|
||||||
res = fs::get_home_as_string();
|
res = fs::get_home_as_string();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user