From 405d0898630a1c35e8e5ece072d8703fd68aca3b Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Tue, 27 Oct 2009 20:23:28 -0700 Subject: [PATCH] DO NOT MERGE: Fix loss of focus after wakeup into incall screen Because of the asynchronous behavior of keyguard, and incall explicitly disabling keyguard, sometimes the window manager would wind up in a state in which the "correct" app and activity window were shown, but focus was recalculated "too soon," at a time when keyguard was just about gone but not quite, and incall was not yet fully shown. In this case there was no currently valid event target, but the final show of the incall window would not prompt a focus recalculation, so that "no current focus" state would incorrectly persist, resulting in spurious ANRs until some other phone activity forced a focus update. We now detect the problematic case when windows are shown, and make sure to recalculate focus explicitly thereafter. This change does *not* fix the underlying race conditions that have been resulting in mismatched state within the window manager, but it does force a validation pass that puts things in order so that normal operation can continue. Change-Id: I8e7f5f0795f0042a0da074aeed385e3fbc210360 --- .../java/com/android/server/WindowManagerService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java index cd6a3712a8bf3..6418901915c1a 100644 --- a/services/java/com/android/server/WindowManagerService.java +++ b/services/java/com/android/server/WindowManagerService.java @@ -9303,6 +9303,15 @@ public class WindowManagerService extends IWindowManager.Stub & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { wallpaperMayChange = true; } + if (changed && !forceHiding + && (mCurrentFocus == null) + && (mFocusedApp != null)) { + // It's possible that the last focus recalculation left no + // current focused window even though the app has come to the + // foreground already. In this case, we make sure to recalculate + // focus when we show a window. + focusMayChange = true; + } } mPolicy.animatingWindowLw(w, attrs);