Skip to content
Snippets Groups Projects
Verified Commit 16d56535 authored by akwizgran's avatar akwizgran
Browse files

Check connectivity after all AP state changes.

parent dcd6fda0
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,6 @@ import static android.content.Intent.ACTION_SCREEN_OFF; ...@@ -29,7 +29,6 @@ import static android.content.Intent.ACTION_SCREEN_OFF;
import static android.content.Intent.ACTION_SCREEN_ON; import static android.content.Intent.ACTION_SCREEN_ON;
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
import static android.net.ConnectivityManager.TYPE_WIFI; import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.wifi.WifiManager.EXTRA_WIFI_STATE;
import static android.os.Build.VERSION.SDK_INT; import static android.os.Build.VERSION.SDK_INT;
import static android.os.PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED; import static android.os.PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED;
import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.MINUTES;
...@@ -44,7 +43,6 @@ class AndroidNetworkManager implements NetworkManager, Service { ...@@ -44,7 +43,6 @@ class AndroidNetworkManager implements NetworkManager, Service {
// See android.net.wifi.WifiManager // See android.net.wifi.WifiManager
private static final String WIFI_AP_STATE_CHANGED_ACTION = private static final String WIFI_AP_STATE_CHANGED_ACTION =
"android.net.wifi.WIFI_AP_STATE_CHANGED"; "android.net.wifi.WIFI_AP_STATE_CHANGED";
private static final int WIFI_AP_STATE_ENABLED = 13;
private final ScheduledExecutorService scheduler; private final ScheduledExecutorService scheduler;
private final EventBus eventBus; private final EventBus eventBus;
...@@ -114,18 +112,17 @@ class AndroidNetworkManager implements NetworkManager, Service { ...@@ -114,18 +112,17 @@ class AndroidNetworkManager implements NetworkManager, Service {
String action = i.getAction(); String action = i.getAction();
if (LOG.isLoggable(INFO)) LOG.info("Received broadcast " + action); if (LOG.isLoggable(INFO)) LOG.info("Received broadcast " + action);
updateConnectionStatus(); updateConnectionStatus();
if (isSleepOrDozeEvent(i)) { if (isSleepOrDozeEvent(action)) {
// Allow time for the network to be enabled or disabled
scheduleConnectionStatusUpdate(1, MINUTES); scheduleConnectionStatusUpdate(1, MINUTES);
} else if (isApEnabledEvent(i)) { } else if (isApEvent(action)) {
// The state change may be broadcast before the AP address is // The state change may be broadcast before the AP address is
// visible, so delay handling the event // visible, so delay handling the event
// TODO: Wait longer, and also wait after stopping - see #1301 scheduleConnectionStatusUpdate(5, SECONDS);
scheduleConnectionStatusUpdate(1, SECONDS);
} }
} }
private boolean isSleepOrDozeEvent(Intent i) { private boolean isSleepOrDozeEvent(String action) {
String action = i.getAction();
boolean isSleep = ACTION_SCREEN_ON.equals(action) || boolean isSleep = ACTION_SCREEN_ON.equals(action) ||
ACTION_SCREEN_OFF.equals(action); ACTION_SCREEN_OFF.equals(action);
boolean isDoze = SDK_INT >= 23 && boolean isDoze = SDK_INT >= 23 &&
...@@ -133,9 +130,8 @@ class AndroidNetworkManager implements NetworkManager, Service { ...@@ -133,9 +130,8 @@ class AndroidNetworkManager implements NetworkManager, Service {
return isSleep || isDoze; return isSleep || isDoze;
} }
private boolean isApEnabledEvent(Intent i) { private boolean isApEvent(String action) {
return WIFI_AP_STATE_CHANGED_ACTION.equals(i.getAction()) && return WIFI_AP_STATE_CHANGED_ACTION.equals(action);
i.getIntExtra(EXTRA_WIFI_STATE, 0) == WIFI_AP_STATE_ENABLED;
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment