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