From 53c5ca59b6ee69d5acf088e79acca2e680049a4a Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 10 Apr 2019 18:09:41 -0400 Subject: [PATCH] Cleanup SuLogger --- .../magisk/components/GeneralReceiver.java | 14 ++------------ .../com/topjohnwu/magisk/utils/SuLogger.java | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/components/GeneralReceiver.java b/app/src/main/java/com/topjohnwu/magisk/components/GeneralReceiver.java index 9a1e7711f..e31b90ce8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/components/GeneralReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/components/GeneralReceiver.java @@ -8,9 +8,7 @@ import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.ClassMap; import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.SuRequestActivity; -import com.topjohnwu.magisk.container.Policy; import com.topjohnwu.magisk.uicomponents.Notifications; import com.topjohnwu.magisk.uicomponents.Shortcuts; import com.topjohnwu.magisk.utils.DownloadApp; @@ -19,14 +17,6 @@ import com.topjohnwu.superuser.Shell; public class GeneralReceiver extends BroadcastReceiver { - private static SuLogger SU_LOGGER = new SuLogger() { - @Override - public String getMessage(Policy policy) { - return App.self.getString(policy.policy == Policy.ALLOW ? - R.string.su_allow_toast : R.string.su_deny_toast, policy.appName); - } - }; - private String getPkg(Intent i) { return i.getData() == null ? "" : i.getData().getEncodedSchemeSpecificPart(); } @@ -54,10 +44,10 @@ public class GeneralReceiver extends BroadcastReceiver { app.startActivity(i); break; case "log": - SU_LOGGER.handleLogs(intent); + SuLogger.handleLogs(intent); break; case "notify": - SU_LOGGER.handleNotify(intent); + SuLogger.handleNotify(intent); break; case "boot_complete": default: diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java b/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java index b5573a20b..0a41cedfe 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java @@ -8,14 +8,15 @@ import android.widget.Toast; import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.Config; +import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.container.Policy; import com.topjohnwu.magisk.container.SuLogEntry; import java.util.Date; -public abstract class SuLogger { +public class SuLogger { - public void handleLogs(Intent intent) { + public static void handleLogs(Intent intent) { int fromUid = intent.getIntExtra("from.uid", -1); if (fromUid < 0) return; @@ -64,13 +65,16 @@ public abstract class SuLogger { app.mDB.addLog(log); } - private void handleNotify(Policy policy) { + private static void handleNotify(Policy policy) { if (policy.notification && - (int) Config.get(Config.Key.SU_NOTIFICATION) == Config.Value.NOTIFICATION_TOAST) - Utils.toast(getMessage(policy), Toast.LENGTH_SHORT); + (int) Config.get(Config.Key.SU_NOTIFICATION) == Config.Value.NOTIFICATION_TOAST) { + Utils.toast(App.self.getString(policy.policy == Policy.ALLOW ? + R.string.su_allow_toast : R.string.su_deny_toast, policy.appName), + Toast.LENGTH_SHORT); + } } - public void handleNotify(Intent intent) { + public static void handleNotify(Intent intent) { int fromUid = intent.getIntExtra("from.uid", -1); if (fromUid < 0) return; if (fromUid == Process.myUid()) return; @@ -81,6 +85,4 @@ public abstract class SuLogger { handleNotify(policy); } catch (PackageManager.NameNotFoundException ignored) {} } - - public abstract String getMessage(Policy policy); }