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