赞
踩
第一章 引言
第二章 关机流程
2.1 PhonewindowManager
2.2 PhoneWindowManager.interceptKeyBeforeQueueing
2.3 PhoneWindowManager.interceptPowerKeyDown
2.4 PhoneWindowManager.powerLongPress()
2.5 PowerAction.onPress()
2.6 WindowManagerService.shutdown
2.7 ShutdownThread.shutdown()
2.8 ShutdownThread.shutdownInner()
2.9 ShutdownThread.beginShutdownSequence()
2.10 ShutdowmThread.run()
2.11 ShutdownThread.rebootOrShutdown()
第一章 引言
在开始分析关机流程之前,我们先总结几个关机的关键字,以便我们加深我们对关机流程的理解,关键字如下:
InputReader,ShutdownThread,LIGHTS
Line 5981: 05-28 15:24:36.220 838 996 D InputReader: processEventsLocked: type=3 Count=3 code=57 value=-1 deviceId=6 //通常我们以最后一个InputReader输出作为关机的起始时间;
Line 5992: 05-28 15:24:36.248 838 838 D ShutdownThread: Attempting to use SysUI shutdown UI //我们可以通过ShutdownThread的log打印确定这段时间内是否有异常;
Line 5993: 05-28 15:24:36.248 838 838 D ShutdownThread: SysUI handling shutdown UI
Line 6000: 05-28 15:24:36.256 838 5800 I ShutdownThread: Sending shutdown broadcast…
Line 6126: 05-28 15:24:36.605 838 5800 I ShutdownThread: Shutting down activity manager…
Line 7120: 05-28 15:24:38.212 838 5800 I ShutdownThread: Shutting down package manager…
Line 7138: 05-28 15:24:38.249 838 5866 I ShutdownThread: Waiting for Radio…
Line 7139: 05-28 15:24:38.249 838 5866 I ShutdownThread: Radio shutdown complete.
Line 7361: 05-28 15:24:38.759 838 5800 I ShutdownThread: Performing low-level shutdown…
Line 7458: 05-28 15:24:39.027 434 434 D LIGHTS : file:vendor/sprd/modules/lights/lights.c, func:write_int, path=/sys/class/backlight/sprd_backlight/brightness, value=0 //最后一句lights的打印此时屏幕灭屏,我们通常观察的关机结束以此为准;
第二章 关机流程
2.1 PhonewindowManager
Android 系统的关机流程是从用户按 power 键开始的,所有的按键处理都是通过 PhoneWindowManager.interceptKeyBeforeQueueing() 方法进行处理。
2.2 PhoneWindowManager.interceptKeyBeforeQueueing
257 public class PhoneWindowManager extends AbsPhoneWindowManager implements WindowManagerPolicy {
3817 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
…….
// Handle special keys.
3909 switch (keyCode) {
…
case KeyEvent.KEYCODE_POWER: {
4029 EventLogTags.writeInterceptPower(
4030 KeyEvent.actionToString(event.getAction()),
4031 mPowerKeyHandled ? 1 : 0, mPowerKeyPressCounter);
4032 // Any activity on the power button stops the accessibility shortcut
4033 cancelPendingAccessibilityShortcutAction();
4034 result &= ~ACTION_PASS_TO_USER;
4035 isWakeKey = false; // wake-up will be handled separately
4036 if (down) {
4037 /SPRD : add power debug log start/
4038 Slog.d(TAG, “Receive Input KeyEvent of Powerkey down”);
4039 /SPRD : add power debug log end/
4040 interceptPowerKeyDown(event, interactive);
4041 } else {
4042 /SPRD : add power debug log start/
4043 Slog.d(TAG, “Receive Input KeyEvent of Powerkey up”);
4044 /SPRD : add power debug log end/
4045 interceptPowerKeyUp(event, interactive, canceled);
4046 }
4047 break;
4048 }
2.3 PhoneWindowManager.interceptPowerKeyDown
946 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
…
// Latch power key state to detect screenshot chord.
960 if (interactive && !mScreenshotChordPowerKeyTriggered
961 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
962 mScreenshotChordPowerKeyTriggered = true;
963 mScreenshotChordPowerKeyTime = event.getDownTime();
964 interceptScr
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。