Skip to content

Commit

Permalink
Don't crash if config got corrupted and inform the user (#295)
Browse files Browse the repository at this point in the history
* Fix crash notification reason is off-screen (fixes #294)

* Indicate a broken config on the welcome wizard (fixes #293)

* SyncthingService must stop if the config got corrupted (fixes #292)

* Show crash notification extraInfo below notification title (fixes #294)

* Fix NPE when config elements gui, options are missing (fixes #291)

* Updated de translation

* Update en translation

* Updated translations

* Remove debug log
  • Loading branch information
Catfriend1 authored Jan 31, 2019
1 parent 1bdc8fe commit a30163e
Show file tree
Hide file tree
Showing 35 changed files with 59 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,29 +97,14 @@ protected void onCreate(Bundle savedInstanceState) {
mRunningOnTV = Util.isRunningOnTV(this);
Log.d(TAG, mRunningOnTV ? "Running on a TV Device" : "Running on a non-TV Device");

/**
* Check if a valid config exists that can be read and parsed.
*/
Boolean configParseable = false;
Boolean configExists = Constants.getConfigFile(this).exists();
if (configExists) {
ConfigXml configParseTest = new ConfigXml(this);
try {
configParseTest.loadConfig();
configParseable = true;
} catch (ConfigXml.OpenConfigException e) {
Log.d(TAG, "Failed to parse existing config. Will show key generation slide ...");
}
}

/**
* Check if prerequisites to run the app are still in place.
* If anything mandatory is missing, the according welcome slide(s) will be shown.
*/
Boolean showSlideStoragePermission = !haveStoragePermission();
Boolean showSlideIgnoreDozePermission = !haveIgnoreDozePermission();
Boolean showSlideLocationPermission = !haveLocationPermission();
Boolean showSlideKeyGeneration = !configExists || !configParseable;
Boolean showSlideKeyGeneration = !checkForParseableConfig();

/**
* If we don't have to show slides for mandatory prerequisites,
Expand Down Expand Up @@ -583,10 +568,33 @@ protected void onPostExecute(Void aVoid) {
return;
}
TextView keygenStatus = (TextView) firstStartActivity.findViewById(R.id.key_generation_status);
if (!firstStartActivity.checkForParseableConfig()) {
keygenStatus.setText(firstStartActivity.getString(R.string.config_read_failed));
return;
}
keygenStatus.setText(firstStartActivity.getString(R.string.key_generation_success));
Button nextButton = (Button) firstStartActivity.findViewById(R.id.btn_next);
nextButton.setVisibility(View.VISIBLE);
nextButton.requestFocus();
}
}

private Boolean checkForParseableConfig() {
/**
* Check if a valid config exists that can be read and parsed.
*/
Boolean configExists = Constants.getConfigFile(this).exists();
if (!configExists) {
return false;
}
Boolean configParseable = false;
ConfigXml configParseTest = new ConfigXml(this);
try {
configParseTest.loadConfig();
configParseable = true;
} catch (ConfigXml.OpenConfigException e) {
Log.d(TAG, "Failed to parse existing config. Will show key generation slide ...");
}
return configParseable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void showCrashedNotification(@StringRes int title, String extraInfo) {
Intent intent = new Intent(mContext, LogActivity.class);
Notification n = getNotificationBuilder(mInfoChannel)
.setContentTitle(mContext.getString(title, extraInfo))
.setContentText(mContext.getString(R.string.notification_crash_text))
.setContentText(mContext.getString(R.string.notification_crash_text, extraInfo))
.setSmallIcon(R.drawable.ic_stat_notify)
.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, 0))
.setAutoCancel(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,11 @@ private void applyCustomRunConditions(RunConditionMonitor runConditionMonitor) {
try {
configXml.loadConfig();
} catch (ConfigXml.OpenConfigException e) {
mNotificationHandler.showCrashedNotification(R.string.config_read_failed, "applyCustomRunConditions:ConfigXml.OpenConfigException");
mNotificationHandler.showCrashedNotification(R.string.config_read_failed, "applyCustomRunConditions:OpenConfigException");
synchronized (mStateLock) {
onServiceStateChange(State.ERROR);
}
stopSelf();
return;
}

Expand Down Expand Up @@ -508,10 +509,11 @@ private void launchStartupTask(SyncthingRunnable.Command srCommand) {
try {
mConfig.loadConfig();
} catch (ConfigXml.OpenConfigException e) {
mNotificationHandler.showCrashedNotification(R.string.config_read_failed, "ConfigXml.OpenConfigException");
mNotificationHandler.showCrashedNotification(R.string.config_read_failed, "launchStartupTask:OpenConfigException");
synchronized (mStateLock) {
onServiceStateChange(State.ERROR);
}
stopSelf();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ private void updateIfNeeded() {

/* Section - GUI */
Element gui = getGuiElement();
if (gui == null) {
throw new OpenConfigException();
}

// Platform-specific: Force REST API and Web UI access to use TLS 1.2 or not.
Boolean forceHttps = Constants.osSupportsTLS12();
Expand Down Expand Up @@ -293,6 +296,9 @@ private void updateIfNeeded() {
// https://github.com/syncthing/syncthing/issues/4348
Element options = (Element) mConfig.getDocumentElement()
.getElementsByTagName("options").item(0);
if (options == null) {
throw new OpenConfigException();
}
changed = setConfigElement(options, "weakHashSelectionMethod", "never") || changed;

/* Dismiss "fsWatcherNotification" according to https://github.com/syncthing/syncthing-android/pull/1051 */
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
<!-- Text for WebGuiActivity loading view -->
<string name="web_gui_loading">Изчакване на потребителския интерфейс</string>


<!-- SettingsFragment -->


Expand All @@ -208,7 +209,6 @@
<string name="category_run_conditions">Условия на работа</string>
<string name="category_behaviour">Поведение</string>
<string name="category_syncthing_options">Настройки на Syncthing</string>
<string name="category_debug">Дебъг</string>
<string name="category_experimental">Експериментални</string>

<!-- Preference screen - Run conditions -->
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/res/values-ca-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@

<string name="ignore">Ignora</string>

<!-- MainActivity -->



<!-- Exception dialog message -->
<string name="exception_known_bug_notice">S\'ha trobat un error conegut que encara no està resolt. Vegeu %1$s/%2$s per més informació. Siusplau doneu una descripció precisa del que ha passat amb antelació.</string>

Expand Down Expand Up @@ -320,7 +316,6 @@
<string name="category_behaviour">Comportament</string>
<string name="category_syncthing_options">Opcions del Syncthing</string>
<string name="category_backup">Importa i Exporta</string>
<string name="category_debug">Depuració</string>
<string name="category_experimental">Experimental</string>

<!-- Preference screen - Run conditions -->
Expand All @@ -331,8 +326,6 @@
<string name="run_on_mobile_data_summary">Executa quan el dispositiu es connecti a través de la xarxa de dades mòbils. Advertència: Si sincronitzeu gran quantitat de dades podríeu consumir un volum important del pla de dades del vostre operador mòbil.</string>

<string name="run_on_wifi_title">Executa amb Wi-Fi</string>
<string name="run_on_wifi_summary">Executa quan el dispositiu es connecti a una xarxa Wi-Fi.</string>

<string name="run_on_metered_wifi_title">Executa amb Wi-Fi mesurada</string>
<string name="run_on_metered_wifi_summary">Executa quan el dispositiu estigui connectat a una xarxa Wi-Fi mesurada, com ara una zona amb cobertura o un ancoratge. Advertència: Si sincronitzeu gran quantitat de dades podríeu consumir un volum important del pla de dades del vostre operador mòbil.</string>

Expand Down Expand Up @@ -610,7 +603,6 @@
<string name="reason_mobile_data_disallowed">El Syncthing no té permís per funcionar amb connexions de dades mòbils.</string>
<string name="reason_on_mobile_data">El Syncthing està funcionant perquè les dades mòbils estan actives.</string>
<string name="reason_not_on_mobile_data">El Syncthing pot funcionar amb connexions de dades mòbils però les dades mòbils no estan connectades.</string>
<string name="reason_wifi_disallowed">El Syncthing no té permís per funcionar amb WiFi.</string>
<!-- SyncthingService -->


Expand Down Expand Up @@ -640,8 +632,6 @@

<string name="notification_crash_title">El Syncthing s\'ha bloquejat %1$s</string>

<string name="notification_crash_text">Feu clic per veure els registres</string>

<string name="notifications_persistent_channel">El Syncthing està actiu</string>
<string name="notification_persistent_waiting_channel">Vigilant les condicions d\'execució</string>
<string name="notifications_other_channel">Altres notificacions</string>
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
<!-- Text for WebGuiActivity loading view -->
<string name="web_gui_loading">Čeká se na Syncthing GUI</string>


<!-- SettingsFragment -->


Expand All @@ -220,7 +221,6 @@
<string name="category_run_conditions">Podmínky spuštění</string>
<string name="category_behaviour">Chování</string>
<string name="category_syncthing_options">Nastavení Syncthing</string>
<string name="category_debug">Ladění</string>
<string name="category_experimental">Experimentální</string>

<!-- Preference screen - Run conditions -->
Expand Down Expand Up @@ -427,8 +427,6 @@

<string name="notification_crash_title">Syncthing spadl %1$s</string>

<string name="notification_crash_text">Pro prohlížení logů klikněte</string>

<string name="notifications_other_channel">Ostatní upozornění</string>

<!-- RestApi -->
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
<!-- Text for WebGuiActivity loading view -->
<string name="web_gui_loading">Venter på GUI</string>


<!-- SettingsFragment -->


Expand All @@ -216,7 +217,6 @@
<string name="category_run_conditions">Kør betingelser</string>
<string name="category_behaviour">Adfærd</string>
<string name="category_syncthing_options">Syncthing Muligheder</string>
<string name="category_debug">Debug</string>
<string name="category_experimental">Eksperimentalt</string>

<!-- Preference screen - Run conditions -->
Expand Down Expand Up @@ -407,8 +407,6 @@

<string name="notification_crash_title">Syncthing crashede %1$s</string>

<string name="notification_crash_text">Klik for at se logs</string>

<!-- RestApi -->


Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>

<string name="notification_crash_title">Syncthing ist abgestürzt (Exit-Code %1$s)</string>

<string name="notification_crash_text">Klicken um Logs anzuzeigen</string>
<string name="notification_crash_text">Klicke für Logs (%1$s)</string>

<string name="notifications_persistent_channel">Syncthing läuft</string>
<string name="notification_persistent_waiting_channel">Laufkonditionen werden überwacht</string>
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
<!-- Text for WebGuiActivity loading view -->
<string name="web_gui_loading">Αναμονή για το GUI</string>


<!-- SettingsFragment -->


Expand All @@ -216,7 +217,6 @@
<string name="category_run_conditions">Συνθήκες εκτέλεσης</string>
<string name="category_behaviour">Συμπεριφορά</string>
<string name="category_syncthing_options">Επιλογές Syncthing</string>
<string name="category_debug">Αποσφαλμάτωση</string>
<string name="category_experimental">Πειραματικά</string>

<!-- Preference screen - Run conditions -->
Expand Down Expand Up @@ -417,8 +417,6 @@

<string name="notification_crash_title">Το Syncthing κατέρρευσε %1$s</string>

<string name="notification_crash_text">Πατήστε για να δείτε την καταγραφή συμβάντων</string>

<string name="notifications_other_channel">Άλλες ειδοποιήσεις</string>

<!-- RestApi -->
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es-rMX/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
<!-- Text for WebGuiActivity loading view -->
<string name="web_gui_loading">Esperando por la Interfaz</string>


<!-- SettingsFragment -->


Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@
<string name="category_run_conditions">Condiciones de ejecución</string>
<string name="category_behaviour">Comportamiento</string>
<string name="category_syncthing_options">Opciones de Syncthing</string>
<string name="category_debug">Depuración</string>
<string name="category_experimental">Experimental</string>

<!-- Preference screen - Run conditions -->
Expand Down Expand Up @@ -383,8 +382,6 @@

<string name="notification_crash_title">Syncthing se ha estrellado %1$s</string>

<string name="notification_crash_text">Haga clic para ver los registros</string>

<!-- RestApi -->


Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
<!-- Text for WebGuiActivity loading view -->
<string name="web_gui_loading">Käyttöliittymä käynnistyy</string>


<!-- SettingsFragment -->


Expand All @@ -220,7 +221,6 @@
<string name="category_run_conditions">Käyntiehdot</string>
<string name="category_behaviour">Käyttäytyminen</string>
<string name="category_syncthing_options">Syncthing asetukset</string>
<string name="category_debug">Vianhaku</string>
<string name="category_experimental">Kokeellinen</string>

<!-- Preference screen - Run conditions -->
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@
<string name="category_run_conditions">Conditions d\'exécution</string>
<string name="category_behaviour">Comportement</string>
<string name="category_syncthing_options">Options Syncthing</string>
<string name="category_debug">Debug</string>
<string name="category_experimental">Expérimental</string>

<!-- Preference screen - Run conditions -->
Expand Down Expand Up @@ -482,8 +481,6 @@

<string name="notification_crash_title">Syncthing s\'est planté %1$s</string>

<string name="notification_crash_text">Cliquer pour voir les journaux</string>

<string name="notifications_persistent_channel">Syncthing en marche</string>
<string name="notification_persistent_waiting_channel">Surveillance des conditions de fonctionnement</string>
<string name="notifications_other_channel">Autres notifications</string>
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Az összesített statisztika nyilvánosan elérhető a https://data.syncthing.ne
<!-- Text for WebGuiActivity loading view -->
<string name="web_gui_loading">Várakozás a grafikus felületre</string>


<!-- SettingsFragment -->


Expand All @@ -233,7 +234,6 @@ Az összesített statisztika nyilvánosan elérhető a https://data.syncthing.ne
<string name="category_run_conditions">Futás feltételei</string>
<string name="category_behaviour">Viselkedés</string>
<string name="category_syncthing_options">Syncthing opciók</string>
<string name="category_debug">Hibakeresés</string>
<string name="category_experimental">Kísérleti</string>

<!-- Preference screen - Run conditions -->
Expand Down Expand Up @@ -471,8 +471,6 @@ VIGYÁZAT! Más alkalmazások kiolvashatják a backupból a titkos kulcsot, és

<string name="notification_crash_title">A Syncthing összeomlott %1$s</string>

<string name="notification_crash_text">Koppints a naplók megtekintéséhez</string>

<string name="notifications_persistent_channel">Syncthing aktív</string>
<string name="notification_persistent_waiting_channel">Futási feltételek monitorozása</string>
<string name="notifications_other_channel">További értesítések</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<!-- Text for WebGuiActivity loading view -->
<string name="web_gui_loading">Memuat GUI</string>


<!-- SettingsFragment -->


Expand All @@ -210,7 +211,6 @@
<string name="category_run_conditions">Syarat Operasi</string>
<string name="category_behaviour">Perilaku</string>
<string name="category_syncthing_options">Opsi Syncthing</string>
<string name="category_debug">Debug</string>
<string name="category_experimental">Ujicoba</string>

<!-- Preference screen - Run conditions -->
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@
<string name="category_run_conditions">Condizioni di funzionamento</string>
<string name="category_behaviour">Comportamento</string>
<string name="category_syncthing_options">Opzioni di Syncthing</string>
<string name="category_debug">Debug</string>
<string name="category_experimental">Sperimentale</string>

<!-- Preference screen - Run conditions -->
Expand Down Expand Up @@ -479,8 +478,6 @@

<string name="notification_crash_title">Syncthing è andato in crash %1$s</string>

<string name="notification_crash_text">Clicca per visualizzare i log</string>

<string name="notifications_persistent_channel">Syncthing attivo</string>
<string name="notification_persistent_waiting_channel">Monitoraggio delle condizioni di esecuzione</string>
<string name="notifications_other_channel">Altre notifiche</string>
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@
<string name="category_run_conditions">実行条件</string>
<string name="category_behaviour">動作</string>
<string name="category_syncthing_options">同期オプション</string>
<string name="category_debug">デバッグ</string>
<string name="category_experimental">実験的</string>

<!-- Preference screen - Run conditions -->
Expand Down Expand Up @@ -416,8 +415,6 @@

<string name="notification_crash_title">Syncthing がクラッシュしました %1$s</string>

<string name="notification_crash_text">クリックしてログを表示</string>

<string name="notifications_other_channel">他の通知</string>

<!-- RestApi -->
Expand Down
Loading

0 comments on commit a30163e

Please sign in to comment.