From f1872135681e10a309fd9d2e25d5e428987c7de6 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 8 Apr 2019 15:44:05 -0400 Subject: [PATCH] Run update check service only in background --- app/src/main/java/com/topjohnwu/magisk/SplashActivity.java | 2 ++ .../topjohnwu/magisk/components/UpdateCheckService.java | 7 +++++-- app/src/main/java/com/topjohnwu/magisk/utils/Utils.java | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index e47cf01ee..3f4700338 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -9,6 +9,7 @@ import androidx.appcompat.app.AlertDialog; import com.topjohnwu.magisk.components.BaseActivity; import com.topjohnwu.magisk.database.RepoDatabaseHelper; +import com.topjohnwu.magisk.tasks.CheckUpdates; import com.topjohnwu.magisk.tasks.UpdateRepos; import com.topjohnwu.magisk.uicomponents.Notifications; import com.topjohnwu.magisk.uicomponents.Shortcuts; @@ -63,6 +64,7 @@ public class SplashActivity extends BaseActivity { // Schedule periodic update checks Utils.scheduleUpdateCheck(); + CheckUpdates.check(); // Setup shortcuts Shortcuts.setup(this); diff --git a/app/src/main/java/com/topjohnwu/magisk/components/UpdateCheckService.java b/app/src/main/java/com/topjohnwu/magisk/components/UpdateCheckService.java index 4fe184d17..d76738f13 100644 --- a/app/src/main/java/com/topjohnwu/magisk/components/UpdateCheckService.java +++ b/app/src/main/java/com/topjohnwu/magisk/components/UpdateCheckService.java @@ -3,6 +3,7 @@ package com.topjohnwu.magisk.components; import androidx.annotation.NonNull; import androidx.work.ListenableWorker; +import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.tasks.CheckUpdates; @@ -14,8 +15,10 @@ public class UpdateCheckService extends DelegateWorker { @NonNull @Override public ListenableWorker.Result doWork() { - Shell.getShell(); - CheckUpdates.check(this::onCheckDone); + if (App.self.foreground == null) { + Shell.getShell(); + CheckUpdates.check(this::onCheckDone); + } return ListenableWorker.Result.success(); } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 0705ae4c1..d7f18fd60 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -158,7 +158,6 @@ public class Utils { ExistingPeriodicWorkPolicy.REPLACE, request); } else { WorkManager.getInstance().cancelUniqueWork(Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID); - CheckUpdates.check(); } }