mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 14:21:16 +00:00
Show notification with info if Syncthing crashes
This commit is contained in:
parent
1be1fbc1fe
commit
245470a9d4
2 changed files with 26 additions and 9 deletions
|
@ -1,18 +1,23 @@
|
||||||
package com.nutomic.syncthingandroid.service;
|
package com.nutomic.syncthingandroid.service;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.annimon.stream.Stream;
|
import com.annimon.stream.Stream;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.nutomic.syncthingandroid.BuildConfig;
|
import com.nutomic.syncthingandroid.R;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
|
@ -37,8 +42,9 @@ public class SyncthingRunnable implements Runnable {
|
||||||
private static final String TAG_NICE = "SyncthingRunnableIoNice";
|
private static final String TAG_NICE = "SyncthingRunnableIoNice";
|
||||||
private static final String TAG_KILL = "SyncthingRunnableKill";
|
private static final String TAG_KILL = "SyncthingRunnableKill";
|
||||||
public static final String UNIT_TEST_PATH = "was running";
|
public static final String UNIT_TEST_PATH = "was running";
|
||||||
public static final String BINARY_NAME = "libsyncthing.so";
|
private static final String BINARY_NAME = "libsyncthing.so";
|
||||||
private static final int LOG_FILE_MAX_LINES = 10000;
|
private static final int LOG_FILE_MAX_LINES = 10000;
|
||||||
|
private static final int NOTIFICATION_ID_CRASH = 9;
|
||||||
|
|
||||||
private static final AtomicReference<Process> mSyncthing = new AtomicReference<>();
|
private static final AtomicReference<Process> mSyncthing = new AtomicReference<>();
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
@ -158,13 +164,20 @@ public class SyncthingRunnable implements Runnable {
|
||||||
.setAction(SyncthingService.ACTION_RESTART));
|
.setAction(SyncthingService.ACTION_RESTART));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Report Syncthing crashes, using Exception in debug mode or log in release mode.
|
// Show notification to inform user about crash.
|
||||||
String message = "Syncthing binary crashed with error code " +
|
Intent intent = new Intent();
|
||||||
Integer.toString(ret) + ", output:\n" + mErrorLog;
|
intent.setAction(android.content.Intent.ACTION_VIEW);
|
||||||
if (BuildConfig.DEBUG)
|
intent.setDataAndType(Uri.fromFile(mLogFile), "text/plain");
|
||||||
throw new RuntimeException(message);
|
Notification n = new NotificationCompat.Builder(mContext)
|
||||||
else
|
.setContentTitle(mContext.getString(R.string.notification_crash_title))
|
||||||
Log.e(TAG, message);
|
.setContentText(mContext.getString(R.string.notification_crash_text))
|
||||||
|
.setSmallIcon(R.drawable.ic_stat_notify)
|
||||||
|
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, 0))
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.build();
|
||||||
|
NotificationManager nm = (NotificationManager)
|
||||||
|
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
nm.notify(NOTIFICATION_ID_CRASH, n);
|
||||||
}
|
}
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
Log.e(TAG, "Failed to execute syncthing binary or read output", e);
|
Log.e(TAG, "Failed to execute syncthing binary or read output", e);
|
||||||
|
|
|
@ -451,6 +451,10 @@ Please report any problems you encounter via Github.</string>
|
||||||
<!-- ID of the default folder created on first start (camera folder). Must only contain 'a-z0-9_-'. Parameter is the device name-->
|
<!-- ID of the default folder created on first start (camera folder). Must only contain 'a-z0-9_-'. Parameter is the device name-->
|
||||||
<string name="default_folder_id">%1$s-photos</string>
|
<string name="default_folder_id">%1$s-photos</string>
|
||||||
|
|
||||||
|
<string name="notification_crash_title">Syncthing has crashed</string>
|
||||||
|
|
||||||
|
<string name="notification_crash_text">Click to view logs</string>
|
||||||
|
|
||||||
<!-- RestApi -->
|
<!-- RestApi -->
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue