blob: b5826f0c1106b771774ac6ca099b857a54588d87 [file] [log] [blame]
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001/*
2 * Copyright (C) 2016 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 com.android.server.wm;
18
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070019import org.junit.Test;
Wale Ogunwale17f175c2017-02-07 16:54:10 -080020import org.junit.Ignore;
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070021import org.junit.runner.RunWith;
22
Wale Ogunwale5fc70962016-09-09 22:36:19 -070023import android.platform.test.annotations.Presubmit;
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070024import android.support.test.filters.SmallTest;
25import android.support.test.runner.AndroidJUnit4;
Andrii Kulian4ede3e02017-01-12 11:52:31 -080026import android.view.Surface;
27import android.view.WindowManager;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070028
Andrii Kulian4ede3e02017-01-12 11:52:31 -080029import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
30import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070031import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Wale Ogunwale07bcab72016-10-14 15:30:09 -070032import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070033import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
34import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070035import static org.junit.Assert.assertEquals;
36import static org.junit.Assert.assertNull;
Wale Ogunwale07bcab72016-10-14 15:30:09 -070037import static org.junit.Assert.assertTrue;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070038
39/**
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070040 * Tests for the {@link AppWindowToken} class.
Wale Ogunwaled1c37912016-08-16 03:19:39 -070041 *
Wale Ogunwale07bcab72016-10-14 15:30:09 -070042 * Build/Install/Run:
43 * bit FrameworksServicesTests:com.android.server.wm.AppWindowTokenTests
Wale Ogunwaled1c37912016-08-16 03:19:39 -070044 */
45@SmallTest
Wale Ogunwale5fc70962016-09-09 22:36:19 -070046@Presubmit
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070047@RunWith(AndroidJUnit4.class)
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080048public class AppWindowTokenTests extends WindowTestsBase {
Wale Ogunwaled1c37912016-08-16 03:19:39 -070049
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070050 @Test
Wale Ogunwale07bcab72016-10-14 15:30:09 -070051 public void testAddWindow_Order() throws Exception {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -080052 final TestAppWindowToken token = new TestAppWindowToken(sDisplayContent);
Wale Ogunwale07bcab72016-10-14 15:30:09 -070053
54 assertEquals(0, token.getWindowsCount());
55
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080056 final WindowState win1 = createWindow(null, TYPE_APPLICATION, token, "win1");
57 final WindowState startingWin = createWindow(null, TYPE_APPLICATION_STARTING, token,
58 "startingWin");
59 final WindowState baseWin = createWindow(null, TYPE_BASE_APPLICATION, token, "baseWin");
60 final WindowState win4 = createWindow(null, TYPE_APPLICATION, token, "win4");
Wale Ogunwale07bcab72016-10-14 15:30:09 -070061
Wale Ogunwale07bcab72016-10-14 15:30:09 -070062 // Should not contain the windows that were added above.
63 assertEquals(4, token.getWindowsCount());
64 assertTrue(token.hasWindow(win1));
65 assertTrue(token.hasWindow(startingWin));
66 assertTrue(token.hasWindow(baseWin));
67 assertTrue(token.hasWindow(win4));
68
69 // The starting window should be on-top of all other windows.
70 assertEquals(startingWin, token.getLastChild());
71
72 // The base application window should be below all other windows.
73 assertEquals(baseWin, token.getFirstChild());
Wale Ogunwale17f175c2017-02-07 16:54:10 -080074 token.removeImmediately();
Wale Ogunwale07bcab72016-10-14 15:30:09 -070075 }
76
77 @Test
Wale Ogunwaled1c37912016-08-16 03:19:39 -070078 public void testFindMainWindow() throws Exception {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -080079 final TestAppWindowToken token = new TestAppWindowToken(sDisplayContent);
Wale Ogunwaled1c37912016-08-16 03:19:39 -070080
81 assertNull(token.findMainWindow());
82
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080083 final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, token, "window1");
84 final WindowState window11 = createWindow(window1, FIRST_SUB_WINDOW, token, "window11");
85 final WindowState window12 = createWindow(window1, FIRST_SUB_WINDOW, token, "window12");
Wale Ogunwaled1c37912016-08-16 03:19:39 -070086 assertEquals(window1, token.findMainWindow());
87 window1.mAnimatingExit = true;
88 assertEquals(window1, token.findMainWindow());
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080089 final WindowState window2 = createWindow(null, TYPE_APPLICATION_STARTING, token, "window2");
Wale Ogunwaled1c37912016-08-16 03:19:39 -070090 assertEquals(window2, token.findMainWindow());
Wale Ogunwale17f175c2017-02-07 16:54:10 -080091 token.removeImmediately();
Wale Ogunwaled1c37912016-08-16 03:19:39 -070092 }
Andrii Kulian4ede3e02017-01-12 11:52:31 -080093
94 @Test
95 public void testLandscapeSeascapeRotationByApp() throws Exception {
96 // Some plumbing to get the service ready for rotation updates.
97 sWm.mDisplayReady = true;
98 sWm.mDisplayEnabled = true;
99
100 // Create an app window with token on a display.
101 final TaskStack stack = createTaskStackOnDisplay(sDisplayContent);
102 final Task task = createTaskInStack(stack, 0 /* userId */);
103 final TestAppWindowToken appWindowToken = new TestAppWindowToken(sDisplayContent);
104 task.addChild(appWindowToken, 0);
105 final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(
106 TYPE_BASE_APPLICATION);
107 attrs.setTitle("AppWindow");
108 final TestWindowState appWindow = new TestWindowState(attrs, appWindowToken);
109 appWindowToken.addWindow(appWindow);
110
111 // Set initial orientation and update.
112 appWindowToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
113 sWm.updateOrientationFromAppTokens(sDisplayContent.getOverrideConfiguration(), null,
114 sDisplayContent.getDisplayId());
Andrii Kulian8ee72852017-03-10 10:36:45 -0800115 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, sDisplayContent.getLastOrientation());
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800116 appWindow.resizeReported = false;
117
118 // Update the orientation to perform 180 degree rotation and check that resize was reported.
119 appWindowToken.setOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
120 sWm.updateOrientationFromAppTokens(sDisplayContent.getOverrideConfiguration(), null,
121 sDisplayContent.getDisplayId());
122 sWm.mRoot.performSurfacePlacement(false /* recoveringMemory */);
Andrii Kulian8ee72852017-03-10 10:36:45 -0800123 assertEquals(SCREEN_ORIENTATION_REVERSE_LANDSCAPE, sDisplayContent.getLastOrientation());
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800124 assertTrue(appWindow.resizeReported);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800125 appWindow.removeImmediately();
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800126 }
127
128 @Test
129 public void testLandscapeSeascapeRotationByPolicy() throws Exception {
130 // Some plumbing to get the service ready for rotation updates.
131 sWm.mDisplayReady = true;
132 sWm.mDisplayEnabled = true;
133
134 // Create an app window with token on a display.
Bryce Lee6272c7f2017-03-17 17:22:35 -0700135 final DisplayContent defaultDisplayContent = sWm.getDefaultDisplayContentLocked();
136 final TaskStack stack = createTaskStackOnDisplay(defaultDisplayContent);
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800137 final Task task = createTaskInStack(stack, 0 /* userId */);
Bryce Lee6272c7f2017-03-17 17:22:35 -0700138 final TestAppWindowToken appWindowToken = new TestAppWindowToken(defaultDisplayContent);
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800139 task.addChild(appWindowToken, 0);
140 final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(
141 TYPE_BASE_APPLICATION);
142 attrs.setTitle("AppWindow");
143 final TestWindowState appWindow = new TestWindowState(attrs, appWindowToken);
144 appWindowToken.addWindow(appWindow);
145
146 // Set initial orientation and update.
Bryce Lee310de9e2017-03-15 10:18:21 -0700147 performRotation(Surface.ROTATION_90);
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800148 appWindow.resizeReported = false;
149
150 // Update the rotation to perform 180 degree rotation and check that resize was reported.
Bryce Lee310de9e2017-03-15 10:18:21 -0700151 performRotation(Surface.ROTATION_270);
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800152 assertTrue(appWindow.resizeReported);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800153 appWindow.removeImmediately();
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800154 }
Bryce Lee310de9e2017-03-15 10:18:21 -0700155
156 private void performRotation(int rotationToReport) {
157 ((TestWindowManagerPolicy) sWm.mPolicy).rotationToReport = rotationToReport;
158 sWm.updateRotation(false, false);
159 // Simulate animator finishing orientation change
160 sWm.mRoot.mOrientationChangeComplete = true;
161 sWm.mRoot.performSurfacePlacement(false /* recoveringMemory */);
162 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700163}