版本信息:
Linux 3.10
Android 4.4
http://blog.csdn.net/u013686019/article/details/53691879
Android休眠在framework的处理涉及两个系统服务,InputManagerService和PowerManagerService。InputManagerService负责处理PowerKey产生的Input事件,根据事件类型调用PowerManagerService的休眠、唤醒接口:
void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
uint32_t& policyFlags) {
if (wmActions & WM_ACTION_GO_TO_SLEEP) {
ALOGD("handleInterceptActions: Going to sleep.");
android_server_PowerManagerService_goToSleep(when);
}
if (wmActions & WM_ACTION_WAKE_UP) {
ALOGD("handleInterceptActions: Waking up.");
android_server_PowerManagerService_wakeUp(when);
}
if (wmActions & WM_ACTION_PASS_TO_USER) {
policyFlags |= POLICY_FLAG_PASS_TO_USER;
}
}
PowerManagerService执行具体的休眠、唤醒动作:
private void goToSleepInternal(long eventTime, int reason) {
Slog.i(TAG, "goToSleepInternal, reason: " + reason);
synchronized (mLock) {
if (goToSleepNoUpdateLocked(eventTime, reason)) {
updatePowerStateLocked();
}
}
}
}
private void updatePowerStateLocked() {
// Phase 0: Basic state updates.
// Phase 1: Update wakefulness.
// Loop because the wake lock and user activity computations are influenced
// by changes in wakefulness.
// Phase 2: Update dreams and display power state.
// Phase 3: Send notifications, if needed.
// Phase 4: Update suspend blocker.
// Because we might release the last suspend blocker here, we need to make sure
// we finished everything else first!
updateSuspendBlockerLocked();
}
它们之间关系如下图:
由于这两个服务涉及framework最核心的功能且其代码实现繁复,这里只贴出其处理流程,具体细节其他篇幅再续。本篇目的:始知此事要躬行,如果有意弄清流程,提供一个参照。
1、InputManagerService服务加载:
SystemServer.java (frameworks\base\services\java\com\android\server)
InputManagerService inputManager = null;
inputManager = new InputManagerService(context, wmHandler);
inputManager.start();
2、