1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-25 22:01:16 +00:00

Added preference to enable/disable crash notifications

This commit is contained in:
Felix Ableitner 2017-04-11 13:10:05 +09:00
parent fddc555a31
commit 71839eb550
3 changed files with 31 additions and 18 deletions

View file

@ -55,6 +55,7 @@ public class SyncthingRunnable implements Runnable {
private String[] mCommand;
private String mErrorLog;
private final File mLogFile;
private final SharedPreferences mPreferences;
public enum Command {
generate, // Generate keys, a config file and immediately exit.
@ -71,6 +72,7 @@ public class SyncthingRunnable implements Runnable {
mContext = context;
mSyncthingBinary = mContext.getApplicationInfo().nativeLibraryDir + "/" + BINARY_NAME;
mLogFile = new File(mContext.getExternalFilesDir(null), "syncthing.log");
mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
switch (command) {
case generate:
mCommand = new String[]{ mSyncthingBinary, "-generate", mContext.getFilesDir().toString() };
@ -96,6 +98,7 @@ public class SyncthingRunnable implements Runnable {
mSyncthingBinary = mContext.getApplicationInfo().nativeLibraryDir + "/" + BINARY_NAME;
mCommand = manualCommand;
mLogFile = new File(mContext.getExternalFilesDir(null), "syncthing.log");
mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
}
@Override
@ -167,20 +170,23 @@ public class SyncthingRunnable implements Runnable {
.setAction(SyncthingService.ACTION_RESTART));
break;
default:
// Show notification to inform user about crash.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(mLogFile), "text/plain");
Notification n = new NotificationCompat.Builder(mContext)
.setContentTitle(mContext.getString(R.string.notification_crash_title))
.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);
Log.w(TAG, "Syncthing has crashed (exit code " + ret + ")");
if (mPreferences.getBoolean("notify_crashes", false)) {
// Show notification to inform user about crash.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(mLogFile), "text/plain");
Notification n = new NotificationCompat.Builder(mContext)
.setContentTitle(mContext.getString(R.string.notification_crash_title))
.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) {
Log.e(TAG, "Failed to execute syncthing binary or read output", e);
@ -196,16 +202,14 @@ public class SyncthingRunnable implements Runnable {
* Returns true if root is available and enabled in settings.
*/
private boolean useRoot() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
return sp.getBoolean(SyncthingService.PREF_USE_ROOT, false) && Shell.SU.available();
return mPreferences.getBoolean(SyncthingService.PREF_USE_ROOT, false) && Shell.SU.available();
}
/**
* Returns true if the experimental setting for using wake locks has been enabled in settings.
*/
private boolean useWakeLock() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
return sp.getBoolean(SyncthingService.PREF_USE_WAKE_LOCK, false);
return mPreferences.getBoolean(SyncthingService.PREF_USE_WAKE_LOCK, false);
}
/**

View file

@ -357,6 +357,10 @@ Please report any problems you encounter via Github.</string>
<!-- Summary for the log activity -->
<string name="open_log_summary">Open the Syncthing and Android log window</string>
<string name="notify_crashes_title">Notify about Syncthing crashes</string>
<string name="notify_crashes_summary">Show a notification whenever a Syncthing crash is detected</string>
<string name="syncthing_forum_title">Syncthing Forum</string>
<string name="syncthing_forum_summary">Go to the Syncthing Forum</string>
<string name="syncthing_forum_url" translatable="false">https://forum.syncthing.net/</string>

View file

@ -154,6 +154,11 @@
android:action=".activities.LogActivity" />
</Preference>
<CheckBoxPreference
android:key="notify_crashes"
android:title="@string/notify_crashes_title"
android:summary="@string/notify_crashes_summary"/>
<EditTextPreference
android:key="sttrace"
android:title="@string/sttrace_title"