|
20 | 20 | import android.content.BroadcastReceiver;
|
21 | 21 | import android.content.Context;
|
22 | 22 | import android.content.Intent;
|
| 23 | +import android.net.NetworkInfo; |
23 | 24 | import android.net.wifi.WifiManager;
|
24 | 25 | import android.support.annotation.NonNull;
|
25 | 26 |
|
@@ -68,17 +69,19 @@ void reschedule(@NonNull Context context, @NonNull Intent broadcastIntent, @NonN
|
68 | 69 | broadcastIntent.getAction().equals(Intent.ACTION_MY_PACKAGE_REPLACED)) {
|
69 | 70 | context.startService(eventServiceIntent);
|
70 | 71 | logger.info("Rescheduling event flushing if necessary");
|
71 |
| - } else if (broadcastIntent.getAction().equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION) |
72 |
| - && broadcastIntent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false)) { |
| 72 | + } else if (broadcastIntent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { |
| 73 | + NetworkInfo networkInfo = broadcastIntent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); |
| 74 | + if (networkInfo.getState() == NetworkInfo.State.CONNECTING) { |
73 | 75 |
|
74 |
| - if (serviceScheduler.isScheduled(eventServiceIntent)) { |
75 |
| - // If we get wifi and the event flushing service is scheduled preemptively |
76 |
| - // flush events before the next interval occurs. If sending fails even |
77 |
| - // with wifi the service will be rescheduled on the interval. |
78 |
| - // Wifi connection state changes all the time and starting services is expensive |
79 |
| - // so it's important to only do this if we have stored events. |
80 |
| - context.startService(eventServiceIntent); |
81 |
| - logger.info("Preemptively flushing events since wifi became available"); |
| 76 | + if (serviceScheduler.isScheduled(eventServiceIntent)) { |
| 77 | + // If we get wifi and the event flushing service is scheduled preemptively |
| 78 | + // flush events before the next interval occurs. If sending fails even |
| 79 | + // with wifi the service will be rescheduled on the interval. |
| 80 | + // Wifi connection state changes all the time and starting services is expensive |
| 81 | + // so it's important to only do this if we have stored events. |
| 82 | + context.startService(eventServiceIntent); |
| 83 | + logger.info("Preemptively flushing events since wifi became available"); |
| 84 | + } |
82 | 85 | }
|
83 | 86 | } else {
|
84 | 87 | logger.warn("Received unsupported broadcast action to event rescheduler");
|
|
0 commit comments