Don't try to start swap again if we have gone from network -> no network.
This commit is contained in:
parent
94e3cf85ba
commit
8364aa15f1
@ -441,14 +441,18 @@ public class SwapService extends Service {
|
||||
/**
|
||||
* Handles checking if the {@link SwapService} is running, and only restarts it if it was running.
|
||||
*/
|
||||
public void restartWifiIfEnabled() {
|
||||
public void stopWifiIfEnabled(final boolean restartAfterStopping) {
|
||||
if (wifiSwap.isConnected()) {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Utils.debugLog(TAG, "Restarting WiFi swap service");
|
||||
Utils.debugLog(TAG, "Stopping the currently running WiFi swap service (on background thread)");
|
||||
wifiSwap.stop();
|
||||
wifiSwap.start();
|
||||
|
||||
if (restartAfterStopping) {
|
||||
Utils.debugLog(TAG, "Restarting WiFi swap service after stopping (still on background thread)");
|
||||
wifiSwap.start();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.execute();
|
||||
@ -632,7 +636,7 @@ public class SwapService extends Service {
|
||||
@Override
|
||||
public void onPreferenceChange() {
|
||||
Log.i(TAG, "Swap over HTTPS preference changed.");
|
||||
restartWifiIfEnabled();
|
||||
stopWifiIfEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
@ -640,7 +644,8 @@ public class SwapService extends Service {
|
||||
private final BroadcastReceiver onWifiChange = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent i) {
|
||||
restartWifiIfEnabled();
|
||||
boolean hasIp = FDroidApp.ipAddressString != null;
|
||||
stopWifiIfEnabled(hasIp);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -181,7 +181,7 @@ public class WifiStateChangeService extends Service {
|
||||
getApplicationContext().bindService(swapService, new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
((SwapService.Binder) service).getService().restartWifiIfEnabled();
|
||||
((SwapService.Binder) service).getService().stopWifiIfEnabled(true);
|
||||
getApplicationContext().unbindService(this);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user