Use correct stream for native logging, use tag SyncthingNativeCode, simplify Code.
This commit is contained in:
parent
1c1197b85b
commit
dfc589d714
|
@ -3,11 +3,9 @@ package com.nutomic.syncthingandroid.syncthing;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Looper;
|
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
@ -34,7 +32,6 @@ import java.io.InputStreamReader;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,16 +131,8 @@ public class SyncthingService extends Service {
|
||||||
*/
|
*/
|
||||||
public static class NativeExecutionException extends RuntimeException {
|
public static class NativeExecutionException extends RuntimeException {
|
||||||
|
|
||||||
private final String mLog;
|
|
||||||
|
|
||||||
public NativeExecutionException(String message, String log) {
|
public NativeExecutionException(String message, String log) {
|
||||||
super(message);
|
super(message + "\n" + log);
|
||||||
mLog = log;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
|
||||||
return super.getMessage() + "\n" + mLog;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +156,7 @@ public class SyncthingService extends Service {
|
||||||
dos.writeBytes("exit\n");
|
dos.writeBytes("exit\n");
|
||||||
dos.flush();
|
dos.flush();
|
||||||
|
|
||||||
log(process.getInputStream(), Log.INFO);
|
log(process.getErrorStream());
|
||||||
|
|
||||||
ret = process.waitFor();
|
ret = process.waitFor();
|
||||||
}
|
}
|
||||||
|
@ -181,6 +170,7 @@ public class SyncthingService extends Service {
|
||||||
process.destroy();
|
process.destroy();
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
stopSelf();
|
stopSelf();
|
||||||
|
mNativeLogLock.lock();
|
||||||
// Include the log for Play Store crash reports.
|
// Include the log for Play Store crash reports.
|
||||||
throw new NativeExecutionException("Syncthing binary returned error code " +
|
throw new NativeExecutionException("Syncthing binary returned error code " +
|
||||||
Integer.toString(ret), mNativeLog);
|
Integer.toString(ret), mNativeLog);
|
||||||
|
@ -193,9 +183,8 @@ public class SyncthingService extends Service {
|
||||||
* Logs the outputs of a stream to logcat and mNativeLog.
|
* Logs the outputs of a stream to logcat and mNativeLog.
|
||||||
*
|
*
|
||||||
* @param is The stream to log.
|
* @param is The stream to log.
|
||||||
* @param priority The log level, eg Log.INFO or Log.WARN.
|
|
||||||
*/
|
*/
|
||||||
private void log(final InputStream is, final int priority) {
|
private void log(final InputStream is) {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -205,7 +194,7 @@ public class SyncthingService extends Service {
|
||||||
try {
|
try {
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
mNativeLogLock.lock();
|
mNativeLogLock.lock();
|
||||||
Log.println(priority, TAG, ": " + line);
|
Log.i("SyncthingNativeCode", line);
|
||||||
mNativeLog += line + "\n";
|
mNativeLog += line + "\n";
|
||||||
mNativeLogLock.unlock();
|
mNativeLogLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue