Set root task focused if one of its children is focused
There are several "unorganized" non-root tasks that aren't available in TaskOrganizer, e.g. Home, and when they are in focus no task in WM shell is focused without this change. Bug: 207687679 Test: dumpsys activity service SystemUIService WMShell Test: atest WmTests:TaskTests#testPropagateFocusedStateToRootTask Change-Id: I48dafb50d70eced55a883f50d84519f884233503
This commit is contained in:
@@ -4291,13 +4291,14 @@ class Task extends TaskFragment {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the task is currently focused.
|
||||
* @return {@code true} if the task is currently focused or one of its children is focused.
|
||||
*/
|
||||
boolean isFocused() {
|
||||
if (mDisplayContent == null || mDisplayContent.mFocusedApp == null) {
|
||||
return false;
|
||||
}
|
||||
return mDisplayContent.mFocusedApp.getTask() == this;
|
||||
final Task focusedTask = mDisplayContent.mFocusedApp.getTask();
|
||||
return focusedTask == this || (focusedTask != null && focusedTask.getParent() == this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4317,6 +4318,8 @@ class Task extends TaskFragment {
|
||||
*/
|
||||
void onAppFocusChanged(boolean hasFocus) {
|
||||
dispatchTaskInfoChangedIfNeeded(false /* force */);
|
||||
final Task parentTask = getParent().asTask();
|
||||
if (parentTask != null) parentTask.dispatchTaskInfoChangedIfNeeded(false /* force */);
|
||||
}
|
||||
|
||||
void onPictureInPictureParamsChanged() {
|
||||
|
||||
@@ -432,6 +432,24 @@ public class TaskTests extends WindowTestsBase {
|
||||
Assert.assertThat(info.baseIntent, not(sameInstance(task.getBaseIntent())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropagateFocusedStateToRootTask() {
|
||||
final Task rootTask = createTask(mDefaultDisplay);
|
||||
final Task leafTask = createTaskInRootTask(rootTask, 0 /* userId */);
|
||||
|
||||
final ActivityRecord activity = createActivityRecord(leafTask);
|
||||
|
||||
leafTask.getDisplayContent().setFocusedApp(activity);
|
||||
|
||||
assertTrue(leafTask.getTaskInfo().isFocused);
|
||||
assertTrue(rootTask.getTaskInfo().isFocused);
|
||||
|
||||
leafTask.getDisplayContent().setFocusedApp(null);
|
||||
|
||||
assertFalse(leafTask.getTaskInfo().isFocused);
|
||||
assertFalse(rootTask.getTaskInfo().isFocused);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnsToHomeRootTask() throws Exception {
|
||||
final Task task = createTask(1);
|
||||
|
||||
Reference in New Issue
Block a user