mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-11 04:25:53 +00:00
Disable Syncthing in flight mode (fixes #1173)
... and allow to enable it on phone that have problems detecting wifi connection if the user manually enables one during flight mode.
This commit is contained in:
parent
7f187a18f3
commit
35d4421cbf
5 changed files with 23 additions and 2 deletions
|
@ -103,6 +103,7 @@ public class SettingsActivity extends SyncthingActivity {
|
||||||
private ListPreference mPowerSource;
|
private ListPreference mPowerSource;
|
||||||
private CheckBoxPreference mRunOnMobileData;
|
private CheckBoxPreference mRunOnMobileData;
|
||||||
private CheckBoxPreference mRunOnWifi;
|
private CheckBoxPreference mRunOnWifi;
|
||||||
|
private CheckBoxPreference mRunInFlightMode;
|
||||||
private WifiSsidPreference mWifiSsidWhitelist;
|
private WifiSsidPreference mWifiSsidWhitelist;
|
||||||
|
|
||||||
private Preference mCategorySyncthingOptions;
|
private Preference mCategorySyncthingOptions;
|
||||||
|
@ -167,6 +168,8 @@ public class SettingsActivity extends SyncthingActivity {
|
||||||
(CheckBoxPreference) findPreference(Constants.PREF_RUN_ON_WIFI);
|
(CheckBoxPreference) findPreference(Constants.PREF_RUN_ON_WIFI);
|
||||||
mWifiSsidWhitelist =
|
mWifiSsidWhitelist =
|
||||||
(WifiSsidPreference) findPreference(Constants.PREF_WIFI_SSID_WHITELIST);
|
(WifiSsidPreference) findPreference(Constants.PREF_WIFI_SSID_WHITELIST);
|
||||||
|
mRunInFlightMode =
|
||||||
|
(CheckBoxPreference) findPreference(Constants.PREF_RUN_IN_FLIGHT_MODE);
|
||||||
|
|
||||||
ListPreference languagePref = (ListPreference) findPreference(Languages.PREFERENCE_LANGUAGE);
|
ListPreference languagePref = (ListPreference) findPreference(Languages.PREFERENCE_LANGUAGE);
|
||||||
PreferenceScreen categoryBehaviour = (PreferenceScreen) findPreference("category_behaviour");
|
PreferenceScreen categoryBehaviour = (PreferenceScreen) findPreference("category_behaviour");
|
||||||
|
|
|
@ -18,6 +18,7 @@ public class Constants {
|
||||||
// to_be_deleted public static final String PREF_SYNC_ONLY_WIFI_SSIDS = "sync_only_wifi_ssids_set";
|
// to_be_deleted public static final String PREF_SYNC_ONLY_WIFI_SSIDS = "sync_only_wifi_ssids_set";
|
||||||
// to_be_deleted public static final String PREF_SYNC_ONLY_CHARGING = "sync_only_charging";
|
// to_be_deleted public static final String PREF_SYNC_ONLY_CHARGING = "sync_only_charging";
|
||||||
public static final String PREF_POWER_SOURCE = "power_source";
|
public static final String PREF_POWER_SOURCE = "power_source";
|
||||||
|
public static final String PREF_RUN_IN_FLIGHT_MODE = "run_in_flight_mode";
|
||||||
public static final String PREF_RESPECT_BATTERY_SAVING = "respect_battery_saving";
|
public static final String PREF_RESPECT_BATTERY_SAVING = "respect_battery_saving";
|
||||||
public static final String PREF_USE_ROOT = "use_root";
|
public static final String PREF_USE_ROOT = "use_root";
|
||||||
public static final String PREF_NOTIFICATION_TYPE = "notification_type";
|
public static final String PREF_NOTIFICATION_TYPE = "notification_type";
|
||||||
|
|
|
@ -103,6 +103,7 @@ public class RunConditionMonitor implements SharedPreferences.OnSharedPreference
|
||||||
Constants.PREF_RUN_ON_WIFI,
|
Constants.PREF_RUN_ON_WIFI,
|
||||||
Constants.PREF_WIFI_SSID_WHITELIST,
|
Constants.PREF_WIFI_SSID_WHITELIST,
|
||||||
Constants.PREF_POWER_SOURCE,
|
Constants.PREF_POWER_SOURCE,
|
||||||
|
Constants.PREF_RUN_IN_FLIGHT_MODE,
|
||||||
Constants.PREF_RESPECT_BATTERY_SAVING
|
Constants.PREF_RESPECT_BATTERY_SAVING
|
||||||
);
|
);
|
||||||
if (watched.contains(key)) {
|
if (watched.contains(key)) {
|
||||||
|
@ -156,13 +157,14 @@ public class RunConditionMonitor implements SharedPreferences.OnSharedPreference
|
||||||
*/
|
*/
|
||||||
private boolean decideShouldRun() {
|
private boolean decideShouldRun() {
|
||||||
// Get run conditions preferences.
|
// Get run conditions preferences.
|
||||||
boolean prefAlwaysRunInBackground = mPreferences.getBoolean(Constants.PREF_ALWAYS_RUN_IN_BACKGROUND, false);
|
|
||||||
boolean prefRespectPowerSaving = mPreferences.getBoolean(Constants.PREF_RESPECT_BATTERY_SAVING, true);
|
|
||||||
boolean prefRunOnMobileData= mPreferences.getBoolean(Constants.PREF_RUN_ON_MOBILE_DATA, false);
|
boolean prefRunOnMobileData= mPreferences.getBoolean(Constants.PREF_RUN_ON_MOBILE_DATA, false);
|
||||||
boolean prefRunOnWifi= mPreferences.getBoolean(Constants.PREF_RUN_ON_WIFI, true);
|
boolean prefRunOnWifi= mPreferences.getBoolean(Constants.PREF_RUN_ON_WIFI, true);
|
||||||
String prefPowerSource = mPreferences.getString(Constants.PREF_POWER_SOURCE, POWER_SOURCE_AC_BATTERY);
|
String prefPowerSource = mPreferences.getString(Constants.PREF_POWER_SOURCE, POWER_SOURCE_AC_BATTERY);
|
||||||
Set<String> whitelistedWifiSsids = mPreferences.getStringSet(Constants.PREF_WIFI_SSID_WHITELIST, new HashSet<>());
|
Set<String> whitelistedWifiSsids = mPreferences.getStringSet(Constants.PREF_WIFI_SSID_WHITELIST, new HashSet<>());
|
||||||
boolean prefWifiWhitelistEnabled = !whitelistedWifiSsids.isEmpty();
|
boolean prefWifiWhitelistEnabled = !whitelistedWifiSsids.isEmpty();
|
||||||
|
boolean prefRunInFlightMode = mPreferences.getBoolean(Constants.PREF_RUN_IN_FLIGHT_MODE, false);
|
||||||
|
boolean prefRespectPowerSaving = mPreferences.getBoolean(Constants.PREF_RESPECT_BATTERY_SAVING, true);
|
||||||
|
boolean prefAlwaysRunInBackground = mPreferences.getBoolean(Constants.PREF_ALWAYS_RUN_IN_BACKGROUND, false);
|
||||||
|
|
||||||
// PREF_POWER_SOURCE
|
// PREF_POWER_SOURCE
|
||||||
switch (prefPowerSource) {
|
switch (prefPowerSource) {
|
||||||
|
@ -209,6 +211,12 @@ public class RunConditionMonitor implements SharedPreferences.OnSharedPreference
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run in flight mode.
|
||||||
|
if (prefRunInFlightMode && isFlightMode()) {
|
||||||
|
Log.v(TAG, "decideShouldRun: prefRunInFlightMode && isFlightMode");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If none of the above run conditions matched, don't run.
|
* If none of the above run conditions matched, don't run.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -324,6 +324,9 @@ Please report any problems you encounter via Github.</string>
|
||||||
<string name="respect_battery_saving_title">Respect Android battery saving setting</string>
|
<string name="respect_battery_saving_title">Respect Android battery saving setting</string>
|
||||||
<string name="respect_battery_saving_summary">Disable Syncthing if battery saving is active</string>
|
<string name="respect_battery_saving_summary">Disable Syncthing if battery saving is active</string>
|
||||||
|
|
||||||
|
<string name="run_in_flight_mode_title">Run when device is in flight mode</string>
|
||||||
|
<string name="run_in_flight_mode_summary">Enable if your phone has problems detecting manually connected wifi during flight mode.</string>
|
||||||
|
|
||||||
<string name="service_settings_title">Service setting</string>
|
<string name="service_settings_title">Service setting</string>
|
||||||
<string name="service_settings_summary">Running Syncthing as a service adds a persistent notification to prevent it from being ended by android. Checking this option starts syncthing automatically when the phone boots.</string>
|
<string name="service_settings_summary">Running Syncthing as a service adds a persistent notification to prevent it from being ended by android. Checking this option starts syncthing automatically when the phone boots.</string>
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,12 @@
|
||||||
android:summary="@string/respect_battery_saving_summary"
|
android:summary="@string/respect_battery_saving_summary"
|
||||||
android:defaultValue="true" />
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="run_in_flight_mode"
|
||||||
|
android:title="@string/run_in_flight_mode_title"
|
||||||
|
android:summary="@string/run_in_flight_mode_summary"
|
||||||
|
android:defaultValue="false" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="static_service_settings"
|
android:key="static_service_settings"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
|
|
Loading…
Reference in a new issue