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.
|
* 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()) {
|
if (wifiSwap.isConnected()) {
|
||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
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.stop();
|
||||||
|
|
||||||
|
if (restartAfterStopping) {
|
||||||
|
Utils.debugLog(TAG, "Restarting WiFi swap service after stopping (still on background thread)");
|
||||||
wifiSwap.start();
|
wifiSwap.start();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
@ -632,7 +636,7 @@ public class SwapService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onPreferenceChange() {
|
public void onPreferenceChange() {
|
||||||
Log.i(TAG, "Swap over HTTPS preference changed.");
|
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() {
|
private final BroadcastReceiver onWifiChange = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent i) {
|
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() {
|
getApplicationContext().bindService(swapService, new ServiceConnection() {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
((SwapService.Binder) service).getService().restartWifiIfEnabled();
|
((SwapService.Binder) service).getService().stopWifiIfEnabled(true);
|
||||||
getApplicationContext().unbindService(this);
|
getApplicationContext().unbindService(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user