Reputation: 2053
I want an app that drains the battery by using the CPU resources in a controlled fashion. Her, by controlled fashion, what I meant to say is that let's say 'X units/ms' is the maximum amount of the battery drain rate and the 'Y units/ms' is the minimum amount of battery drain rate.
Now, I want to give an integer from 1 to 100 as an input to the program and my app generates a battery drain corresponding to its value. Assume, only this app is running on the system.
So, is there any way to do this?
Upvotes: 3
Views: 1028
Reputation: 91
Due to the differences in hardware and configuration, such an app would likely need to calibrate itself. That is, it should run power-consuming tasks while monitoring the battery, to estimate how much power those power-consuming tasks take.
So, there are two things needed:
Battery Monitoring
Android provides an Intent for getting battery information. There's an SDK tutorial1. Unfortunately, the granularity of the results will be limited, likely to each percentage point. This means you need longer calibration tests and your results (and thus drain) will be of limited accuracy.
Power Consuming Tasks
The CPU is generally not the biggest power consumer in a mobile device. Whether the LCD is on might affect the drain more than tying up all of your CPU cores. Radio hardware (3G/GPS/WIFI) can also produce a higher drain than the CPU. An LCD at max brightness will drain more power than an LCD on at min brightness. An AMOLED would drain less power than the LCD.
The performance of different tasks will vary greatly depending on the hardware being used. This is what necessitates calibration.
Upvotes: 1