From f299e0c0edee9382499522804b8718656bc75396 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 21 Sep 2024 19:08:11 +0200 Subject: [PATCH] Ask for power optimisation disabling on Android --- sbapp/buildozer.spec | 2 +- sbapp/main.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sbapp/buildozer.spec b/sbapp/buildozer.spec index 13a7cdf..35b1d19 100644 --- a/sbapp/buildozer.spec +++ b/sbapp/buildozer.spec @@ -29,7 +29,7 @@ android.presplash_color = #00000000 orientation = portrait fullscreen = 0 -android.permissions = INTERNET,POST_NOTIFICATIONS,WAKE_LOCK,FOREGROUND_SERVICE,CHANGE_WIFI_MULTICAST_STATE,BLUETOOTH_CONNECT,ACCESS_NETWORK_STATE,ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATION,MANAGE_EXTERNAL_STORAGE,ACCESS_BACKGROUND_LOCATION,RECORD_AUDIO +android.permissions = INTERNET,POST_NOTIFICATIONS,WAKE_LOCK,FOREGROUND_SERVICE,CHANGE_WIFI_MULTICAST_STATE,BLUETOOTH_CONNECT,ACCESS_NETWORK_STATE,ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATION,MANAGE_EXTERNAL_STORAGE,ACCESS_BACKGROUND_LOCATION,RECORD_AUDIO,REQUEST_IGNORE_BATTERY_OPTIMIZATIONS android.api = 31 android.minapi = 24 diff --git a/sbapp/main.py b/sbapp/main.py index 456d15b..027ca8d 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -406,6 +406,20 @@ class SidebandApp(MDApp): else: self.open_conversations() + if RNS.vendor.platformutils.is_android(): + if self.sideband.getstate("android.power_restricted", allow_cache=False): + RNS.log("Android power restrictions detected, background connectivity will not work. Asking for permissions.", RNS.LOG_DEBUG) + def pm_job(dt): + Settings = autoclass("android.provider.Settings") + Intent = autoclass("android.content.Intent") + Uri = autoclass("android.net.Uri") + + requestIntent = Intent() + requestIntent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) + requestIntent.setData(Uri.parse("package:io.unsigned.sideband")) + mActivity.startActivity(requestIntent) + Clock.schedule_once(pm_job, 1.5) + if not self.root.ids.screen_manager.has_screen("messages_screen"): self.messages_screen = Builder.load_string(messages_screen_kv) self.messages_screen.app = self