From d420fd070be7840168c45a6030fce4d37e49b6a0 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Thu, 11 Jul 2019 16:47:54 +0200 Subject: [PATCH 1/7] UI: Add "roaming" run condition ref: #177 --- app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/app_settings.xml | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8c848cff6..83613e93d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -431,6 +431,9 @@ Please report any problems you encounter via Github. Run on mobile data Run when device is connected via the mobile data network. Warning: This can consume a lot of data from your mobile operator data plan if you sync large amounts of data. + Run while roaming + Allow the device to use mobile data while roaming. + Run on Wi-Fi Run when device is connected to a Wi-Fi or ethernet network. diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index f8eeebd81..cd0dfbcc6 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -46,6 +46,13 @@ android:summary="@string/run_on_mobile_data_summary" android:defaultValue="false" /> + + + Date: Thu, 11 Jul 2019 16:59:00 +0200 Subject: [PATCH 2/7] Settings UI: Add "roaming" run condition --- .../syncthingandroid/activities/SettingsActivity.java | 10 +++++++++- .../nutomic/syncthingandroid/service/Constants.java | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java index f74715297..faa963198 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java @@ -166,6 +166,7 @@ public static class SettingsFragment extends PreferenceFragment private PreferenceScreen mCategoryRunConditions; private ListPreference mPowerSource; private CheckBoxPreference mRunOnMobileData; + private CheckBoxPreference mRunOnRoaming; private CheckBoxPreference mRunOnWifi; private CheckBoxPreference mRunOnMeteredWifi; private CheckBoxPreference mUseWifiWhitelist; @@ -285,7 +286,9 @@ public void onActivityCreated(Bundle savedInstanceState) { mWifiSsidWhitelist = (WifiSsidPreference) findPreference(Constants.PREF_WIFI_SSID_WHITELIST); mRunOnMobileData = - (CheckBoxPreference) findPreference(Constants.PREF_RUN_ON_WIFI); + (CheckBoxPreference) findPreference(Constants.PREF_RUN_ON_MOBILE_DATA); + mRunOnRoaming = + (CheckBoxPreference) findPreference(Constants.PREF_RUN_ON_ROAMING); mPowerSource = (ListPreference) findPreference(Constants.PREF_POWER_SOURCE); mRunInFlightMode = @@ -295,6 +298,8 @@ public void onActivityCreated(Bundle savedInstanceState) { mUseWifiWhitelist.setEnabled(mRunOnWifi.isChecked()); mWifiSsidWhitelist.setEnabled(mRunOnWifi.isChecked() && mUseWifiWhitelist.isChecked()); + mRunOnRoaming.setEnabled(mRunOnMobileData.isChecked()); + screen.findPreference(Constants.PREF_POWER_SOURCE).setSummary(mPowerSource.getEntry()); String wifiSsidSummary = TextUtils.join(", ", mPreferences.getStringSet(Constants.PREF_WIFI_SSID_WHITELIST, new HashSet<>())); screen.findPreference(Constants.PREF_WIFI_SSID_WHITELIST).setSummary(TextUtils.isEmpty(wifiSsidSummary) ? @@ -593,6 +598,9 @@ public boolean onRunConditionPreferenceChange(Preference preference, Object o) { getString(R.string.run_on_whitelisted_wifi_networks, wifiSsidSummary) ); break; + case Constants.PREF_RUN_ON_MOBILE_DATA: + mRunOnRoaming.setEnabled((Boolean) o); + break; } mPendingRunConditions = true; return true; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java b/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java index 74c5b8558..9d640a1a2 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java @@ -19,6 +19,7 @@ public class Constants { // Preferences - Run conditions public static final String PREF_START_SERVICE_ON_BOOT = "always_run_in_background"; public static final String PREF_RUN_ON_MOBILE_DATA = "run_on_mobile_data"; + public static final String PREF_RUN_ON_ROAMING = "run_on_roaming"; public static final String PREF_RUN_ON_WIFI = "run_on_wifi"; public static final String PREF_RUN_ON_METERED_WIFI = "run_on_metered_wifi"; public static final String PREF_USE_WIFI_SSID_WHITELIST = "use_wifi_whitelist"; From 6151103d8ae53389784bf13c141d545b768a1b1b Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Thu, 11 Jul 2019 17:18:01 +0200 Subject: [PATCH 3/7] Update strings.xml --- app/src/main/res/values/strings.xml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 83613e93d..2789508b6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -803,9 +803,17 @@ Please report any problems you encounter via Github. Phone is not running on battery power. Syncthing is not running as the phone is currently power saving. Syncthing is not running as Android currently has \'Auto-sync data\' disabled. + + Syncthing is not configured to run on mobile data connection. - Syncthing is running as mobile data is currently connected. + Syncthing is allowed to run on mobile data. Syncthing is allowed to run on mobile data connection but mobile data isn\'t connected. + + + Syncthing is allowed to run on roaming and non-roaming mobile data connections. + Syncthing is allowed to run on non-roaming mobile data connections. The active connection is non-roaming. + Syncthing is not running as you disallowed it to run on roaming mobile data connections. + Syncthing is not allowed to run on WiFi or ethernet. Syncthing is allowed to run on WiFi and WiFi is currently connected. Syncthing is allowed to run on WiFi but WiFi isn\'t connected or the phone is in flight mode. From 0550c87e2c213967536be95ad8a4945c45ee1a01 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Thu, 11 Jul 2019 17:18:41 +0200 Subject: [PATCH 4/7] Handle roaming state in RunConditionMonitor (fixes #177) --- .../service/RunConditionMonitor.java | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java b/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java index b38239284..8bf68e78d 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java @@ -374,6 +374,25 @@ private SyncConditionResult checkConditionSyncOnMobileData(String prefNameSyncOn return new SyncConditionResult(false, res.getString(R.string.reason_not_on_mobile_data)); } + /** + * Constants.PREF_RUN_ON_ROAMING + */ + private SyncConditionResult checkConditionSyncOnRoaming(String prefNameSyncOnRoaming) { + boolean prefSyncOnRoaming = mPreferences.getBoolean(prefNameSyncOnRoaming, false); + if (prefSyncOnRoaming) { + // Condition is always met as we allow both types of mobile data networks - roaming and non-roaming. + return new SyncConditionResult(true, "\n" + res.getString(R.string.reason_on_roaming_nonroaming_mobile_data)); + } + + // Check if we are on a non-roaming mobile data network. + if (!isRoamingNetworkConnection()) { + return new SyncConditionResult(true, "\n" + res.getString(R.string.reason_on_nonroaming_mobile_data)); + } + + // We disallowed non-roaming mobile data and are connected to a mobile data network in roaming mode. + return new SyncConditionResult(false, "\n" + res.getString(R.string.reason_not_nonroaming_mobile_data)); + } + /** * Determines if Syncthing should currently run. * Updates mRunDecisionExplanation. @@ -439,7 +458,14 @@ private boolean decideShouldRun() { if (scr.conditionMet) { // Mobile data is connected. LogV("decideShouldRun: checkConditionSyncOnMobileData"); - return true; + + scr = checkConditionSyncOnRoaming(Constants.PREF_RUN_ON_ROAMING); + mRunDecisionExplanation += scr.explanation; + if (scr.conditionMet) { + // Mobile data connection type is allowed. + LogV("decideShouldRun: checkConditionSyncOnMobileData && checkConditionSyncOnRoaming"); + return true; + } } // Run on WiFi? @@ -628,6 +654,20 @@ private boolean isMobileDataConnection() { } } + private boolean isRoamingNetworkConnection() { + ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo ni = cm.getActiveNetworkInfo(); + if (ni == null) { + // In flight mode. + return false; + } + if (!ni.isConnected()) { + // No network connection. + return false; + } + return ni.isRoaming(); + } + private boolean isWifiOrEthernetConnection() { ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); From e1a4c5635931f1f16d3b7adaff6d7e19d72943d8 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Thu, 11 Jul 2019 17:44:17 +0200 Subject: [PATCH 5/7] Add "feedback required" notice --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2789508b6..c74e82f8a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -432,7 +432,7 @@ Please report any problems you encounter via Github. Run when device is connected via the mobile data network. Warning: This can consume a lot of data from your mobile operator data plan if you sync large amounts of data. Run while roaming - Allow the device to use mobile data while roaming. + Allow the device to use mobile data while roaming. (!) Please post feedback to GitHub if this works correctly. Run on Wi-Fi Run when device is connected to a Wi-Fi or ethernet network. From 589665eea337ba3e8295b5d631a818769c057367 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Thu, 11 Jul 2019 17:50:33 +0200 Subject: [PATCH 6/7] Update strings.xml --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c74e82f8a..c7fa32b21 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -432,7 +432,7 @@ Please report any problems you encounter via Github. Run when device is connected via the mobile data network. Warning: This can consume a lot of data from your mobile operator data plan if you sync large amounts of data. Run while roaming - Allow the device to use mobile data while roaming. (!) Please post feedback to GitHub if this works correctly. + Allow Syncthing to use mobile data while roaming. (!) Please post feedback to GitHub if this works correctly. Run on Wi-Fi Run when device is connected to a Wi-Fi or ethernet network. From ea71f1167a22105752a594664a2533d9370ef662 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Thu, 11 Jul 2019 17:56:45 +0200 Subject: [PATCH 7/7] Imported de translation --- app/src/main/res/values-de/strings.xml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 6f0531090..9a58bce2b 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -428,6 +428,9 @@ Bitte melden Sie auftretende Probleme via GitHub. Starte bei mobiler Datenverbindung Starte, wenn das Gerät über das mobile Datennetzwerk verbunden ist. Warnung: Wenn Du große Datenmengen synchronisierst, kann dies einen hohen Verbrauch deines mobilen Datentarifs verursachen. + Starte während Roaming + Ermögliche Syncthing, mobile Daten während dem Roaming zu verwenden. (!) Bitte hinterlasse ein Feedback bei GitHub, wenn dies korrekt funktioniert. + Starte bei WLAN-Verbindung Starte, wenn das Gerät mit einem WLAN- oder Kabel-Netzwerk verbunden ist. @@ -779,9 +782,17 @@ Bitte melden Sie auftretende Probleme via GitHub. Telefon wird nicht batteriebetrieben Syncthing läuft nicht, weil das Telefon im Energiesparmodus ist. Syncthing läuft nicht, weil die Android-Kachel \"Automatische Datensynchronisation\" ausgeschaltet ist. + + Syncthing wurde nicht konfiguriert, die mobile Datenverbindung zu nutzen. - Syncthing läuft, weil die mobile Datenverbindung aufgebaut ist. + Syncthing darf die mobile Datenverbindung nutzen. Syncthing darf bei mobiler Datenverbindung laufen, jedoch sind mobile Daten nicht verbunden. + + + Syncthing darf bei mobilen Roaming- und Nicht-Roaming-Datenverbindungen ausgeführt werden. + Syncthing darf auf mobilen Datenverbindungen ohne Roaming ausgeführt werden. Die aktive Verbindung ist ohne Roaming. + Syncthing läuft nicht, da verboten wurde, dass es auf mobilen Datenverbindungen mit Roaming läuft. + Syncthing wurde verboten, die WLAN- oder Kabel-Verbindung zu nutzen. Syncthing darf bei WLAN-Verbindung laufen und WLAN ist gerade verbunden. Syncthing darf bei WLAN-Verbindung laufen, jedoch ist WLAN gerade nicht verbunden oder das Telefon befindet sich im Flugzeugmodus.