From c6b3f06b95bd6db673ff4dbfc959b183de6c7ef8 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 22 Feb 2020 01:28:33 -0800 Subject: [PATCH] Cleanup stuffs --- app/build.gradle | 2 +- app/proguard-kotlin.pro | 20 ------------- app/proguard-rules.pro | 9 ++++++ app/src/main/java/a/g.java | 15 ---------- app/src/main/java/a/stubs.kt | 29 ------------------- .../java/com/topjohnwu/magisk/core/Hacks.kt | 1 - .../magisk/core/UpdateCheckService.kt | 14 +++++---- .../com/topjohnwu/magisk/core/utils/Utils.kt | 27 +++++++++-------- 8 files changed, 33 insertions(+), 84 deletions(-) delete mode 100644 app/proguard-kotlin.pro delete mode 100644 app/src/main/java/a/g.java diff --git a/app/build.gradle b/app/build.gradle index c1c05dfea..63457d763 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), - 'proguard-rules.pro', 'proguard-kotlin.pro' + 'proguard-rules.pro' } } diff --git a/app/proguard-kotlin.pro b/app/proguard-kotlin.pro deleted file mode 100644 index 00782e548..000000000 --- a/app/proguard-kotlin.pro +++ /dev/null @@ -1,20 +0,0 @@ -## So every class is case insensitive to avoid some bizare problems --dontusemixedcaseclassnames - -## If reflection issues come up uncomment this, that should temporarily fix it -#-keep class kotlin.** { *; } -#-keep class kotlin.Metadata { *; } -#-keepclassmembers class kotlin.Metadata { -# public ; -#} - -## Never warn about Kotlin, it should work as-is --dontwarn kotlin.** - -## Removes runtime null checks - doesn't really matter if it crashes on kotlin or java NPE --assumenosideeffects class kotlin.jvm.internal.Intrinsics { - static void checkParameterIsNotNull(java.lang.Object, java.lang.String); -} - -## Useless option for dex --dontpreverify \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 2704c812d..3419b8058 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -16,6 +16,15 @@ # public *; #} +# Kotlin +-assumenosideeffects class kotlin.jvm.internal.Intrinsics { + public static void checkExpressionValueIsNotNull(...); + public static void checkNotNullExpressionValue(...); + public static void checkReturnedValueIsNotNull(...); + public static void checkFieldIsNotNull(...); + public static void checkParameterIsNotNull(...); +} + # Stubs -keep class a.* { *; } diff --git a/app/src/main/java/a/g.java b/app/src/main/java/a/g.java deleted file mode 100644 index e8b94881b..000000000 --- a/app/src/main/java/a/g.java +++ /dev/null @@ -1,15 +0,0 @@ -package a; - -import android.content.Context; - -import androidx.annotation.NonNull; -import androidx.work.WorkerParameters; - -import com.topjohnwu.magisk.core.UpdateCheckService; - -public class g extends w { - /* Stub */ - public g(@NonNull Context context, @NonNull WorkerParameters workerParams) { - super(context, workerParams); - } -} diff --git a/app/src/main/java/a/stubs.kt b/app/src/main/java/a/stubs.kt index 91dffbeb4..0dfc800e3 100644 --- a/app/src/main/java/a/stubs.kt +++ b/app/src/main/java/a/stubs.kt @@ -1,17 +1,12 @@ package a -import android.content.Context -import androidx.work.Worker -import androidx.work.WorkerParameters import com.topjohnwu.magisk.core.App import com.topjohnwu.magisk.core.GeneralReceiver import com.topjohnwu.magisk.core.SplashActivity -import com.topjohnwu.magisk.core.base.BaseWorkerWrapper import com.topjohnwu.magisk.core.download.DownloadService import com.topjohnwu.magisk.legacy.flash.FlashActivity import com.topjohnwu.magisk.legacy.surequest.SuRequestActivity import com.topjohnwu.magisk.ui.MainActivity -import java.lang.reflect.ParameterizedType class b : MainActivity() @@ -29,27 +24,3 @@ class h : GeneralReceiver() class j : DownloadService() class m : SuRequestActivity() - -/** - * Wrapper class to workaround Proguard rule : - * -keep class * extends Worker - * */ -abstract class w( - context: Context, - workerParams: WorkerParameters -) : Worker(context, workerParams) { - - private var base: T? = null - - override fun doWork() = base?.doWork() ?: Result.failure() - - override fun onStopped() = base?.onStopped() ?: Unit - - init { - try { - base = ((javaClass.genericSuperclass as ParameterizedType) - .actualTypeArguments[0] as Class).newInstance() - base?.attachWorker(this) - } catch (e : java.lang.Exception) {} - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt index ac0d3925e..6316b1883 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt @@ -147,7 +147,6 @@ object ClassMap { 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, DownloadService::class.java to a.j::class.java, SuRequestActivity::class.java to a.m::class.java, 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 162918caa..677a9b3c8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/UpdateCheckService.kt @@ -1,18 +1,20 @@ package com.topjohnwu.magisk.core -import androidx.work.ListenableWorker +import android.content.Context +import androidx.work.Worker +import androidx.work.WorkerParameters import com.topjohnwu.magisk.BuildConfig -import com.topjohnwu.magisk.core.base.BaseWorkerWrapper import com.topjohnwu.magisk.core.view.Notifications import com.topjohnwu.magisk.data.repository.MagiskRepository import com.topjohnwu.magisk.extensions.inject import com.topjohnwu.superuser.Shell -class UpdateCheckService : BaseWorkerWrapper() { +class UpdateCheckService(context: Context, workerParams: WorkerParameters) + : Worker(context, workerParams) { private val magiskRepo: MagiskRepository by inject() - override fun doWork(): ListenableWorker.Result { + override fun doWork(): Result { // Make sure shell initializer was ran Shell.getShell() return runCatching { @@ -21,9 +23,9 @@ class UpdateCheckService : BaseWorkerWrapper() { Notifications.managerUpdate(applicationContext) else if (Info.env.magiskVersionCode < Info.remote.magisk.versionCode) Notifications.magiskUpdate(applicationContext) - ListenableWorker.Result.success() + Result.success() }.getOrElse { - ListenableWorker.Result.failure() + Result.failure() } } } 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 068e6d503..049c97d72 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 @@ -7,9 +7,11 @@ import android.net.Uri import android.os.Environment import android.widget.Toast import androidx.work.* -import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.core.* +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.extensions.get import com.topjohnwu.superuser.internal.UiThreadHandler import java.io.File @@ -38,19 +40,20 @@ object Utils { fun scheduleUpdateCheck(context: Context) { if (Config.checkUpdate) { val constraints = Constraints.Builder() - .setRequiredNetworkType(NetworkType.CONNECTED) - .setRequiresDeviceIdle(true) - .build() + .setRequiredNetworkType(NetworkType.CONNECTED) + .setRequiresDeviceIdle(true) + .build() val request = PeriodicWorkRequest - .Builder(ClassMap[UpdateCheckService::class.java] as Class, 12, TimeUnit.HOURS) - .setConstraints(constraints) - .build() + .Builder(UpdateCheckService::class.java, 12, TimeUnit.HOURS) + .setConstraints(constraints) + .build() WorkManager.getInstance(context).enqueueUniquePeriodicWork( - Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID, - ExistingPeriodicWorkPolicy.REPLACE, request) + Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID, + ExistingPeriodicWorkPolicy.REPLACE, request + ) } else { WorkManager.getInstance(context) - .cancelUniqueWork(Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID) + .cancelUniqueWork(Const.ID.CHECK_MAGISK_UPDATE_WORKER_ID) } } @@ -67,7 +70,7 @@ object Utils { } } - fun ensureDownloadPath(path : String) = + fun ensureDownloadPath(path: String) = File(Environment.getExternalStorageDirectory(), path).run { if ((exists() && isDirectory) || mkdirs()) this else null }