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