Power/energy consumption comes from hardware component utilization in the device. Energy efficiency comes from limiting hardware resource usage. Also, look carefully at your methods for utilizing hardware components, and make use of the most efficient methods.
The Android framework is designed to be energy efficient. When apps need hardware data or contents, Android provides passive event-driven mechanisms instead of prompting applications to actively poll the data. This is because active polling introduces more CPU or hardware utilization than event driven methods, which suggests we should utilize event driven mechanisms to cache the events in the app. Android provides events like intents, notifications and content observer to notify the apps on the changes of hardware components or the changes of contents. Each kind of event is managed by internal services. Once the services detect changes, the services notify the apps.
Suppose we design an app that needs location data. Android provides a location service enabling location data to multiple applications. The service allows the app developer to specify the location provider: GPS, network or passive. Deciding which provider to use is a trade-off in accuracy, speed and energy efficiency. Once an app registers itself to the location service with specified criteria, the location service sends location change notifications to the app according to the criteria.
Android Alarms (based on the AlarmManager class) give you a way to perform time-based operations outside the lifetime of your application. For example, you could use an alarm to initiate a long-running operation, such as starting a service once a day to download a weather forecast.
Android Suspend:
In android patched kernel, going to request_suspend_state() in kernel/power/earlysuspend.c (since android add the Early suspend & wakelock feather in kernel). For detail understand that, let first introduce several new feather android imported.
Files:
· linux_source/kernel/power/main.c
· linux_source/kernel/power/earlysuspend.c
· linux_source/kernel/power/wakelock.c
Early Suspend:
Early suspend is a mechanism that android introduced into linux kernel. This state is btween really suspend, and trun off screen. After Screen is off, several device such as LCD backlight, gsensor, touchscreen will stop for battery life and functional requirement.
Late Resume
Late resume is a mechinism pairs to early suspend, executed after the kernel and system resume finished. It will resume the devices suspended during early suspend.
Wake Lock
Wake lock acts as a core member in android power management system. wake lock is a lock can be hold by kernel space ,system servers and applications with or without timeout. In an android patched linux kernel (referenced as android kernel below) will timing how many and how long the lock have. If there isn't any of wake lock prevent suspend(WAKE_LOCK_SUSPEND), android kernel will call linux suspend (pm_suspend()) to let entire system going to suspend.
Suspend vs Hibernate:
Suspend
does not turn off your computer. It puts the computer and all
peripherals on a low power consumption mode. Suspend saves the state of
your computer to RAM. If the battery runs out or the computer turns off
for some reason, the current session and unsaved changes will be lost.
Hibernate
saves the state of your computer to the hard disk and completely powers
off. When resuming, the saved state is restored to RAM.
Linux
kernel currently there are three methods of suspending available:
suspend to RAM (usually called just suspend), suspend to disk (usually
known ashibernate), and hybrid suspend (sometimes aptly called suspend
to both):
- Suspend to RAM method cuts power to most parts of the machine aside from the RAM, which is required to restore the machine's state. Because of the large power savings, it is advisable for laptops to automatically enter this mode when the computer is running on batteries and the lid is closed (or the user is inactive for some time).
- Suspend to disk method saves the machine's state into swap space and completely powers off the machine. When the machine is powered on, the state is restored. Until then, there is zero power consumption.
- Suspend to both method saves the machine's state into swap space, but does not power off the machine. Instead, it invokes usual suspend to RAM. Therefore, if the battery is not depleted, the system can resume from RAM. If the battery is depleted, the system can be resumed from disk, which is much slower than resuming from RAM, but the machine's state has not been lost.
There
are multiple low level interfaces (backends) providing basic
functionality, and some high level interfaces providing tweaks to handle
problematic hardware drivers/kernel modules (e.g. video card
re-initialization).
ref:
Android Power Management -
Linux Kernel Power Management -
Developing Power Aware Applications on Android - https://software.intel.com/en-us/articles/developing-power-aware-applications-on-android
Advanced Android Power Management and Implementation of Wakelocks - http://www.ktm2m.net/~suhopark/apm2.pdf
Power
Management from Linux Kernel to Android -
http://www.csie.ntu.edu.tw/~b97080/HW-Review%20%20Reports_20100517/HW-Review%20%20Reports/Report/%5B4%5DPower%20Management%20from%20Linux%20Kernel%20to%20Android.pdf
Handling Screen OFF and Screen ON Intents - http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/
Android alarm receivers - http://code.tutsplus.com/ tutorials/android- fundamentals-scheduling- recurring-tasks--mobile-5788
Suspend vs Hibernate - https://wiki.archlinux.org/index.php/Suspend_and_Hibernate
Android: detecting charge state - http://aspyct.org/blog/2013/05/16/android-detecting-charge-state/
Changing battery state using adb - http://www.stealthcopter.com/blog/2010/07/changing-the-battery-percentage-in-an-avd-android-virtual-device-emulator
Android PowerManager service - https://android.googlesource. com/platform/frameworks/base/+ / 84e2756c0f3794c6efe5568a9d0910 1ba689fb39/services/java/com/ android/server/power/ PowerManagerService.java