diff --git a/app/src/main/java/com/topjohnwu/magisk/ClassMap.java b/app/src/main/java/com/topjohnwu/magisk/ClassMap.java deleted file mode 100644 index 4013d5918..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/ClassMap.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.topjohnwu.magisk; - -import com.topjohnwu.magisk.model.download.DownloadModuleService; -import com.topjohnwu.magisk.model.receiver.GeneralReceiver; -import com.topjohnwu.magisk.model.update.UpdateCheckService; -import com.topjohnwu.magisk.ui.MainActivity; -import com.topjohnwu.magisk.ui.SplashActivity; -import com.topjohnwu.magisk.ui.flash.FlashActivity; -import com.topjohnwu.magisk.ui.surequest.SuRequestActivity; - -import java.util.HashMap; -import java.util.Map; - -public class ClassMap { - private static Map classMap = new HashMap<>(); - - static { - classMap.put(App.class, a.e.class); - classMap.put(MainActivity.class, a.b.class); - classMap.put(SplashActivity.class, a.c.class); - classMap.put(FlashActivity.class, a.f.class); - classMap.put(UpdateCheckService.class, a.g.class); - classMap.put(GeneralReceiver.class, a.h.class); - classMap.put(DownloadModuleService.class, a.j.class); - classMap.put(SuRequestActivity.class, a.m.class); - } - - public static Class get(Class c) { - return classMap.get(c); - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/ClassMap.kt b/app/src/main/java/com/topjohnwu/magisk/ClassMap.kt new file mode 100644 index 000000000..92ce3a884 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/ClassMap.kt @@ -0,0 +1,27 @@ +package com.topjohnwu.magisk + +import com.topjohnwu.magisk.model.download.DownloadModuleService +import com.topjohnwu.magisk.model.receiver.GeneralReceiver +import com.topjohnwu.magisk.model.update.UpdateCheckService +import com.topjohnwu.magisk.ui.MainActivity +import com.topjohnwu.magisk.ui.SplashActivity +import com.topjohnwu.magisk.ui.flash.FlashActivity +import com.topjohnwu.magisk.ui.surequest.SuRequestActivity + +object ClassMap { + private val map = mapOf( + App::class.java to a.e::class.java, + MainActivity::class.java to a.b::class.java, + SplashActivity::class.java to a.c::class.java, + FlashActivity::class.java to a.f::class.java, + UpdateCheckService::class.java to a.g::class.java, + GeneralReceiver::class.java to a.h::class.java, + DownloadModuleService::class.java to a.j::class.java, + SuRequestActivity::class.java to a.m::class.java + ) + + @JvmStatic + operator fun get(c: Class<*>): Class<*>? { + return map.getOrElse(c) { null } //as? Class + } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt index 725736b50..e5b030905 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt @@ -41,7 +41,7 @@ open class GeneralReceiver : BroadcastReceiver() { } when (action) { SuRequestActivity.REQUEST -> { - val i = Intent(context, ClassMap.get(SuRequestActivity::class.java)) + val i = Intent(context, ClassMap[SuRequestActivity::class.java]) .setAction(action) .putExtra("socket", intent.getStringExtra("socket")) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt index 57c86b028..1aa718252 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -48,7 +48,7 @@ open class MainActivity : MagiskActivity() { override fun onCreate(savedInstanceState: Bundle?) { if (!SplashActivity.DONE) { - startActivity(Intent(this, ClassMap.get(SplashActivity::class.java))) + startActivity(Intent(this, ClassMap[SplashActivity::class.java])) finish() } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt index 24df89c3d..f75fb2483 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt @@ -66,7 +66,7 @@ open class SplashActivity : AppCompatActivity() { //UpdateRepos().exec() } - val intent = Intent(this, ClassMap.get(MainActivity::class.java)) + val intent = Intent(this, ClassMap[MainActivity::class.java]) intent.putExtra(Const.Key.OPEN_SECTION, getIntent().getStringExtra(Const.Key.OPEN_SECTION)) DONE = true startActivity(intent) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt index 9aff75076..08a14441f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt @@ -28,7 +28,7 @@ class ModulesFragment : MagiskFragment( override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (requestCode == Const.ID.FETCH_ZIP && resultCode == Activity.RESULT_OK && data != null) { // Get the URI of the selected file - val intent = Intent(activity, ClassMap.get(FlashActivity::class.java)) + val intent = Intent(activity, ClassMap[FlashActivity::class.java]) intent.setData(data.data).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP) startActivity(intent) } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt index 4cc750e68..2ed02d623 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt @@ -82,7 +82,7 @@ class ReposFragment : MagiskFragment(), fun download(install: Boolean) { context.runWithExternalRW { - val intent = Intent(activity, ClassMap.get(DownloadModuleService::class.java)) + val intent = Intent(activity, ClassMap[DownloadModuleService::class.java]) .putExtra("repo", item).putExtra("install", install) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { context.startForegroundService(intent) //hmm, service starts itself in foreground, this seems unnecessary 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 af954af5f..cc7d9f068 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit; import androidx.annotation.WorkerThread; import androidx.work.Constraints; import androidx.work.ExistingPeriodicWorkPolicy; +import androidx.work.ListenableWorker; import androidx.work.NetworkType; import androidx.work.PeriodicWorkRequest; import androidx.work.WorkManager; @@ -110,13 +111,15 @@ public class Utils { return BuildConfig.VERSION_NAME.contains("-"); } + @SuppressWarnings("unchecked") public static void scheduleUpdateCheck() { if (Config.get(Config.Key.CHECK_UPDATES)) { Constraints constraints = new Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) .build(); + Class service = (Class) ClassMap.get(UpdateCheckService.class); PeriodicWorkRequest request = new PeriodicWorkRequest - .Builder(ClassMap.get(UpdateCheckService.class), 12, TimeUnit.HOURS) + .Builder(service, 12, TimeUnit.HOURS) .setConstraints(constraints) .build(); WorkManager.getInstance().enqueueUniquePeriodicWork(