Run update check service only in background

This commit is contained in:
topjohnwu 2019-04-08 15:44:05 -04:00
parent fc0df84edd
commit f187213568
3 changed files with 7 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import androidx.appcompat.app.AlertDialog;
import com.topjohnwu.magisk.components.BaseActivity; import com.topjohnwu.magisk.components.BaseActivity;
import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.database.RepoDatabaseHelper;
import com.topjohnwu.magisk.tasks.CheckUpdates;
import com.topjohnwu.magisk.tasks.UpdateRepos; import com.topjohnwu.magisk.tasks.UpdateRepos;
import com.topjohnwu.magisk.uicomponents.Notifications; import com.topjohnwu.magisk.uicomponents.Notifications;
import com.topjohnwu.magisk.uicomponents.Shortcuts; import com.topjohnwu.magisk.uicomponents.Shortcuts;
@ -63,6 +64,7 @@ public class SplashActivity extends BaseActivity {
// Schedule periodic update checks // Schedule periodic update checks
Utils.scheduleUpdateCheck(); Utils.scheduleUpdateCheck();
CheckUpdates.check();
// Setup shortcuts // Setup shortcuts
Shortcuts.setup(this); Shortcuts.setup(this);

View File

@ -3,6 +3,7 @@ package com.topjohnwu.magisk.components;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.work.ListenableWorker; import androidx.work.ListenableWorker;
import com.topjohnwu.magisk.App;
import com.topjohnwu.magisk.BuildConfig; import com.topjohnwu.magisk.BuildConfig;
import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Config;
import com.topjohnwu.magisk.tasks.CheckUpdates; import com.topjohnwu.magisk.tasks.CheckUpdates;
@ -14,8 +15,10 @@ public class UpdateCheckService extends DelegateWorker {
@NonNull @NonNull
@Override @Override
public ListenableWorker.Result doWork() { public ListenableWorker.Result doWork() {
if (App.self.foreground == null) {
Shell.getShell(); Shell.getShell();
CheckUpdates.check(this::onCheckDone); CheckUpdates.check(this::onCheckDone);
}
return ListenableWorker.Result.success(); return ListenableWorker.Result.success();
} }

View File

@ -158,7 +158,6 @@ public class Utils {
ExistingPeriodicWorkPolicy.REPLACE, request); ExistingPeriodicWorkPolicy.REPLACE, request);
} else { } else {
WorkManager.getInstance().cancelUniqueWork(Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID); WorkManager.getInstance().cancelUniqueWork(Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID);
CheckUpdates.check();
} }
} }