Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d71ec09 authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "Sync log on IO thread"

parents 08f09685 1f9bbc0d
Loading
Loading
Loading
Loading
+40 −4
Original line number Diff line number Diff line
@@ -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;
            }
            synchronized (mLock) {
            final long now = System.currentTimeMillis();
            mHandler.log(now, message);
        }

        void logInner(long now, Object[] message) {
            synchronized (mLock) {
                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;
                    }
                }
            }
        }
    }
}