Unless you change the default wifi sleep policy. The question is slightly moot
1) you need to have wifi enabled, and it must be connected to an SSID for the handset to remember it. The handset will not (in a default state) connect to an unknown SSID.
2) the wifi sleep policy will disable the wifi after the inactivity period once the handset screen is turned off. The wifi sleep policy is under home > menu > settings > wireless & networks > wifi settings > menu > advanced. In the default configuration, the sleep policy is to turn off if the screen is off (after the IDLE timer runs out).
Code:
12-27 01:45:39.404: DEBUG/WifiService(1014): ACTION_SCREEN_OFF
12-27 01:45:39.435: DEBUG/WifiService(1014): setting ACTION_DEVICE_IDLE timer for 900000ms
900000 ms = 900 sec = 15 minutes. At the conclusion of this time, if no user input is given, the wifi will turn off. Data requests, will then be carried out by the 3g modem. You can see this some times, when you wake up the phone and your wifi isn't connected. You'll see the 3g icon, and it will then quickly switch back to the wifi connection (if available).
The difference between 3g or wifi, rather comes down to localized variables. The most power consumption on any radio (wifi or cellular) is at what transmit power does the radio need to obtain for the receiver to accept the transmission without errors. This in itself is factored by a slew of variables.
For some ppl. Keeping the phone on 3g will be better, others, keeping it on wifi might be better.
Keeping the phone from having to transmit and the cpu spun down to the lowest sleep state is what will keep the phone running the longest. But ... at that point its a brick that your paying for
BTW this is when the app spare parts is handy for looking at what is waking up the phone the most.
Pushed data:
Depending on the application, it can be handled differently, but within general terms. Push data such as say an IMAP IDLE command, keeps a long living TCP connection open and waits for the other end to send data. Since the phone is running a Linux networking stack, exploring the
/proc/sys/net/ipv4/tcp_keepalive_* settings will tell you how often the phone will "check" on the connection. Unless android or the handset manufacturer changed the settings, they default to 7200 seconds (2 hours), before the network stack will test to see if the TCP connection is still alive. The application can of course send data way before this to check for itself.
If your running a common DLINK or linksys WAP on your DSL or cable / fiber connection, the router itself may clean up these connections to the outside world in as little as 5 minutes. If the NAT/Firewall doesn't see traffic via that TCP connection for over 5 minutes, it may "forget" it. Sometimes this is directly configurable by the user. Sometimes not. If the NAT device is nicer it may have a soft limit, allowing the connection to persist until it starts running out of ports, in which it will start to reclaim these orphaned connections.
Applications that use lots and lots of connections can cause the stateful packet filter portion to starve of connection tracking slots, causing it to reclaim these older connections. P2P, bit-torrent, etc.. or just several users hammering away..... if the NAT / router is nice it will send a close FIN/RST tcp packet to the handset telling it that connection is no longer valid. Phone wakes up, tells the upper layers, and then the connection is re-established ...
Or the phone during its wake up period, checks up on the connection finding out its dead, and then again, has to re-up the connection.
This all happens whether its 3g or wifi... Wifi, in certain circumstances may make for a more hostile environment where the phone has to constantly wake up every few minutes to find out that its connection is dropped.
So really its comes down to... how often and at what TX power.
and .... then the phone after 15 minutes:
Code:
12-27 02:05:50.209: DEBUG/WifiService(1014): got ACTION_DEVICE_IDLE
12-27 02:05:50.217: INFO/wpa_supplicant(2673): CTRL-EVENT-STATE-CHANGE id=1 state=8
12-27 02:05:50.224: VERBOSE/WifiMonitor(1014): Event [CTRL-EVENT-STATE-CHANGE id=1 state=8]
12-27 02:05:50.224: VERBOSE/WifiStateTracker(1014): Changing supplicant state: COMPLETED ==> DORMANT
12-27 02:05:50.224: DEBUG/WifiStateTracker(1014): Deconfiguring interface and stopping DHCP
12-27 02:05:50.240: INFO/wpa_supplicant(2673): CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys
12-27 02:05:50.240: VERBOSE/WifiMonitor(1014): Event [CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys]
12-27 02:05:50.248: INFO/wpa_supplicant(2673): CTRL-EVENT-STATE-CHANGE id=-1 state=8
12-27 02:05:50.248: VERBOSE/WifiMonitor(1014): Event [CTRL-EVENT-STATE-CHANGE id=-1 state=8]
12-27 02:05:51.243: DEBUG/NetworkStateTracker(1014): setDetailed state, old =CONNECTED and new state=IDLE
12-27 02:05:51.287: INFO/wpa_supplicant(2673): CTRL-EVENT-DRIVER-STATE STOPPED
12-27 02:05:51.295: VERBOSE/WifiMonitor(1014): Event [CTRL-EVENT-DRIVER-STATE STOPPED]
12-27 02:05:51.295: VERBOSE/WifiStateTracker(1014): New network state is DISCONNECTED
12-27 02:05:51.302: VERBOSE/WifiStateTracker(1014): Changing supplicant state: DORMANT ==> DORMANT
12-27 02:05:51.302: DEBUG/ConnectivityService(1014): ConnectivityChange for WIFI: DISCONNECTED/IDLE
12-27 02:05:51.302: DEBUG/DataConnectionTracker(1076): enableApnType(default), isApnTypeActive = false and state = IDLE
12-27 02:05:51.302: DEBUG/DataConnectionTracker(1076): setEnabled(0, true) with old state = false and enabledCount = 0
12-27 02:05:51.310: DEBUG/DataConnectionTracker(1076): EVENT_APN_ENABLE_REQUEST 0, 1
12-27 02:05:51.310: DEBUG/DataConnectionTracker(1076): dataEnabled = false, enabledCount = 0, isApnTypeActive = false
12-27 02:05:51.341: VERBOSE/ConnectivityService(1014): Attempting to switch to MOBILE
12-27 02:05:51.451: DEBUG/NetworkStateTracker(1014): setDetailed state, old =DISCONNECTED and new state=CONNECTING
12-27 02:05:51.459: DEBUG/ConnectivityService(1014): ConnectivityChange for MOBILE: CONNECTING/CONNECTING
12-27 02:05:55.076: DEBUG/NetworkStateTracker(1014): setDetailed state, old =CONNECTING and new state=CONNECTED
12-27 02:05:55.076: DEBUG/ConnectivityService(1014): ConnectivityChange for MOBILE: CONNECTED/CONNECTED