Remove unused files

This commit is contained in:
topjohnwu 2019-08-08 00:29:27 -07:00
parent 5ba5f5f94e
commit 48395ba860
22 changed files with 29 additions and 269 deletions

View File

@ -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'

View File

@ -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<Context>().resources }

View File

@ -1,10 +0,0 @@
package com.topjohnwu.magisk.di
import org.koin.dsl.module
val miscModule = module {
// define miscs here
}

View File

@ -5,6 +5,5 @@ val koinModules = listOf(
networkingModule,
databaseModule,
repositoryModule,
viewModelModules,
miscModule
viewModelModules
)

View File

@ -1,6 +0,0 @@
package com.topjohnwu.magisk.di
import org.koin.core.qualifier.named
val SUTimeout = named("su_timeout")
val Protected = named("protected")

View File

@ -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<Policy>{
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());
}
}

View File

@ -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
)

View File

@ -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()

View File

@ -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<Context>().readUri(uri).use { input ->
zip.outputStream().use { out -> input.copyTo(out) }
}
}
}

View File

@ -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

View File

@ -1,6 +0,0 @@
package com.topjohnwu.magisk.ui.home
enum class MagiskItem {
MANAGER, MAGISK
}

View File

@ -1,6 +0,0 @@
package com.topjohnwu.magisk.ui.home
enum class MagiskState {
NO_ROOT, NOT_INSTALLED, UP_TO_DATE, OBSOLETE, LOADING
}

View File

@ -1,5 +0,0 @@
package com.topjohnwu.magisk.ui.home
enum class SafetyNetState {
LOADING, PASS, FAILED, IDLE
}

View File

@ -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)

View File

@ -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<SuRequestViewModel, ActivityReques
override val viewModel: SuRequestViewModel by viewModel()
override fun onBackPressed() {
viewModel.handler?.handleAction(Policy.DENY, -1)
viewModel.handler?.handleAction(MagiskPolicy.DENY, -1)
}
override fun onCreate(savedInstanceState: Bundle?) {

View File

@ -19,7 +19,6 @@ import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.data.database.PolicyDao
import com.topjohnwu.magisk.extensions.now
import com.topjohnwu.magisk.model.entity.MagiskPolicy
import com.topjohnwu.magisk.model.entity.Policy
import com.topjohnwu.magisk.model.entity.recycler.SpinnerRvItem
import com.topjohnwu.magisk.model.entity.toPolicy
import com.topjohnwu.magisk.model.events.DieEvent
@ -94,12 +93,12 @@ class SuRequestViewModel(
}
fun grantPressed() {
handler?.handleAction(Policy.ALLOW)
handler?.handleAction(MagiskPolicy.ALLOW)
timer?.cancel()
}
fun denyPressed() {
handler?.handleAction(Policy.DENY)
handler?.handleAction(MagiskPolicy.DENY)
timer?.cancel()
}
@ -168,18 +167,18 @@ class SuRequestViewModel(
return false
// If not interactive, response directly
if (policy?.policy != Policy.INTERACTIVE) {
if (policy?.policy != MagiskPolicy.INTERACTIVE) {
handler?.handleAction()
return true
}
when (Config.suAutoReponse) {
Config.Value.SU_AUTO_DENY -> {
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() {

View File

@ -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));
}
}

View File

@ -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()
}

View File

@ -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

View File

@ -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<K, V extends Comparable<? super V>> extends HashMap<K, V> {
private List<V> sorted = new ArrayList<>();
@NonNull
@Override
public Collection<V> 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<? extends K, ? extends V> m) {
sorted.clear();
super.putAll(m);
}
@Override
public V remove(Object key) {
sorted.clear();
return super.remove(key);
}
}

View File

@ -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

View File

@ -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<View>(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<TextView>(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()
}
}