am 9bf6c5ce: Merge "Fix method for determining focused window." into klp-dev

* commit '9bf6c5cec834343104aa326b65b86c064c86c6cb':
  Fix method for determining focused window.
This commit is contained in:
Craig Mautner
2013-09-24 12:35:25 -07:00
committed by Android Git Automerger

View File

@@ -158,7 +158,7 @@ public class WindowManagerService extends IWindowManager.Stub
DisplayManagerService.WindowManagerFuncs, DisplayManager.DisplayListener { DisplayManagerService.WindowManagerFuncs, DisplayManager.DisplayListener {
static final String TAG = "WindowManager"; static final String TAG = "WindowManager";
static final boolean DEBUG = false; static final boolean DEBUG = false;
static final boolean DEBUG_ADD_REMOVE = true; static final boolean DEBUG_ADD_REMOVE = false;
static final boolean DEBUG_FOCUS = false; static final boolean DEBUG_FOCUS = false;
static final boolean DEBUG_FOCUS_LIGHT = DEBUG_FOCUS || false; static final boolean DEBUG_FOCUS_LIGHT = DEBUG_FOCUS || false;
static final boolean DEBUG_ANIM = false; static final boolean DEBUG_ANIM = false;
@@ -9770,21 +9770,6 @@ public class WindowManagerService extends IWindowManager.Stub
} }
private WindowState findFocusedWindowLocked(DisplayContent displayContent) { private WindowState findFocusedWindowLocked(DisplayContent displayContent) {
// Set nextApp to the first app and set taskNdx and tokenNdx to point to the app following.
final ArrayList<Task> tasks = displayContent.getTasks();
int taskNdx = tasks.size() - 1;
AppTokenList tokens = taskNdx >= 0 ? tasks.get(taskNdx).mAppTokens : null;
int tokenNdx = tokens != null ? tokens.size() - 1 : -1;
WindowToken nextApp = tokenNdx >= 0 ? tokens.get(tokenNdx) : null;
--tokenNdx;
if (tokenNdx < 0) {
--taskNdx;
if (taskNdx >= 0) {
tokens = tasks.get(taskNdx).mAppTokens;
tokenNdx = tokens.size() - 1;
}
}
final WindowList windows = displayContent.getWindowList(); final WindowList windows = displayContent.getWindowList();
for (int i = windows.size() - 1; i >= 0; i--) { for (int i = windows.size() - 1; i >= 0; i--) {
final WindowState win = windows.get(i); final WindowState win = windows.get(i);
@@ -9795,59 +9780,51 @@ public class WindowManagerService extends IWindowManager.Stub
+ ", flags=" + win.mAttrs.flags + ", flags=" + win.mAttrs.flags
+ ", canReceive=" + win.canReceiveKeys()); + ", canReceive=" + win.canReceiveKeys());
AppWindowToken thisApp = win.mAppToken; AppWindowToken wtoken = win.mAppToken;
// If this window's application has been removed, just skip it. // If this window's application has been removed, just skip it.
if (thisApp != null && (thisApp.removed || thisApp.sendingToBottom)) { if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
if (DEBUG_FOCUS) Slog.v(TAG, "Skipping " + thisApp + " because " if (DEBUG_FOCUS) Slog.v(TAG, "Skipping " + wtoken + " because "
+ (thisApp.removed ? "removed" : "sendingToBottom")); + (wtoken.removed ? "removed" : "sendingToBottom"));
continue; continue;
} }
// If there is a focused app, don't allow focus to go to any if (!win.canReceiveKeys()) {
// windows below it. If this is an application window, step continue;
// through the app tokens until we find its app. }
if (thisApp != null && nextApp != null && thisApp != nextApp
&& win.mAttrs.type != TYPE_APPLICATION_STARTING) { // Descend through all of the app tokens and find the first that either matches
final WindowToken origAppToken = nextApp; // win.mAppToken (return win) or mFocusedApp (return null).
final int origTaskNdx = taskNdx; if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING &&
final int origTokenNdx = tokenNdx; mFocusedApp != null) {
for ( ; taskNdx >= 0; --taskNdx) { ArrayList<Task> tasks = displayContent.getTasks();
tokens = tasks.get(taskNdx).mAppTokens; for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
int tokenNdx = tokens.size() - 1;
for ( ; tokenNdx >= 0; --tokenNdx) { for ( ; tokenNdx >= 0; --tokenNdx) {
if (nextApp == mFocusedApp) { final AppWindowToken token = tokens.get(tokenNdx);
// Whoops, we are below the focused app... no focus for you! if (wtoken == token) {
if (localLOGV || DEBUG_FOCUS) Slog.v(
TAG, "findFocusedWindow: Reached focused app=" + mFocusedApp);
return null;
}
nextApp = tokens.get(tokenNdx);
if (nextApp == thisApp) {
break; break;
} }
if (mFocusedApp == token) {
// Whoops, we are below the focused app... no focus for you!
if (localLOGV || DEBUG_FOCUS_LIGHT) Slog.v(TAG,
"findFocusedWindow: Reached focused app=" + mFocusedApp);
return null;
}
} }
if (thisApp == nextApp) { if (tokenNdx >= 0) {
// Early exit from loop, must have found the matching token.
break; break;
} }
} }
if (thisApp != nextApp) {
// Uh oh, the app token doesn't exist! This shouldn't
// happen, but if it does we can get totally hosed...
// so restart at the original app.
nextApp = origAppToken;
// return indices to same place.
taskNdx = origTaskNdx;
tokenNdx = origTokenNdx;
}
} }
// Dispatch to this window if it is wants key events. if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "findFocusedWindow: Found new focus @ " + i +
if (win.canReceiveKeys()) { " = " + win);
if (DEBUG_FOCUS_LIGHT) Slog.v( return win;
TAG, "findFocusedWindow: Found new focus @ " + i + " = " + win);
return win;
}
} }
if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "findFocusedWindow: No focusable windows."); if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "findFocusedWindow: No focusable windows.");
return null; return null;
} }