android: reduce battery usage by not using permanent wakelock (#6176)

* android, desktop: core API event timeout setting

* chat_recv_msg_wait with STM timeout

* Revert "chat_recv_msg_wait with STM timeout"

This reverts commit fdfa2964c5.

* do not use permanent wake lock

* wakelock option, get wakelock on network information change

* remove option
This commit is contained in:
Evgeny
2025-08-19 21:02:50 +01:00
committed by GitHub
parent 24e1680a45
commit 83923b9740
9 changed files with 56 additions and 11 deletions
@@ -46,6 +46,7 @@ class SimplexApp: Application(), LifecycleEventObserver {
override fun onCreate() {
super.onCreate()
AppContextProvider.initialize(this)
if (ProcessPhoenix.isPhoenixProcess(this)) {
return
} else {
@@ -144,11 +144,18 @@ class SimplexService: Service() {
return@withLongRunningApi
}
saveServiceState(self, ServiceState.STARTED)
wakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager).run {
newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG).apply {
acquire()
}
}
// Permanent wakelock prevents deep sleep and results in high battery usage.
// Instead, the app relies on being whitelisted for unrestricted battery usage,
// and also takes wakelock on network events and on network information changes, which allows it to reconnect.
// Network events and information changes are delivered even when device is in deep sleep.
// Possibly, we may need to additionally use "alarms" to wake the app periodically,
// but in all pre-release tests the app was reliably delivering messages in deep sleep, even restored dropped connections.
//
// wakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager).run {
// newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG).apply {
// acquire()
// }
// }
} finally {
isCheckingNewMessages = false
}
@@ -167,7 +174,7 @@ class SimplexService: Service() {
}
return null
}
private fun createServiceNotification(title: String, text: String): Notification {
val pendingIntent: PendingIntent = Intent(this, MainActivity::class.java).let { notificationIntent ->
PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE)