summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mateusz Cicheński <mateuszc@google.com> 2023-08-30 03:17:48 +0000
committer Mateusz Cicheński <mateuszc@google.com> 2023-08-31 18:54:35 +0000
commit2ee01372e47d48bc7818eb525671522f9f549128 (patch)
tree5456460d7ecd8df475331b1ae0de56021a09f5c4
parent4c3db108d80ebb33e65d7ce03461c78afbc5f8b3 (diff)
Use the task windowing mode to determine inheritance
This matters in very unique scenario: - activity A1 is launched in Task T1 with launchMode=singleInstance - it then launches activity A2, activity A2 gets hosted in T2 due to launchMode of A1 - then A2 enters PiP - user expands PiP via the menu overlay icon - A2 decides to startActivity(...) A1 in the onPictureInPictureParamsChanged - A2 also calls finish() on itself At that point T2 was in PINNED windowing mode, but A2 was already not. The existing logic would have compared the A2 windowing mode and A1 windowing mode, and since both would be not PINNED, it would then decide to inherit the task windowing mode, making T1 now in PINNED windowing mode. This leads to wrong WM state, as T1 was not meant to be in that windowing mode. Bug: 296071915 Test: atest TaskLaunchParamsModifierTests Change-Id: I005f92ef7dbb334c64466d83eb5bbe6b4c03d144
-rw-r--r--services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java2
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java3
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java33
3 files changed, 36 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
index ad46770432a1..bd3913063a3f 100644
--- a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
+++ b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
@@ -559,7 +559,7 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
return false;
}
- final int sourceWindowingMode = source.getWindowingMode();
+ final int sourceWindowingMode = source.getTask().getWindowingMode();
if (sourceWindowingMode != WINDOWING_MODE_FULLSCREEN
&& sourceWindowingMode != WINDOWING_MODE_FREEFORM) {
return false;
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java
index 1ba8f7db531e..9c754b969604 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java
@@ -1679,9 +1679,10 @@ public class ActivityStarterTests extends WindowTestsBase {
@Test
public void testResultCanceledWhenNotAllowedStartingActivity() {
+ final Task task = new TaskBuilder(mSupervisor).build();
final ActivityStarter starter = prepareStarter(0, false);
final ActivityRecord targetRecord = new ActivityBuilder(mAtm).build();
- final ActivityRecord sourceRecord = new ActivityBuilder(mAtm).build();
+ final ActivityRecord sourceRecord = new ActivityBuilder(mAtm).setTask(task).build();
targetRecord.resultTo = sourceRecord;
// Abort the activity start and ensure the sourceRecord gets the result (RESULT_CANCELED).
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
index 739737eb318d..07cfbf094e5d 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
@@ -678,6 +678,39 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
WINDOWING_MODE_FULLSCREEN);
}
+ @Test
+ public void testInheritsSourceTaskWindowingModeWhenActivityIsInDifferentWindowingMode() {
+ final TestDisplayContent fullscreenDisplay = createNewDisplayContent(
+ WINDOWING_MODE_FULLSCREEN);
+ final ActivityRecord source = createSourceActivity(fullscreenDisplay);
+ source.setWindowingMode(WINDOWING_MODE_PINNED);
+ source.getTask().setWindowingMode(WINDOWING_MODE_FREEFORM);
+
+ assertEquals(RESULT_CONTINUE,
+ new CalculateRequestBuilder().setSource(source).calculate());
+
+ assertEquivalentWindowingMode(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode,
+ WINDOWING_MODE_FULLSCREEN);
+ }
+
+ @Test
+ public void testDoesNotInheritsSourceTaskWindowingModeWhenActivityIsInFreeformWindowingMode() {
+ // The activity could end up in different windowing mode state after calling finish()
+ // while the task would still hold the WINDOWING_MODE_PINNED state, or in other words
+ // be still in the Picture in Picture mode.
+ final TestDisplayContent fullscreenDisplay = createNewDisplayContent(
+ WINDOWING_MODE_FULLSCREEN);
+ final ActivityRecord source = createSourceActivity(fullscreenDisplay);
+ source.setWindowingMode(WINDOWING_MODE_FREEFORM);
+ source.getTask().setWindowingMode(WINDOWING_MODE_PINNED);
+
+ assertEquals(RESULT_CONTINUE,
+ new CalculateRequestBuilder().setSource(source).calculate());
+
+ assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
+ WINDOWING_MODE_FULLSCREEN);
+ }
+
@Test
public void testKeepsPictureInPictureLaunchModeInOptions() {