mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 06:11:19 +00:00
* Tell user if location is disabled but "run on selected" WiFi is enabled. * Update status tab while user looks at the UI and syncthing is disabled * UI: Offer a solution
This commit is contained in:
parent
12bc08c6dd
commit
28040869e6
3 changed files with 45 additions and 26 deletions
|
@ -226,9 +226,6 @@ public class StatusFragment extends ListFragment implements SyncthingService.OnS
|
||||||
* while the user is looking at the current tab.
|
* while the user is looking at the current tab.
|
||||||
*/
|
*/
|
||||||
private void onTimerEvent() {
|
private void onTimerEvent() {
|
||||||
if (mServiceState != SyncthingService.State.ACTIVE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MainActivity mainActivity = (MainActivity) getActivity();
|
MainActivity mainActivity = (MainActivity) getActivity();
|
||||||
if (mainActivity == null) {
|
if (mainActivity == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -236,6 +233,10 @@ public class StatusFragment extends ListFragment implements SyncthingService.OnS
|
||||||
if (mainActivity.isFinishing()) {
|
if (mainActivity.isFinishing()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (mServiceState != SyncthingService.State.ACTIVE) {
|
||||||
|
updateStatus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
RestApi restApi = mainActivity.getApi();
|
RestApi restApi = mainActivity.getApi();
|
||||||
if (restApi == null) {
|
if (restApi == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -243,6 +244,7 @@ public class StatusFragment extends ListFragment implements SyncthingService.OnS
|
||||||
Log.v(TAG, "Invoking REST status queries");
|
Log.v(TAG, "Invoking REST status queries");
|
||||||
restApi.getSystemStatus(this::onReceiveSystemStatus);
|
restApi.getSystemStatus(this::onReceiveSystemStatus);
|
||||||
restApi.getConnections(this::onReceiveConnections);
|
restApi.getConnections(this::onReceiveConnections);
|
||||||
|
// onReceiveSystemStatus, onReceiveConnections will call {@link #updateStatus}.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -227,30 +227,34 @@ public class RunConditionMonitor {
|
||||||
// Run on wifi.
|
// Run on wifi.
|
||||||
if (prefRunOnWifi) {
|
if (prefRunOnWifi) {
|
||||||
if (isWifiOrEthernetConnection()) {
|
if (isWifiOrEthernetConnection()) {
|
||||||
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_on_wifi);
|
try {
|
||||||
if (prefRunOnMeteredWifi) {
|
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_on_wifi);
|
||||||
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_on_metered_nonmetered_wifi);
|
if (prefRunOnMeteredWifi) {
|
||||||
// We are on non-metered or metered wifi. Check if wifi whitelist run condition is met.
|
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_on_metered_nonmetered_wifi);
|
||||||
if (wifiWhitelistConditionMet(prefWifiWhitelistEnabled, whitelistedWifiSsids)) {
|
// We are on non-metered or metered wifi. Check if wifi whitelist run condition is met.
|
||||||
Log.v(TAG, "decideShouldRun: prefRunOnWifi && isWifiOrEthernetConnection && prefRunOnMeteredWifi && wifiWhitelistConditionMet");
|
|
||||||
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_on_whitelisted_wifi);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_not_on_whitelisted_wifi);
|
|
||||||
} else {
|
|
||||||
// Check if we are on a non-metered wifi.
|
|
||||||
if (!isMeteredNetworkConnection()) {
|
|
||||||
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_on_nonmetered_wifi);
|
|
||||||
// Check if wifi whitelist run condition is met.
|
|
||||||
if (wifiWhitelistConditionMet(prefWifiWhitelistEnabled, whitelistedWifiSsids)) {
|
if (wifiWhitelistConditionMet(prefWifiWhitelistEnabled, whitelistedWifiSsids)) {
|
||||||
Log.v(TAG, "decideShouldRun: prefRunOnWifi && isWifiOrEthernetConnection && !prefRunOnMeteredWifi && !isMeteredNetworkConnection && wifiWhitelistConditionMet");
|
Log.v(TAG, "decideShouldRun: prefRunOnWifi && isWifiOrEthernetConnection && prefRunOnMeteredWifi && wifiWhitelistConditionMet");
|
||||||
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_on_whitelisted_wifi);
|
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_on_whitelisted_wifi);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_not_on_whitelisted_wifi);
|
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_not_on_whitelisted_wifi);
|
||||||
} else {
|
} else {
|
||||||
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_not_nonmetered_wifi);
|
// Check if we are on a non-metered wifi.
|
||||||
|
if (!isMeteredNetworkConnection()) {
|
||||||
|
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_on_nonmetered_wifi);
|
||||||
|
// Check if wifi whitelist run condition is met.
|
||||||
|
if (wifiWhitelistConditionMet(prefWifiWhitelistEnabled, whitelistedWifiSsids)) {
|
||||||
|
Log.v(TAG, "decideShouldRun: prefRunOnWifi && isWifiOrEthernetConnection && !prefRunOnMeteredWifi && !isMeteredNetworkConnection && wifiWhitelistConditionMet");
|
||||||
|
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_on_whitelisted_wifi);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_not_on_whitelisted_wifi);
|
||||||
|
} else {
|
||||||
|
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_not_nonmetered_wifi);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (LocationUnavailableException e) {
|
||||||
|
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_location_unavailable);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_not_on_wifi);
|
mRunDecisionExplanation += "\n" + res.getString(R.string.reason_not_on_wifi);
|
||||||
|
@ -283,8 +287,8 @@ public class RunConditionMonitor {
|
||||||
* Return whether the wifi whitelist run condition is met.
|
* Return whether the wifi whitelist run condition is met.
|
||||||
* Precondition: An active wifi connection has been detected.
|
* Precondition: An active wifi connection has been detected.
|
||||||
*/
|
*/
|
||||||
private boolean wifiWhitelistConditionMet(boolean prefWifiWhitelistEnabled,
|
private boolean wifiWhitelistConditionMet (boolean prefWifiWhitelistEnabled,
|
||||||
Set<String> whitelistedWifiSsids) {
|
Set<String> whitelistedWifiSsids) throws LocationUnavailableException {
|
||||||
if (!prefWifiWhitelistEnabled) {
|
if (!prefWifiWhitelistEnabled) {
|
||||||
Log.v(TAG, "handleWifiWhitelist: !prefWifiWhitelistEnabled");
|
Log.v(TAG, "handleWifiWhitelist: !prefWifiWhitelistEnabled");
|
||||||
return true;
|
return true;
|
||||||
|
@ -403,7 +407,8 @@ public class RunConditionMonitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isWifiConnectionWhitelisted(Set<String> whitelistedSsids) {
|
private boolean isWifiConnectionWhitelisted(Set<String> whitelistedSsids)
|
||||||
|
throws LocationUnavailableException{
|
||||||
WifiManager wifiManager = (WifiManager) mContext.getApplicationContext()
|
WifiManager wifiManager = (WifiManager) mContext.getApplicationContext()
|
||||||
.getSystemService(Context.WIFI_SERVICE);
|
.getSystemService(Context.WIFI_SERVICE);
|
||||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||||
|
@ -413,11 +418,22 @@ public class RunConditionMonitor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String wifiSsid = wifiInfo.getSSID();
|
String wifiSsid = wifiInfo.getSSID();
|
||||||
if (wifiSsid == null) {
|
if (wifiSsid == null || wifiSsid.equals("<unknown ssid>")) {
|
||||||
Log.w(TAG, "isWifiConnectionWhitelisted: Got null SSID. Try to enable android location service.");
|
throw new LocationUnavailableException("isWifiConnectionWhitelisted: Got null SSID. Try to enable android location service.");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return whitelistedSsids.contains(wifiSsid);
|
return whitelistedSsids.contains(wifiSsid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class LocationUnavailableException extends Exception {
|
||||||
|
|
||||||
|
public LocationUnavailableException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocationUnavailableException(String message, Throwable throwable) {
|
||||||
|
super(message, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -634,6 +634,7 @@ Please report any problems you encounter via Github.</string>
|
||||||
<string name="reason_not_on_whitelisted_wifi">Syncthing is not running as the current WiFi network\'s name is not whitelisted.</string>
|
<string name="reason_not_on_whitelisted_wifi">Syncthing is not running as the current WiFi network\'s name is not whitelisted.</string>
|
||||||
<string name="reason_on_nonmetered_wifi">Syncthing is allowed to run on non-metered WiFi connections. The active WiFi connection is non-metered.</string>
|
<string name="reason_on_nonmetered_wifi">Syncthing is allowed to run on non-metered WiFi connections. The active WiFi connection is non-metered.</string>
|
||||||
<string name="reason_not_nonmetered_wifi">Syncthing is not running as you disallowed it to run on metered WiFi connections.</string>
|
<string name="reason_not_nonmetered_wifi">Syncthing is not running as you disallowed it to run on metered WiFi connections.</string>
|
||||||
|
<string name="reason_location_unavailable">You enabled \'Run on selected WiFi networks\' in the settings. Android location services are currently turned off. According to Android restrictions, Syncthing cannot determine the current WiFi network name to decide if it should run. Solution: Turn location on and reconnect WiFi.</string>
|
||||||
<string name="reason_on_flight_mode">Syncthing is running as you allowed it to run when flight mode is active.</string>
|
<string name="reason_on_flight_mode">Syncthing is running as you allowed it to run when flight mode is active.</string>
|
||||||
|
|
||||||
<!-- SyncthingService -->
|
<!-- SyncthingService -->
|
||||||
|
|
Loading…
Reference in a new issue