mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-29 05:29:08 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user