summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-11-24 14:13:08 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-11-24 16:43:09 +0000
commit0aa4cbeb10fa3024d6b13a1960730ba261b37bad (patch)
treec70e9e85cecf6b90a9b0be90c695cd16ac8c475b /android/src
parent6b9120724681885968b5161c7e782776ee0fda0d (diff)
downloadmullvadvpn-0aa4cbeb10fa3024d6b13a1960730ba261b37bad.tar.xz
mullvadvpn-0aa4cbeb10fa3024d6b13a1960730ba261b37bad.zip
Call `startForeground` as soon as possible
Synchronization is not needed because it will happen on the UI thread.
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt24
1 files changed, 8 insertions, 16 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
index 2daf1477ba..d8786d1196 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
@@ -26,7 +26,6 @@ class ForegroundNotificationManager(
private sealed class UpdaterMessage {
class UpdateNotification : UpdaterMessage()
class UpdateAction : UpdaterMessage()
- class AcknowledgeStartForegroundService : UpdaterMessage()
class NewTunnelState(val newState: TunnelState) : UpdaterMessage()
}
@@ -105,7 +104,14 @@ class ForegroundNotificationManager(
}
fun acknowledgeStartForegroundService() {
- updater.sendBlocking(UpdaterMessage.AcknowledgeStartForegroundService())
+ // When sending start commands to the service, it is necessary to request the service to be
+ // on the foreground. With such request, when the service is started it must be placed on
+ // the foreground with a call to startForeground before a timeout expires, otherwise Android
+ // kills the app.
+ showOnForeground()
+
+ // Restore the notification to its correct state.
+ updater.sendBlocking(UpdaterMessage.UpdateNotification())
}
private fun runUpdater() = GlobalScope.actor<UpdaterMessage>(
@@ -116,9 +122,6 @@ class ForegroundNotificationManager(
when (message) {
is UpdaterMessage.UpdateNotification -> updateNotification()
is UpdaterMessage.UpdateAction -> updateNotificationAction()
- is UpdaterMessage.AcknowledgeStartForegroundService -> {
- doAcknowledgeStartForegroundService()
- }
is UpdaterMessage.NewTunnelState -> {
tunnelStateNotification.tunnelState = message.newState
updateNotification()
@@ -129,17 +132,6 @@ class ForegroundNotificationManager(
tunnelStateNotification.visible = false
}
- private fun doAcknowledgeStartForegroundService() {
- // When sending start commands to the service, it is necessary to request the service to be
- // on the foreground. With such request, when the service is started it must be placed on
- // the foreground with a call to startForeground before a timeout expires, otherwise Android
- // kills the app.
- showOnForeground()
-
- // Restore the notification to its correct state.
- updateNotification()
- }
-
private fun showOnForeground() {
service.startForeground(
TunnelStateNotification.NOTIFICATION_ID,