mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Listen for wifi AP state changes.
We won't necessarily receive a connectivity change event when the wifi AP is enabled.
This commit is contained in:
@@ -20,12 +20,15 @@ import javax.annotation.Nullable;
|
|||||||
import static android.content.Context.CONNECTIVITY_SERVICE;
|
import static android.content.Context.CONNECTIVITY_SERVICE;
|
||||||
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 java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static org.briarproject.bramble.util.AndroidUtils.logNetworkState;
|
import static org.briarproject.bramble.util.AndroidUtils.logNetworkState;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class AndroidLanTcpPlugin extends LanTcpPlugin {
|
class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||||
|
|
||||||
|
private static final String WIFI_AP_STATE_ACTION =
|
||||||
|
"android.net.wifi.WIFI_AP_STATE_CHANGED";
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(AndroidLanTcpPlugin.class.getName());
|
Logger.getLogger(AndroidLanTcpPlugin.class.getName());
|
||||||
|
|
||||||
@@ -47,7 +50,9 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
|||||||
running = true;
|
running = true;
|
||||||
// Register to receive network status events
|
// Register to receive network status events
|
||||||
networkStateReceiver = new NetworkStateReceiver();
|
networkStateReceiver = new NetworkStateReceiver();
|
||||||
IntentFilter filter = new IntentFilter(CONNECTIVITY_ACTION);
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(CONNECTIVITY_ACTION);
|
||||||
|
filter.addAction(WIFI_AP_STATE_ACTION);
|
||||||
appContext.registerReceiver(networkStateReceiver, filter);
|
appContext.registerReceiver(networkStateReceiver, filter);
|
||||||
if (LOG.isLoggable(INFO)) logNetworkState(appContext, LOG);
|
if (LOG.isLoggable(INFO)) logNetworkState(appContext, LOG);
|
||||||
}
|
}
|
||||||
@@ -66,12 +71,18 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
|||||||
public void onReceive(Context ctx, Intent i) {
|
public void onReceive(Context ctx, Intent i) {
|
||||||
if (!running) return;
|
if (!running) return;
|
||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
LOG.info("Connectivity change");
|
if (CONNECTIVITY_ACTION.equals(i.getAction())) {
|
||||||
Bundle extras = i.getExtras();
|
LOG.info("Connectivity change");
|
||||||
if (extras != null) {
|
Bundle extras = i.getExtras();
|
||||||
LOG.info("Extras:");
|
if (extras != null) {
|
||||||
for (String key : extras.keySet())
|
LOG.info("Extras:");
|
||||||
LOG.info("\t" + key + ": " + extras.get(key));
|
for (String key : extras.keySet())
|
||||||
|
LOG.info("\t" + key + ": " + extras.get(key));
|
||||||
|
}
|
||||||
|
} else if (WIFI_AP_STATE_ACTION.equals(i.getAction())) {
|
||||||
|
int state = i.getIntExtra(EXTRA_WIFI_STATE, 0);
|
||||||
|
if (state == 13) LOG.info("Wifi AP enabled");
|
||||||
|
else LOG.info("Wifi AP state " + state);
|
||||||
}
|
}
|
||||||
logNetworkState(appContext, LOG);
|
logNetworkState(appContext, LOG);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user