diff options
author | 2025-01-06 04:21:29 -0800 | |
---|---|---|
committer | 2025-01-06 04:21:29 -0800 | |
commit | 471a8036bebc7f3ff064a9ce893beafe945df7ea (patch) | |
tree | f79cc45ede50c4ce133bf977b0808d4008f27f37 /tests/FlickerTests | |
parent | 40a39e23fa1eb7adb3000b90dc263025eb32cf96 (diff) | |
parent | d752b2e3b7168a2d3acd9da8e7a436f5d79abf00 (diff) |
Merge "Test entering PIP from split-screen with bottom half layout" into main
Diffstat (limited to 'tests/FlickerTests')
4 files changed, 217 insertions, 15 deletions
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)); |