1 /* 2 * wpadebug - wpa_supplicant and Wi-Fi debugging app for Android 3 * Copyright (c) 2013, Jouni Malinen <j@w1.fi> 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9 package w1.fi.wpadebug; 10 11 import android.content.BroadcastReceiver; 12 import android.content.Context; 13 import android.content.Intent; 14 import android.net.NetworkInfo; 15 import android.net.wifi.SupplicantState; 16 import android.net.wifi.WifiInfo; 17 import android.os.Bundle; 18 import android.util.Log; 19 20 public class WifiReceiver extends BroadcastReceiver 21 { 22 private static final String TAG = "wpadebug"; 23 24 @Override onReceive(Context c, Intent intent)25 public void onReceive(Context c, Intent intent) 26 { 27 String act = intent.getAction(); 28 Log.d(TAG, "Received broadcast intent: action=" + act); 29 30 Bundle bundles = intent.getExtras(); 31 if (bundles == null) 32 return; 33 34 if (bundles.containsKey("bssid")) { 35 String val; 36 val = intent.getStringExtra("bssid"); 37 if (val != null) 38 Log.d(TAG, " bssid: " + val); 39 } 40 41 if (bundles.containsKey("networkInfo")) { 42 NetworkInfo info; 43 info = (NetworkInfo) intent.getParcelableExtra("networkInfo"); 44 if (info != null) 45 Log.d(TAG, " networkInfo: " + info); 46 } 47 48 if (bundles.containsKey("newRssi")) { 49 int val; 50 val = intent.getIntExtra("newRssi", -1); 51 Log.d(TAG, " newRssi: " + val); 52 } 53 54 if (bundles.containsKey("newState")) { 55 SupplicantState state; 56 state = (SupplicantState) intent.getParcelableExtra("newState"); 57 if (state != null) 58 Log.d(TAG, " newState: " + state); 59 } 60 61 if (bundles.containsKey("previous_wifi_state")) { 62 int wifi_state; 63 wifi_state = intent.getIntExtra("previous_wifi_state", -1); 64 if (wifi_state != -1) 65 Log.d(TAG, " previous_wifi_state: " + wifi_state); 66 } 67 68 if (bundles.containsKey("connected")) { 69 boolean connected; 70 connected = intent.getBooleanExtra("connected", false); 71 Log.d(TAG, " connected: " + connected); 72 } 73 74 if (bundles.containsKey("supplicantError")) { 75 int error; 76 error = intent.getIntExtra("supplicantError", -1); 77 if (error != -1) 78 Log.d(TAG, " supplicantError: " + error); 79 } 80 81 if (bundles.containsKey("wifiInfo")) { 82 WifiInfo info; 83 info = (WifiInfo) intent.getParcelableExtra("wifiInfo"); 84 if (info != null) 85 Log.d(TAG, " wifiInfo: " + info); 86 } 87 88 if (bundles.containsKey("wifi_state")) { 89 int wifi_state; 90 wifi_state = intent.getIntExtra("wifi_state", -1); 91 if (wifi_state != -1) 92 Log.d(TAG, " wifi_state: " + wifi_state); 93 } 94 } 95 } 96