1 /* 2 * Copyright (C) 2024 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 android.graphics.Point; 20 import android.server.wm.ActivityManagerTestBase.VirtualDisplaySession; 21 import android.server.wm.WindowManagerState; 22 23 import androidx.annotation.NonNull; 24 25 /** 26 * A helper class to manage secondary display for testing. 27 */ 28 public class MultiDisplayTestHelper { 29 30 public static final Point SIMULATED_DISPLAY_SIZE = new Point(1920, 1080); 31 32 public static final int SIMULATED_DISPLAY_DENSITY_DP = 160; 33 34 private final VirtualDisplaySession mSession; 35 36 private int mSecondaryDisplayId; 37 MultiDisplayTestHelper(@onNull VirtualDisplaySession session)38 public MultiDisplayTestHelper(@NonNull VirtualDisplaySession session) { 39 mSession = session; 40 } 41 42 /** 43 * Sets up a secondary display for testing. 44 * <p> 45 * Note that this method should be put before 46 * {@link ActivityEmbeddingTestBase#setUp() super.setUp} so that {@code mReportedDisplayMetrics} 47 * could be set correctly. 48 */ setUpTestDisplay()49 public void setUpTestDisplay() { 50 final WindowManagerState.DisplayContent display = 51 createLandscapeLargeScreenSimulatedDisplay(mSession); 52 mSecondaryDisplayId = display.mId; 53 } 54 55 /** 56 * Release the display instance. 57 * <p> 58 * This method is usually called in {@code tearDown}. 59 */ releaseDisplay()60 public void releaseDisplay() { 61 mSession.close(); 62 } 63 64 /** 65 * Returns the display ID of created display. 66 */ getSecondaryDisplayId()67 public int getSecondaryDisplayId() { 68 return mSecondaryDisplayId; 69 } 70 71 /** 72 * Creates a landscape large screen simulated display to verify AE on multi-display environment. 73 */ createLandscapeLargeScreenSimulatedDisplay( @onNull VirtualDisplaySession virtualDisplaySession)74 public static WindowManagerState.DisplayContent createLandscapeLargeScreenSimulatedDisplay( 75 @NonNull VirtualDisplaySession virtualDisplaySession) { 76 return virtualDisplaySession 77 .setSimulateDisplay(true) 78 .setSimulationDisplaySize(SIMULATED_DISPLAY_SIZE.x, SIMULATED_DISPLAY_SIZE.y) 79 .setDensityDpi(SIMULATED_DISPLAY_DENSITY_DP) 80 .createDisplay(); 81 } 82 } 83