Skip to content

Commit

Permalink
No longer write the log to file from Java code
Browse files Browse the repository at this point in the history
Due to SELinux, it's pretty much impossible to open file for writing in
the Zygote process and keep writing to it from application and system
processes. On 64-bit ROMs, it's even more complicated because there are
two Zygote processes.

Messages will still be written to logcat and are captured from there in
native coding.
  • Loading branch information
rovo89 committed Feb 13, 2015
1 parent a1cf28c commit d0101bb
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions src/de/robv/android/xposed/XposedBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.text.DateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -69,9 +64,6 @@ public final class XposedBridge {
private static final int RUNTIME_DALVIK = 1;
private static final int RUNTIME_ART = 2;

private static PrintWriter logWriter = null;
// log for initialization of a few mods is about 500 bytes, so 2*20 kB (2*~350 lines) should be enough
private static final int MAX_LOGFILE_SIZE = 20*1024;
private static boolean disableHooks = false;
public static boolean disableResources = false;

Expand All @@ -94,24 +86,8 @@ public final class XposedBridge {
protected static void main(String[] args) {
// Initialize the Xposed framework and modules
try {
// Initialize log file
try {
File logFile = new File(BASE_DIR + "log/error.log");
if (isZygote && logFile.length() > MAX_LOGFILE_SIZE)
logFile.renameTo(new File(BASE_DIR + "log/error.log.old"));
logWriter = new PrintWriter(new FileWriter(logFile, true));
logFile.setReadable(true, false);
logFile.setWritable(true, false);
} catch (IOException ignored) {}

String date = DateFormat.getDateTimeInstance().format(new Date());
determineXposedVersion();
log("-----------------\n" + date + " UTC\n"
+ "Loading Xposed v" + XPOSED_BRIDGE_VERSION
+ " (for " + (isZygote ? "Zygote" : startClassName) + ")...");

if (isZygote)
log("Running ROM '" + Build.DISPLAY + "' with fingerprint '" + Build.FINGERPRINT + "'");
log("Initializing XposedBridge version " + XPOSED_BRIDGE_VERSION);

runtime = getRuntime();
if (initNative()) {
Expand Down Expand Up @@ -509,10 +485,6 @@ private static void loadModule(String apk) {
*/
public synchronized static void log(String text) {
Log.i("Xposed", text);
if (logWriter != null) {
logWriter.println(text);
logWriter.flush();
}
}

/**
Expand All @@ -524,11 +496,7 @@ public synchronized static void log(String text) {
* @param t The Throwable object for the stack trace.
*/
public synchronized static void log(Throwable t) {
Log.i("Xposed", Log.getStackTraceString(t));
if (logWriter != null) {
t.printStackTrace(logWriter);
logWriter.flush();
}
Log.e("Xposed", Log.getStackTraceString(t));
}

/**
Expand Down

0 comments on commit d0101bb

Please sign in to comment.