I'm using accelerometer and gyroscope in my Android app. I want to profile my app for its power consumption. Lets say the app, read these two sensors every 100 millisecond, add all its three axis (x,y,z), and store them in a file.
Now I am not sure if these two sensor are always on or not ? If yes, then most of the power consumption will come from how I use or process these sensors' values in my app. So I have the following questions.
Are these two sensors always on or active ? (If so, any reference).
What does then the register and deregister does ? If they are always on,
then it won't make any difference to deregister them, at least in
terms of power consumption.
Background or reasoning behind these questions:
Gyroscope consumes more power than accelerometer (based on my analysis, its 4-6 times higher). Now if these sensors are always on then I can use them both in my app because my app is not the reason for the power consumption caused by the active status of these sensors. My app will be responsible for the power consumption due to the way I use these sensor values, and how often I read them. However, if these are disabled or off (consuming no power at all), then I have to make a careful decision if I want to use them or not because when I register them, then I am also increasing the power consumption due to their active status in addition to the processing their values.
Mostly as addition to the answer from Andriy Omelchenko with some more links:
1.
This is broadly and "manufacturer independent" documented in Androids Architecture Documentation in the Sensors Section. Specifically that Accelerometer and Gyroscope are handled as non-wakup sensors which report events continuously but may not wake up the SoC.
So yes, you can assume these 2 sensors are always on.
2.
Furthermore the documentation states: If an Application needs the data in background, it needs to hold a Wakelock - probably the Partial Wakelock which will keep the system from going into low power/sleep mode - such that events are processed and delivered without being dropped. Obviously this will drain the battery faster.
You could imply that registering/unregistering may have a low effect on power as long as you don't keep a Wakelock.
But in general you shouldn't assume it is useless to register/deregister sensors for power optimization - except one-shot sensors. Not only because of the power used for processing and delivery of events to apps and the possibility of keeping the system from its sleep. It is a Framework recommendation and these are normally not without cause like the use of register with report delay to make use of batching if possible. The impact may change with different hardware or other factors.
It could also be a funny bug source if - for example - you assume that data is provided depending on the Wakelock: The documentation only states that for non-wake-up sensors the driver is not allowed to hold a Wakelock and the sensor shouldn't wake the SoC. Meaning your app could be processing events in the background or not depending on device, system, installed apps and so on.
From Official site: "Always make sure to disable sensors you don't need, especially when your activity is paused. Failing to do so can drain the battery in just a few hours. Note that the system will not disable sensors automatically when the screen turns off."
"Are these two sensors always on or active?" - seems this question has no general answer because it depends on hardware. Actually accelerometer and gyroscope has low power consumption, but they support by OS may consume more battery.
"What does then the register and deregister does ?" - eliminates power consumption for data processing from them.
The accelerometer and gyroscope are not always on. That would be crazy - absolutely anything that draws power in a mobile device is put into a low power mode where-ever possible (no application is currently requesting it). Hence the need to register / deregister.
There isn't a strict specification to require this from hardware manufacturers, because this is a common sense optimization to increase battery life.
Related
I wish to use for my app ActivityRecognitionClient, and I wish it will run always in the background. But how much battery actually it consume and what is the best interval for battery optimization?
In the reference it only says
"Larger values will result in fewer activity detections while improving battery life. Smaller values will result in more frequent activity detections but will consume more power since the device must be woken up more frequently"
Can you tell me in real life how much it will consume per refresh rate?
It is nearly impossible to correctly answer this question because the answer is a resounding "it depends."
The amount of battery power that a particular action will consume on a phone is difficult to determine because there are a ton of different factors that play into it.
First, Android attempts to batch many types of requests such as this together, so if 10 different apps wants to detect updates ever 5 minutes, it will only do it once every 5 minutes instead of 10 times every 5 minutes. Which app and which action is responsible for that?
Second, activity detection relies on whatever sensors (and models of sensors) are available on the device. Different devices have different GPS chips, accelerometer chips, etc. Some devices may not have all of those types of sensors as well. These all change the amount of energy activity recognition will consume.
These are just a few of the reasons it is difficult to determine how much energy an update will consume.
The answer for "how often should I request updates" is "as infrequently as your app can tolerate." Think about your use case and the general statement that more frequent updates will consume more power, and make the appropriate decision from there.
I am eager to know how ActivityRecognition which is in GooglePlay Services works?
I think activities are recognized by accelerometer data.Is it right?.Please give me the details how it goes?
I was looking for this answer also and your post was one of the top results on Google. I did a little more digging and found this https://developer.android.com/reference/com/google/android/gms/location/ActivityRecognitionApi.html which says:
The activities are detected by periodically waking up the device and reading short bursts of sensor data. It only makes use of low power sensors in order to keep the power usage to a minimum. For example, it can detect if the user is currently on foot, in a car, on a bicycle or still.
It doesn't explicitly say which sensors it uses, but we can safely assume that accelerometer is one of them. Since it says sensors (plural) it evidently uses others. But since it says low power you don't have to worry about it using GPS or anything like that. However, it does say that it wakes the device up which would bring it out of its super power saving mode. So, even though it is low power you still may not want it running every 5 seconds all day long. The documentation further down says:
A common use case is that an application wants to monitor activities in the background and perform an action when a specific activity is detected. To do this without needing a service that is always on in the background consuming resources, detected activities are delivered via an intent. The application specifies a PendingIntent callback (typically an IntentService) which will be called when activities are detected. See the documentation of PendingIntent for more details.
I'm trying to design an app which changes it's behaviour according to battery draining rate.
That is, there are two states state1 and state2.
it checks for draining rate of each state.
and switches over to the particular state which drains less battery.
so is it possible to check the draining rate of my app (in particular).
ps: both the states use display and network connections.
if yes how can I get the draining rate?
I've noticed in the Battery options of android setting contains per app battery usage can I access these values?
You have two main states (LOW and OKEY). However, I don't think you can access battery usage statistics par apps.
You can read this : http://developer.android.com/training/monitoring-device-state/battery-monitoring.html
IMO, you can do what you want with that.
i have added a feature in my app that uses the proximity and accelerometer sensors (the second is to detect shakes). This is implemented in an always running service (if the user selects it of course). But I fear for the battery usage that my ap will have. I have NOT used any wake locks but i still get readings even when screen is off as i can see in my logs. The question is: what of the following is true?
The two mentioned sensors are activated anyway by android system
the whole time (in which case me collecting the readings as well
does not affect battery life...i guess).
Android system turns these sensors off most of the time (in which
case me keeping them always on through my service affects battery
life)
If (2) is true: Is it possible to implement my own sleep cycle for the sensors or will the whole toggle process make things worse?
Amount of power taken by sensor varies from sensor to sensor, and device to device.
On average, your most power hungry sensors are the GPS, accelerometer and gyroscope. Leaving them On all the time will reduce the battery faster.So you should pause the sensor when the device is where-ever not necessary.
After that, the light sensor and compass are much less battery intensive, but if you use them for long enough even they'll affect battery life.
besides this you can test your app for sometime how much it takes, or you can use getPower () to return the power in mA used by this sensor while in use.
There is no exact method for this actually.If your app have to use the sensor then use it when its needed.
thanks
u can reduce the power consumption by reading the sensor's value at some competitively larger time like 50ms,
i.e. any android cell read the data at 5ms or 10ms depend on brand of cell phone and we can manually reduce that time to 50ms to 70ms.
it would increase the battery life and won't affect on process as well.
thank you
I am developing a GeoFencing Android App that notifies user whenever they are close to a certain region (similar to Start Monitoring for Region in iOS).
I know I can use AddProximityAlert in Android but I am concern about the power consumption as I will add around 50 geo points.
The question is: would the power consumption change on adding more points ? or it will stay the same regardless how many points I added ?
You'd have to make tests to know for sure :-) But my understanding is that the LocationManager checks periodically the current position (one "expensive" GPS check every 4 minutes if screen is off, more often if it's on, couldn't find how often) and then compares the location with all the registered center-points. So the power consumption, GPS-wise, is limited, and after that it's just "normal" CPU consumption created by checking an array of points.
HTH
I haven't done any tests before but I think the power consumption depends on hardware refreshing rate. You can set up a comparison test with no geo-point and multiple geo-point. You may need to stand still to ensure the same GPS visibility. And use some power consumption tool, such as Battery Historian, to evaluate the power consumption.