wpadebug: Add broadcast intent receiver for Wi-Fi events

This makes it easier to debug Android framework actions with all the
related broadcast intents being logged.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-05-12 21:06:59 +03:00
parent e679f140b9
commit 53aafe75e0
2 changed files with 105 additions and 0 deletions

View File

@ -53,5 +53,15 @@
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<receiver android:name="w1.fi.wpadebug.WifiReceiver">
<intent-filter>
<action android:name="android.net.wifi.STATE_CHANGE" />
<action android:name="android.net.wifi.RSSI_CHANGED" />
<action android:name="android.net.wifi.SCAN_RESULTS" />
<action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />
<action android:name="android.net.wifi.supplicant.STATE_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>

View File

@ -0,0 +1,95 @@
/*
* wpadebug - wpa_supplicant and Wi-Fi debugging app for Android
* Copyright (c) 2013, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
*/
package w1.fi.wpadebug;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo;
import android.os.Bundle;
import android.util.Log;
public class WifiReceiver extends BroadcastReceiver
{
private static final String TAG = "wpadebug";
@Override
public void onReceive(Context c, Intent intent)
{
String act = intent.getAction();
Log.d(TAG, "Received broadcast intent: action=" + act);
Bundle bundles = intent.getExtras();
if (bundles == null)
return;
if (bundles.containsKey("bssid")) {
String val;
val = intent.getStringExtra("bssid");
if (val != null)
Log.d(TAG, " bssid: " + val);
}
if (bundles.containsKey("networkInfo")) {
NetworkInfo info;
info = (NetworkInfo) intent.getParcelableExtra("networkInfo");
if (info != null)
Log.d(TAG, " networkInfo: " + info);
}
if (bundles.containsKey("newRssi")) {
int val;
val = intent.getIntExtra("newRssi", -1);
Log.d(TAG, " newRssi: " + val);
}
if (bundles.containsKey("newState")) {
SupplicantState state;
state = (SupplicantState) intent.getParcelableExtra("newState");
if (state != null)
Log.d(TAG, " newState: " + state);
}
if (bundles.containsKey("previous_wifi_state")) {
int wifi_state;
wifi_state = intent.getIntExtra("previous_wifi_state", -1);
if (wifi_state != -1)
Log.d(TAG, " previous_wifi_state: " + wifi_state);
}
if (bundles.containsKey("connected")) {
boolean connected;
connected = intent.getBooleanExtra("connected", false);
Log.d(TAG, " connected: " + connected);
}
if (bundles.containsKey("supplicantError")) {
int error;
error = intent.getIntExtra("supplicantError", -1);
if (error != -1)
Log.d(TAG, " supplicantError: " + error);
}
if (bundles.containsKey("wifiInfo")) {
WifiInfo info;
info = (WifiInfo) intent.getParcelableExtra("wifiInfo");
if (info != null)
Log.d(TAG, " wifiInfo: " + info);
}
if (bundles.containsKey("wifi_state")) {
int wifi_state;
wifi_state = intent.getIntExtra("wifi_state", -1);
if (wifi_state != -1)
Log.d(TAG, " wifi_state: " + wifi_state);
}
}
}