From 94e5bc86fb12bdea8d00c00262a48b5e49236f40 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 15 Aug 2019 21:40:14 +0200 Subject: [PATCH] Ignore battery optimization settings to prevent suspension --- app/src/main/AndroidManifest.xml | 1 + app/src/main/java/com/termux/app/TermuxService.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ea251c7d..e428a693 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,6 +13,7 @@ + = Build.VERSION_CODES.M) { + String packageName = getPackageName(); + if (!pm.isIgnoringBatteryOptimizations(packageName)) { + Intent whitelist = new Intent(); + whitelist.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + whitelist.setData(Uri.parse("package:" + packageName)); + whitelist.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(whitelist); + } + } + updateNotification(); } } else if (ACTION_UNLOCK_WAKE.equals(action)) {