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 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 20 | import static android.view.Display.DEFAULT_DISPLAY; |
| 21 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
| 22 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 23 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 24 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 25 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 26 | import static org.junit.Assert.assertEquals; |
| 27 | import static org.junit.Assert.assertTrue; |
| 28 | |
Wale Ogunwale | 42bab78 | 2017-05-02 13:16:39 -0700 | [diff] [blame] | 29 | import org.junit.Ignore; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 30 | import org.junit.Test; |
| 31 | import org.junit.runner.RunWith; |
| 32 | |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 33 | import android.content.res.Configuration; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 34 | import android.platform.test.annotations.Presubmit; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 35 | import android.support.test.filters.SmallTest; |
| 36 | import android.support.test.runner.AndroidJUnit4; |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame^] | 37 | import android.util.SparseIntArray; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 38 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 39 | import java.util.Arrays; |
| 40 | import java.util.LinkedList; |
| 41 | import java.util.List; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Tests for the {@link DisplayContent} class. |
| 45 | * |
| 46 | * Build/Install/Run: |
| 47 | * bit FrameworksServicesTests:com.android.server.wm.DisplayContentTests |
| 48 | */ |
| 49 | @SmallTest |
| 50 | @Presubmit |
| 51 | @RunWith(AndroidJUnit4.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 52 | public class DisplayContentTests extends WindowTestsBase { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 53 | |
| 54 | @Test |
| 55 | public void testForAllWindows() throws Exception { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 56 | final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 57 | mDisplayContent, "exiting app"); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 58 | final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken; |
| 59 | exitingAppToken.mIsExiting = true; |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 60 | exitingAppToken.getTask().mStack.mExitingAppTokens.add(exitingAppToken); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 61 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 62 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 63 | mWallpaperWindow, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 64 | exitingAppWindow, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 65 | mChildAppWindowBelow, |
| 66 | mAppWindow, |
| 67 | mChildAppWindowAbove, |
| 68 | mDockedDividerWindow, |
| 69 | mStatusBarWindow, |
| 70 | mNavBarWindow, |
| 71 | mImeWindow, |
| 72 | mImeDialogWindow)); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Test |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 76 | public void testForAllWindows_WithAppImeTarget() throws Exception { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 77 | final WindowState imeAppTarget = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 78 | createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget"); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 79 | |
| 80 | sWm.mInputMethodTarget = imeAppTarget; |
| 81 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 82 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 83 | mWallpaperWindow, |
| 84 | mChildAppWindowBelow, |
| 85 | mAppWindow, |
| 86 | mChildAppWindowAbove, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 87 | imeAppTarget, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 88 | mImeWindow, |
| 89 | mImeDialogWindow, |
| 90 | mDockedDividerWindow, |
| 91 | mStatusBarWindow, |
| 92 | mNavBarWindow)); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 93 | } |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 94 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 95 | @Test |
| 96 | public void testForAllWindows_WithChildWindowImeTarget() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 97 | sWm.mInputMethodTarget = mChildAppWindowAbove; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 98 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 99 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 100 | mWallpaperWindow, |
| 101 | mChildAppWindowBelow, |
| 102 | mAppWindow, |
| 103 | mChildAppWindowAbove, |
| 104 | mImeWindow, |
| 105 | mImeDialogWindow, |
| 106 | mDockedDividerWindow, |
| 107 | mStatusBarWindow, |
| 108 | mNavBarWindow)); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 109 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 110 | |
| 111 | @Test |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 112 | public void testForAllWindows_WithStatusBarImeTarget() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 113 | sWm.mInputMethodTarget = mStatusBarWindow; |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 114 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 115 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 116 | mWallpaperWindow, |
| 117 | mChildAppWindowBelow, |
| 118 | mAppWindow, |
| 119 | mChildAppWindowAbove, |
| 120 | mDockedDividerWindow, |
| 121 | mStatusBarWindow, |
| 122 | mImeWindow, |
| 123 | mImeDialogWindow, |
| 124 | mNavBarWindow)); |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | @Test |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 128 | public void testForAllWindows_WithInBetweenWindowToken() throws Exception { |
| 129 | // This window is set-up to be z-ordered between some windows that go in the same token like |
| 130 | // the nav bar and status bar. |
| 131 | final WindowState voiceInteractionWindow = createWindow(null, TYPE_VOICE_INTERACTION, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 132 | mDisplayContent, "voiceInteractionWindow"); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 133 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 134 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 135 | mWallpaperWindow, |
| 136 | mChildAppWindowBelow, |
| 137 | mAppWindow, |
| 138 | mChildAppWindowAbove, |
| 139 | mDockedDividerWindow, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 140 | voiceInteractionWindow, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 141 | mStatusBarWindow, |
| 142 | mNavBarWindow, |
| 143 | mImeWindow, |
| 144 | mImeDialogWindow)); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 145 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 146 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 147 | @Test |
| 148 | public void testComputeImeTarget() throws Exception { |
| 149 | // Verify that an app window can be an ime target. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 150 | final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin"); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 151 | appWin.setHasSurface(true); |
| 152 | assertTrue(appWin.canBeImeTarget()); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 153 | WindowState imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 154 | assertEquals(appWin, imeTarget); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 155 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 156 | // Verify that an child window can be an ime target. |
| 157 | final WindowState childWin = createWindow(appWin, |
| 158 | TYPE_APPLICATION_ATTACHED_DIALOG, "childWin"); |
| 159 | childWin.setHasSurface(true); |
| 160 | assertTrue(childWin.canBeImeTarget()); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 161 | imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 162 | assertEquals(childWin, imeTarget); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 163 | } |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 164 | |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 165 | /** |
| 166 | * This tests stack movement between displays and proper stack's, task's and app token's display |
| 167 | * container references updates. |
| 168 | */ |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 169 | @Test |
| 170 | public void testMoveStackBetweenDisplays() throws Exception { |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 171 | // Create a second display. |
| 172 | final DisplayContent dc = createNewDisplay(); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 173 | |
| 174 | // Add stack with activity. |
| 175 | final TaskStack stack = createTaskStackOnDisplay(dc); |
| 176 | assertEquals(dc.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 177 | assertEquals(dc, stack.getParent().getParent()); |
| 178 | assertEquals(dc, stack.getDisplayContent()); |
| 179 | |
| 180 | final Task task = createTaskInStack(stack, 0 /* userId */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 181 | final WindowTestUtils.TestAppWindowToken token = new WindowTestUtils.TestAppWindowToken(dc); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 182 | task.addChild(token, 0); |
| 183 | assertEquals(dc, task.getDisplayContent()); |
| 184 | assertEquals(dc, token.getDisplayContent()); |
| 185 | |
| 186 | // Move stack to first display. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 187 | mDisplayContent.moveStackToDisplay(stack, true /* onTop */); |
| 188 | assertEquals(mDisplayContent.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 189 | assertEquals(mDisplayContent, stack.getParent().getParent()); |
| 190 | assertEquals(mDisplayContent, stack.getDisplayContent()); |
| 191 | assertEquals(mDisplayContent, task.getDisplayContent()); |
| 192 | assertEquals(mDisplayContent, token.getDisplayContent()); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 193 | } |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * This tests override configuration updates for display content. |
| 197 | */ |
| 198 | @Test |
| 199 | public void testDisplayOverrideConfigUpdate() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 200 | final int displayId = mDisplayContent.getDisplayId(); |
| 201 | final Configuration currentOverrideConfig = mDisplayContent.getOverrideConfiguration(); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 202 | |
| 203 | // Create new, slightly changed override configuration and apply it to the display. |
| 204 | final Configuration newOverrideConfig = new Configuration(currentOverrideConfig); |
| 205 | newOverrideConfig.densityDpi += 120; |
| 206 | newOverrideConfig.fontScale += 0.3; |
| 207 | |
| 208 | sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, displayId); |
| 209 | |
| 210 | // Check that override config is applied. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 211 | assertEquals(newOverrideConfig, mDisplayContent.getOverrideConfiguration()); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /** |
| 215 | * This tests global configuration updates when default display config is updated. |
| 216 | */ |
| 217 | @Test |
| 218 | public void testDefaultDisplayOverrideConfigUpdate() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 219 | final Configuration currentConfig = mDisplayContent.getConfiguration(); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 220 | |
| 221 | // Create new, slightly changed override configuration and apply it to the display. |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 222 | final Configuration newOverrideConfig = new Configuration(currentConfig); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 223 | newOverrideConfig.densityDpi += 120; |
| 224 | newOverrideConfig.fontScale += 0.3; |
| 225 | |
| 226 | sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, DEFAULT_DISPLAY); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 227 | |
| 228 | // 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] | 229 | Configuration globalConfig = sWm.mRoot.getConfiguration(); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 230 | assertEquals(newOverrideConfig.densityDpi, globalConfig.densityDpi); |
| 231 | assertEquals(newOverrideConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 232 | |
| 233 | // Return back to original values. |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 234 | sWm.setNewDisplayOverrideConfiguration(currentConfig, DEFAULT_DISPLAY); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 235 | globalConfig = sWm.mRoot.getConfiguration(); |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 236 | assertEquals(currentConfig.densityDpi, globalConfig.densityDpi); |
| 237 | assertEquals(currentConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 238 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 239 | |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 240 | @Test |
Wale Ogunwale | 42bab78 | 2017-05-02 13:16:39 -0700 | [diff] [blame] | 241 | @Ignore |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 242 | public void testFocusedWindowMultipleDisplays() throws Exception { |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame^] | 243 | // Create a focusable window and check that focus is calculated correctly |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 244 | final WindowState window1 = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 245 | createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1"); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 246 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 247 | |
| 248 | // Check that a new display doesn't affect focus |
| 249 | final DisplayContent dc = createNewDisplay(); |
| 250 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 251 | |
| 252 | // Add a window to the second display, and it should be focused |
| 253 | final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2"); |
| 254 | assertEquals(window2, sWm.mRoot.computeFocusedWindow()); |
| 255 | |
| 256 | // Move the first window to the to including parents, and make sure focus is updated |
| 257 | window1.getParent().positionChildAt(POSITION_TOP, window1, true); |
| 258 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 259 | } |
| 260 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 261 | /** |
| 262 | * This tests setting the maximum ui width on a display. |
| 263 | */ |
| 264 | @Test |
| 265 | public void testMaxUiWidth() throws Exception { |
| 266 | final int baseWidth = 1440; |
| 267 | final int baseHeight = 2560; |
| 268 | final int baseDensity = 300; |
| 269 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 270 | mDisplayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 271 | |
| 272 | final int maxWidth = 300; |
| 273 | final int resultingHeight = (maxWidth * baseHeight) / baseWidth; |
| 274 | final int resultingDensity = (maxWidth * baseDensity) / baseWidth; |
| 275 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 276 | mDisplayContent.setMaxUiWidth(maxWidth); |
| 277 | verifySizes(mDisplayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 278 | |
| 279 | // Assert setting values again does not change; |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 280 | mDisplayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
| 281 | verifySizes(mDisplayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 282 | |
| 283 | final int smallerWidth = 200; |
| 284 | final int smallerHeight = 400; |
| 285 | final int smallerDensity = 100; |
| 286 | |
| 287 | // Specify smaller dimension, verify that it is honored |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 288 | mDisplayContent.updateBaseDisplayMetrics(smallerWidth, smallerHeight, smallerDensity); |
| 289 | verifySizes(mDisplayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 290 | |
| 291 | // Verify that setting the max width to a greater value than the base width has no effect |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 292 | mDisplayContent.setMaxUiWidth(maxWidth); |
| 293 | verifySizes(mDisplayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 296 | /** |
| 297 | * This test enforces that the pinned stack is always kept as the top stack. |
| 298 | */ |
| 299 | @Test |
| 300 | public void testPinnedStackLocation() { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 301 | createStackControllerOnStackOnDisplay(PINNED_STACK_ID, mDisplayContent); |
| 302 | final int initialStackCount = mDisplayContent.getStackCount(); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 303 | // Ensure that the pinned stack was placed at the end |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 304 | assertEquals(initialStackCount - 1, mDisplayContent.getStaskPosById(PINNED_STACK_ID)); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 305 | // By default, this should try to create a new stack on top |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 306 | createTaskStackOnDisplay(mDisplayContent); |
| 307 | final int afterStackCount = mDisplayContent.getStackCount(); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 308 | // Make sure the stack count has increased |
| 309 | assertEquals(initialStackCount + 1, afterStackCount); |
| 310 | // Ensure that the pinned stack is still on top |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 311 | assertEquals(afterStackCount - 1, mDisplayContent.getStaskPosById(PINNED_STACK_ID)); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame^] | 314 | /** |
| 315 | * Test that WM does not report displays to AM that are pending to be removed. |
| 316 | */ |
| 317 | @Test |
| 318 | public void testDontReportDeferredRemoval() { |
| 319 | // Create a display and add an animating window to it. |
| 320 | final DisplayContent dc = createNewDisplay(); |
| 321 | final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
| 322 | window.mAnimatingExit = true; |
| 323 | // Request display removal, it should be deferred. |
| 324 | dc.removeIfPossible(); |
| 325 | // Request ordered display ids from WM. |
| 326 | final SparseIntArray orderedDisplayIds = new SparseIntArray(); |
| 327 | sWm.getDisplaysInFocusOrder(orderedDisplayIds); |
| 328 | // Make sure that display that is marked for removal is not reported. |
| 329 | assertEquals(-1, orderedDisplayIds.indexOfValue(dc.getDisplayId())); |
| 330 | } |
| 331 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 332 | private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth, |
| 333 | int expectedBaseHeight, int expectedBaseDensity) { |
| 334 | assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth); |
| 335 | assertEquals(displayContent.mBaseDisplayHeight, expectedBaseHeight); |
| 336 | assertEquals(displayContent.mBaseDisplayDensity, expectedBaseDensity); |
| 337 | } |
| 338 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 339 | private void assertForAllWindowsOrder(List<WindowState> expectedWindows) { |
| 340 | final LinkedList<WindowState> actualWindows = new LinkedList(); |
| 341 | |
| 342 | // Test forward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 343 | mDisplayContent.forAllWindows(actualWindows::addLast, false /* traverseTopToBottom */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 344 | assertEquals(expectedWindows.size(), actualWindows.size()); |
| 345 | for (WindowState w : expectedWindows) { |
| 346 | assertEquals(w, actualWindows.pollFirst()); |
| 347 | } |
| 348 | assertTrue(actualWindows.isEmpty()); |
| 349 | |
| 350 | // Test backward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 351 | mDisplayContent.forAllWindows(actualWindows::addLast, true /* traverseTopToBottom */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 352 | assertEquals(expectedWindows.size(), actualWindows.size()); |
| 353 | for (WindowState w : expectedWindows) { |
| 354 | assertEquals(w, actualWindows.pollLast()); |
| 355 | } |
| 356 | assertTrue(actualWindows.isEmpty()); |
| 357 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 358 | } |