Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 19 | import org.junit.Test; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 20 | import org.junit.Ignore; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 21 | import org.junit.runner.RunWith; |
| 22 | |
Wale Ogunwale | 5fc7096 | 2016-09-09 22:36:19 -0700 | [diff] [blame] | 23 | import android.platform.test.annotations.Presubmit; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 24 | import android.support.test.filters.SmallTest; |
| 25 | import android.support.test.runner.AndroidJUnit4; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 26 | import android.view.Surface; |
| 27 | import android.view.WindowManager; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 28 | |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 29 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 30 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 32 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 33 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 35 | import static org.junit.Assert.assertEquals; |
| 36 | import static org.junit.Assert.assertNull; |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 37 | import static org.junit.Assert.assertTrue; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 40 | * Tests for the {@link AppWindowToken} class. |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 41 | * |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 42 | * Build/Install/Run: |
| 43 | * bit FrameworksServicesTests:com.android.server.wm.AppWindowTokenTests |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 44 | */ |
| 45 | @SmallTest |
Wale Ogunwale | 5fc7096 | 2016-09-09 22:36:19 -0700 | [diff] [blame] | 46 | @Presubmit |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 47 | @RunWith(AndroidJUnit4.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 48 | public class AppWindowTokenTests extends WindowTestsBase { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 49 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 50 | @Test |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 51 | public void testAddWindow_Order() throws Exception { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 52 | final TestAppWindowToken token = new TestAppWindowToken(sDisplayContent); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 53 | |
| 54 | assertEquals(0, token.getWindowsCount()); |
| 55 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 56 | 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 Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 61 | |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 62 | // 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 Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 74 | token.removeImmediately(); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Test |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 78 | public void testFindMainWindow() throws Exception { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 79 | final TestAppWindowToken token = new TestAppWindowToken(sDisplayContent); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 80 | |
| 81 | assertNull(token.findMainWindow()); |
| 82 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 83 | 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 Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 86 | assertEquals(window1, token.findMainWindow()); |
| 87 | window1.mAnimatingExit = true; |
| 88 | assertEquals(window1, token.findMainWindow()); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 89 | final WindowState window2 = createWindow(null, TYPE_APPLICATION_STARTING, token, "window2"); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 90 | assertEquals(window2, token.findMainWindow()); |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 91 | token.removeImmediately(); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 92 | } |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 93 | |
| 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 Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 115 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, sDisplayContent.getLastOrientation()); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 116 | 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 Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 123 | assertEquals(SCREEN_ORIENTATION_REVERSE_LANDSCAPE, sDisplayContent.getLastOrientation()); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 124 | assertTrue(appWindow.resizeReported); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 125 | appWindow.removeImmediately(); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 126 | } |
| 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 Lee | 6272c7f | 2017-03-17 17:22:35 -0700 | [diff] [blame^] | 135 | final DisplayContent defaultDisplayContent = sWm.getDefaultDisplayContentLocked(); |
| 136 | final TaskStack stack = createTaskStackOnDisplay(defaultDisplayContent); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 137 | final Task task = createTaskInStack(stack, 0 /* userId */); |
Bryce Lee | 6272c7f | 2017-03-17 17:22:35 -0700 | [diff] [blame^] | 138 | final TestAppWindowToken appWindowToken = new TestAppWindowToken(defaultDisplayContent); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 139 | 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 Lee | 310de9e | 2017-03-15 10:18:21 -0700 | [diff] [blame] | 147 | performRotation(Surface.ROTATION_90); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 148 | appWindow.resizeReported = false; |
| 149 | |
| 150 | // Update the rotation to perform 180 degree rotation and check that resize was reported. |
Bryce Lee | 310de9e | 2017-03-15 10:18:21 -0700 | [diff] [blame] | 151 | performRotation(Surface.ROTATION_270); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 152 | assertTrue(appWindow.resizeReported); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 153 | appWindow.removeImmediately(); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 154 | } |
Bryce Lee | 310de9e | 2017-03-15 10:18:21 -0700 | [diff] [blame] | 155 | |
| 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 Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 163 | } |