I am developing a mobile monitoring system on Android, so I need a platform, that is mobile, lightweighted and that has some computing performance. I have chosen Android, but I've run to a problem that tablet's chargers cant catch up with power consumption.
I can't know for sure how much CPU will application consume (maybe 30%, 40%?), but let's say 100% to be sure.
Is there a way to achieve nonstop run? Maybe tablet with non-usb charger?
edit: Simply speaking I need to charge the device more quickly, then it consume power. Optimization and lowering power consumption by turning down hardware that is not needed right now doesnt seem as a solution since application can be used for entire time...
What you want is a a partial WakeLock.
WakeLock gives you the ability to stop the device from entering sleep-mode. There are several levels of Wakelock, you are (if I'm correct) interested in turning of the screen to minimize the power consumption but not put the device to sleep and halt computation. For this there is PARTIAL_WAKE_LOCK.
Make sure to have the right permission for your app before acquiring the WakeLock or you will get a security permission.
Another thing you might want to consider is to use a high-output charger that supplies more than the lowest rated chargers (500mA).
Related
Recently I have developed an android app . The app is ok . But the user is complaining that app causing battery drain . Even some battery optimizer app (Like Battery Doctor) suggesting my app to force stop as it is causing battery draining too fast . There are a lot of service (like sync service , socket service) and broadcast receiver is used in this app and alarm manager is used in the app. How can I detect actually which is responsible for battery draining ?
I addressed the major contributors to battery drain in another of my posts.
If I understand correctly, you want to identify which section of code (including libraries) of your app is the culprit.
Here's my suggestion:
Confirm that there is a problem: Get as identical a phone configuration as possible, say by having the user send a dump of all processes running on their phone, and confirm there is a problem.
Confirm that it's your app: run tests with your app running and without. Make sure you take several measurements.
(A) If you have a profiler, use it to profile your application and identify potential issues. (B) If you don't have a profiler, create some dummy input, and start exercising your app while cutting out different functionality. Measure the battery drain.
NOTE: If the drain is small, detection becomes an issue. It's the old signal to noise ratio thing. The smaller the drain, the more measurements you have to take to determine what it is. Of course, the smaller the drain, the less of an issue it is.
I am writing an app to evaluate the feasibility of a Bluetooth P2P network on Android.
I noticed that on a Galaxy Nexus, it uses very little battery, while on a Nexus S, it drains the battery very quickly. This is directly caused by high CPU load due to Bluetooth.
Now, I would like to collect information about how much battery drain my app causes on the devices it is installed upon. Simply logging time vs. battery level is useless since I don't know when the device is in use, and even if I logged that, I would not know if the user is playing 3D games while Torrenting over WiFi or reading an eBook on a dimmed screen.
To make the problem worse, not all battery usage caused by my app is attributed to it in the battery screen - some is listed as "Bluetooth", for example (again, device-dependent).
Is there any easy, privacy-preserving way to get useful information on non-rooted devices? The devices are not under my control. I cannot simply go look in the menu, I cannot use ADB.
The Android API doesn't support this currently. The only available documentation is the one describing how to use BatteryManager's broadcasts, which only supply the overall battery level and no per-application details.
I suppose that even if there are undocumented ways to emulate what the System Settings battery manager shows, they would require rooting.
AFAIK there is no way to do this. The closest you can get to doing this is to hook up the device to a monitoring tool like little eye labs which does draw the battery consumed by your app over time on a graph. It also supports marking key events in the app's lifetime like turning on WIFI / bluetooth etc.
There is no support for doing this remotely, but you can get the data on your own test devices.
This approach is quite crude, but it may help. You can use the existing BatteryManager broadcasts to track changes to the overall battery level while your app is active.
Knowing when your app is active is a separate issue. If your app consists entirely of Activities, then you can get good results by starting to track whenever any of your Activities' onResume() methods is called, and stopping tracking in onPause(). If you can have all your Activities derive from a single base Activity class, then this is quite easy. See How to detect when an Android app goes to the background and come back to the foreground for suggestions on how to track this.
If your app is more complex, and the smart stuff happens in a longer-running component like a Service, then it's much harder.
This is crude, but at least it would help you distinguish "playing 3D games" from "using my app".
I can't seem to find this info in the docs...
On a phone or tablet I understand we need things like acquiring WakeLocks and WifiLocks because of battery consumption. However, on a TV that's constantly plugged in I can't imagine a need for these.
So, on a Google TV:
Does the screen stay on the entire time?
Does the screen ever dim?
Does the CPU stay on the entire time?
Do I ever need to worry about things like WakeLocks, WifiLocks, or MulticastLocks?
My experience is only with the Logitech Revue, which controls the TV over HDMI. As such, it has limited control over power save features. That said, here's my experiences with it...
Does the screen stay on the entire time?
Yes. It's always sending a signal.
Does the screen ever dim?
No, but it does have a screensaver that turns on after a while.
Presumably, you could use a wakelock to disable this (though I've never tested it).
Does the CPU stay on the entire time?
I'd like to think that the CPU can throttle itself down if it's idle, the same as most desktops/laptops. I've never instrumented it to test though.
This shouldn't be something your app needs to worry about though.
Do I ever need to worry about things like WakeLocks, WifiLocks, or MulticastLocks?
WakeLocks = Possibly, to disable the screensaver.
WifiLocks/MulticastLocks = Probably not, but it's good practice to do so anyway. It will make porting your application between devices easier, and it's always possible something will change in the future as GTV is deployed on more devices.
I observed that I can download a file faster if I use wget with the screen on application,
that acquires a screen dim wake lock than doing the same without this application and
having the screen turned off.. I downloaded exactly the same file (from my apache web server) and the time is almost two times faster when I used the screen on application. To download the file I use a ported versions of wget.. And here is my question:
Does Android lower the download rate when the screen turns off?
Or due to the fact that the screen on app acquires a wake lock, forces the CPU to be always on, so more CPU cycles are spent for the download process.. I am a little bit confused..
Short answer is yes, Android sometimes does lower the download rate when the screen turns off. According to this Android bug report (starred by 90 users),
It seems that, even with "Wifi Sleep Policy" set to "Never", the wifi on some Android devices will enter Power Save mode (a.k.a. PSP mode) when the screen turns off.
PSP mode apparently causes the wifi device to sleep, but wake up periodically and ask its access point to deliver packets that were addressed to to the device while it was asleep. This necessarily causes additional, "spiky" network latency. This additional latency means that some network-oriented applications experience problems when the screen turns off.
This more or less correlates with the behavior you're describing. This issue affects only some phones, not all, and only some versions of Android. I suggest you visit the bug report above, there is a long discussion of this issue.
How to solve this issue
There is a workaround for Android 2.3 at least: You need to acquire WIFI_MODE_HIGH_PERF lock:
In this Wi-Fi lock mode, Wi-Fi will be kept active as in mode WIFI_MODE_FULL but it operates at high performance with minimum packet loss and low packet latency even when the device screen is off. This mode will consume more power and hence should be used only when there is a need for such an active connection.
CPU clock scaling in Android
Android is based on Linux kernel, and uses CPUFreq Governors to adjust CPU frequency to conserve the battery. Exact policies and frequencies vary from vendor to vendor and are subject to change. There are also utilities that let you adjust these policies, but they all require rooted phone. Usually, Android phones lower CPU frequency and use "powersave" governor when the screen is turned off.
However, I don't think network traffic on a phone is CPU-bound. That is, even when in power-safe mode, network throughput is a bottleneck, not CPU speed.
Is there an Android API for stop charging even though physically the charging is on?
Reading previous answers, it looks like there's no way to do this exclusively in software. However, it should be relatively easy to do it with a little hardware help - i.e. by using any Bluetooth- or WiFi-enabled smart electrical switch with open API. The phone could then switch the charger on or off programmatically whenever it feels like it.
Is there an Android API for stop charging even though physically the charging is on?
AFAIK no.
Justification:
android.intent.action.BATTERY_CHANGED is a protected intent that can only be sent by the system. Therefore you cannot duplicate or override the functionality.
You guys are all missing the point - the purpose of limiting charging is to increase battery lifespan by keeping it away from fully charged conditions (and near empty but that's a different issue). If you anticipate needing a full charge then tell it to charge to 100.
If you can't set a charge limit then the battery would rarely be idle and ideally charged when on the charger. It probably requires device level support though.
https://play.google.com/store/apps/details?id=es.guille.stopcharge uses echo "0" > /sys/class/power_supply/battery/device/charge. It works for me on a nexus 4 (rooted), as long as the device isn't fully charged (in a charging state).
Also relevant: https://android.stackexchange.com/questions/15001/how-can-i-avoid-the-battery-charging-when-connected-via-usb
Contrary to some answers indicating it's not possible, it is, indeed possible with ROOT. You can find some apps on the Play Store that will allow you to do this (with root permission, of course).
The best app that works on every phone I've tried it on is Battery Charge Limit. You can download it from the Play Store or the XDA discussion thread. The app is under active development so, if you find that your phone isn't supported, just submit an issue on its GitHub page.
NB: I am not the developer of this application.
This is unfortunately not possible. Android only have read APIs for battery data.
Battery charging control is internal to the Android kernel and battery IC modules. Manufacturers do change it from time to time, like HTC is having small cycles from 95-100% (a bad idea IMO), Samsung does stop charges as soon as it reaches 100%, but I've never seen a device able to stop charging before 100% to reduce battery aging :(.
At best if we're lucky, a sysfs interface might help do that, but it requires root and will differ from device to device.
Just to add to this. Samsung phones do not stop charging after 100%. As far as I'm aware they "trickle" charge past this point however they recommend you do not charge your phone past 100% for over 1 hour. Battery manufacturers like Anker also state the same so the idea of stopping the charge at 100% would be really useful. The risks of leaving the phone on charge are battery bloat and eventually cell rupture. I wasn't aware of this to start off with an killed my samsung battery within 3 months of owning the phone.
To expand on the original question. I've noticed some kernels allow fast charging. If they are able to alter the charge rate up could we alter the charge rate down (trickle) to meet a desired finish time (when your morning alarm goes off)??
I have installed a timer on the AC receptacle where I plug my Moto E's charger into. After guestimating how much time the battery needs to charge to about 85%, I set the timer. This is not my idea of a solution, but at least it keeps my phone from being charged to 100%, as I usually err on the short side when setting the timer.
I dont think there would be such an api. If it does exist it needs to be supported by the device manufacture as its not a pure OS lever feature. The same reason would make it a bad idea to use it as not all devices will support it.
That being said it would be a bad idea to use/implement it , mobile devices are not built to directly run from the power supply and a user will not plug in the cable if he/she did not want to actually charge the device.