Add settings for shell logging

This commit is contained in:
topjohnwu
2016-09-30 11:35:46 +08:00
parent ff6bae936d
commit 21504f1329
7 changed files with 24 additions and 85 deletions
@@ -1,24 +1,15 @@
package com.topjohnwu.magisk.utils;
import android.app.Application;
import android.content.Context;
import android.preference.PreferenceManager;
import android.util.Log;
public class Logger {
private static final String LOG_TAG = "Magisk: DEV";
private static final boolean logShell = true;
public static boolean logShell, devLog;
public static void dev(String msg, Object... args) {
Context context = null;
try {
context = getApplicationUsingReflection();
} catch (Exception e) {
e.printStackTrace();
}
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("developer_logging", false)) {
if (devLog) {
if (args.length == 1 && args[0] instanceof Throwable) {
Log.d(LOG_TAG, msg, (Throwable) args[0]);
} else {
@@ -28,13 +19,7 @@ public class Logger {
}
public static void dev(String msg) {
Context context = null;
try {
context = getApplicationUsingReflection();
} catch (Exception e) {
e.printStackTrace();
}
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("developer_logging", false)) {
if (devLog) {
Log.d(LOG_TAG, msg);
}
}
@@ -44,9 +29,4 @@ public class Logger {
Log.d(root ? "SU" : "SH", msg);
}
}
private static Application getApplicationUsingReflection() throws Exception {
return (Application) Class.forName("android.app.AppGlobals")
.getMethod("getInitialApplication").invoke(null, (Object[]) null);
}
}