onFinishedGoingToSleep方法的调用流程:
1 外部调用KeyguardService的setKeyguardEnabled方法。
com.android.server.policy.keyguard.KeyguardServiceWrapper
com.android.server.policy.keyguard.KeyguardServiceDelegate在其 bindService 中 bind 了 KeyguardService 并封装到一个KeyguardServiceWrapper对象中,
SystemServer 的方法 startSystemUi 启动 SystemUi 之后会在PhoneWindowManager 调用 bindKeyguard ,
SystemServer -> PhoneWindowManager -> KeyguardServiceDelegate
PhoneWindowManager 的 mKeyguardDelegate
Called when the device has finished going to sleep
以下是对PowerManagerService的分析:
启动时的流程:
Notifier#onWakefulnessChangeStarted
PowerManagerService
继承 SystemService ,在 SystemServer 中被启动,并注册了以下:
publishBinderService(Context.POWER_SERVICE, mBinderService, /* allowIsolated= */ false,
DUMP_FLAG_PRIORITY_DEFAULT | DUMP_FLAG_PRIORITY_CRITICAL);
/**
* Wakefulness: The device is asleep. It can only be awoken by a call to wakeUp().
* The screen should be off or in the process of being turned off by the display controller.
* The device typically passes through the dozing state first.
*/
public static final int WAKEFULNESS_ASLEEP = 0;
/**
* Wakefulness: The device is fully awake. It can be put to sleep by a call to goToSleep().
* When the user activity timeout expires, the device may start dreaming or go to sleep.
*/
public static final int WAKEFULNESS_AWAKE = 1;
/**
* Wakefulness: The device is dreaming. It can be awoken by a call to wakeUp(),
* which ends the dream. The device goes to sleep when goToSleep() is called, when
* the dream ends or when unplugged.
* User activity may brighten the screen but does not end the dream.
*/
public static final int WAKEFULNESS_DREAMING = 2;
/**
* Wakefulness: The device is dozing. It is almost asleep but is allowing a special
* low-power "doze" dream to run which keeps the display on but lets the application
* processor be suspended. It can be awoken by a call to wakeUp() which ends the dream.
* The device fully goes to sleep if the dream cannot be started or ends on its own.
*/
public static final int WAKEFULNESS_DOZING = 3;
系统开机会先进入WAKEFULNESS_DOZING ,
要理解清楚 MSG_USER_ACTIVITY_TIMEOUT的处理:
在 updateUserActivitySummaryLocked 中发送一个延迟的信息 MSG_USER_ACTIVITY_TIMEOUT ,如果后面没有取消这个信息,则会执行 updateWakefulnessLocked -》 goToSleepNoUpdateLocked 然后到 setWakefulnessLocked(WAKEFULNESS_DOZING, reason, eventTime);
mNotifier.onWakefulnessChangeStarted(wakefulness, reason, eventTime);
取消MSG_USER_ACTIVITY_TIMEOUT 需要dirty满足以下条件任意之一:
DIRTY_WAKE_LOCKS
DIRTY_USER_ACTIVITY
DIRTY_WAKEFULNESS
DIRTY_SETTINGS
How to show or hide keyguard:
you can call PhoneWindowManager#enableKeyguard()