Sync log on IO thread
Change-Id: Ifa1a0afd2faca9e992841d7fd7f79d7d1b615559 Fixes: 118428335 Test: Manual test with toggling sync and checking "dumpsys content -a"
This commit is contained in:
committed by
Artem Iglikov
parent
7e77dbb1be
commit
1f9bbc0d6b
@@ -20,12 +20,17 @@ import android.app.job.JobParameters;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.FileUtils;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.SystemProperties;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.util.IntPair;
|
||||
import com.android.server.IoThread;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
@@ -65,10 +70,11 @@ public class SyncLogger {
|
||||
*/
|
||||
public static synchronized SyncLogger getInstance() {
|
||||
if (sInstance == null) {
|
||||
final String flag = SystemProperties.get("debug.synclog");
|
||||
final boolean enable =
|
||||
Build.IS_DEBUGGABLE
|
||||
|| "1".equals(SystemProperties.get("debug.synclog"))
|
||||
|| Log.isLoggable(TAG, Log.VERBOSE);
|
||||
(Build.IS_DEBUGGABLE
|
||||
|| "1".equals(flag)
|
||||
|| Log.isLoggable(TAG, Log.VERBOSE)) && !"0".equals(flag);
|
||||
if (enable) {
|
||||
sInstance = new RotatingFileLogger();
|
||||
} else {
|
||||
@@ -142,8 +148,11 @@ public class SyncLogger {
|
||||
|
||||
private static final boolean DO_LOGCAT = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
private final MyHandler mHandler;
|
||||
|
||||
RotatingFileLogger() {
|
||||
mLogPath = new File(Environment.getDataSystemDirectory(), "syncmanager-log");
|
||||
mHandler = new MyHandler(IoThread.get().getLooper());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,8 +172,12 @@ public class SyncLogger {
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
final long now = System.currentTimeMillis();
|
||||
mHandler.log(now, message);
|
||||
}
|
||||
|
||||
void logInner(long now, Object[] message) {
|
||||
synchronized (mLock) {
|
||||
final long now = System.currentTimeMillis();
|
||||
openLogLocked(now);
|
||||
if (mLogWriter == null) {
|
||||
return; // Couldn't open log file?
|
||||
@@ -272,5 +285,28 @@ public class SyncLogger {
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private class MyHandler extends Handler {
|
||||
public static final int MSG_LOG_ID = 1;
|
||||
|
||||
MyHandler(Looper looper) {
|
||||
super(looper);
|
||||
}
|
||||
|
||||
public void log(long now, Object[] message) {
|
||||
obtainMessage(MSG_LOG_ID, IntPair.first(now), IntPair.second(now), message)
|
||||
.sendToTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_LOG_ID: {
|
||||
logInner(IntPair.of(msg.arg1, msg.arg2), (Object[]) msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user