Types of wake locks in android? - android

How many types of wake locks in android and what are they?
1) Wake lock
2) WiFi lock
do we have any other locks other than above 2?
do we have any lock for avoiding the 3G modem (Data connection) to avoid it from going to sleep mode due to inactivity?
Please let me know if any have idea on the same.
Thanks.

do we have any other locks other than above 2?
Not really.
do we have any lock for avoiding the 3G modem (Data connection) to avoid it from going to sleep mode due to inactivity?
No, because the mobile data connection does not go into sleep mode. While the mobile data connection does go through various power states, it automatically switches between them as necessary, and if you have an outstanding connection, it will not go into standby.

Related

How to turn WIFI radio on?

According to this the Wi-Fi radio may turn off when the user has not used the device in a while. Acquiring a WifiLock will keep the radio on until the lock is released, however holding a WifiLock adversely affects battery life. So is there any way to turn the wifi radio back on when it was turned off by the system?
Are you looking for a way to turn WiFi on every time it turns off? Or a way to turn it on when you need it? Either way, get a WiFi lock when you need WiFi, and release the lock when you don't need WiFi.
The reason that a WiFi lock drains the battery is because it may be keeping the WiFi on when it's not actually necessary. But if your goal is to keep the WiFi on, then avoiding a WiFi lock won't help the battery situation.

Wifi sleep policy and wifi lock which one overrides when both conflict?

If an android user has setup the WIFI SLEEP POLICY (KEEP WIFI ON DURING SLEEP) to NEVER, that is wifi should sleep when phone is locked or sleep.
And an app aquires a Wifi wake lock when the phone is not sleeping. While the app keeps the lock if the phones sleeps which setting should prevail ?
Sleep policy ? which tells that wifi should turn off
or the lock aquired by the app ? which attempts to keep wifi ON
There is no clear explanation about this in android documentation any tips would be great as I don't want redundant code in my app

ADB wifi unreachable when it looses connection in device with wake lock (CPU only)?

I am using wake lock on my Nexus 4 to force it to stay awake (I am using wake lock with CPU only option). However, after sometime, ADB wifi looses connecting and I am unable to reconnect to it again unless I turn the screen back on.
Does anyone know solution to this problem? I have the need to keep the screen off, while still be able to access phone via ADB wifi.
You need a wifi lock - check the docs here. In short, the CPU lock won't keep the wifi radio on too - you need a separate (wifi) lock for that.

Different possibilites for keeping wifi radio turned on?

I have been reading as much as I can regarding the developer docs for the Android SDK about the following:
Wifi wakelock
WifiManager.WIFI_MODE_FULL_HIGH_PERF
Wifi sleep policy
They all make sense in their own context but I can't see the "big picture" so to speak.
I guess that both the wifi wakelock and the WIFI_MODE_FULL_HIGH_PERF setting overrides the user sleep policy. Is that right?
If I have the sleep policy on "Never", and I just make experimental APK:s for myself which is downloading stuff in the background via wifi, I guess I don't need the wifi wake lock nor the WIFI_MODE_FULL_HIGH_PERF?
The code I have seen using a wifi wake lock has also acquired a power wake lock. Is there any occasion where I only want to acquire the wifi lock but not the power lock?
If the device goes into a deep sleep and shuts down wi-fi radio, the wi-fi lock will wake it back up when the lock is acquired. Correct, this is regardless of your wi-fi policy.
I think you have it backwards- the policy question says "Keep Wi-Fi on during sleep" so if you want to avoid the need for wifi locks, you would choose the "Always" option value. I'd like to see a battery consumption analysis of Wi-Fi stay connected, versus sporadic 4G in deep sleep...
I have never needed or used a power wake lock. Just system and wifi, and everything has worked fine for me to perform the functions desired.

Check for wifi networks signal in sleep mode

My objective is to be able to scan changes in Wi-Fi networks (mainly to check what networks are available). Right know I'm doing it by registering a reciever:
registerReceiver(wifiReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION));
where WifiReceiver is my BroadcastReceiver.
The problem is that it works only when the phone is on. As soon as it goes to sleep mode (either by pushing the power button or after some time), the receiver stops receiving. I already acquired a wake lock in onCreate of my main class and releasing it in onDestroy (it's a partial wake lock). Additionally I've tried this:
Settings.System.putInt(getContentResolver(),Settings.System.WIFI_SLEEP_POLICY, Settings.System.WIFI_SLEEP_POLICY_NEVER);
to keep wifi from sleeping. Unfortunately that didn't help.
Is there any possibility to scan for network changes, even when phone is asleep? I want to be able to check what networks are in range (by SSID). Maybe I should use another action?
Appreciate your help.
Literally, no, the hardware isn't typically designed nor the low level drivers written to allow wifi to operate while the application CPU is in sleep mode - unlike the case with the mobile network interface which is intended to receive push events like phone calls, sms, and gmail "tickles".
So your choices are to either manage to successfully prevent the device from sleeping (good bye battery) or wake up periodically using an alarm, kick the wifi active, and poll the situation (still not good for battery life, but not as drastically so).
I'm afraid this sleep behaviour is managed by the system under (on Android 2.3.4) Settings > Wireless & Networks > Wi-Fi Settings > Press Menu > Advanced > Wi-Fi Sleep policy.
This could actually go against the users will, careful with that.
However I think there has to be a way to modify this param. programmatically, using this settings : Settings.System, and of course the corresponding permission in your manifest.

Categories

Resources