mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 03:11:30 +00:00
Show dialog if syncthing binary crashes instead of just crashing (ref #58).
This commit is contained in:
parent
d46d1d4e48
commit
6ccf1667e8
3 changed files with 44 additions and 15 deletions
|
@ -12,6 +12,7 @@
|
|||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
package com.nutomic.syncthingandroid.syncthing;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.gui.MainActivity;
|
||||
|
@ -125,16 +129,7 @@ public class SyncthingService extends Service {
|
|||
return START_STICKY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown when execution of the native syncthing binary returns an error.
|
||||
* Prints the syncthing log.
|
||||
*/
|
||||
public static class NativeExecutionException extends RuntimeException {
|
||||
|
||||
public NativeExecutionException(String message, String log) {
|
||||
super(message + "\n" + log);
|
||||
}
|
||||
}
|
||||
private Handler mMainThreadHandler;
|
||||
|
||||
/**
|
||||
* Runs the syncthing binary from command line, and prints its output to logcat (on exit).
|
||||
|
@ -167,13 +162,34 @@ public class SyncthingService extends Service {
|
|||
Log.e(TAG, "Failed to execute syncthing binary or read output", e);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
dos.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
Log.w(TAG, "Failed to close shell stream", e);
|
||||
}
|
||||
process.destroy();
|
||||
final int retVal = ret;
|
||||
if (ret != 0) {
|
||||
stopSelf();
|
||||
mNativeLogLock.lock();
|
||||
// Include the log for Play Store crash reports.
|
||||
throw new NativeExecutionException("Syncthing binary returned error code " +
|
||||
Integer.toString(ret), mNativeLog);
|
||||
mMainThreadHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
AlertDialog dialog = new AlertDialog.Builder(SyncthingService.this)
|
||||
.setTitle(R.string.binary_crashed_title)
|
||||
.setMessage(getString(R.string.binary_crashed_message, retVal))
|
||||
.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface,
|
||||
int i) {
|
||||
System.exit(0);
|
||||
}
|
||||
})
|
||||
.create();
|
||||
dialog.getWindow()
|
||||
.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -341,6 +357,7 @@ public class SyncthingService extends Service {
|
|||
new PostTask().execute(mApi.getUrl(), PostTask.URI_SHUTDOWN, urlAndKey.second, "");
|
||||
registerOnWebGuiAvailableListener(mApi);
|
||||
new PollWebGuiAvailableTask().execute();
|
||||
mMainThreadHandler = new Handler();
|
||||
new Thread(new SyncthingRunnable()).start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -211,6 +211,17 @@ Please report any problems you encounter.</string>
|
|||
<!-- Menu item to select the current folder -->
|
||||
<string name="select_folder">Select Folder</string>
|
||||
|
||||
<!-- SyncthingService -->
|
||||
|
||||
|
||||
<!-- Title of the dialog shown when the syncthing binary returns an error -->
|
||||
<string name="binary_crashed_title">Syncthing Binary Crashed</string>
|
||||
|
||||
|
||||
<!-- Message of the dialog shown when the syncthing binary returns an error -->
|
||||
<string name="binary_crashed_message">The syncthing binary has exited with error code %1$d.\n\n
|
||||
If this error persists, try reinstalling the app and restarting your device.\n\n</string>
|
||||
|
||||
<!-- RestApi -->
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue