Linus Tufvesson | 147ee82 | 2020-02-04 17:10:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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; |
| 18 | |
| 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
wilsonshih | b99547c | 2020-03-19 17:41:18 +0800 | [diff] [blame] | 21 | import static org.junit.Assert.assertTrue; |
| 22 | |
Linus Tufvesson | 147ee82 | 2020-02-04 17:10:27 +0000 | [diff] [blame] | 23 | import android.content.Intent; |
Linus Tufvesson | 147ee82 | 2020-02-04 17:10:27 +0000 | [diff] [blame] | 24 | import android.platform.test.annotations.Presubmit; |
| 25 | import android.server.wm.app.Components; |
| 26 | import android.view.Display; |
| 27 | |
| 28 | import org.junit.Test; |
| 29 | |
| 30 | import java.util.List; |
| 31 | |
Andrii Kulian | 447d9b0 | 2020-06-05 15:59:42 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Build/Install/Run: |
| 34 | * atest CtsWindowManagerDeviceTestCases:PresentationTest |
| 35 | */ |
Linus Tufvesson | 147ee82 | 2020-02-04 17:10:27 +0000 | [diff] [blame] | 36 | @Presubmit |
| 37 | public class PresentationTest extends MultiDisplayTestBase { |
| 38 | |
| 39 | // WindowManager.LayoutParams.TYPE_PRESENTATION |
| 40 | private static final int TYPE_PRESENTATION = 2037; |
| 41 | |
| 42 | @Test |
| 43 | public void testPresentationFollowsDisplayFlag() { |
Riddle Hsu | cdf0ddf | 2020-03-19 18:36:09 +0800 | [diff] [blame] | 44 | for (Display display : mDm.getDisplays()) { |
Linus Tufvesson | 147ee82 | 2020-02-04 17:10:27 +0000 | [diff] [blame] | 45 | launchPresentationActivity(display.getDisplayId()); |
| 46 | if ((display.getFlags() & Display.FLAG_PRESENTATION) != Display.FLAG_PRESENTATION) { |
| 47 | assertNoPresentationDisplayed(); |
| 48 | } else { |
| 49 | assertPresentationOnDisplay(display.getDisplayId()); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | @Test |
| 55 | public void testPresentationAllowedOnPresentationDisplay() { |
| 56 | WindowManagerState.DisplayContent display = |
| 57 | createManagedVirtualDisplaySession() |
| 58 | .setPresentationDisplay(true) |
| 59 | .setPublicDisplay(true) |
| 60 | .createDisplay(); |
| 61 | |
| 62 | assertThat(display.getFlags() & Display.FLAG_PRESENTATION) |
| 63 | .isEqualTo(Display.FLAG_PRESENTATION); |
| 64 | |
| 65 | launchPresentationActivity(display.mId); |
| 66 | assertPresentationOnDisplay(display.mId); |
| 67 | } |
| 68 | |
| 69 | @Test |
wilsonshih | b99547c | 2020-03-19 17:41:18 +0800 | [diff] [blame] | 70 | public void testPresentationDismissAfterResizeDisplay() { |
| 71 | final VirtualDisplaySession virtualDisplaySession = createManagedVirtualDisplaySession(); |
| 72 | WindowManagerState.DisplayContent display = virtualDisplaySession |
| 73 | .setPresentationDisplay(true) |
| 74 | .setPublicDisplay(true) |
Keun young Park | f2c95d9 | 2020-06-09 20:44:20 -0700 | [diff] [blame] | 75 | .setResizeDisplay(false) // resize only through resizeDisplay call |
wilsonshih | b99547c | 2020-03-19 17:41:18 +0800 | [diff] [blame] | 76 | .createDisplay(); |
| 77 | |
| 78 | assertThat(display.getFlags() & Display.FLAG_PRESENTATION) |
| 79 | .isEqualTo(Display.FLAG_PRESENTATION); |
| 80 | |
| 81 | launchPresentationActivity(display.mId); |
| 82 | assertPresentationOnDisplay(display.mId); |
| 83 | |
| 84 | virtualDisplaySession.resizeDisplay(); |
| 85 | |
| 86 | assertTrue("Presentation must dismiss on external public display", |
| 87 | mWmState.waitForWithAmState( |
| 88 | state -> !isPresentationOnDisplay(state, display.mId), |
| 89 | "Presentation window dismiss")); |
| 90 | } |
| 91 | |
| 92 | @Test |
Linus Tufvesson | 147ee82 | 2020-02-04 17:10:27 +0000 | [diff] [blame] | 93 | public void testPresentationBlockedOnNonPresentationDisplay() { |
| 94 | WindowManagerState.DisplayContent display = |
| 95 | createManagedVirtualDisplaySession() |
| 96 | .setPresentationDisplay(false) |
| 97 | .createDisplay(); |
| 98 | |
| 99 | assertThat(display.getFlags() & Display.FLAG_PRESENTATION).isEqualTo(0); |
| 100 | launchPresentationActivity(display.mId); |
| 101 | assertNoPresentationDisplayed(); |
| 102 | } |
| 103 | |
wilsonshih | b99547c | 2020-03-19 17:41:18 +0800 | [diff] [blame] | 104 | private boolean isPresentationOnDisplay(WindowManagerState windowManagerState, int displayId) { |
| 105 | final List<WindowManagerState.WindowState> states = |
| 106 | windowManagerState.getMatchingWindowType(TYPE_PRESENTATION); |
| 107 | for (WindowManagerState.WindowState ws : states) { |
| 108 | if (ws.getDisplayId() == displayId) return true; |
| 109 | } |
| 110 | return false; |
| 111 | } |
| 112 | |
Linus Tufvesson | 147ee82 | 2020-02-04 17:10:27 +0000 | [diff] [blame] | 113 | private void assertNoPresentationDisplayed() { |
| 114 | final List<WindowManagerState.WindowState> presentationWindows = |
| 115 | mWmState.getWindowsByPackageName( |
| 116 | Components.PRESENTATION_ACTIVITY.getPackageName(), TYPE_PRESENTATION); |
| 117 | assertThat(presentationWindows).isEmpty(); |
| 118 | } |
| 119 | |
| 120 | private void assertPresentationOnDisplay(int displayId) { |
| 121 | final List<WindowManagerState.WindowState> presentationWindows = |
| 122 | mWmState.getWindowsByPackageName( |
| 123 | Components.PRESENTATION_ACTIVITY.getPackageName(), TYPE_PRESENTATION); |
| 124 | assertThat(presentationWindows).hasSize(1); |
| 125 | WindowManagerState.WindowState presentationWindowState = presentationWindows.get(0); |
| 126 | assertThat(presentationWindowState.getDisplayId()).isEqualTo(displayId); |
| 127 | } |
| 128 | |
| 129 | private void launchPresentationActivity(int displayId) { |
| 130 | Intent intent = new Intent(); |
| 131 | intent.setComponent(Components.PRESENTATION_ACTIVITY); |
| 132 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 133 | intent.putExtra(Components.PresentationActivity.KEY_DISPLAY_ID, displayId); |
| 134 | mContext.startActivity(intent); |
| 135 | waitAndAssertTopResumedActivity( |
| 136 | Components.PRESENTATION_ACTIVITY, |
| 137 | Display.DEFAULT_DISPLAY, |
| 138 | "Launched activity must be on top"); |
| 139 | } |
| 140 | } |