Merge "Set root task focused if one of its children is focused"

This commit is contained in:
Garfield Tan
2022-11-16 17:54:23 +00:00
committed by Android (Google) Code Review
2 changed files with 23 additions and 2 deletions

View File

@@ -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() {

View File

@@ -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);