Ask for power optimisation disabling on Android

This commit is contained in:
Mark Qvist 2024-09-21 19:08:11 +02:00
parent cf8f704319
commit f299e0c0ed
2 changed files with 15 additions and 1 deletions

View File

@ -29,7 +29,7 @@ android.presplash_color = #00000000
orientation = portrait orientation = portrait
fullscreen = 0 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.api = 31
android.minapi = 24 android.minapi = 24

View File

@ -406,6 +406,20 @@ class SidebandApp(MDApp):
else: else:
self.open_conversations() 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"): if not self.root.ids.screen_manager.has_screen("messages_screen"):
self.messages_screen = Builder.load_string(messages_screen_kv) self.messages_screen = Builder.load_string(messages_screen_kv)
self.messages_screen.app = self self.messages_screen.app = self