1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +00:00

Show dialog if syncthing binary crashes instead of just crashing (ref #58).

This commit is contained in:
Felix Ableitner 2014-07-05 19:14:54 +02:00
parent d46d1d4e48
commit 6ccf1667e8
3 changed files with 44 additions and 15 deletions

View file

@ -12,6 +12,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application <application
android:allowBackup="false" android:allowBackup="false"

View file

@ -1,14 +1,18 @@
package com.nutomic.syncthingandroid.syncthing; package com.nutomic.syncthingandroid.syncthing;
import android.app.AlertDialog;
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.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
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;
import android.view.WindowManager;
import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.gui.MainActivity; import com.nutomic.syncthingandroid.gui.MainActivity;
@ -125,16 +129,7 @@ public class SyncthingService extends Service {
return START_STICKY; return START_STICKY;
} }
/** private Handler mMainThreadHandler;
* 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);
}
}
/** /**
* Runs the syncthing binary from command line, and prints its output to logcat (on exit). * 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); Log.e(TAG, "Failed to execute syncthing binary or read output", e);
} }
finally { finally {
try {
dos.close();
}
catch (IOException e) {
Log.w(TAG, "Failed to close shell stream", e);
}
process.destroy(); process.destroy();
final int retVal = ret;
if (ret != 0) { if (ret != 0) {
stopSelf(); mMainThreadHandler.post(new Runnable() {
mNativeLogLock.lock(); public void run() {
// Include the log for Play Store crash reports. AlertDialog dialog = new AlertDialog.Builder(SyncthingService.this)
throw new NativeExecutionException("Syncthing binary returned error code " + .setTitle(R.string.binary_crashed_title)
Integer.toString(ret), mNativeLog); .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, ""); new PostTask().execute(mApi.getUrl(), PostTask.URI_SHUTDOWN, urlAndKey.second, "");
registerOnWebGuiAvailableListener(mApi); registerOnWebGuiAvailableListener(mApi);
new PollWebGuiAvailableTask().execute(); new PollWebGuiAvailableTask().execute();
mMainThreadHandler = new Handler();
new Thread(new SyncthingRunnable()).start(); new Thread(new SyncthingRunnable()).start();
} }
} }

View file

@ -211,6 +211,17 @@ Please report any problems you encounter.</string>
<!-- Menu item to select the current folder --> <!-- Menu item to select the current folder -->
<string name="select_folder">Select Folder</string> <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 --> <!-- RestApi -->