Skip to content

Commit 254e616

Browse files
committed
ui: use applicationScope helper when possible
Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 6753862 commit 254e616

File tree

1 file changed

+8
-7
lines changed
  • ui/src/main/java/com/wireguard/android/updater

1 file changed

+8
-7
lines changed

ui/src/main/java/com/wireguard/android/updater/Updater.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.wireguard.android.Application
2121
import com.wireguard.android.BuildConfig
2222
import com.wireguard.android.activity.MainActivity
2323
import com.wireguard.android.util.UserKnobs
24+
import com.wireguard.android.util.applicationScope
2425
import kotlinx.coroutines.CoroutineScope
2526
import kotlinx.coroutines.Dispatchers
2627
import kotlinx.coroutines.Job
@@ -76,7 +77,7 @@ object Updater {
7677
object Complete : Progress()
7778
class Available(val version: String) : Progress() {
7879
fun update() {
79-
Application.getCoroutineScope().launch {
80+
applicationScope.launch {
8081
UserKnobs.setUpdaterNewerVersionConsented(version)
8182
}
8283
}
@@ -100,7 +101,7 @@ object Updater {
100101
}
101102

102103
fun markAsDone() {
103-
Application.getCoroutineScope().launch {
104+
applicationScope.launch {
104105
if (installerActive())
105106
return@launch
106107
delay(7.seconds)
@@ -333,13 +334,13 @@ object Updater {
333334
PackageInstaller.STATUS_PENDING_USER_ACTION -> {
334335
val id = intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, 0)
335336
val userIntervention = IntentCompat.getParcelableExtra(intent, Intent.EXTRA_INTENT, Intent::class.java)!!
336-
Application.getCoroutineScope().launch {
337+
applicationScope.launch {
337338
emitProgress(Progress.NeedsUserIntervention(userIntervention, id))
338339
}
339340
}
340341

341342
PackageInstaller.STATUS_SUCCESS -> {
342-
Application.getCoroutineScope().launch {
343+
applicationScope.launch {
343344
emitProgress(Progress.Complete)
344345
}
345346
context.applicationContext.unregisterReceiver(this)
@@ -352,7 +353,7 @@ object Updater {
352353
} catch (_: SecurityException) {
353354
}
354355
val message = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE) ?: "Installation error $status"
355-
Application.getCoroutineScope().launch {
356+
applicationScope.launch {
356357
val e = Exception(message)
357358
Log.e(TAG, "Update failure", e)
358359
emitProgress(Progress.Failure(e))
@@ -414,14 +415,14 @@ object Updater {
414415
UserKnobs.updaterNewerVersionConsented.firstOrNull()?.let { Version(it) > CURRENT_VERSION } != true
415416
)
416417
emitProgress(Progress.Available(ver))
417-
}.launchIn(Application.getCoroutineScope())
418+
}.launchIn(applicationScope)
418419

419420
UserKnobs.updaterNewerVersionConsented.onEach { ver ->
420421
if (ver != null && Version(ver) > CURRENT_VERSION)
421422
updaterScope.launch {
422423
downloadAndUpdateWrapErrors()
423424
}
424-
}.launchIn(Application.getCoroutineScope())
425+
}.launchIn(applicationScope)
425426
}
426427

427428
class AppUpdatedReceiver : BroadcastReceiver() {

0 commit comments

Comments
 (0)