1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.server.wm.jetpack.embedding; 18 19 import static android.server.wm.jetpack.utils.ExtensionUtil.assumeExtensionSupportedDevice; 20 import static android.server.wm.jetpack.utils.ExtensionUtil.getWindowExtensions; 21 22 import static org.junit.Assume.assumeNotNull; 23 import static org.junit.Assume.assumeTrue; 24 25 import android.app.ActivityTaskManager; 26 import android.server.wm.ActivityManagerTestBase.ReportedDisplayMetrics; 27 import android.server.wm.UiDeviceUtils; 28 import android.server.wm.jetpack.utils.TestValueCountConsumer; 29 import android.server.wm.jetpack.utils.WindowManagerJetpackTestBase; 30 import android.view.Display; 31 32 import androidx.test.core.app.ApplicationProvider; 33 import androidx.window.extensions.WindowExtensions; 34 import androidx.window.extensions.embedding.ActivityEmbeddingComponent; 35 import androidx.window.extensions.embedding.SplitInfo; 36 37 import org.junit.After; 38 import org.junit.Before; 39 40 import java.util.List; 41 42 /** 43 * Base test class for the {@link androidx.window.extensions} implementation provided on the device 44 * (and only if one is available) for the Activity Embedding functionality. 45 */ 46 public class ActivityEmbeddingTestBase extends WindowManagerJetpackTestBase { 47 48 protected ActivityEmbeddingComponent mActivityEmbeddingComponent; 49 protected TestValueCountConsumer<List<SplitInfo>> mSplitInfoConsumer; 50 protected ReportedDisplayMetrics mReportedDisplayMetrics = 51 ReportedDisplayMetrics.getDisplayMetrics(Display.DEFAULT_DISPLAY); 52 53 @Override 54 @Before setUp()55 public void setUp() { 56 super.setUp(); 57 assumeTrue(supportsMultiWindow()); 58 assumeExtensionSupportedDevice(); 59 WindowExtensions windowExtensions = getWindowExtensions(); 60 assumeNotNull(windowExtensions); 61 mActivityEmbeddingComponent = windowExtensions.getActivityEmbeddingComponent(); 62 assumeNotNull(mActivityEmbeddingComponent); 63 mSplitInfoConsumer = new TestValueCountConsumer<>(); 64 mActivityEmbeddingComponent.setSplitInfoCallback(mSplitInfoConsumer); 65 66 67 UiDeviceUtils.pressWakeupButton(); 68 UiDeviceUtils.pressUnlockButton(); 69 } 70 71 /** Checks whether the device supports the multi-window feature or not. */ supportsMultiWindow()72 private static boolean supportsMultiWindow() { 73 return ActivityTaskManager.supportsMultiWindow(ApplicationProvider.getApplicationContext()); 74 } 75 76 @After cleanUp()77 public void cleanUp() { 78 mReportedDisplayMetrics.restoreDisplayMetrics(); 79 } 80 } 81