2016-09-21 21:55:20 +00:00
|
|
|
package com.topjohnwu.magisk.utils;
|
|
|
|
|
2016-09-22 04:36:28 +00:00
|
|
|
import android.app.Application;
|
|
|
|
import android.content.Context;
|
2016-09-25 05:16:28 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2016-09-21 21:55:20 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
public class Logger {
|
|
|
|
|
2016-09-27 16:33:01 +00:00
|
|
|
private static final String LOG_TAG = "Magisk: DEV";
|
2016-09-21 21:55:20 +00:00
|
|
|
|
2016-09-30 02:41:40 +00:00
|
|
|
private static final boolean logShell = true;
|
|
|
|
|
2016-09-27 16:33:01 +00:00
|
|
|
public static void dev(String msg, Object... args) {
|
2016-09-22 04:36:28 +00:00
|
|
|
Context context = null;
|
|
|
|
try {
|
|
|
|
context = getApplicationUsingReflection();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2016-09-25 05:16:28 +00:00
|
|
|
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("developer_logging", false)) {
|
2016-09-21 21:55:20 +00:00
|
|
|
if (args.length == 1 && args[0] instanceof Throwable) {
|
|
|
|
Log.d(LOG_TAG, msg, (Throwable) args[0]);
|
|
|
|
} else {
|
|
|
|
Log.d(LOG_TAG, String.format(msg, args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 04:36:28 +00:00
|
|
|
|
2016-09-27 16:33:01 +00:00
|
|
|
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)) {
|
|
|
|
Log.d(LOG_TAG, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-30 02:41:40 +00:00
|
|
|
public static void shell(boolean root, String msg) {
|
|
|
|
if (logShell) {
|
|
|
|
Log.d(root ? "SU" : "SH", msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-22 04:36:28 +00:00
|
|
|
private static Application getApplicationUsingReflection() throws Exception {
|
|
|
|
return (Application) Class.forName("android.app.AppGlobals")
|
|
|
|
.getMethod("getInitialApplication").invoke(null, (Object[]) null);
|
|
|
|
}
|
2016-09-21 21:55:20 +00:00
|
|
|
}
|