Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -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 | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 19 | import static android.view.Display.DEFAULT_DISPLAY; |
| 20 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
| 21 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 22 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 23 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame^] | 24 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 25 | import static org.junit.Assert.assertEquals; |
| 26 | import static org.junit.Assert.assertTrue; |
| 27 | |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 28 | import org.junit.Test; |
| 29 | import org.junit.runner.RunWith; |
| 30 | |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 31 | import android.content.res.Configuration; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 32 | import android.platform.test.annotations.Presubmit; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 33 | import android.support.test.filters.SmallTest; |
| 34 | import android.support.test.runner.AndroidJUnit4; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 35 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 36 | import java.util.Arrays; |
| 37 | import java.util.LinkedList; |
| 38 | import java.util.List; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Tests for the {@link DisplayContent} class. |
| 42 | * |
| 43 | * Build/Install/Run: |
| 44 | * bit FrameworksServicesTests:com.android.server.wm.DisplayContentTests |
| 45 | */ |
| 46 | @SmallTest |
| 47 | @Presubmit |
| 48 | @RunWith(AndroidJUnit4.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 49 | public class DisplayContentTests extends WindowTestsBase { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 50 | |
| 51 | @Test |
| 52 | public void testForAllWindows() throws Exception { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 53 | final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION, |
| 54 | sDisplayContent, "exiting app"); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 55 | final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken; |
| 56 | exitingAppToken.mIsExiting = true; |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 57 | exitingAppToken.getTask().mStack.mExitingAppTokens.add(exitingAppToken); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 58 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 59 | assertForAllWindowsOrder(Arrays.asList( |
| 60 | sWallpaperWindow, |
| 61 | exitingAppWindow, |
| 62 | sChildAppWindowBelow, |
| 63 | sAppWindow, |
| 64 | sChildAppWindowAbove, |
| 65 | sDockedDividerWindow, |
| 66 | sStatusBarWindow, |
| 67 | sNavBarWindow, |
| 68 | sImeWindow, |
| 69 | sImeDialogWindow)); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Test |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 73 | public void testForAllWindows_WithAppImeTarget() throws Exception { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 74 | final WindowState imeAppTarget = |
| 75 | createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "imeAppTarget"); |
| 76 | |
| 77 | sWm.mInputMethodTarget = imeAppTarget; |
| 78 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 79 | assertForAllWindowsOrder(Arrays.asList( |
| 80 | sWallpaperWindow, |
| 81 | sChildAppWindowBelow, |
| 82 | sAppWindow, |
| 83 | sChildAppWindowAbove, |
| 84 | imeAppTarget, |
| 85 | sImeWindow, |
| 86 | sImeDialogWindow, |
| 87 | sDockedDividerWindow, |
| 88 | sStatusBarWindow, |
| 89 | sNavBarWindow)); |
| 90 | } |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 91 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 92 | @Test |
| 93 | public void testForAllWindows_WithChildWindowImeTarget() throws Exception { |
| 94 | sWm.mInputMethodTarget = sChildAppWindowAbove; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 95 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 96 | assertForAllWindowsOrder(Arrays.asList( |
| 97 | sWallpaperWindow, |
| 98 | sChildAppWindowBelow, |
| 99 | sAppWindow, |
| 100 | sChildAppWindowAbove, |
| 101 | sImeWindow, |
| 102 | sImeDialogWindow, |
| 103 | sDockedDividerWindow, |
| 104 | sStatusBarWindow, |
| 105 | sNavBarWindow)); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 106 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 107 | |
| 108 | @Test |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 109 | public void testForAllWindows_WithStatusBarImeTarget() throws Exception { |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 110 | sWm.mInputMethodTarget = sStatusBarWindow; |
| 111 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 112 | assertForAllWindowsOrder(Arrays.asList( |
| 113 | sWallpaperWindow, |
| 114 | sChildAppWindowBelow, |
| 115 | sAppWindow, |
| 116 | sChildAppWindowAbove, |
| 117 | sDockedDividerWindow, |
| 118 | sStatusBarWindow, |
| 119 | sImeWindow, |
| 120 | sImeDialogWindow, |
| 121 | sNavBarWindow)); |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | @Test |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 125 | public void testForAllWindows_WithInBetweenWindowToken() throws Exception { |
| 126 | // This window is set-up to be z-ordered between some windows that go in the same token like |
| 127 | // the nav bar and status bar. |
| 128 | final WindowState voiceInteractionWindow = createWindow(null, TYPE_VOICE_INTERACTION, |
| 129 | sDisplayContent, "voiceInteractionWindow"); |
| 130 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 131 | assertForAllWindowsOrder(Arrays.asList( |
| 132 | sWallpaperWindow, |
| 133 | sChildAppWindowBelow, |
| 134 | sAppWindow, |
| 135 | sChildAppWindowAbove, |
| 136 | sDockedDividerWindow, |
| 137 | voiceInteractionWindow, |
| 138 | sStatusBarWindow, |
| 139 | sNavBarWindow, |
| 140 | sImeWindow, |
| 141 | sImeDialogWindow)); |
| 142 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 143 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 144 | @Test |
| 145 | public void testComputeImeTarget() throws Exception { |
| 146 | // Verify that an app window can be an ime target. |
| 147 | final WindowState appWin = createWindow(null, TYPE_APPLICATION, sDisplayContent, "appWin"); |
| 148 | appWin.setHasSurface(true); |
| 149 | assertTrue(appWin.canBeImeTarget()); |
| 150 | WindowState imeTarget = sDisplayContent.computeImeTarget(false /* updateImeTarget */); |
| 151 | assertEquals(appWin, imeTarget); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 152 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 153 | // Verify that an child window can be an ime target. |
| 154 | final WindowState childWin = createWindow(appWin, |
| 155 | TYPE_APPLICATION_ATTACHED_DIALOG, "childWin"); |
| 156 | childWin.setHasSurface(true); |
| 157 | assertTrue(childWin.canBeImeTarget()); |
| 158 | imeTarget = sDisplayContent.computeImeTarget(false /* updateImeTarget */); |
| 159 | assertEquals(childWin, imeTarget); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 160 | } |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 161 | |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 162 | /** |
| 163 | * This tests stack movement between displays and proper stack's, task's and app token's display |
| 164 | * container references updates. |
| 165 | */ |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 166 | @Test |
| 167 | public void testMoveStackBetweenDisplays() throws Exception { |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 168 | // Create a second display. |
| 169 | final DisplayContent dc = createNewDisplay(); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 170 | |
| 171 | // Add stack with activity. |
| 172 | final TaskStack stack = createTaskStackOnDisplay(dc); |
| 173 | assertEquals(dc.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 174 | assertEquals(dc, stack.getParent().getParent()); |
| 175 | assertEquals(dc, stack.getDisplayContent()); |
| 176 | |
| 177 | final Task task = createTaskInStack(stack, 0 /* userId */); |
| 178 | final TestAppWindowToken token = new TestAppWindowToken(dc); |
| 179 | task.addChild(token, 0); |
| 180 | assertEquals(dc, task.getDisplayContent()); |
| 181 | assertEquals(dc, token.getDisplayContent()); |
| 182 | |
| 183 | // Move stack to first display. |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 184 | sDisplayContent.moveStackToDisplay(stack); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 185 | assertEquals(sDisplayContent.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 186 | assertEquals(sDisplayContent, stack.getParent().getParent()); |
| 187 | assertEquals(sDisplayContent, stack.getDisplayContent()); |
| 188 | assertEquals(sDisplayContent, task.getDisplayContent()); |
| 189 | assertEquals(sDisplayContent, token.getDisplayContent()); |
| 190 | } |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * This tests override configuration updates for display content. |
| 194 | */ |
| 195 | @Test |
| 196 | public void testDisplayOverrideConfigUpdate() throws Exception { |
| 197 | final int displayId = sDisplayContent.getDisplayId(); |
| 198 | final Configuration currentOverrideConfig = sDisplayContent.getOverrideConfiguration(); |
| 199 | |
| 200 | // Create new, slightly changed override configuration and apply it to the display. |
| 201 | final Configuration newOverrideConfig = new Configuration(currentOverrideConfig); |
| 202 | newOverrideConfig.densityDpi += 120; |
| 203 | newOverrideConfig.fontScale += 0.3; |
| 204 | |
| 205 | sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, displayId); |
| 206 | |
| 207 | // Check that override config is applied. |
| 208 | assertEquals(newOverrideConfig, sDisplayContent.getOverrideConfiguration()); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /** |
| 212 | * This tests global configuration updates when default display config is updated. |
| 213 | */ |
| 214 | @Test |
| 215 | public void testDefaultDisplayOverrideConfigUpdate() throws Exception { |
| 216 | final Configuration currentOverrideConfig = sDisplayContent.getOverrideConfiguration(); |
| 217 | |
| 218 | // Create new, slightly changed override configuration and apply it to the display. |
| 219 | final Configuration newOverrideConfig = new Configuration(currentOverrideConfig); |
| 220 | newOverrideConfig.densityDpi += 120; |
| 221 | newOverrideConfig.fontScale += 0.3; |
| 222 | |
| 223 | sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, DEFAULT_DISPLAY); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 224 | |
| 225 | // Check that global configuration is updated, as we've updated default display's config. |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 226 | Configuration globalConfig = sWm.mRoot.getConfiguration(); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 227 | assertEquals(newOverrideConfig.densityDpi, globalConfig.densityDpi); |
| 228 | assertEquals(newOverrideConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 229 | |
| 230 | // Return back to original values. |
| 231 | sWm.setNewDisplayOverrideConfiguration(currentOverrideConfig, DEFAULT_DISPLAY); |
| 232 | globalConfig = sWm.mRoot.getConfiguration(); |
| 233 | assertEquals(currentOverrideConfig.densityDpi, globalConfig.densityDpi); |
| 234 | assertEquals(currentOverrideConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 235 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 236 | |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame^] | 237 | @Test |
| 238 | public void testFocusedWindowMultipleDisplays() throws Exception { |
| 239 | // Create a focusable window and check that focus is calcualted correctly |
| 240 | final WindowState window1 = |
| 241 | createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "window1"); |
| 242 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 243 | |
| 244 | // Check that a new display doesn't affect focus |
| 245 | final DisplayContent dc = createNewDisplay(); |
| 246 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 247 | |
| 248 | // Add a window to the second display, and it should be focused |
| 249 | final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2"); |
| 250 | assertEquals(window2, sWm.mRoot.computeFocusedWindow()); |
| 251 | |
| 252 | // Move the first window to the to including parents, and make sure focus is updated |
| 253 | window1.getParent().positionChildAt(POSITION_TOP, window1, true); |
| 254 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 255 | } |
| 256 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 257 | private void assertForAllWindowsOrder(List<WindowState> expectedWindows) { |
| 258 | final LinkedList<WindowState> actualWindows = new LinkedList(); |
| 259 | |
| 260 | // Test forward traversal. |
| 261 | sDisplayContent.forAllWindows(actualWindows::addLast, false /* traverseTopToBottom */); |
| 262 | assertEquals(expectedWindows.size(), actualWindows.size()); |
| 263 | for (WindowState w : expectedWindows) { |
| 264 | assertEquals(w, actualWindows.pollFirst()); |
| 265 | } |
| 266 | assertTrue(actualWindows.isEmpty()); |
| 267 | |
| 268 | // Test backward traversal. |
| 269 | sDisplayContent.forAllWindows(actualWindows::addLast, true /* traverseTopToBottom */); |
| 270 | assertEquals(expectedWindows.size(), actualWindows.size()); |
| 271 | for (WindowState w : expectedWindows) { |
| 272 | assertEquals(w, actualWindows.pollLast()); |
| 273 | } |
| 274 | assertTrue(actualWindows.isEmpty()); |
| 275 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 276 | } |