From 48395ba860686a79bf9c1eb9060867c4fc6404cc Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 8 Aug 2019 00:29:27 -0700 Subject: [PATCH] Remove unused files --- app/proguard-rules.pro | 3 - .../topjohnwu/magisk/di/ApplicationModule.kt | 4 ++ .../com/topjohnwu/magisk/di/MiscModule.kt | 10 --- .../java/com/topjohnwu/magisk/di/Modules.kt | 3 +- .../com/topjohnwu/magisk/di/NamedInjection.kt | 6 -- .../topjohnwu/magisk/model/entity/Policy.java | 61 ------------------- .../model/entity/recycler/PolicyRvItem.kt | 5 +- .../magisk/model/events/ViewEvents.kt | 2 - .../topjohnwu/magisk/tasks/InstallerHelper.kt | 18 ------ .../topjohnwu/magisk/ui/home/HomeViewModel.kt | 11 ++++ .../topjohnwu/magisk/ui/home/MagiskItem.kt | 6 -- .../topjohnwu/magisk/ui/home/MagiskState.kt | 6 -- .../magisk/ui/home/SafetyNetState.kt | 5 -- .../magisk/ui/superuser/SuperuserViewModel.kt | 3 +- .../magisk/ui/surequest/SuRequestActivity.kt | 4 +- .../magisk/ui/surequest/SuRequestViewModel.kt | 15 +++-- .../com/topjohnwu/magisk/utils/Logger.java | 26 -------- .../com/topjohnwu/magisk/utils/RootUtils.kt | 1 - .../com/topjohnwu/magisk/utils/SuLogger.kt | 4 +- .../magisk/utils/ValueSortedMap.java | 43 ------------- .../magisk/utils/feature/Annotations.kt | 16 ----- .../topjohnwu/magisk/view/SnackbarMaker.kt | 46 -------------- 22 files changed, 29 insertions(+), 269 deletions(-) delete mode 100644 app/src/main/java/com/topjohnwu/magisk/di/MiscModule.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/di/NamedInjection.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/model/entity/Policy.java delete mode 100644 app/src/main/java/com/topjohnwu/magisk/tasks/InstallerHelper.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskItem.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskState.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/ui/home/SafetyNetState.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/utils/Logger.java delete mode 100644 app/src/main/java/com/topjohnwu/magisk/utils/ValueSortedMap.java delete mode 100644 app/src/main/java/com/topjohnwu/magisk/utils/feature/Annotations.kt delete mode 100644 app/src/main/java/com/topjohnwu/magisk/view/SnackbarMaker.kt diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index e0aea4215..db9f789a9 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -36,9 +36,6 @@ # Strip logging -assumenosideeffects class timber.log.Timber.Tree { *; } --assumenosideeffects class com.topjohnwu.magisk.utils.Logger { - public *** debug(...); -} # Excessive obfuscation -repackageclasses 'a' diff --git a/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt index 7a2788a7e..e05af66fa 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt @@ -8,8 +8,12 @@ import android.os.Bundle import androidx.preference.PreferenceManager import com.skoumal.teanity.rxbus.RxBus import com.topjohnwu.magisk.App +import org.koin.core.qualifier.named import org.koin.dsl.module +val SUTimeout = named("su_timeout") +val Protected = named("protected") + val applicationModule = module { single { RxBus() } factory { get().resources } diff --git a/app/src/main/java/com/topjohnwu/magisk/di/MiscModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/MiscModule.kt deleted file mode 100644 index 037a9edd6..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/di/MiscModule.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.topjohnwu.magisk.di - -import org.koin.dsl.module - - -val miscModule = module { - - // define miscs here - -} diff --git a/app/src/main/java/com/topjohnwu/magisk/di/Modules.kt b/app/src/main/java/com/topjohnwu/magisk/di/Modules.kt index 850e09c88..8fd05268e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/Modules.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/Modules.kt @@ -5,6 +5,5 @@ val koinModules = listOf( networkingModule, databaseModule, repositoryModule, - viewModelModules, - miscModule + viewModelModules ) diff --git a/app/src/main/java/com/topjohnwu/magisk/di/NamedInjection.kt b/app/src/main/java/com/topjohnwu/magisk/di/NamedInjection.kt deleted file mode 100644 index 7840947af..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/di/NamedInjection.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.topjohnwu.magisk.di - -import org.koin.core.qualifier.named - -val SUTimeout = named("su_timeout") -val Protected = named("protected") \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/Policy.java b/app/src/main/java/com/topjohnwu/magisk/model/entity/Policy.java deleted file mode 100644 index cb7797e40..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/Policy.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.topjohnwu.magisk.model.entity; - -import android.content.ContentValues; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; - -import androidx.annotation.NonNull; - -import com.topjohnwu.magisk.utils.Utils; - - -public class Policy implements Comparable{ - public static final int INTERACTIVE = 0; - public static final int DENY = 1; - public static final int ALLOW = 2; - - public int uid, policy = INTERACTIVE; - public long until; - public boolean logging = true, notification = true; - public String packageName, appName; - public ApplicationInfo info; - - public Policy(int uid, PackageManager pm) throws PackageManager.NameNotFoundException { - String[] pkgs = pm.getPackagesForUid(uid); - if (pkgs == null || pkgs.length == 0) - throw new PackageManager.NameNotFoundException(); - this.uid = uid; - packageName = pkgs[0]; - info = pm.getApplicationInfo(packageName, 0); - appName = Utils.INSTANCE.getAppLabel(info, pm); - } - - public Policy(ContentValues values, PackageManager pm) throws PackageManager.NameNotFoundException { - uid = values.getAsInteger("uid"); - packageName = values.getAsString("package_name"); - policy = values.getAsInteger("policy"); - until = values.getAsInteger("until"); - logging = values.getAsInteger("logging") != 0; - notification = values.getAsInteger("notification") != 0; - info = pm.getApplicationInfo(packageName, 0); - if (info.uid != uid) - throw new PackageManager.NameNotFoundException(); - appName = info.loadLabel(pm).toString(); - } - - public ContentValues getContentValues() { - ContentValues values = new ContentValues(); - values.put("uid", uid); - values.put("package_name", packageName); - values.put("policy", policy); - values.put("until", until); - values.put("logging", logging ? 1 : 0); - values.put("notification", notification ? 1 : 0); - return values; - } - - @Override - public int compareTo(@NonNull Policy policy) { - return appName.toLowerCase().compareTo(policy.appName.toLowerCase()); - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt index cbe2b13d7..e72437fe6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt @@ -9,7 +9,6 @@ import com.topjohnwu.magisk.R import com.topjohnwu.magisk.extensions.inject import com.topjohnwu.magisk.extensions.toggle import com.topjohnwu.magisk.model.entity.MagiskPolicy -import com.topjohnwu.magisk.model.entity.Policy import com.topjohnwu.magisk.model.events.PolicyEnableEvent import com.topjohnwu.magisk.model.events.PolicyUpdateEvent @@ -18,7 +17,7 @@ class PolicyRvItem(val item: MagiskPolicy, val icon: Drawable) : ComparableRvIte override val layoutRes: Int = R.layout.item_policy val isExpanded = KObservableField(false) - val isEnabled = KObservableField(item.policy == Policy.ALLOW) + val isEnabled = KObservableField(item.policy == MagiskPolicy.ALLOW) val shouldNotify = KObservableField(item.notification) val shouldLog = KObservableField(item.logging) @@ -28,7 +27,7 @@ class PolicyRvItem(val item: MagiskPolicy, val icon: Drawable) : ComparableRvIte private val currentStateItem get() = item.copy( - policy = if (isEnabled.value) Policy.ALLOW else Policy.DENY, + policy = if (isEnabled.value) MagiskPolicy.ALLOW else MagiskPolicy.DENY, notification = shouldNotify.value, logging = shouldLog.value ) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt b/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt index bec22b81f..206e765d1 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt @@ -2,7 +2,6 @@ package com.topjohnwu.magisk.model.events import android.app.Activity import com.skoumal.teanity.viewevents.ViewEvent -import com.topjohnwu.magisk.model.entity.Policy import com.topjohnwu.magisk.model.entity.module.Repo import io.reactivex.subjects.PublishSubject @@ -36,5 +35,4 @@ class PermissionEvent( class BackPressEvent : ViewEvent() -class SuDialogEvent(val policy: Policy) : ViewEvent() class DieEvent : ViewEvent() \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/tasks/InstallerHelper.kt b/app/src/main/java/com/topjohnwu/magisk/tasks/InstallerHelper.kt deleted file mode 100644 index ca92a4fe8..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/tasks/InstallerHelper.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.topjohnwu.magisk.tasks - -import android.content.Context -import android.net.Uri -import com.topjohnwu.magisk.extensions.get -import com.topjohnwu.magisk.extensions.readUri -import java.io.File - -object InstallerHelper { - @JvmStatic - fun copyFileTo(uri: Uri, zip: File) { - zip.deleteRecursively() - - get().readUri(uri).use { input -> - zip.outputStream().use { out -> input.copyTo(out) } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index 9871ee3bc..285f60874 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -15,6 +15,17 @@ import com.topjohnwu.magisk.ui.base.MagiskViewModel import com.topjohnwu.magisk.utils.ISafetyNetHelper import com.topjohnwu.superuser.Shell +enum class SafetyNetState { + LOADING, PASS, FAILED, IDLE +} + +enum class MagiskState { + NO_ROOT, NOT_INSTALLED, UP_TO_DATE, OBSOLETE, LOADING +} + +enum class MagiskItem { + MANAGER, MAGISK +} class HomeViewModel( private val magiskRepo: MagiskRepository diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskItem.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskItem.kt deleted file mode 100644 index 8f26b0c1d..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskItem.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.topjohnwu.magisk.ui.home - - -enum class MagiskItem { - MANAGER, MAGISK -} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskState.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskState.kt deleted file mode 100644 index 8d880001d..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/MagiskState.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.topjohnwu.magisk.ui.home - - -enum class MagiskState { - NO_ROOT, NOT_INSTALLED, UP_TO_DATE, OBSOLETE, LOADING -} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/SafetyNetState.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/SafetyNetState.kt deleted file mode 100644 index fc0df345d..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/SafetyNetState.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.topjohnwu.magisk.ui.home - -enum class SafetyNetState { - LOADING, PASS, FAILED, IDLE -} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt index 48073d942..954696716 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt @@ -13,7 +13,6 @@ import com.topjohnwu.magisk.R import com.topjohnwu.magisk.data.database.PolicyDao import com.topjohnwu.magisk.extensions.toggle import com.topjohnwu.magisk.model.entity.MagiskPolicy -import com.topjohnwu.magisk.model.entity.Policy import com.topjohnwu.magisk.model.entity.recycler.PolicyRvItem import com.topjohnwu.magisk.model.events.PolicyEnableEvent import com.topjohnwu.magisk.model.events.PolicyUpdateEvent @@ -118,7 +117,7 @@ class SuperuserViewModel( val app = item.item.copy(policy = if (enable) MagiskPolicy.ALLOW else MagiskPolicy.DENY) updatePolicy(app) - .map { it.policy == Policy.ALLOW } + .map { it.policy == MagiskPolicy.ALLOW } .subscribeK { val textId = if (it) R.string.su_snack_grant else R.string.su_snack_deny val text = resources.getString(textId).format(item.item.appName) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.kt index 44beaab41..dc4f54b09 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.kt @@ -8,7 +8,7 @@ import android.view.Window import com.skoumal.teanity.viewevents.ViewEvent import com.topjohnwu.magisk.R import com.topjohnwu.magisk.databinding.ActivityRequestBinding -import com.topjohnwu.magisk.model.entity.Policy +import com.topjohnwu.magisk.model.entity.MagiskPolicy import com.topjohnwu.magisk.model.events.DieEvent import com.topjohnwu.magisk.model.receiver.GeneralReceiver import com.topjohnwu.magisk.ui.base.MagiskActivity @@ -21,7 +21,7 @@ open class SuRequestActivity : MagiskActivity { - handler?.handleAction(Policy.DENY, 0) + handler?.handleAction(MagiskPolicy.DENY, 0) return true } Config.Value.SU_AUTO_ALLOW -> { - handler?.handleAction(Policy.ALLOW, 0) + handler?.handleAction(MagiskPolicy.ALLOW, 0) return true } } @@ -199,7 +198,7 @@ class SuRequestViewModel( override fun onFinish() { denyText.value = resources.getString(R.string.deny) - handler?.handleAction(Policy.DENY) + handler?.handleAction(MagiskPolicy.DENY) } } timer?.start() @@ -229,7 +228,7 @@ class SuRequestViewModel( } override fun onAuthenticationSucceeded(result: FingerprintManager.AuthenticationResult) { - handler?.handleAction(Policy.ALLOW) + handler?.handleAction(MagiskPolicy.ALLOW) } override fun onAuthenticationFailed() { diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java b/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java deleted file mode 100644 index 8bd790d36..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.topjohnwu.magisk.utils; - -import android.util.Log; - -import com.topjohnwu.magisk.BuildConfig; -import com.topjohnwu.magisk.Const; - -public class Logger { - - public static void debug(String line) { - if (BuildConfig.DEBUG) - Log.d(Const.DEBUG_TAG, "DEBUG: " + line); - } - - public static void debug(String fmt, Object... args) { - debug(Utils.INSTANCE.fmt(fmt, args)); - } - - public static void error(String line) { - Log.e(Const.DEBUG_TAG, "ERROR: " + line); - } - - public static void error(String fmt, Object... args) { - error(Utils.INSTANCE.fmt(fmt, args)); - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/RootUtils.kt b/app/src/main/java/com/topjohnwu/magisk/utils/RootUtils.kt index d3f77fdaf..6cbfc75da 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/RootUtils.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/RootUtils.kt @@ -153,7 +153,6 @@ class RootUtils : Shell.Initializer() { companion object { - @JvmStatic fun rmAndLaunch(rm: String, component: ComponentName) { Shell.su("(rm_launch $rm ${component.flattenToString()})").exec() } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.kt b/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.kt index 54e705eb5..b6134d584 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.kt @@ -11,7 +11,6 @@ import com.topjohnwu.magisk.data.database.PolicyDao import com.topjohnwu.magisk.data.repository.LogRepository import com.topjohnwu.magisk.extensions.inject import com.topjohnwu.magisk.model.entity.MagiskPolicy -import com.topjohnwu.magisk.model.entity.Policy import com.topjohnwu.magisk.model.entity.toLog import com.topjohnwu.magisk.model.entity.toPolicy import java.util.* @@ -20,7 +19,6 @@ object SuLogger { private val context: Context by inject() - @JvmStatic fun handleLogs(intent: Intent) { val fromUid = intent.getIntExtra("from.uid", -1) @@ -72,7 +70,7 @@ object SuLogger { if (policy.notification && Config.suNotification == Config.Value.NOTIFICATION_TOAST) { Utils.toast( context.getString( - if (policy.policy == Policy.ALLOW) + if (policy.policy == MagiskPolicy.ALLOW) R.string.su_allow_toast else R.string.su_deny_toast, policy.appName diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/ValueSortedMap.java b/app/src/main/java/com/topjohnwu/magisk/utils/ValueSortedMap.java deleted file mode 100644 index ff19f1aa3..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/utils/ValueSortedMap.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.topjohnwu.magisk.utils; - -import androidx.annotation.NonNull; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ValueSortedMap> extends HashMap { - - private List sorted = new ArrayList<>(); - - @NonNull - @Override - public Collection values() { - if (sorted.isEmpty()) { - sorted.addAll(super.values()); - Collections.sort(sorted); - } - return sorted; - } - - @Override - public V put(K key, V value) { - sorted.clear(); - return super.put(key, value); - } - - @Override - public void putAll(Map m) { - sorted.clear(); - super.putAll(m); - } - - @Override - public V remove(Object key) { - sorted.clear(); - return super.remove(key); - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/feature/Annotations.kt b/app/src/main/java/com/topjohnwu/magisk/utils/feature/Annotations.kt deleted file mode 100644 index 2f7fb6361..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/utils/feature/Annotations.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.topjohnwu.magisk.utils.feature - -@Retention(AnnotationRetention.SOURCE) -annotation class WIP - - -@Retention(AnnotationRetention.SOURCE) -annotation class Beta - - -@Retention(AnnotationRetention.SOURCE) -annotation class Alpha - - -@Retention(AnnotationRetention.SOURCE) -annotation class Unstable \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/view/SnackbarMaker.kt b/app/src/main/java/com/topjohnwu/magisk/view/SnackbarMaker.kt deleted file mode 100644 index 409dfce1f..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/view/SnackbarMaker.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.topjohnwu.magisk.view - -import android.app.Activity -import android.net.Uri -import android.view.View -import android.widget.TextView -import androidx.annotation.StringRes -import com.google.android.material.snackbar.Snackbar -import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.extensions.fileName - -object SnackbarMaker { - - fun make(activity: Activity, text: CharSequence, duration: Int): Snackbar { - val view = activity.findViewById(android.R.id.content) - return make(view, text, duration) - } - - fun make(activity: Activity, @StringRes resId: Int, duration: Int): Snackbar { - return make(activity, activity.getString(resId), duration) - } - - fun make(view: View, text: CharSequence, duration: Int): Snackbar { - val snack = Snackbar.make(view, text, duration) - setup(snack) - return snack - } - - fun make(view: View, @StringRes resId: Int, duration: Int): Snackbar { - val snack = Snackbar.make(view, resId, duration) - setup(snack) - return snack - } - - private fun setup(snack: Snackbar) { - val text = snack.view.findViewById(com.google.android.material.R.id.snackbar_text) - text.maxLines = Integer.MAX_VALUE - } - - fun showUri(activity: Activity, uri: Uri) { - make(activity, activity.getString(R.string.internal_storage, - "/Download/" + uri.fileName), - Snackbar.LENGTH_LONG) - .setAction(R.string.ok) { }.show() - } -}