blob: 4b34c9b1195ea0d629faaf5bad1f48ccd3789070 [file] [log] [blame]
Linus Tufvesson147ee822020-02-04 17:10:27 +00001/*
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
17package android.server.wm;
18
19import static com.google.common.truth.Truth.assertThat;
20
wilsonshihb99547c2020-03-19 17:41:18 +080021import static org.junit.Assert.assertTrue;
22
Linus Tufvesson147ee822020-02-04 17:10:27 +000023import android.content.Intent;
Linus Tufvesson147ee822020-02-04 17:10:27 +000024import android.platform.test.annotations.Presubmit;
25import android.server.wm.app.Components;
26import android.view.Display;
27
28import org.junit.Test;
29
30import java.util.List;
31
Andrii Kulian447d9b02020-06-05 15:59:42 -070032/**
33 * Build/Install/Run:
34 * atest CtsWindowManagerDeviceTestCases:PresentationTest
35 */
Linus Tufvesson147ee822020-02-04 17:10:27 +000036@Presubmit
37public 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 Hsucdf0ddf2020-03-19 18:36:09 +080044 for (Display display : mDm.getDisplays()) {
Linus Tufvesson147ee822020-02-04 17:10:27 +000045 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
wilsonshihb99547c2020-03-19 17:41:18 +080070 public void testPresentationDismissAfterResizeDisplay() {
71 final VirtualDisplaySession virtualDisplaySession = createManagedVirtualDisplaySession();
72 WindowManagerState.DisplayContent display = virtualDisplaySession
73 .setPresentationDisplay(true)
74 .setPublicDisplay(true)
Keun young Parkf2c95d92020-06-09 20:44:20 -070075 .setResizeDisplay(false) // resize only through resizeDisplay call
wilsonshihb99547c2020-03-19 17:41:18 +080076 .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 Tufvesson147ee822020-02-04 17:10:27 +000093 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
wilsonshihb99547c2020-03-19 17:41:18 +0800104 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 Tufvesson147ee822020-02-04 17:10:27 +0000113 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}