Merge "Changed task focused to be based on focused app vs. window" into sc-v2-dev

This commit is contained in:
Wale Ogunwale
2021-07-28 13:23:22 +00:00
committed by Android (Google) Code Review
3 changed files with 11 additions and 50 deletions

View File

@@ -504,11 +504,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
*/
WindowState mCurrentFocus = null;
/**
* The last focused window that we've notified the client that the focus is changed.
*/
WindowState mLastFocus = null;
/**
* The foreground app of this display. Windows below this app cannot be the focused window. If
* the user taps on the area outside of the task of the focused app, we will notify AM about the
@@ -1244,12 +1239,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
// removing from parent.
token.getParent().removeChild(token);
}
if (token.hasChild(prevDc.mLastFocus)) {
// If the reparent window token contains previous display's last focus window, means
// it will end up to gain window focus on the target display, so it should not be
// notified that it lost focus from the previous display.
prevDc.mLastFocus = null;
}
}
addWindowToken(token.token, token);
@@ -3204,9 +3193,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);
pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
if (mLastFocus != mCurrentFocus) {
pw.print(" mLastFocus="); pw.println(mLastFocus);
}
pw.print(" mFocusedApp="); pw.println(mFocusedApp);
if (mFixedRotationLaunchingApp != null) {
pw.println(" mFixedRotationLaunchingApp=" + mFixedRotationLaunchingApp);
@@ -3437,8 +3423,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
}
}
onWindowFocusChanged(oldFocus, newFocus);
int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus);
if (imWindowChanged && oldFocus != mInputMethodWindow) {
@@ -3489,7 +3473,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
mWmService.mAccessibilityController));
}
mLastFocus = mCurrentFocus;
return true;
}
@@ -3497,20 +3480,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
accessibilityController.onWindowFocusChangedNot(getDisplayId());
}
private static void onWindowFocusChanged(WindowState oldFocus, WindowState newFocus) {
final Task focusedTask = newFocus != null ? newFocus.getTask() : null;
final Task unfocusedTask = oldFocus != null ? oldFocus.getTask() : null;
if (focusedTask == unfocusedTask) {
return;
}
if (focusedTask != null) {
focusedTask.onWindowFocusChanged(true /* hasFocus */);
}
if (unfocusedTask != null) {
unfocusedTask.onWindowFocusChanged(false /* hasFocus */);
}
}
/**
* Set the new focused app to this display.
*
@@ -3534,7 +3503,14 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
}
ProtoLog.i(WM_DEBUG_FOCUS_LIGHT, "setFocusedApp %s displayId=%d Callers=%s",
newFocus, getDisplayId(), Debug.getCallers(4));
final Task oldTask = mFocusedApp != null ? mFocusedApp.getTask() : null;
final Task newTask = newFocus != null ? newFocus.getTask() : null;
mFocusedApp = newFocus;
if (oldTask != newTask) {
if (oldTask != null) oldTask.onAppFocusChanged(false);
if (newTask != null) newTask.onAppFocusChanged(true);
}
getInputMonitor().setFocusedAppLw(newFocus);
updateTouchExcludeRegion();
return true;
@@ -4230,7 +4206,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
if (DEBUG_INPUT_METHOD) {
Slog.i(TAG_WM, "Desired input method target: " + imFocus);
Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId);
Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId);
}
if (DEBUG_INPUT_METHOD) {

View File

@@ -4314,10 +4314,10 @@ class Task extends TaskFragment {
* @return true if the task is currently focused.
*/
private boolean isFocused() {
if (mDisplayContent == null || mDisplayContent.mCurrentFocus == null) {
if (mDisplayContent == null || mDisplayContent.mFocusedApp == null) {
return false;
}
return mDisplayContent.mCurrentFocus.getTask() == this;
return mDisplayContent.mFocusedApp.getTask() == this;
}
/**
@@ -4374,10 +4374,9 @@ class Task extends TaskFragment {
* Called on the task of a window which gained or lost focus.
* @param hasFocus
*/
void onWindowFocusChanged(boolean hasFocus) {
void onAppFocusChanged(boolean hasFocus) {
updateShadowsRadius(hasFocus, getSyncTransaction());
// TODO(b/180525887): Un-comment once there is resolution on the bug.
// dispatchTaskInfoChangedIfNeeded(false /* force */);
dispatchTaskInfoChangedIfNeeded(false /* force */);
}
void onPictureInPictureParamsChanged() {

View File

@@ -871,19 +871,6 @@ public class DisplayContentTests extends WindowTestsBase {
.setDisplayInfoOverrideFromWindowManager(dc.getDisplayId(), null);
}
@UseTestDisplay
@Test
public void testClearLastFocusWhenReparentingFocusedWindow() {
final DisplayContent defaultDisplay = mWm.getDefaultDisplayContentLocked();
final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION,
defaultDisplay, "window");
defaultDisplay.mLastFocus = window;
mDisplayContent.mCurrentFocus = window;
mDisplayContent.reParentWindowToken(window.mToken);
assertNull(defaultDisplay.mLastFocus);
}
@Test
public void testGetPreferredOptionsPanelGravityFromDifferentDisplays() {
final DisplayContent portraitDisplay = createNewDisplay();