mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 04:41:16 +00:00
Improve error handling if config can't be opened
This commit is contained in:
parent
4941d7e412
commit
ee0e361101
5 changed files with 15 additions and 12 deletions
|
@ -66,4 +66,8 @@ public class Constants {
|
|||
static File getSyncthingBinary(Context context) {
|
||||
return new File(context.getApplicationInfo().nativeLibraryDir, "libsyncthing.so");
|
||||
}
|
||||
|
||||
static File getLogFile(Context context) {
|
||||
return new File(context.getExternalFilesDir(null), "syncthing.log");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.SyncthingApp;
|
||||
import com.nutomic.syncthingandroid.activities.FirstStartActivity;
|
||||
import com.nutomic.syncthingandroid.activities.LogActivity;
|
||||
import com.nutomic.syncthingandroid.activities.MainActivity;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -92,10 +94,11 @@ public class NotificationHandler {
|
|||
mNotificationManager.cancel(ID_PERSISTENT);
|
||||
}
|
||||
|
||||
public void showCrashedNotification(Intent intent) {
|
||||
if (mPreferences.getBoolean("notify_crashes", false)) {
|
||||
public void showCrashedNotification(@StringRes int title, boolean force) {
|
||||
if (force || mPreferences.getBoolean("notify_crashes", false)) {
|
||||
Intent intent = new Intent(mContext, LogActivity.class);
|
||||
Notification n = new NotificationCompat.Builder(mContext)
|
||||
.setContentTitle(mContext.getString(R.string.notification_crash_title))
|
||||
.setContentTitle(mContext.getString(title))
|
||||
.setContentText(mContext.getString(R.string.notification_crash_text))
|
||||
.setSmallIcon(R.drawable.ic_stat_notify)
|
||||
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, 0))
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.nutomic.syncthingandroid.service;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.os.PowerManager;
|
||||
import android.text.TextUtils;
|
||||
|
@ -11,6 +10,7 @@ import android.util.Log;
|
|||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.SyncthingApp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
@ -69,7 +69,7 @@ public class SyncthingRunnable implements Runnable {
|
|||
((SyncthingApp) context.getApplicationContext()).component().inject(this);
|
||||
mContext = context;
|
||||
mSyncthingBinary = Constants.getSyncthingBinary(mContext);
|
||||
mLogFile = new File(mContext.getExternalFilesDir(null), "syncthing.log");
|
||||
mLogFile = Constants.getLogFile(mContext);
|
||||
mUseRoot = mPreferences.getBoolean(Constants.PREF_USE_ROOT, false) && Shell.SU.available();
|
||||
switch (command) {
|
||||
case generate:
|
||||
|
@ -141,10 +141,7 @@ public class SyncthingRunnable implements Runnable {
|
|||
break;
|
||||
default:
|
||||
Log.w(TAG, "Syncthing has crashed (exit code " + ret + ")");
|
||||
// Show notification to inform user about crash.
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(Uri.fromFile(mLogFile), "text/plain");
|
||||
mNotificationHandler.showCrashedNotification(intent);
|
||||
mNotificationHandler.showCrashedNotification(R.string.notification_crash_title, false);
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
Log.e(TAG, "Failed to execute syncthing binary or read output", e);
|
||||
|
|
|
@ -220,8 +220,7 @@ public class SyncthingService extends Service implements
|
|||
mConfig = new ConfigXml(SyncthingService.this);
|
||||
mConfig.updateIfNeeded();
|
||||
} catch (ConfigXml.OpenConfigException e) {
|
||||
Toast.makeText(SyncthingService.this, R.string.config_create_failed,
|
||||
Toast.LENGTH_LONG).show();
|
||||
mNotificationHandler.showCrashedNotification(R.string.config_create_failed, true);
|
||||
onApiChange(State.ERROR);
|
||||
cancel(true);
|
||||
}
|
||||
|
|
|
@ -527,7 +527,7 @@ Please report any problems you encounter via Github.</string>
|
|||
<string name="toast_folder_observer_stack_overflow">Directory tree too deep. Check for cyclic symlinks</string>
|
||||
|
||||
<!-- Toast shown if syncthing failed to create a config -->
|
||||
<string name="config_create_failed">Failed to create a Syncthing config. Please check the logs.</string>
|
||||
<string name="config_create_failed">Failed to create config</string>
|
||||
|
||||
<!-- Label of the default folder created of first start (camera folder). -->
|
||||
<string name="default_folder_label">Camera</string>
|
||||
|
|
Loading…
Reference in a new issue