From cfb13798db73849ce1cef0ae5943dbb52703b590 Mon Sep 17 00:00:00 2001 From: Craig Mautner Date: Wed, 14 Jan 2015 12:20:35 -0800 Subject: [PATCH] Place window at top when adding by base layer When addAppWindowToListLocked defaults to adding based on mBaseLayer it went from the lowest window to the highest window looking for a window whose base layer was larger and dropping the new window below that window. If the Home activity is the InputMethodTarget then when the home ActivityStack moves to the back the InputMethod will follow. This puts the InputMethod, with it's high base layer value below most activities. If a new activity window is added using the mBaseLayer rule above it was placed at the bottom of the window list below the InputMethod window. Being at the bottom it never received focus and input to the activity timed out causing ANR. This change starts the mBaseLayer search at the top window and works its way down looking for the first window whose mBaseLayer is less than or equal to the new window's mBaseLayer and inserting the new window above that window. This causes it to be placed at the top of all activities even if the InputMethod is near the bottom. Fixes bug 17721767. Change-Id: I037064de7604b670841e985479eb5857b47af1d7 --- .../java/com/android/server/wm/WindowManagerService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index ac17691cb82b1..edaa6d6aa761b 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -1166,15 +1166,15 @@ public class WindowManagerService extends IWindowManager.Stub // Just search for the start of this layer. final int myLayer = win.mBaseLayer; int i; - for (i = 0; i < N; i++) { + for (i = N - 1; i >= 0; --i) { WindowState w = windows.get(i); - if (w.mBaseLayer > myLayer) { + if (w.mBaseLayer <= myLayer) { break; } } if (true || DEBUG_FOCUS_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, - "Based on layer: Adding window " + win + " at " + i + " of " + N); - windows.add(i, win); + "Based on layer: Adding window " + win + " at " + (i + 1) + " of " + N); + windows.add(i + 1, win); mWindowsChanged = true; return tokenWindowsPos; }