Android Sleep/Standby Mode - android

I have made an app that starts a service, which starts a timer, which fires off a small function after an amount of time. This is working great on the emulator and on the Motorola Droid 1, but it doesn't work on the Droid X when the phone has been put into sleep mode. What I have discovered is that the timer seems to pause when the phone is in sleep. It doesn't seem to do this on the Droid 1, or the emulator. I'm sure the workaround isn't too difficult, so I'm not asking for help(for once) I just want an explanation, to better understand this.
My question is what exactly does "sleep mode" do on android systems? What does it stop, what doesn't it stop, etc. By sleep mode I mean, of course, when you press the power button and the screen goes black. What exactly is happening? Any insight is appreciated.

I'm sure the workaround isn't too difficult
Using AlarmManager is a bit tricky.
My question is what exactly does "sleep mode" do on android systems?
Primarily, it shuts down the CPU. Along the way, non-essential radios (WiFi, GPS) will have been shut down as well.
What does it stop, what doesn't it stop, etc.
About the only thing you can count on not stopping is the GSM or CDMA radio (for incoming calls, SMSes, and IP packets) and AlarmManager.
By sleep mode I mean, of course, when you press the power button and the screen goes black.
Actually, that's not sleep mode, per se. That is the screen turning off.
The device will go into sleep mode shortly thereafter, if nothing is keeping it awake with a WakeLock. However, there is no guarantee that within a millisecond of you pressing that button and the screen turning off that the CPU is off.

Related

Can't simulate sleep mode on Android emulator

I am trying to put my emulators into sleep mode to test some behavior.
For this, I deactivate the charger, set the battery to "uncharging" and a low battery %. Then I lock the screen over the power button (swipe to unlock is activated).
Then I start some background operation (for example an IntentService) without holding a wake lock and leave the app, but everything just keeps running as if the screen was on.
The emulator seems to not fall into sleep.
Not a duplicate since I am already following these exact steps (as described above)

Does moving the device wake it up from DOZE

I'm seeking information regarding the specific behavior of Android device during DOZE mode, also known as Idle mode. My app provides sensor info periodically with setExactAndAllowIdle() method. This of course doesn't work perfectly, but since the device is (or should be) static (with screen turned off and unplug from charger) I do not need the access to the sensor. My question is: if the device is stationary and in DOZE mode, does moving the device wake it up from DOZE? I've tested with adb and the answer is no, but when I tested with a device it somewhat gave the impression that moving the device actually caused it to leave DOZE mode.
I'm specifically asking about the moving action (without turning on the screen) whether it does or does not wake the device from DOZE.
Another question is:
Is there a way to programmatically tell what action woke the device from DOZE? I'm aware of PowerManager.isDeviceIdle().
Thanks in advance for your answers.
As soon as the user wakes the device by moving it, turning on the screen, or connecting a charger, the system exits Doze and all apps return to normal activity
source
So, Yes it does make wakes up by moving.
Is there a way to programmatically tell what action woke the device from DOZE?
I don't think so.
As CommonsWare have mentioned that he isn't sure about it, now I'm confident enough to simply tell you, No :)

Broadcast Receiver for volume up button

I am aware that this question has been asked already in this site, but I could not find my answer. SO this is what i am trying ot do. My power button in my phone is not working properly. So could is there a way to override my volume up button to unlock my phone.
I am planning to implement broadcast receiver But could not find the appropriate intent-filter. Another alternative that I thought was to run a service when the screen is locked, but I am not quite sure if I can listen to key events.
So if any of the above mentioned is possible, could you hint on how to get it done or suggest another alternative?
No, It do not think so. This can not be done.
There is no broadcast for volume up or down button presently. You can implement a service that will listen for any changes in the volume but it is not recommended to run a service all the time since that consumes both battery and memory.
The only solution that I can think of is using ContentObservers for listening to the changes in the settings such as volume of streams. This answer here will provide you with the code to use ContentObserver to listen for volume up or down. https://stackoverflow.com/a/7017516/1979347
This functionality you speak of has already been done multiple times and can be found on Google Play. However, I'm not sure how they did it, or how much their solution drains the battery.
I just did a test on my G2 (Android 4.2.2), I launched a broadcast monitor, I switched to the homescreen, and I changed the volume from there.
Apparently, it can detect if the volume is turned up only when it changes from silent mode > to Vibration mode > or to Sound mode. Conversely, when pressing the down volume, I think we can detect the change when it goes from the Sound Mode > to Vibration Mode > or to Silent Mode.
This is probably not what you wanted to hear, but I just wanted to confirm what the others were saying. On a non-rooted phone, what they're saying is mostly correct. On a rooted phone however, there are custom ROMs that have solved this issue.
By the way, what brand/model is your phone? On my phone, when the headset gets connected, the phone lights up. So I suppose, one could always do it the way iPhone owners do it for their phones. You'd have to cut the extremity of a head phone jack, coat half of the pin in plastic, and super glue a button on top of it to allow you to easily twist the head.

Does Android have two different sleep modes

When the user presses on the Power button to turn off the screen, at some point Android goes into sleep mode shutting down the CPU. It isn't clear whether this happens immediately or after a period of time. Does the CPU stay fully or partially awake for a duration and then go into a complete sleep mode?
When the user presses the power button, Android goes into screen off mode. Some time after this, the device will go into sleep mode if nothing is kept awake using a Wakelock. The duration of this period is uncertain. See here for more:
https://stackoverflow.com/a/5120225/1369222

Detect Volume Button Press when Screen off

I have a service that detects when the display of my Android phone is turned on or off. When turned off, the service calls an activity that uses dispatchKeyEvent to detect when the volume up button has been pressed. Unfortunately, apparently the activity can't do this when the screen is off. (See this post.)
I've noticed, though, that something at some level is detecting that event, since the following LogCat message appears when I press the volume-up button when the screen is off: "CatService: Return current sInstance". The message seems to be device specific, since on a different device something different appears in the log, but I'm really only concerned about the first device.
I've done some research into CatService, but haven't found much and can't figure out how I might be able to use it, or whatever is generating the log message, to detect the volume up button press. I'd appreciate any light that anyone can shed on this.
The only way to keep detecting things like this when the screen is off is to acquire a WakeLock that will allow the screen to turn off, and still let your app function. However, this drains the battery life quite a bit, and should only be used when absolutely necessary.
In this case, you will need a PARTIAL_WAKE_LOCK.

Categories

Resources