I see that my calling thread hangs in its own code when calling WifiManager.enableNetwork (). So far, I was able to reproduce this hang on a Motorola Xoom tablet running Android 3.2.1. I tested on several other phones and tablets (all of them were either Froyo or Gingerbread) and did not see the problem. Xoom is the only dual-core device I need to test (and I reproduced the problem on two different Xooms), so it seems to me that I am facing some very subtle Android stream requirements when interacting with WifiManager. The stack trace in which my calling thread hangs:
BinderProxy.transact(int, Parcel, Parcel, int) line: not available [native method] IWifiManager$Stub$Proxy.enableNetwork(int, boolean) line: 513 WifiManager.enableNetwork(int, boolean) line: 587
My application is trying to connect to a known Wi-Fi access point, perform some tests, and then reconnect the device to its original access point (if it was previously connected). Before establishing the connection, we already checked that Wi-Fi is turned on, and we performed a check to check if our SSID for the access point was found. This connection setup code runs in AsyncTask and looks something like this:
... private WifiManager mWifiManager; private List<WifiConfiguration> mConfiguredNets = new ArrayList<WifiConfiguration>(); private Object mConnectMonitor = new Object(); private NetworkInfo.State mNetworkState = State.UNKNOWN; private final BroadcastReceiver mConnectionStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context inContext, final Intent inIntent) { final String action = inIntent.getAction(); if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { NetworkInfo ni = (NetworkInfo)inIntent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); State state = ni.getState(); if (state == State.CONNECTED) { synchronized (mConnectMonitor) { mNetworkState = state; mConnectMonitor.notify(); } } } } }; public void runninInAsyncTask(Context activityContext, int networkID) { mWifiManager = (WifiManager)activityContext.getSystemService(Context.WIFI_SERVICE);
This code was based on the Wifi settings menu code in the open source Android Gingerbread. Is there anything missing about calling WifiManager.enableNetwork () that I am missing? Do I need to run it on a specific thread? I tried to make sure enableNetwork () is called in the user interface thread (by moving the logic to the broadcast receiver). It seemed to help a bit, but I was still able to reproduce the hang. Maybe this is something special for Honeycomb? Right now, these 2 Xooms are the only Honeycomb devices I have for testing, so they are the only data points that I have.
FROM
source share