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