Android Power Management【by Steve Guo】

本文详细介绍了Android系统的电源管理模块架构及工作原理。该模块通过三种输入渠道进行操作,并提供了重启和关机服务。当电池电量低于阈值时,设备会自动关机。此外,文章还展示了如何在应用程序中调用电源管理接口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Overview

PowerManagement1

The above picture shows the overall architecture design of Android power management module. Android implements a very simple power management mechanism. Currently it only supports set screen on/off, screen backlight on/off, keyboard backlight on/off, button backlight on/off and adjust screen brightness. It does not support Sleep or Standby mode to fully use CPU’s capability.

The power management module has three channels to receive input: RPC call, Batter state change event and Power Setting change event. It communicated with other modules through either broadcasting intent or directly API call. The module also provide reboot and shutdown service. When battery is lower than thredshold, it will automatically shutdown the device.

The module will automatically set screen dim and off according to whether any user activity happens or not. The full state machine is shown as follows:

PowerManagement2

Detail

PowerManagerService.java is the core service. It calls Power.java to do the real work.

PowerManager.java is the proxy to RPC call PowerManagerService.java.

Power.java communicates with the low level through JNI.

android_os_Power.cpp is the JNI native implementation for Power.java. It calls Power.c to do the real work.

Power.c controls the power device driver through read/write the following sys files.

    "/sys/android_power/acquire_partial_wake_lock",

    "/sys/android_power/acquire_full_wake_lock",

    "/sys/android_power/release_wake_lock",

    "/sys/android_power/request_state"

    "/sys/android_power/auto_off_timeout",

    "/sys/class/leds/lcd-backlight/brightness",

    "/sys/class/leds/button-backlight/brightness",

    "/sys/class/leds/keyboard-backlight/brightness"

BatteryService.java registers itself as a UEvent observer for the path “/sys/class/power_supply”. If anything is changed in this path, it gets current state through JNI and then broadcasts ACTION_BATTERY_CHANGED intent.

com_android_server_BatteryService.cpp is the JNI native implementation for BatteryService.java. It gets current battery state through reading from the following files:

    "/sys/class/power_supply/ac/online"

    "/sys/class/power_supply/usb/online"

    "/sys/class/power_supply/battery/status"

    "/sys/class/power_supply/battery/health"

    "/sys/class/power_supply/battery/present"

    "/sys/class/power_supply/battery/capacity"

    "/sys/class/power_supply/battery/batt_vol"

    "/sys/class/power_supply/battery/batt_temp"

    "/sys/class/power_supply/battery/technology"

How to use

To call power module in app, the following is the sample code:

PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);

PowerManager.WakeLock wl = pm.newWakeLock(

PowerManager.SCREEN_DIM_WAKE_LOCK

| PowerManager.ON_AFTER_RELEASE,

TAG);

wl.acquire();

// ...

wl.release();

 

原文地址: http://letsgoustc.spaces.live.com/blog/cns!89AD27DFB5E249BA!526.entry

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值