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