diff --git a/tests/FlickerTests/Android.bp b/tests/FlickerTests/Android.bp index 7731e098d9f5f..855d3c1f4ea7d 100644 --- a/tests/FlickerTests/Android.bp +++ b/tests/FlickerTests/Android.bp @@ -46,6 +46,7 @@ android_test { "launcher-helper-lib", "launcher-aosp-tapl", "platform-test-annotations", + "wm-flicker-window-extensions", ], } @@ -83,5 +84,21 @@ java_library { "flickertestapplib", "truth-prebuilt", "app-helpers-core", + "wm-flicker-window-extensions", ], } + +android_library_import { + name: "wm-flicker-window-extensions_nodeps", + aars: ["libs/window-extensions-release.aar"], + sdk_version: "current", +} + +java_library { + name: "wm-flicker-window-extensions", + sdk_version: "current", + static_libs: [ + "wm-flicker-window-extensions_nodeps", + ], + installable: false, +} diff --git a/tests/FlickerTests/AndroidManifest.xml b/tests/FlickerTests/AndroidManifest.xml index fda6091964569..e173eba0a3934 100644 --- a/tests/FlickerTests/AndroidManifest.xml +++ b/tests/FlickerTests/AndroidManifest.xml @@ -43,6 +43,7 @@ + { + return FlickerTestParameterFactory.getInstance() + .getConfigNonRotationTests( + repetitions = 1, + supportedRotations = listOf(Surface.ROTATION_0, Surface.ROTATION_90), + supportedNavigationModes = listOf( + WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY, + WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY + ) + ) + } + } +} diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ActivityEmbeddingAppHelper.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ActivityEmbeddingAppHelper.kt new file mode 100644 index 0000000000000..a01f633cbae47 --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ActivityEmbeddingAppHelper.kt @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2022 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.server.wm.flicker.helpers + +import android.app.Instrumentation +import android.support.test.launcherhelper.ILauncherStrategy +import android.support.test.launcherhelper.LauncherStrategyFactory +import android.util.Log +import androidx.test.uiautomator.By +import androidx.test.uiautomator.Until +import androidx.window.extensions.WindowExtensions +import androidx.window.extensions.WindowExtensionsProvider +import androidx.window.extensions.embedding.ActivityEmbeddingComponent +import com.android.server.wm.flicker.testapp.ActivityOptions +import com.android.server.wm.traces.common.FlickerComponentName +import com.android.server.wm.traces.common.windowmanager.WindowManagerState.Companion.STATE_RESUMED +import com.android.server.wm.traces.parser.toFlickerComponent +import com.android.server.wm.traces.parser.windowmanager.WindowManagerStateHelper +import org.junit.Assume.assumeNotNull + +class ActivityEmbeddingAppHelper @JvmOverloads constructor( + instr: Instrumentation, + launcherName: String = ActivityOptions.ACTIVITY_EMBEDDING_LAUNCHER_NAME, + component: FlickerComponentName = MAIN_ACTIVITY_COMPONENT, + launcherStrategy: ILauncherStrategy = LauncherStrategyFactory + .getInstance(instr) + .launcherStrategy +) : StandardAppHelper(instr, launcherName, component, launcherStrategy) { + + /** + * Clicks the button to launch the placeholder primary activity, which should launch the + * placeholder secondary activity based on the placeholder rule. + */ + fun launchPlaceholderSplit(wmHelper: WindowManagerStateHelper) { + val launchButton = uiDevice.wait( + Until.findObject(By.res(getPackage(), "launch_placeholder_split_button")), + FIND_TIMEOUT) + require(launchButton != null) { + "Can't find launch placeholder split button on screen." + } + launchButton.click() + wmHelper.StateSyncBuilder() + .withActivityState(PLACEHOLDER_PRIMARY_COMPONENT, STATE_RESUMED) + .withActivityState(PLACEHOLDER_SECONDARY_COMPONENT, STATE_RESUMED) + .waitForAndVerify() + } + + companion object { + private const val TAG = "ActivityEmbeddingAppHelper" + + val MAIN_ACTIVITY_COMPONENT = ActivityOptions + .ACTIVITY_EMBEDDING_MAIN_ACTIVITY_COMPONENT_NAME.toFlickerComponent() + + val PLACEHOLDER_PRIMARY_COMPONENT = ActivityOptions + .ACTIVITY_EMBEDDING_PLACEHOLDER_PRIMARY_ACTIVITY_COMPONENT_NAME.toFlickerComponent() + + val PLACEHOLDER_SECONDARY_COMPONENT = ActivityOptions + .ACTIVITY_EMBEDDING_PLACEHOLDER_SECONDARY_ACTIVITY_COMPONENT_NAME + .toFlickerComponent() + + @JvmStatic + fun getWindowExtensions(): WindowExtensions? { + try { + return WindowExtensionsProvider.getWindowExtensions() + } catch (e: NoClassDefFoundError) { + Log.d(TAG, "Extension implementation not found") + } catch (e: UnsupportedOperationException) { + Log.d(TAG, "Stub Extension") + } + return null + } + + @JvmStatic + fun getActivityEmbeddingComponent(): ActivityEmbeddingComponent? { + return getWindowExtensions()?.activityEmbeddingComponent + } + + @JvmStatic + fun assumeActivityEmbeddingSupportedDevice() { + assumeNotNull(getActivityEmbeddingComponent()) + } + } +} diff --git a/tests/FlickerTests/test-apps/flickerapp/Android.bp b/tests/FlickerTests/test-apps/flickerapp/Android.bp index 78660c04d8d4f..0c698abeceeb4 100644 --- a/tests/FlickerTests/test-apps/flickerapp/Android.bp +++ b/tests/FlickerTests/test-apps/flickerapp/Android.bp @@ -26,6 +26,11 @@ android_test { srcs: ["**/*.java"], sdk_version: "current", test_suites: ["device-tests"], + static_libs: [ + "androidx.test.ext.junit", + "wm-flicker-common-app-helpers", + "wm-flicker-window-extensions", + ], } java_library { diff --git a/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml b/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml index 3e2130dc480fd..387f19b2396fc 100644 --- a/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml +++ b/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml @@ -15,12 +15,14 @@ --> + package="com.android.server.wm.flicker.testapp"> + + + + + + + + + + + + diff --git a/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_embedding_base_layout.xml b/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_embedding_base_layout.xml new file mode 100644 index 0000000000000..3a02cadc90dd9 --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_embedding_base_layout.xml @@ -0,0 +1,24 @@ + + + + + diff --git a/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_embedding_main_layout.xml b/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_embedding_main_layout.xml new file mode 100644 index 0000000000000..19c81a8ba0f51 --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_embedding_main_layout.xml @@ -0,0 +1,32 @@ + + + + +