views:

213

answers:

2

Hi, I have written some software which uses Wifi as a possible internet-connection medium.. I did notice though, that after some time (I am guessing around the 15-20 minutes) after the device has gone into power save mode (anyways when the screen has gone black) the Wifi connection will simply be dropped, even though it is still being used :( This on a ADP 2 (thus a Google Ion with Android 1.6)... I was able to get the following Log :

06-10 15:04:27.009: DEBUG/WifiService(72): got ACTION_DEVICE_IDLE
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: ERROR/wpa_supplicant(538): Set_key: Wrong Key
06-10 15:04:27.069: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-STATE-CHANGE id=0 state=8]
06-10 15:04:27.079: VERBOSE/WifiStateTracker(72): Changing supplicant state: COMPLETED ==> DORMANT
06-10 15:04:27.079: DEBUG/WifiStateTracker(72): Deconfiguring interface and stopping DHCP
06-10 15:04:27.099: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys]
06-10 15:04:27.099: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-STATE-CHANGE id=-1 state=8]
06-10 15:04:27.139: WARN/Smack/Packet(169): notify conn break (IOEx), close connection
06-10 15:04:27.139: DEBUG/Smack(169): [XMPPConn] close connection, notifyClosed=false
06-10 15:04:27.139: ERROR/MediaPlayer(390): error (1, -17)
06-10 15:04:27.139: ERROR/MediaPlayer(390): Error (1,-17)
06-10 15:04:28.109: VERBOSE/WifiMonitor(72): Event [CTRL-EVENT-DRIVER-STATE STOPPED]
06-10 15:04:28.129: VERBOSE/WifiStateTracker(72): New network state is DISCONNECTED
06-10 15:04:28.129: VERBOSE/WifiStateTracker(72): Changing supplicant state: DORMANT ==> DORMANT
06-10 15:04:28.189: INFO/MediaUploader(199): No need to wake up
06-10 15:04:28.189: DEBUG/GpsLocationProvider(72): updateNetworkState available
06-10 15:04:28.189: DEBUG/GpsLocationProvider(72): NetworkThread wait for 4484259ms
06-10 15:04:28.289: DEBUG/NetworkLocationProvider(72): onDataConnectionStateChanged 3
06-10 15:04:28.299: DEBUG/GpsLocationProvider(72): state: CONNECTING apnName: iinternet reason: null
06-10 15:04:32.979: DEBUG/NetworkLocationProvider(72): onDataConnectionStateChanged 3
06-10 15:04:33.029: DEBUG/GpsLocationProvider(72): state: CONNECTED apnName: iinternet reason: null
06-10 15:04:33.099: DEBUG/GpsLocationProvider(72): updateNetworkState available
06-10 15:04:33.099: DEBUG/GpsLocationProvider(72): NetworkThread wait for 4479355ms
06-10 15:04:33.129: INFO/MediaUploader(199): No need to wake up
06-10 15:04:33.299: INFO/ActivityManager(72): Stopping service: com.android.mms/.transaction.TransactionService
06-10 15:04:33.339: ERROR/TransactionSettings(156): Invalid APN setting: MMSC is empty
06-10 15:04:33.419: INFO/ActivityManager(72): Stopping service: com.android.providers.downloads/.DownloadService
06-10 15:04:38.309: DEBUG/dalvikvm(199): GC freed 301 objects / 19232 bytes in 92ms
06-10 15:04:43.349: DEBUG/dalvikvm(216): GC freed 1430 objects / 84920 bytes in 121ms
06-10 15:04:48.319: DEBUG/dalvikvm(156): GC freed 323 objects / 15152 bytes in 96ms

Is this some kind of known bug/feature ? If so how to get around it ? Also is there someway to actually intercept this EVENT and then soimehow ignore it or re-setup a wifi connection ? Thanks in advance

+3  A: 

You need to create a wifi lock. Here is how you do it:

WifiManager wifimanager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
WifiLock lock = wifimanager.createWifiLock("my_lock");

lock.acquire();

// your code here

lock.release();

Note you should only create a wifi lock when you're actively using wifi (i.e. downloading a large file), otherwise you will needlessly impact battery life.

irlennard
hhmm should I be checking if a wifi connection is available/set-up beforehand or can I just place a lock and if there is no wifi-connection the API will take care of that ?
TiGer
Good question. The docs don't mention it, but I imagine the lock has no effect when there is no wifi connection.
irlennard
A: 

I get a SecurityException when I call WifiLock.acquire(). Am I missing a uses-permission in my manifest or is there something I need to check beforehand in code? I'm assuming it has to do with the advanced settings in the wifi settings page set to NEVER.

Josh P
ur gonna need :<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/><uses-permission android:name="android.permission.WAKE_LOCK"/>
TiGer
Thanks I'll give that a try tonight and let everyone know how it goes. That sounds like what I was looking for anyway.
Josh P