From 5b28a713e0b10db1ceae0df7b5303f99e70d8291 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 23 Jul 2020 22:43:25 -0700 Subject: [PATCH] Move functions around --- app/build.gradle.kts | 6 ++--- app/signing/build.gradle.kts | 4 ++-- .../topjohnwu/magisk/core/SplashActivity.kt | 3 +-- .../magisk/core/UpdateCheckService.kt | 24 +++++++++++++++++-- .../com/topjohnwu/magisk/core/utils/Utils.kt | 23 ------------------ .../magisk/ui/settings/SettingsItems.kt | 3 ++- 6 files changed, 30 insertions(+), 33 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cc9294829..887cecd9b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -140,10 +140,10 @@ dependencies { implementation("androidx.preference:preference:1.1.1") implementation("androidx.recyclerview:recyclerview:1.1.0") implementation("androidx.fragment:fragment-ktx:1.2.5") - implementation("androidx.work:work-runtime-ktx:2.3.4") + implementation("androidx.work:work-runtime-ktx:2.4.0") implementation("androidx.transition:transition:1.3.1") implementation("androidx.multidex:multidex:2.0.1") - implementation("androidx.core:core-ktx:1.3.0") + implementation("androidx.core:core-ktx:1.3.1") implementation("androidx.localbroadcastmanager:localbroadcastmanager:1.0.0") - implementation("com.google.android.material:material:1.2.0-beta01") + implementation("com.google.android.material:material:1.2.0-rc01") } diff --git a/app/signing/build.gradle.kts b/app/signing/build.gradle.kts index 717dff915..7f8904e90 100644 --- a/app/signing/build.gradle.kts +++ b/app/signing/build.gradle.kts @@ -30,6 +30,6 @@ repositories { dependencies { implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) - api("org.bouncycastle:bcprov-jdk15on:1.65.01") - api("org.bouncycastle:bcpkix-jdk15on:1.65") + api("org.bouncycastle:bcprov-jdk15on:1.66") + api("org.bouncycastle:bcpkix-jdk15on:1.66") } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt b/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt index 2d8a8033e..12a74024e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt @@ -5,7 +5,6 @@ import android.content.Context import android.os.Bundle import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.core.utils.Utils import com.topjohnwu.magisk.core.view.Notifications import com.topjohnwu.magisk.core.view.Shortcuts import com.topjohnwu.magisk.data.network.GithubRawServices @@ -52,7 +51,7 @@ open class SplashActivity : Activity() { Config.initialize() handleRepackage() Notifications.setup(this) - Utils.scheduleUpdateCheck(this) + UpdateCheckService.schedule(this) Shortcuts.setup(this) // Pre-fetch network stuffs diff --git a/app/src/main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt b/app/src/main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt index da2cc5543..4ff01280d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt @@ -1,8 +1,7 @@ package com.topjohnwu.magisk.core import android.content.Context -import androidx.work.CoroutineWorker -import androidx.work.WorkerParameters +import androidx.work.* import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.core.view.Notifications import com.topjohnwu.magisk.data.repository.MagiskRepository @@ -11,6 +10,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.koin.core.KoinComponent import org.koin.core.inject +import java.util.concurrent.TimeUnit class UpdateCheckService(context: Context, workerParams: WorkerParameters) : CoroutineWorker(context, workerParams), KoinComponent { @@ -30,4 +30,24 @@ class UpdateCheckService(context: Context, workerParams: WorkerParameters) Result.success() } ?: Result.failure() } + + companion object { + fun schedule(context: Context) { + if (Config.checkUpdate) { + val constraints = Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) + .setRequiresDeviceIdle(true) + .build() + val request = PeriodicWorkRequestBuilder(12, TimeUnit.HOURS) + .setConstraints(constraints) + .build() + WorkManager.getInstance(context).enqueueUniquePeriodicWork( + Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID, + ExistingPeriodicWorkPolicy.REPLACE, request) + } else { + WorkManager.getInstance(context) + .cancelUniqueWork(Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID) + } + } + } } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/Utils.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/Utils.kt index 6be087477..204eb0668 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/Utils.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/Utils.kt @@ -6,16 +6,13 @@ import android.content.res.Resources import android.net.Uri import android.os.Environment import android.widget.Toast -import androidx.work.* import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info -import com.topjohnwu.magisk.core.UpdateCheckService import com.topjohnwu.magisk.ktx.get import com.topjohnwu.superuser.internal.UiThreadHandler import java.io.File -import java.util.concurrent.TimeUnit object Utils { @@ -37,26 +34,6 @@ object Utils { || Config.suMultiuserMode != Config.Value.MULTIUSER_MODE_OWNER_MANAGED) } - fun scheduleUpdateCheck(context: Context) { - if (Config.checkUpdate) { - val constraints = Constraints.Builder() - .setRequiredNetworkType(NetworkType.CONNECTED) - .setRequiresDeviceIdle(true) - .build() - val request = PeriodicWorkRequest - .Builder(UpdateCheckService::class.java, 12, TimeUnit.HOURS) - .setConstraints(constraints) - .build() - WorkManager.getInstance(context).enqueueUniquePeriodicWork( - Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID, - ExistingPeriodicWorkPolicy.REPLACE, request - ) - } else { - WorkManager.getInstance(context) - .cancelUniqueWork(Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID) - } - } - fun openLink(context: Context, link: Uri) { val intent = Intent(Intent.ACTION_VIEW, link) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt index fcd1824f9..be5a4736b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt @@ -11,6 +11,7 @@ import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info +import com.topjohnwu.magisk.core.UpdateCheckService import com.topjohnwu.magisk.core.utils.BiometricHelper import com.topjohnwu.magisk.core.utils.Utils import com.topjohnwu.magisk.core.utils.availableLocales @@ -154,7 +155,7 @@ object UpdateChecker : SettingsItem.Toggle() { override var value = Config.checkUpdate set(value) = setV(value, field, { field = it }) { Config.checkUpdate = it - Utils.scheduleUpdateCheck(get()) + UpdateCheckService.schedule(get()) } }