From 8364aa15f1d03352d8db3de85fd383943e2f457e Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Fri, 26 Feb 2016 09:11:00 +1100 Subject: [PATCH] Don't try to start swap again if we have gone from network -> no network. --- .../org/fdroid/fdroid/localrepo/SwapService.java | 15 ++++++++++----- .../fdroid/fdroid/net/WifiStateChangeService.java | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java b/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java index 0dc8380c3..d82934152 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java @@ -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() { @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); } }; diff --git a/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java b/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java index 0e18b6af7..ccf162460 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java +++ b/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java @@ -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); }