mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-29 07:41:17 +00:00
Added preference to enable/disable crash notifications
This commit is contained in:
parent
fddc555a31
commit
71839eb550
3 changed files with 31 additions and 18 deletions
|
@ -55,6 +55,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
private String[] mCommand;
|
private String[] mCommand;
|
||||||
private String mErrorLog;
|
private String mErrorLog;
|
||||||
private final File mLogFile;
|
private final File mLogFile;
|
||||||
|
private final SharedPreferences mPreferences;
|
||||||
|
|
||||||
public enum Command {
|
public enum Command {
|
||||||
generate, // Generate keys, a config file and immediately exit.
|
generate, // Generate keys, a config file and immediately exit.
|
||||||
|
@ -71,6 +72,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mSyncthingBinary = mContext.getApplicationInfo().nativeLibraryDir + "/" + BINARY_NAME;
|
mSyncthingBinary = mContext.getApplicationInfo().nativeLibraryDir + "/" + BINARY_NAME;
|
||||||
mLogFile = new File(mContext.getExternalFilesDir(null), "syncthing.log");
|
mLogFile = new File(mContext.getExternalFilesDir(null), "syncthing.log");
|
||||||
|
mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case generate:
|
case generate:
|
||||||
mCommand = new String[]{ mSyncthingBinary, "-generate", mContext.getFilesDir().toString() };
|
mCommand = new String[]{ mSyncthingBinary, "-generate", mContext.getFilesDir().toString() };
|
||||||
|
@ -96,6 +98,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
mSyncthingBinary = mContext.getApplicationInfo().nativeLibraryDir + "/" + BINARY_NAME;
|
mSyncthingBinary = mContext.getApplicationInfo().nativeLibraryDir + "/" + BINARY_NAME;
|
||||||
mCommand = manualCommand;
|
mCommand = manualCommand;
|
||||||
mLogFile = new File(mContext.getExternalFilesDir(null), "syncthing.log");
|
mLogFile = new File(mContext.getExternalFilesDir(null), "syncthing.log");
|
||||||
|
mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -167,6 +170,8 @@ public class SyncthingRunnable implements Runnable {
|
||||||
.setAction(SyncthingService.ACTION_RESTART));
|
.setAction(SyncthingService.ACTION_RESTART));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Log.w(TAG, "Syncthing has crashed (exit code " + ret + ")");
|
||||||
|
if (mPreferences.getBoolean("notify_crashes", false)) {
|
||||||
// Show notification to inform user about crash.
|
// Show notification to inform user about crash.
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(android.content.Intent.ACTION_VIEW);
|
intent.setAction(android.content.Intent.ACTION_VIEW);
|
||||||
|
@ -182,6 +187,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
nm.notify(NOTIFICATION_ID_CRASH, n);
|
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);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -196,16 +202,14 @@ public class SyncthingRunnable implements Runnable {
|
||||||
* Returns true if root is available and enabled in settings.
|
* Returns true if root is available and enabled in settings.
|
||||||
*/
|
*/
|
||||||
private boolean useRoot() {
|
private boolean useRoot() {
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
return mPreferences.getBoolean(SyncthingService.PREF_USE_ROOT, false) && Shell.SU.available();
|
||||||
return sp.getBoolean(SyncthingService.PREF_USE_ROOT, false) && Shell.SU.available();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the experimental setting for using wake locks has been enabled in settings.
|
* Returns true if the experimental setting for using wake locks has been enabled in settings.
|
||||||
*/
|
*/
|
||||||
private boolean useWakeLock() {
|
private boolean useWakeLock() {
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
return mPreferences.getBoolean(SyncthingService.PREF_USE_WAKE_LOCK, false);
|
||||||
return sp.getBoolean(SyncthingService.PREF_USE_WAKE_LOCK, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -357,6 +357,10 @@ Please report any problems you encounter via Github.</string>
|
||||||
<!-- Summary for the log activity -->
|
<!-- Summary for the log activity -->
|
||||||
<string name="open_log_summary">Open the Syncthing and Android log window</string>
|
<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_title">Syncthing Forum</string>
|
||||||
<string name="syncthing_forum_summary">Go to the 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>
|
<string name="syncthing_forum_url" translatable="false">https://forum.syncthing.net/</string>
|
||||||
|
|
|
@ -154,6 +154,11 @@
|
||||||
android:action=".activities.LogActivity" />
|
android:action=".activities.LogActivity" />
|
||||||
</Preference>
|
</Preference>
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="notify_crashes"
|
||||||
|
android:title="@string/notify_crashes_title"
|
||||||
|
android:summary="@string/notify_crashes_summary"/>
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="sttrace"
|
android:key="sttrace"
|
||||||
android:title="@string/sttrace_title"
|
android:title="@string/sttrace_title"
|
||||||
|
|
Loading…
Reference in a new issue