Adds testLaunchStoppedActivityWithPiPInSameProcessPreQ
For Pre-Q apps, ensure that activity can be launched from stopped state
while an activity from same process is in PiP mode.
Bug: 137085496
Test: atest CtsWindowManagerDeviceTestCases
Change-Id: I73610b9633049eb668b327861aa86980738767dd
diff --git a/tests/framework/base/windowmanager/app27/AndroidManifest.xml b/tests/framework/base/windowmanager/app27/AndroidManifest.xml
index ab9dbc0..66da0e6 100755
--- a/tests/framework/base/windowmanager/app27/AndroidManifest.xml
+++ b/tests/framework/base/windowmanager/app27/AndroidManifest.xml
@@ -34,6 +34,17 @@
android:exported="true"
/>
+ <activity android:name=".LaunchEnterPipActivity"
+ android:exported="true"
+ />
+
+ <activity android:name=".PipActivity"
+ android:resizeableActivity="false"
+ android:supportsPictureInPicture="true"
+ android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout"
+ android:exported="true"
+ />
+
<activity android:name=".HomeActivity"
android:enabled="false"
android:exported="true">
diff --git a/tests/framework/base/windowmanager/app27/src/android/server/wm/app27/Components.java b/tests/framework/base/windowmanager/app27/src/android/server/wm/app27/Components.java
index fd05e74..bf59582 100644
--- a/tests/framework/base/windowmanager/app27/src/android/server/wm/app27/Components.java
+++ b/tests/framework/base/windowmanager/app27/src/android/server/wm/app27/Components.java
@@ -33,6 +33,12 @@
public static final ComponentName SDK_27_SEPARATE_PROCESS_ACTIVITY =
component(Components.class, "SeparateProcessActivity");
+ public static final ComponentName SDK_27_LAUNCH_ENTER_PIP_ACTIVITY =
+ component(Components.class, "LaunchEnterPipActivity");
+
+ public static final ComponentName SDK_27_PIP_ACTIVITY =
+ component(Components.class, "PipActivity");
+
public static final ComponentName SDK_27_HOME_ACTIVITY =
component(Components.class, "HomeActivity");
}
diff --git a/tests/framework/base/windowmanager/app27/src/android/server/wm/app27/LaunchEnterPipActivity.java b/tests/framework/base/windowmanager/app27/src/android/server/wm/app27/LaunchEnterPipActivity.java
new file mode 100644
index 0000000..ad1e431
--- /dev/null
+++ b/tests/framework/base/windowmanager/app27/src/android/server/wm/app27/LaunchEnterPipActivity.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package android.server.wm.app27;
+
+import static android.server.wm.app.Components.PipActivity.EXTRA_ENTER_PIP;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+
+public class LaunchEnterPipActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+ if (getIntent().hasExtra(EXTRA_ENTER_PIP)) {
+ startActivity(new Intent(this, PipActivity.class));
+ }
+ }
+}
diff --git a/tests/framework/base/windowmanager/app27/src/android/server/wm/app27/PipActivity.java b/tests/framework/base/windowmanager/app27/src/android/server/wm/app27/PipActivity.java
new file mode 100644
index 0000000..6bcf8fa
--- /dev/null
+++ b/tests/framework/base/windowmanager/app27/src/android/server/wm/app27/PipActivity.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package android.server.wm.app27;
+
+import android.app.Activity;
+import android.app.PictureInPictureParams;
+import android.os.Bundle;
+import android.util.Rational;
+
+public class PipActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+ enterPictureInPictureMode(
+ new PictureInPictureParams.Builder()
+ .setAspectRatio(new Rational(1, 1))
+ .build());
+ }
+}
\ No newline at end of file
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java b/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
index e01c51c..98669b7 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
@@ -60,6 +60,8 @@
import static android.server.wm.app.Components.TestActivity.EXTRA_CONFIGURATION;
import static android.server.wm.app.Components.TestActivity.EXTRA_FIXED_ORIENTATION;
import static android.server.wm.app.Components.TestActivity.TEST_ACTIVITY_ACTION_FINISH_SELF;
+import static android.server.wm.app27.Components.SDK_27_LAUNCH_ENTER_PIP_ACTIVITY;
+import static android.server.wm.app27.Components.SDK_27_PIP_ACTIVITY;
import static android.view.Display.DEFAULT_DISPLAY;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
@@ -752,6 +754,30 @@
}
@Test
+ public void testLaunchStoppedActivityWithPiPInSameProcessPreQ() {
+ // Try to enter picture-in-picture from an activity that has more than one activity in the
+ // task and ensure that it works, for pre-Q app
+ launchActivity(SDK_27_LAUNCH_ENTER_PIP_ACTIVITY,
+ EXTRA_ENTER_PIP, "true");
+ waitForEnterPip(SDK_27_PIP_ACTIVITY);
+ assertPinnedStackExists();
+
+ // Puts the host activity to stopped state
+ launchHomeActivity();
+ mAmWmState.assertHomeActivityVisible(true);
+ waitAndAssertActivityState(SDK_27_LAUNCH_ENTER_PIP_ACTIVITY, STATE_STOPPED,
+ "Activity should become STOPPED");
+ mAmWmState.assertVisibility(SDK_27_LAUNCH_ENTER_PIP_ACTIVITY, false);
+
+ // Host activity should be visible after re-launch and PiP window still exists
+ launchActivity(SDK_27_LAUNCH_ENTER_PIP_ACTIVITY);
+ waitAndAssertActivityState(SDK_27_LAUNCH_ENTER_PIP_ACTIVITY, STATE_RESUMED,
+ "Activity should become RESUMED");
+ mAmWmState.assertVisibility(SDK_27_LAUNCH_ENTER_PIP_ACTIVITY, true);
+ assertPinnedStackExists();
+ }
+
+ @Test
public void testEnterPipWithResumeWhilePausingActivityNoStop() throws Exception {
/*
* Launch the resumeWhilePausing activity and ensure that the PiP activity did not get