打开WMS log:adb shell dumpsys window -d enable a
adb logcat |grep -Ei "Looking for focus|findFocusedWindow: Found new focus|Changing focus from|No focusable window|Relayout of Window|Gaining focus|Focus entered window"
//从QuickstepLauncher启动Settings的focus切换
09-23 14:00:35.338 1167 1831 V WindowManager: findFocusedWindow: Found new focus @ Window{4aab40a u0
.....
09-23 14:00:35.347 1167 1831 V WindowManager: Looking for focus: Window{4aab40a u0 com.xxxxlauncher/com.android.quickstep.recents_ui_overrides.src.com.android.launcher3.uioverrides.QuickstepLauncher}, flags=-2121203456, canReceive=true
09-23 14:00:35.347 1167 1831 V WindowManager: findFocusedWindow: Found new focus @ Window{4aab40a u0 com.xxxxlauncher/com.android.quickstep.recents_ui_overrides.src.com.android.launcher3.uioverrides.QuickstepLauncher}
/QuickstepLauncher的为canReceive=true,focus window还是为QuickstepLauncher
......
设置还处于启动中 canReceive=false
09-23 14:00:35.501 1167 1231 V WindowManager: Looking for focus: Window{59c147c u0 Splash Screen com.android.settings}, flags=-2122120936, canReceive=false
09-23 14:00:35.502 1167 1231 V WindowManager: Looking for focus: Window{be54bd3 u0 InputMethod}, flags=-2122317560, canReceive=false
//当QuickstepLauncher的为canReceive=false,
09-23 14:00:35.502 1167 1231 V WindowManager: Looking for focus: Window{4aab40a u0 com.xxxxlauncher/com.android.quickstep.recents_ui_overrides.src.com.android.launcher3.uioverrides.QuickstepLauncher}, flags=-2121203456, canReceive=false
09-23 14:00:35.502 1167 1231 V WindowManager: Looking for focus: Window{176f74a u0 com.android.systemui.ImageWallpaper}, flags=82712, canReceive=false
///由于DisplayContent的mFindFocusedWindow中
671 if (!w.canReceiveKeys()) {
672 return false;
673 }
//返回false,mTmpWindow也没有被赋值还是为null,则 DisplayContent.findFocusedWindow返回null,
updateFocusedWindowLocked {则newFocus为null}<---- findFocusedWindowIfNeeded<----findFocusedWindow
/
3210 Slog.w(TAG_WM, "Changing focus from" + mCurrentFocus + " to " + newFocus
3211 + " displayId=" + getDisplayId() + " Callers=" + Debug.getCallers(4));
09-23 14:00:35.505 1167 1231 V WindowManager: Changing focus from Window{4aab40a u0 com.xxxxlauncher/com.android.quickstep.recents_ui_overrides.src.com.android.launcher3.uioverrides.QuickstepLauncher} to null displayId=0 Callers=com.android.server.wm.RootWindowContainer.updateFocusedWindowLocked:456 com.android.server.wm.WindowManagerService.updateFocusedWindowLocked:5713 com.android.server.wm.WindowManagerService.relayoutWindow:2447 com.android.server.wm.Session.relayout:213
///当设置切换完成canReceive=true
09-23 14:00:36.247 1167 2908 V WindowManager: Looking for focus: Window{64295be u0 com.android.settings/com.android.settings.Settings}, flags=-2122252032, canReceive=true
09-23 14:00:36.247 1167 2908 V WindowManager: findFocusedWindow: Found new focus @ Window{64295be u0 com.android.settings/com.android.settings.Settings}
在DisplayContent中 mCurrentFocus = newFocus;进行焦点切换
09-23 14:00:36.247 1167 2908 V WindowManager: Changing focus from null to Window{64295be u0 com.android.settings/com.android.settings.Settings} displayId=0 Callers=com.android.server.wm.RootWindowContainer.updateFocusedWindowLocked:456 com.android.server.wm.WindowManagerService.updateFocusedWindowLocked:5713 com.android.server.wm.WindowManagerService.relayoutWindow:2447 com.android.server.wm.Session.relayout:213
//Settings界面Relayout of Window
09-23 14:21:31.338 1167 2797 V WindowManager: Relayout of Window{d218f7f u0 com.android.settings/com.android.settings.Settings}: focusMayChange=true
/设置获取焦点WindowManagerService.H.REPORT_FOCUS_CHANGE
09-23 14:21:31.357 1167 1230 I WindowManager: Focus moving from null to Window{d218f7f u0 com.android.settings/com.android.settings.Settings} displayId=0
09-23 14:21:31.357 1167 1230 I WindowManager: Gaining focus: Window{d218f7f u0 com.android.settings/com.android.settings.Settings}
/焦点完成切换
09-23 14:21:31.482 1167 1640 I InputDispatcher: Focus entered window: Window{d218f7f u0 com.android.settings/com.android.settings.Settings} in display 0