diff options
10 files changed, 474 insertions, 20 deletions
diff --git a/libs/WindowManager/Shell/tests/flicker/pip/Android.bp b/libs/WindowManager/Shell/tests/flicker/pip/Android.bp index c760cf1d2094..b8ec1d76d5f7 100644 --- a/libs/WindowManager/Shell/tests/flicker/pip/Android.bp +++ b/libs/WindowManager/Shell/tests/flicker/pip/Android.bp @@ -122,6 +122,8 @@ test_module_config { "com.android.wm.shell.flicker.pip.nonmatchparent.BottomHalfExitPipToAppViaExpandButtonTest", "com.android.wm.shell.flicker.pip.nonmatchparent.BottomHalfExitPipToAppViaIntentTest", "com.android.wm.shell.flicker.pip.nonmatchparent.BottomHalfSetRequestedOrientationWhilePinned", + "com.android.wm.shell.flicker.pip.nonmatchparent.BottomHalfFromSplitScreenAutoEnterPipOnGoToHomeTest", + "com.android.wm.shell.flicker.pip.nonmatchparent.BottomHalfFromSplitScreenEnterPipOnUserLeaveHintTest", ], test_suites: ["device-tests"], } @@ -324,5 +326,19 @@ test_module_config { test_suites: ["device-tests"], } +test_module_config { + name: "WMShellFlickerTestsPip-BottomHalfFromSplitScreenAutoEnterPipOnGoToHomeTest", + base: "WMShellFlickerTestsPip", + include_filters: ["com.android.wm.shell.flicker.pip.nonmatchparent.BottomHalfFromSplitScreenAutoEnterPipOnGoToHomeTest"], + test_suites: ["device-tests"], +} + +test_module_config { + name: "WMShellFlickerTestsPip-BottomHalfFromSplitScreenEnterPipOnUserLeaveHintTest", + base: "WMShellFlickerTestsPip", + include_filters: ["com.android.wm.shell.flicker.pip.nonmatchparent.BottomHalfFromSplitScreenEnterPipOnUserLeaveHintTest"], + test_suites: ["device-tests"], +} + // End breakdowns for WMShellFlickerTestsPip module //////////////////////////////////////////////////////////////////////////////// diff --git a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/AutoEnterPipOnGoToHomeTest.kt b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/AutoEnterPipOnGoToHomeTest.kt index 84d53d59e7df..597674e5dfa6 100644 --- a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/AutoEnterPipOnGoToHomeTest.kt +++ b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/AutoEnterPipOnGoToHomeTest.kt @@ -114,7 +114,7 @@ open class AutoEnterPipOnGoToHomeTest(flicker: LegacyFlickerTest) : EnterPipTran /** Checks that [pipApp] window is animated towards default position in right bottom corner */ @FlakyTest(bugId = 255578530) @Test - fun pipLayerMovesTowardsRightBottomCorner() { + open fun pipLayerMovesTowardsRightBottomCorner() { // in gestural nav the swipe makes PiP first go upwards Assume.assumeFalse(flicker.scenario.isGesturalNavigation) flicker.assertLayers { diff --git a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/FromSplitScreenAutoEnterPipOnGoToHomeTest.kt b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/FromSplitScreenAutoEnterPipOnGoToHomeTest.kt index 1c40d89aec80..f9c60ad14fae 100644 --- a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/FromSplitScreenAutoEnterPipOnGoToHomeTest.kt +++ b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/FromSplitScreenAutoEnterPipOnGoToHomeTest.kt @@ -65,11 +65,11 @@ import org.junit.runners.Parameterized @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @RequiresFlagsDisabled(Flags.FLAG_ENABLE_PIP2) -class FromSplitScreenAutoEnterPipOnGoToHomeTest(flicker: LegacyFlickerTest) : +open class FromSplitScreenAutoEnterPipOnGoToHomeTest(flicker: LegacyFlickerTest) : AutoEnterPipOnGoToHomeTest(flicker) { private val portraitDisplayBounds = WindowUtils.getDisplayBounds(Rotation.ROTATION_0) /** Second app used to enter split screen mode */ - private val secondAppForSplitScreen = + internal val secondAppForSplitScreen = SimpleAppHelper( instrumentation, ActivityOptions.SplitScreen.Primary.LABEL, diff --git a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/FromSplitScreenEnterPipOnUserLeaveHintTest.kt b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/FromSplitScreenEnterPipOnUserLeaveHintTest.kt index 79e2e4e5a82c..40ecdecde4e7 100644 --- a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/FromSplitScreenEnterPipOnUserLeaveHintTest.kt +++ b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/FromSplitScreenEnterPipOnUserLeaveHintTest.kt @@ -67,12 +67,12 @@ import org.junit.runners.Parameterized @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @RequiresFlagsDisabled(Flags.FLAG_ENABLE_PIP2) -class FromSplitScreenEnterPipOnUserLeaveHintTest(flicker: LegacyFlickerTest) : +open class FromSplitScreenEnterPipOnUserLeaveHintTest(flicker: LegacyFlickerTest) : EnterPipTransition(flicker) { override val pipApp: PipAppHelper = PipAppHelper(instrumentation) private val portraitDisplayBounds = WindowUtils.getDisplayBounds(Rotation.ROTATION_0) /** Second app used to enter split screen mode */ - private val secondAppForSplitScreen = + internal val secondAppForSplitScreen = SimpleAppHelper( instrumentation, ActivityOptions.SplitScreen.Primary.LABEL, diff --git a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/nonmatchparent/BottomHalfFromSplitScreenAutoEnterPipOnGoToHomeTest.kt b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/nonmatchparent/BottomHalfFromSplitScreenAutoEnterPipOnGoToHomeTest.kt new file mode 100644 index 000000000000..1311917eedbc --- /dev/null +++ b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/nonmatchparent/BottomHalfFromSplitScreenAutoEnterPipOnGoToHomeTest.kt @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2024 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 com.android.wm.shell.flicker.pip.nonmatchparent + +import android.platform.test.annotations.Presubmit +import android.platform.test.annotations.RequiresDevice +import android.platform.test.annotations.RequiresFlagsDisabled +import android.platform.test.annotations.RequiresFlagsEnabled +import android.tools.flicker.junit.FlickerParametersRunnerFactory +import android.tools.flicker.legacy.FlickerBuilder +import android.tools.flicker.legacy.LegacyFlickerTest +import android.tools.traces.parsers.toFlickerComponent +import com.android.server.wm.flicker.helpers.BottomHalfPipAppHelper +import com.android.server.wm.flicker.testapp.ActivityOptions +import com.android.window.flags.Flags +import com.android.wm.shell.flicker.pip.FromSplitScreenAutoEnterPipOnGoToHomeTest +import com.android.wm.shell.flicker.utils.SplitScreenUtils +import org.junit.Assume +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runners.MethodSorters +import org.junit.runners.Parameterized + +/** + * Test entering pip from a bottom half layout app via auto-enter property when navigating to home + * from split screen. + * + * To run this test: + * `atest WMShellFlickerTestsPip:BottomHalfFromSplitScreenAutoEnterPipOnGoToHomeTest` + * + * Actions: + * ``` + * Launch an app in full screen + * Open all apps and drag another app icon to enter split screen + * Select "Auto-enter PiP" radio button + * Layout the [pipApp] to the bottom half + * Press Home button or swipe up to go Home and put [pipApp] in pip mode + * ``` + * + * Notes: + * ``` + * 1. All assertions are inherited from [EnterPipTest] + * 2. Part of the test setup occurs automatically via + * [android.tools.flicker.legacy.runner.TransitionRunner], + * including configuring navigation mode, initial orientation and ensuring no + * apps are running before setup + * ``` + */ +// TODO(b/380796448): re-enable tests after the support of non-match parent PIP animation for PIP2. +@RequiresFlagsDisabled(com.android.wm.shell.Flags.FLAG_ENABLE_PIP2) +@RequiresFlagsEnabled(Flags.FLAG_BETTER_SUPPORT_NON_MATCH_PARENT_ACTIVITY) +@RequiresDevice +@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class BottomHalfFromSplitScreenAutoEnterPipOnGoToHomeTest(flicker: LegacyFlickerTest) : + FromSplitScreenAutoEnterPipOnGoToHomeTest(flicker) +{ + override val pipApp = BottomHalfPipAppHelper( + instrumentation, + useLaunchingActivity = true, + // Set the activity to fill task to enable auto enter pip via the radio option. + fillTaskOnCreate = true + ) + + /** Defines the transition used to run the test */ + override val transition: FlickerBuilder.() -> Unit + get() = { + setup { + secondAppForSplitScreen.launchViaIntent(wmHelper) + pipApp.launchViaIntent(wmHelper) + tapl.goHome() + SplitScreenUtils.enterSplit( + wmHelper, + tapl, + device, + pipApp, + secondAppForSplitScreen, + flicker.scenario.startRotation + ) + pipApp.enableAutoEnterForPipActivity() + // Set BottomHalfPipActivity to bottom half layout to continue the test. + pipApp.toggleBottomHalfLayout() + wmHelper.StateSyncBuilder() + .withLayerVisible( + ActivityOptions.BottomHalfPip.LAUNCHING_APP_COMPONENT.toFlickerComponent() + ).waitForAndVerify() + } + teardown { + pipApp.exit(wmHelper) + secondAppForSplitScreen.exit(wmHelper) + } + transitions { tapl.goHome() } + } + + @Presubmit + @Test + override fun pipLayerMovesTowardsRightBottomCorner() { + // For bottom half layout in split secondary, the start position may be lower than the final + // pip task position. + } + + /** + * Verifies the left edge of the pip layer moves to the right continuously. + */ + @Presubmit + @Test + fun pipLayerMovesTowardsRight() { + // in gestural nav the swipe makes PiP first go upwards + Assume.assumeFalse(flicker.scenario.isGesturalNavigation) + flicker.assertLayers { + val pipLayerList = this.layers { pipApp.layerMatchesAnyOf(it) && it.isVisible } + pipLayerList.zipWithNext { previous, current -> + current.visibleRegion.isLeftEdgeToTheRight(previous.visibleRegion.region) + } + } + } +}
\ No newline at end of file diff --git a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/nonmatchparent/BottomHalfFromSplitScreenEnterPipOnUserLeaveHintTest.kt b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/nonmatchparent/BottomHalfFromSplitScreenEnterPipOnUserLeaveHintTest.kt new file mode 100644 index 000000000000..2e34b6a127d8 --- /dev/null +++ b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/nonmatchparent/BottomHalfFromSplitScreenEnterPipOnUserLeaveHintTest.kt @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2024 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 com.android.wm.shell.flicker.pip.nonmatchparent + +import android.platform.test.annotations.RequiresDevice +import android.platform.test.annotations.RequiresFlagsDisabled +import android.platform.test.annotations.RequiresFlagsEnabled +import android.tools.flicker.junit.FlickerParametersRunnerFactory +import android.tools.flicker.legacy.FlickerBuilder +import android.tools.flicker.legacy.LegacyFlickerTest +import android.tools.traces.parsers.toFlickerComponent +import com.android.server.wm.flicker.helpers.BottomHalfPipAppHelper +import com.android.server.wm.flicker.testapp.ActivityOptions +import com.android.window.flags.Flags +import com.android.wm.shell.flicker.pip.FromSplitScreenEnterPipOnUserLeaveHintTest +import com.android.wm.shell.flicker.utils.SplitScreenUtils +import org.junit.FixMethodOrder +import org.junit.runners.MethodSorters +import org.junit.runners.Parameterized + +/** + * Test entering pip from a bottom half layout app via enter-pip-on-user-leave property when + * navigating to home from split screen. + * + * To run this test: + * `atest WMShellFlickerTestsPip:BottomHalfFromSplitScreenEnterPipOnUserLeaveHintTest` + * + * Actions: + * ``` + * Launch an app in full screen + * Open all apps and drag another app icon to enter split screen + * Select "Enter PiP on user leave" radio button + * Layout the [pipApp] to the bottom half + * Press Home button or swipe up to go Home and put [pipApp] in pip mode + * ``` + * + * Notes: + * ``` + * 1. All assertions are inherited from [EnterPipTest] + * 2. Part of the test setup occurs automatically via + * [android.tools.flicker.legacy.runner.TransitionRunner], + * including configuring navigation mode, initial orientation and ensuring no + * apps are running before setup + * ``` + */ +// TODO(b/380796448): re-enable tests after the support of non-match parent PIP animation for PIP2. +@RequiresFlagsDisabled(com.android.wm.shell.Flags.FLAG_ENABLE_PIP2) +@RequiresFlagsEnabled(Flags.FLAG_BETTER_SUPPORT_NON_MATCH_PARENT_ACTIVITY) +@RequiresDevice +@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class BottomHalfFromSplitScreenEnterPipOnUserLeaveHintTest(flicker: LegacyFlickerTest) : + FromSplitScreenEnterPipOnUserLeaveHintTest(flicker) +{ + override val pipApp = BottomHalfPipAppHelper( + instrumentation, + useLaunchingActivity = true, + // Set the activity to fill task to enable user leave hint via the radio option. + fillTaskOnCreate = true + ) + + /** Defines the transition used to run the test */ + override val transition: FlickerBuilder.() -> Unit + get() = { + setup { + secondAppForSplitScreen.launchViaIntent(wmHelper) + pipApp.launchViaIntent(wmHelper) + tapl.goHome() + SplitScreenUtils.enterSplit( + wmHelper, + tapl, + device, + pipApp, + secondAppForSplitScreen, + flicker.scenario.startRotation + ) + pipApp.enableEnterPipOnUserLeaveHint() + // Set BottomHalfPipActivity to bottom half layout to continue the test. + pipApp.toggleBottomHalfLayout() + wmHelper.StateSyncBuilder() + .withLayerVisible( + ActivityOptions.BottomHalfPip.LAUNCHING_APP_COMPONENT.toFlickerComponent() + ).waitForAndVerify() + } + teardown { + pipApp.exit(wmHelper) + secondAppForSplitScreen.exit(wmHelper) + } + transitions { tapl.goHome() } + } +}
\ No newline at end of file diff --git a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/BottomHalfPipAppHelper.kt b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/BottomHalfPipAppHelper.kt index ed2cff4a9515..fe344c9b79f2 100644 --- a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/BottomHalfPipAppHelper.kt +++ b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/BottomHalfPipAppHelper.kt @@ -18,25 +18,28 @@ package com.android.server.wm.flicker.helpers import android.app.Instrumentation import android.content.Intent -import android.tools.traces.parsers.toFlickerComponent import android.tools.traces.parsers.WindowManagerStateHelper -import com.android.server.wm.flicker.testapp.ActivityOptions +import android.tools.traces.parsers.toFlickerComponent +import com.android.server.wm.flicker.testapp.ActivityOptions.BottomHalfPip class BottomHalfPipAppHelper( instrumentation: Instrumentation, private val useLaunchingActivity: Boolean = false, + private val fillTaskOnCreate: Boolean = true, ) : PipAppHelper( instrumentation, - appName = ActivityOptions.BottomHalfPip.LABEL, - componentNameMatcher = ActivityOptions.BottomHalfPip.COMPONENT - .toFlickerComponent() + appName = BottomHalfPip.LABEL, + componentNameMatcher = BottomHalfPip.COMPONENT.toFlickerComponent() ) { override val openAppIntent: Intent get() = super.openAppIntent.apply { component = if (useLaunchingActivity) { - ActivityOptions.BottomHalfPip.LAUNCHING_APP_COMPONENT + BottomHalfPip.LAUNCHING_APP_COMPONENT } else { - ActivityOptions.BottomHalfPip.COMPONENT + BottomHalfPip.COMPONENT + } + if (fillTaskOnCreate) { + putExtra(BottomHalfPip.EXTRA_BOTTOM_HALF_LAYOUT, false.toString()) } } @@ -44,9 +47,17 @@ class BottomHalfPipAppHelper( launchViaIntent( wmHelper, Intent().apply { - component = ActivityOptions.BottomHalfPip.COMPONENT + component = BottomHalfPip.COMPONENT addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } ) } + + fun toggleBottomHalfLayout() { + clickObject(TOGGLE_BOTTOM_HALF_LAYOUT_ID) + } + + companion object { + private const val TOGGLE_BOTTOM_HALF_LAYOUT_ID = "toggle_bottom_half_layout" + } }
\ No newline at end of file diff --git a/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_bottom_half_pip.xml b/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_bottom_half_pip.xml new file mode 100644 index 000000000000..2f9c3aa82057 --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_bottom_half_pip.xml @@ -0,0 +1,154 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2024 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. + --> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:background="@android:color/holo_blue_bright"> + + <!-- All the buttons (and other clickable elements) should be arranged in a way so that it is + possible to "cycle" over all them by clicking on the D-Pad DOWN button. The way we do it + here is by arranging them this vertical LL and by relying on the nextFocusDown attribute + where things are arranged differently and to circle back up to the top once we reach the + bottom. --> + + <Button + android:id="@+id/enter_pip" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Enter PIP" + android:onClick="enterPip"/> + + <Button + android:id="@+id/toggle_bottom_half_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Set Bottom Half Layout" + android:onClick="toggleBottomHalfLayout"/> + + <CheckBox + android:id="@+id/with_custom_actions" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="With custom actions"/> + + <RadioGroup + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:checkedButton="@id/enter_pip_on_leave_disabled"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Enter PiP on home press"/> + + <RadioButton + android:id="@+id/enter_pip_on_leave_disabled" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Disabled" + android:onClick="onAutoPipSelected"/> + + <RadioButton + android:id="@+id/enter_pip_on_leave_manual" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Via code behind" + android:onClick="onAutoPipSelected"/> + + <RadioButton + android:id="@+id/enter_pip_on_leave_autoenter" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Auto-enter PiP" + android:onClick="onAutoPipSelected"/> + </RadioGroup> + + <RadioGroup + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:checkedButton="@id/ratio_default"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Ratio"/> + + <RadioButton + android:id="@+id/ratio_default" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Default" + android:onClick="onRatioSelected"/> + + <RadioButton + android:id="@+id/ratio_square" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Square [1:1]" + android:onClick="onRatioSelected"/> + + <RadioButton + android:id="@+id/ratio_wide" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Wide [2:1]" + android:onClick="onRatioSelected"/> + + <RadioButton + android:id="@+id/ratio_tall" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Tall [1:2]" + android:onClick="onRatioSelected"/> + </RadioGroup> + + <CheckBox + android:id="@+id/set_source_rect_hint" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Set SourceRectHint"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Media Session"/> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + + <Button + android:id="@+id/media_session_start" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:nextFocusDown="@id/media_session_stop" + android:text="Start"/> + + <Button + android:id="@+id/media_session_stop" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:nextFocusDown="@id/enter_pip" + android:text="Stop"/> + + </LinearLayout> + +</LinearLayout> diff --git a/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/BottomHalfPipActivity.java b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/BottomHalfPipActivity.java index 3d4865572486..3bbb94515f69 100644 --- a/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/BottomHalfPipActivity.java +++ b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/BottomHalfPipActivity.java @@ -16,9 +16,14 @@ package com.android.server.wm.flicker.testapp; +import static com.android.server.wm.flicker.testapp.ActivityOptions.BottomHalfPip.EXTRA_BOTTOM_HALF_LAYOUT; + import android.app.Activity; +import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; +import android.view.Gravity; +import android.view.View; import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; @@ -26,11 +31,13 @@ import androidx.annotation.NonNull; public class BottomHalfPipActivity extends PipActivity { + private boolean mUseBottomHalfLayout; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.activity_bottom_half_pip); setTheme(R.style.TranslucentTheme); - updateLayout(); } @Override @@ -41,14 +48,28 @@ public class BottomHalfPipActivity extends PipActivity { } /** + * Toggles the layout mode between fill task and half-bottom modes. + */ + public void toggleBottomHalfLayout(View v) { + mUseBottomHalfLayout = !mUseBottomHalfLayout; + updateLayout(); + } + + /** * Sets to match parent layout if the activity is - * {@link Activity#isInPictureInPictureMode()}. Otherwise, set to bottom half - * layout. + * {@link Activity#isInPictureInPictureMode()}. Otherwise, + * follows {@link #mUseBottomHalfLayout}. * * @see #setToBottomHalfMode(boolean) */ private void updateLayout() { - setToBottomHalfMode(!isInPictureInPictureMode()); + final boolean useBottomHalfLayout; + if (isInPictureInPictureMode()) { + useBottomHalfLayout = false; + } else { + useBottomHalfLayout = mUseBottomHalfLayout; + } + setToBottomHalfMode(useBottomHalfLayout); } /** @@ -57,15 +78,31 @@ public class BottomHalfPipActivity extends PipActivity { */ private void setToBottomHalfMode(boolean useBottomHalfLayout) { final WindowManager.LayoutParams attrs = getWindow().getAttributes(); + attrs.gravity = Gravity.BOTTOM; if (useBottomHalfLayout) { final int taskHeight = getWindowManager().getCurrentWindowMetrics().getBounds() .height(); - attrs.y = taskHeight / 2; attrs.height = taskHeight / 2; } else { - attrs.y = 0; attrs.height = LayoutParams.MATCH_PARENT; } getWindow().setAttributes(attrs); } + + @Override + void handleIntentExtra(@NonNull Intent intent) { + super.handleIntentExtra(intent); + if (intent.hasExtra(EXTRA_BOTTOM_HALF_LAYOUT)) { + final String booleanString = intent.getStringExtra(EXTRA_BOTTOM_HALF_LAYOUT); + // We don't use Boolean#parseBoolean here because the impl only checks if the string + // equals to "true", and returns for any other cases. We use our own impl here to + // prevent false positive. + if ("true".equals(booleanString)) { + mUseBottomHalfLayout = true; + } else if ("false".equals(booleanString)) { + mUseBottomHalfLayout = false; + } + } + updateLayout(); + } } diff --git a/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/PipActivity.java b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/PipActivity.java index 13d7f7f0d521..ee25ab2fb66c 100644 --- a/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/PipActivity.java +++ b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/PipActivity.java @@ -350,7 +350,7 @@ public class PipActivity extends Activity { mMediaSession.setActive(newState != STATE_STOPPED); } - private void handleIntentExtra(Intent intent) { + void handleIntentExtra(Intent intent) { // Set the fixed orientation if requested if (intent.hasExtra(EXTRA_PIP_ORIENTATION)) { final int ori = Integer.parseInt(getIntent().getStringExtra(EXTRA_PIP_ORIENTATION)); |