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; |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 24 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
| 25 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 26 | import static android.view.Display.DEFAULT_DISPLAY; |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 27 | import static android.view.DisplayCutout.fromBoundingRect; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
| 29 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 30 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 32 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 33 | |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 34 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 35 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 36 | import static org.hamcrest.Matchers.is; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 37 | import static org.junit.Assert.assertEquals; |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 38 | import static org.junit.Assert.assertFalse; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 39 | import static org.junit.Assert.assertThat; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 40 | import static org.junit.Assert.assertTrue; |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 41 | import static org.mockito.Mockito.doNothing; |
| 42 | import static org.mockito.Mockito.spy; |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 43 | import static org.mockito.Mockito.times; |
| 44 | import static org.mockito.Mockito.verify; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 45 | |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 46 | import android.annotation.SuppressLint; |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 47 | import android.content.res.Configuration; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 48 | import android.graphics.Rect; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 49 | import android.os.SystemClock; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 50 | import android.platform.test.annotations.Presubmit; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 51 | import android.util.DisplayMetrics; |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame] | 52 | import android.util.SparseIntArray; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 53 | import android.view.DisplayCutout; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame^] | 54 | import android.view.Gravity; |
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 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 58 | import androidx.test.filters.FlakyTest; |
| 59 | import androidx.test.filters.SmallTest; |
| 60 | import androidx.test.runner.AndroidJUnit4; |
| 61 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 62 | import com.android.server.wm.utils.WmDisplayCutout; |
| 63 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 64 | import org.junit.Test; |
| 65 | import org.junit.runner.RunWith; |
| 66 | |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 67 | import java.util.ArrayList; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 68 | import java.util.Arrays; |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 69 | import java.util.Collections; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 70 | import java.util.LinkedList; |
| 71 | import java.util.List; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Tests for the {@link DisplayContent} class. |
| 75 | * |
| 76 | * Build/Install/Run: |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 77 | * atest com.android.server.wm.DisplayContentTests |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 78 | */ |
| 79 | @SmallTest |
| 80 | @Presubmit |
| 81 | @RunWith(AndroidJUnit4.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 82 | public class DisplayContentTests extends WindowTestsBase { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 83 | |
| 84 | @Test |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 85 | @FlakyTest(bugId = 77772044) |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 86 | public void testForAllWindows() throws Exception { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 87 | final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 88 | mDisplayContent, "exiting app"); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 89 | final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken; |
| 90 | exitingAppToken.mIsExiting = true; |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 91 | exitingAppToken.getTask().mStack.mExitingAppTokens.add(exitingAppToken); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 92 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 93 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 94 | mWallpaperWindow, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 95 | exitingAppWindow, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 96 | mChildAppWindowBelow, |
| 97 | mAppWindow, |
| 98 | mChildAppWindowAbove, |
| 99 | mDockedDividerWindow, |
| 100 | mStatusBarWindow, |
| 101 | mNavBarWindow, |
| 102 | mImeWindow, |
| 103 | mImeDialogWindow)); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Test |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 107 | public void testForAllWindows_WithAppImeTarget() throws Exception { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 108 | final WindowState imeAppTarget = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 109 | createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget"); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 110 | |
| 111 | sWm.mInputMethodTarget = imeAppTarget; |
| 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, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 118 | imeAppTarget, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 119 | mImeWindow, |
| 120 | mImeDialogWindow, |
| 121 | mDockedDividerWindow, |
| 122 | mStatusBarWindow, |
| 123 | mNavBarWindow)); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 124 | } |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 125 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 126 | @Test |
| 127 | public void testForAllWindows_WithChildWindowImeTarget() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 128 | sWm.mInputMethodTarget = mChildAppWindowAbove; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 129 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 130 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 131 | mWallpaperWindow, |
| 132 | mChildAppWindowBelow, |
| 133 | mAppWindow, |
| 134 | mChildAppWindowAbove, |
| 135 | mImeWindow, |
| 136 | mImeDialogWindow, |
| 137 | mDockedDividerWindow, |
| 138 | mStatusBarWindow, |
| 139 | mNavBarWindow)); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 140 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 141 | |
| 142 | @Test |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 143 | public void testForAllWindows_WithStatusBarImeTarget() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 144 | sWm.mInputMethodTarget = mStatusBarWindow; |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 145 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 146 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 147 | mWallpaperWindow, |
| 148 | mChildAppWindowBelow, |
| 149 | mAppWindow, |
| 150 | mChildAppWindowAbove, |
| 151 | mDockedDividerWindow, |
| 152 | mStatusBarWindow, |
| 153 | mImeWindow, |
| 154 | mImeDialogWindow, |
| 155 | mNavBarWindow)); |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | @Test |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 159 | public void testForAllWindows_WithInBetweenWindowToken() throws Exception { |
| 160 | // This window is set-up to be z-ordered between some windows that go in the same token like |
| 161 | // the nav bar and status bar. |
| 162 | final WindowState voiceInteractionWindow = createWindow(null, TYPE_VOICE_INTERACTION, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 163 | mDisplayContent, "voiceInteractionWindow"); |
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 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 166 | mWallpaperWindow, |
| 167 | mChildAppWindowBelow, |
| 168 | mAppWindow, |
| 169 | mChildAppWindowAbove, |
| 170 | mDockedDividerWindow, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 171 | voiceInteractionWindow, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 172 | mStatusBarWindow, |
| 173 | mNavBarWindow, |
| 174 | mImeWindow, |
| 175 | mImeDialogWindow)); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 176 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 177 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 178 | @Test |
| 179 | public void testComputeImeTarget() throws Exception { |
| 180 | // Verify that an app window can be an ime target. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 181 | final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin"); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 182 | appWin.setHasSurface(true); |
| 183 | assertTrue(appWin.canBeImeTarget()); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 184 | WindowState imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 185 | assertEquals(appWin, imeTarget); |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 186 | appWin.mHidden = false; |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 187 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 188 | // Verify that an child window can be an ime target. |
| 189 | final WindowState childWin = createWindow(appWin, |
| 190 | TYPE_APPLICATION_ATTACHED_DIALOG, "childWin"); |
| 191 | childWin.setHasSurface(true); |
| 192 | assertTrue(childWin.canBeImeTarget()); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 193 | imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 194 | assertEquals(childWin, imeTarget); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 195 | } |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 196 | |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 197 | /** |
| 198 | * This tests stack movement between displays and proper stack's, task's and app token's display |
| 199 | * container references updates. |
| 200 | */ |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 201 | @Test |
| 202 | public void testMoveStackBetweenDisplays() throws Exception { |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 203 | // Create a second display. |
| 204 | final DisplayContent dc = createNewDisplay(); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 205 | |
| 206 | // Add stack with activity. |
| 207 | final TaskStack stack = createTaskStackOnDisplay(dc); |
| 208 | assertEquals(dc.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 209 | assertEquals(dc, stack.getParent().getParent()); |
| 210 | assertEquals(dc, stack.getDisplayContent()); |
| 211 | |
| 212 | final Task task = createTaskInStack(stack, 0 /* userId */); |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 213 | final WindowTestUtils.TestAppWindowToken token = WindowTestUtils.createTestAppWindowToken( |
| 214 | dc); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 215 | task.addChild(token, 0); |
| 216 | assertEquals(dc, task.getDisplayContent()); |
| 217 | assertEquals(dc, token.getDisplayContent()); |
| 218 | |
| 219 | // Move stack to first display. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 220 | mDisplayContent.moveStackToDisplay(stack, true /* onTop */); |
| 221 | assertEquals(mDisplayContent.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 222 | assertEquals(mDisplayContent, stack.getParent().getParent()); |
| 223 | assertEquals(mDisplayContent, stack.getDisplayContent()); |
| 224 | assertEquals(mDisplayContent, task.getDisplayContent()); |
| 225 | assertEquals(mDisplayContent, token.getDisplayContent()); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 226 | } |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * This tests override configuration updates for display content. |
| 230 | */ |
| 231 | @Test |
| 232 | public void testDisplayOverrideConfigUpdate() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 233 | final int displayId = mDisplayContent.getDisplayId(); |
| 234 | final Configuration currentOverrideConfig = mDisplayContent.getOverrideConfiguration(); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 235 | |
| 236 | // Create new, slightly changed override configuration and apply it to the display. |
| 237 | final Configuration newOverrideConfig = new Configuration(currentOverrideConfig); |
| 238 | newOverrideConfig.densityDpi += 120; |
| 239 | newOverrideConfig.fontScale += 0.3; |
| 240 | |
| 241 | sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, displayId); |
| 242 | |
| 243 | // Check that override config is applied. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 244 | assertEquals(newOverrideConfig, mDisplayContent.getOverrideConfiguration()); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /** |
| 248 | * This tests global configuration updates when default display config is updated. |
| 249 | */ |
| 250 | @Test |
| 251 | public void testDefaultDisplayOverrideConfigUpdate() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 252 | final Configuration currentConfig = mDisplayContent.getConfiguration(); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 253 | |
| 254 | // Create new, slightly changed override configuration and apply it to the display. |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 255 | final Configuration newOverrideConfig = new Configuration(currentConfig); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 256 | newOverrideConfig.densityDpi += 120; |
| 257 | newOverrideConfig.fontScale += 0.3; |
| 258 | |
| 259 | sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, DEFAULT_DISPLAY); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 260 | |
| 261 | // 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] | 262 | Configuration globalConfig = sWm.mRoot.getConfiguration(); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 263 | assertEquals(newOverrideConfig.densityDpi, globalConfig.densityDpi); |
| 264 | assertEquals(newOverrideConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 265 | |
| 266 | // Return back to original values. |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 267 | sWm.setNewDisplayOverrideConfiguration(currentConfig, DEFAULT_DISPLAY); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 268 | globalConfig = sWm.mRoot.getConfiguration(); |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 269 | assertEquals(currentConfig.densityDpi, globalConfig.densityDpi); |
| 270 | assertEquals(currentConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 271 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 272 | |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 273 | /** |
| 274 | * Tests tapping on a stack in different display results in window gaining focus. |
| 275 | */ |
| 276 | @Test |
| 277 | public void testInputEventBringsCorrectDisplayInFocus() throws Exception { |
| 278 | DisplayContent dc0 = sWm.getDefaultDisplayContentLocked(); |
| 279 | // Create a second display |
| 280 | final DisplayContent dc1 = createNewDisplay(); |
| 281 | |
| 282 | // Add stack with activity. |
| 283 | final TaskStack stack0 = createTaskStackOnDisplay(dc0); |
| 284 | final Task task0 = createTaskInStack(stack0, 0 /* userId */); |
| 285 | final WindowTestUtils.TestAppWindowToken token = |
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 | task0.addChild(token, 0); |
| 288 | dc0.mTapDetector = new TaskTapPointerEventListener(sWm, dc0); |
| 289 | sWm.registerPointerEventListener(dc0.mTapDetector); |
| 290 | final TaskStack stack1 = createTaskStackOnDisplay(dc1); |
| 291 | final Task task1 = createTaskInStack(stack1, 0 /* userId */); |
| 292 | final WindowTestUtils.TestAppWindowToken token1 = |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 293 | WindowTestUtils.createTestAppWindowToken(dc0); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 294 | task1.addChild(token1, 0); |
| 295 | dc1.mTapDetector = new TaskTapPointerEventListener(sWm, dc0); |
| 296 | sWm.registerPointerEventListener(dc1.mTapDetector); |
| 297 | |
| 298 | // tap on primary display (by sending ACTION_DOWN followed by ACTION_UP) |
| 299 | DisplayMetrics dm0 = dc0.getDisplayMetrics(); |
| 300 | dc0.mTapDetector.onPointerEvent( |
| 301 | createTapEvent(dm0.widthPixels / 2, dm0.heightPixels / 2, true)); |
| 302 | dc0.mTapDetector.onPointerEvent( |
| 303 | createTapEvent(dm0.widthPixels / 2, dm0.heightPixels / 2, false)); |
| 304 | |
| 305 | // Check focus is on primary display. |
| 306 | assertEquals(sWm.mCurrentFocus, dc0.findFocusedWindow()); |
| 307 | |
| 308 | // Tap on secondary display |
| 309 | DisplayMetrics dm1 = dc1.getDisplayMetrics(); |
| 310 | dc1.mTapDetector.onPointerEvent( |
| 311 | createTapEvent(dm1.widthPixels / 2, dm1.heightPixels / 2, true)); |
| 312 | dc1.mTapDetector.onPointerEvent( |
| 313 | createTapEvent(dm1.widthPixels / 2, dm1.heightPixels / 2, false)); |
| 314 | |
| 315 | // Check focus is on secondary. |
| 316 | assertEquals(sWm.mCurrentFocus, dc1.findFocusedWindow()); |
| 317 | } |
| 318 | |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 319 | @Test |
| 320 | public void testFocusedWindowMultipleDisplays() throws Exception { |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame] | 321 | // Create a focusable window and check that focus is calculated correctly |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 322 | final WindowState window1 = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 323 | createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1"); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 324 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 325 | |
| 326 | // Check that a new display doesn't affect focus |
| 327 | final DisplayContent dc = createNewDisplay(); |
| 328 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 329 | |
| 330 | // Add a window to the second display, and it should be focused |
| 331 | final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2"); |
| 332 | assertEquals(window2, sWm.mRoot.computeFocusedWindow()); |
| 333 | |
| 334 | // Move the first window to the to including parents, and make sure focus is updated |
| 335 | window1.getParent().positionChildAt(POSITION_TOP, window1, true); |
| 336 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 337 | } |
| 338 | |
Adrian Roos | 4163d62 | 2018-05-22 16:56:35 +0200 | [diff] [blame] | 339 | @Test |
| 340 | public void testKeyguard_preventsSecondaryDisplayFocus() throws Exception { |
| 341 | final WindowState keyguard = createWindow(null, TYPE_STATUS_BAR, |
| 342 | sWm.getDefaultDisplayContentLocked(), "keyguard"); |
| 343 | assertEquals(keyguard, sWm.mRoot.computeFocusedWindow()); |
| 344 | |
| 345 | // Add a window to a second display, and it should be focused |
| 346 | final DisplayContent dc = createNewDisplay(); |
| 347 | final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, dc, "win"); |
| 348 | assertEquals(win, sWm.mRoot.computeFocusedWindow()); |
| 349 | |
| 350 | mWmRule.getWindowManagerPolicy().keyguardShowingAndNotOccluded = true; |
| 351 | assertEquals(keyguard, sWm.mRoot.computeFocusedWindow()); |
| 352 | } |
| 353 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 354 | /** |
| 355 | * This tests setting the maximum ui width on a display. |
| 356 | */ |
| 357 | @Test |
| 358 | public void testMaxUiWidth() throws Exception { |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 359 | // Prevent base display metrics for test from being updated to the value of real display. |
| 360 | final DisplayContent displayContent = createDisplayNoUpdateDisplayInfo(); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 361 | final int baseWidth = 1440; |
| 362 | final int baseHeight = 2560; |
| 363 | final int baseDensity = 300; |
| 364 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 365 | displayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 366 | |
| 367 | final int maxWidth = 300; |
| 368 | final int resultingHeight = (maxWidth * baseHeight) / baseWidth; |
| 369 | final int resultingDensity = (maxWidth * baseDensity) / baseWidth; |
| 370 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 371 | displayContent.setMaxUiWidth(maxWidth); |
| 372 | verifySizes(displayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 373 | |
| 374 | // Assert setting values again does not change; |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 375 | displayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
| 376 | verifySizes(displayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 377 | |
| 378 | final int smallerWidth = 200; |
| 379 | final int smallerHeight = 400; |
| 380 | final int smallerDensity = 100; |
| 381 | |
| 382 | // Specify smaller dimension, verify that it is honored |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 383 | displayContent.updateBaseDisplayMetrics(smallerWidth, smallerHeight, smallerDensity); |
| 384 | verifySizes(displayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 385 | |
| 386 | // Verify that setting the max width to a greater value than the base width has no effect |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 387 | displayContent.setMaxUiWidth(maxWidth); |
| 388 | verifySizes(displayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 391 | /** |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 392 | * This test enforces that alwaysOnTop stack is placed at proper position. |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 393 | */ |
| 394 | @Test |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 395 | public void testAlwaysOnTopStackLocation() { |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 396 | final TaskStack alwaysOnTopStack = createStackControllerOnStackOnDisplay( |
| 397 | WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer; |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 398 | final Task task = createTaskInStack(alwaysOnTopStack, 0 /* userId */); |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 399 | alwaysOnTopStack.setAlwaysOnTop(true); |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 400 | mDisplayContent.positionStackAt(POSITION_TOP, alwaysOnTopStack, |
| 401 | false /* includingParents */); |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 402 | assertTrue(alwaysOnTopStack.isAlwaysOnTop()); |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 403 | // Ensure always on top state is synced to the children of the stack. |
| 404 | assertTrue(alwaysOnTopStack.getTopChild().isAlwaysOnTop()); |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 405 | assertEquals(alwaysOnTopStack, mDisplayContent.getTopStack()); |
| 406 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 407 | final TaskStack pinnedStack = createStackControllerOnStackOnDisplay( |
| 408 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 409 | assertEquals(pinnedStack, mDisplayContent.getPinnedStack()); |
| 410 | assertEquals(pinnedStack, mDisplayContent.getTopStack()); |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 411 | |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 412 | final TaskStack anotherAlwaysOnTopStack = createStackControllerOnStackOnDisplay( |
| 413 | WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 414 | anotherAlwaysOnTopStack.setAlwaysOnTop(true); |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 415 | mDisplayContent.positionStackAt(POSITION_TOP, anotherAlwaysOnTopStack, |
| 416 | false /* includingParents */); |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 417 | assertTrue(anotherAlwaysOnTopStack.isAlwaysOnTop()); |
| 418 | int topPosition = mDisplayContent.getStacks().size() - 1; |
| 419 | // Ensure the new alwaysOnTop stack is put below the pinned stack, but on top of the |
| 420 | // existing alwaysOnTop stack. |
| 421 | assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 1)); |
| 422 | |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 423 | final TaskStack nonAlwaysOnTopStack = createStackControllerOnStackOnDisplay( |
| 424 | WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 425 | assertEquals(mDisplayContent, nonAlwaysOnTopStack.getDisplayContent()); |
| 426 | topPosition = mDisplayContent.getStacks().size() - 1; |
| 427 | // Ensure the non-alwaysOnTop stack is put below the three alwaysOnTop stacks, but above the |
| 428 | // existing other non-alwaysOnTop stacks. |
| 429 | assertEquals(nonAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 3)); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 430 | |
| 431 | anotherAlwaysOnTopStack.setAlwaysOnTop(false); |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 432 | mDisplayContent.positionStackAt(POSITION_TOP, anotherAlwaysOnTopStack, |
| 433 | false /* includingParents */); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 434 | assertFalse(anotherAlwaysOnTopStack.isAlwaysOnTop()); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 435 | // Ensure, when always on top is turned off for a stack, the stack is put just below all |
| 436 | // other always on top stacks. |
| 437 | assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 2)); |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 438 | anotherAlwaysOnTopStack.setAlwaysOnTop(true); |
| 439 | |
| 440 | // Ensure always on top state changes properly when windowing mode changes. |
| 441 | anotherAlwaysOnTopStack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 442 | assertFalse(anotherAlwaysOnTopStack.isAlwaysOnTop()); |
| 443 | assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 2)); |
| 444 | anotherAlwaysOnTopStack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 445 | assertTrue(anotherAlwaysOnTopStack.isAlwaysOnTop()); |
| 446 | assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 1)); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame] | 449 | /** |
| 450 | * Test that WM does not report displays to AM that are pending to be removed. |
| 451 | */ |
| 452 | @Test |
| 453 | public void testDontReportDeferredRemoval() { |
| 454 | // Create a display and add an animating window to it. |
| 455 | final DisplayContent dc = createNewDisplay(); |
| 456 | final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
| 457 | window.mAnimatingExit = true; |
| 458 | // Request display removal, it should be deferred. |
| 459 | dc.removeIfPossible(); |
| 460 | // Request ordered display ids from WM. |
| 461 | final SparseIntArray orderedDisplayIds = new SparseIntArray(); |
| 462 | sWm.getDisplaysInFocusOrder(orderedDisplayIds); |
| 463 | // Make sure that display that is marked for removal is not reported. |
| 464 | assertEquals(-1, orderedDisplayIds.indexOfValue(dc.getDisplayId())); |
| 465 | } |
| 466 | |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 467 | @Test |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 468 | public void testDisplayCutout_rot0() throws Exception { |
| 469 | synchronized (sWm.getWindowManagerLock()) { |
| 470 | final DisplayContent dc = createNewDisplay(); |
| 471 | dc.mInitialDisplayWidth = 200; |
| 472 | dc.mInitialDisplayHeight = 400; |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 473 | Rect r = new Rect(80, 0, 120, 10); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 474 | final DisplayCutout cutout = new WmDisplayCutout( |
| 475 | fromBoundingRect(r.left, r.top, r.right, r.bottom), null) |
| 476 | .computeSafeInsets(200, 400).getDisplayCutout(); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 477 | |
| 478 | dc.mInitialDisplayCutout = cutout; |
| 479 | dc.setRotation(Surface.ROTATION_0); |
| 480 | dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo. |
| 481 | |
| 482 | assertEquals(cutout, dc.getDisplayInfo().displayCutout); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | @Test |
| 487 | public void testDisplayCutout_rot90() throws Exception { |
| 488 | synchronized (sWm.getWindowManagerLock()) { |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 489 | // Prevent mInitialDisplayCutout from being updated from real display (e.g. null |
| 490 | // if the device has no cutout). |
| 491 | final DisplayContent dc = createDisplayNoUpdateDisplayInfo(); |
| 492 | // Rotation may use real display info to compute bound, so here also uses the |
| 493 | // same width and height. |
| 494 | final int displayWidth = dc.mInitialDisplayWidth; |
| 495 | final int displayHeight = dc.mInitialDisplayHeight; |
| 496 | final int cutoutWidth = 40; |
| 497 | final int cutoutHeight = 10; |
| 498 | final int left = (displayWidth - cutoutWidth) / 2; |
| 499 | final int top = 0; |
| 500 | final int right = (displayWidth + cutoutWidth) / 2; |
| 501 | final int bottom = cutoutHeight; |
| 502 | |
| 503 | final Rect r1 = new Rect(left, top, right, bottom); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 504 | final DisplayCutout cutout = new WmDisplayCutout( |
| 505 | fromBoundingRect(r1.left, r1.top, r1.right, r1.bottom), null) |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 506 | .computeSafeInsets(displayWidth, displayHeight).getDisplayCutout(); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 507 | |
| 508 | dc.mInitialDisplayCutout = cutout; |
| 509 | dc.setRotation(Surface.ROTATION_90); |
| 510 | dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo. |
| 511 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 512 | // ----o---------- ------------- |
| 513 | // | | | | | |
| 514 | // | ------o | o--- |
| 515 | // | | | | |
| 516 | // | | -> | | |
| 517 | // | | ---o |
| 518 | // | | | |
| 519 | // | | ------------- |
| 520 | final Rect r = new Rect(top, left, bottom, right); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 521 | assertEquals(new WmDisplayCutout( |
| 522 | fromBoundingRect(r.left, r.top, r.right, r.bottom), null) |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 523 | .computeSafeInsets(displayHeight, displayWidth) |
| 524 | .getDisplayCutout(), dc.getDisplayInfo().displayCutout); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
| 528 | @Test |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 529 | public void testLayoutSeq_assignedDuringLayout() throws Exception { |
| 530 | synchronized (sWm.getWindowManagerLock()) { |
| 531 | |
| 532 | final DisplayContent dc = createNewDisplay(); |
| 533 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
| 534 | |
| 535 | dc.setLayoutNeeded(); |
| 536 | dc.performLayout(true /* initial */, false /* updateImeWindows */); |
| 537 | |
| 538 | assertThat(win.mLayoutSeq, is(dc.mLayoutSeq)); |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | @Test |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 543 | @SuppressLint("InlinedApi") |
| 544 | public void testOrientationDefinedByKeyguard() { |
| 545 | final DisplayContent dc = createNewDisplay(); |
| 546 | // Create a window that requests landscape orientation. It will define device orientation |
| 547 | // by default. |
| 548 | final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
| 549 | window.mAppToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 550 | |
| 551 | final WindowState keyguard = createWindow(null, TYPE_STATUS_BAR, dc, "keyguard"); |
| 552 | keyguard.mHasSurface = true; |
| 553 | keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 554 | |
| 555 | assertEquals("Screen orientation must be defined by the app window by default", |
| 556 | SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation()); |
| 557 | |
| 558 | keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_PORTRAIT; |
| 559 | assertEquals("Visible keyguard must influence device orientation", |
| 560 | SCREEN_ORIENTATION_PORTRAIT, dc.getOrientation()); |
| 561 | |
| 562 | sWm.setKeyguardGoingAway(true); |
| 563 | assertEquals("Keyguard that is going away must not influence device orientation", |
| 564 | SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation()); |
| 565 | } |
| 566 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 567 | @Test |
| 568 | public void testDisableDisplayInfoOverrideFromWindowManager() { |
| 569 | final DisplayContent dc = createNewDisplay(); |
| 570 | |
| 571 | assertTrue(dc.mShouldOverrideDisplayConfiguration); |
| 572 | sWm.dontOverrideDisplayInfo(dc.getDisplayId()); |
| 573 | |
| 574 | assertFalse(dc.mShouldOverrideDisplayConfiguration); |
| 575 | verify(sWm.mDisplayManagerInternal, times(1)) |
| 576 | .setDisplayInfoOverrideFromWindowManager(dc.getDisplayId(), null); |
| 577 | } |
| 578 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame^] | 579 | @Test |
| 580 | public void testGetPreferredOptionsPanelGravityFromDifferentDisplays() { |
| 581 | final DisplayContent portraitDisplay = createNewDisplay(); |
| 582 | portraitDisplay.mInitialDisplayHeight = 2000; |
| 583 | portraitDisplay.mInitialDisplayWidth = 1000; |
| 584 | |
| 585 | portraitDisplay.setRotation(Surface.ROTATION_0); |
| 586 | assertFalse(isOptionsPanelAtRight(portraitDisplay.getDisplayId())); |
| 587 | portraitDisplay.setRotation(Surface.ROTATION_90); |
| 588 | assertTrue(isOptionsPanelAtRight(portraitDisplay.getDisplayId())); |
| 589 | |
| 590 | final DisplayContent landscapeDisplay = createNewDisplay(); |
| 591 | landscapeDisplay.mInitialDisplayHeight = 1000; |
| 592 | landscapeDisplay.mInitialDisplayWidth = 2000; |
| 593 | |
| 594 | landscapeDisplay.setRotation(Surface.ROTATION_0); |
| 595 | assertTrue(isOptionsPanelAtRight(landscapeDisplay.getDisplayId())); |
| 596 | landscapeDisplay.setRotation(Surface.ROTATION_90); |
| 597 | assertFalse(isOptionsPanelAtRight(landscapeDisplay.getDisplayId())); |
| 598 | } |
| 599 | |
| 600 | private boolean isOptionsPanelAtRight(int displayId) { |
| 601 | return (sWm.getPreferredOptionsPanelGravity(displayId) & Gravity.RIGHT) == Gravity.RIGHT; |
| 602 | } |
| 603 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 604 | private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth, |
| 605 | int expectedBaseHeight, int expectedBaseDensity) { |
| 606 | assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth); |
| 607 | assertEquals(displayContent.mBaseDisplayHeight, expectedBaseHeight); |
| 608 | assertEquals(displayContent.mBaseDisplayDensity, expectedBaseDensity); |
| 609 | } |
| 610 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 611 | /** |
| 612 | * Create DisplayContent that does not update display base/initial values from device to keep |
| 613 | * the values set by test. |
| 614 | */ |
| 615 | private DisplayContent createDisplayNoUpdateDisplayInfo() { |
| 616 | final DisplayContent displayContent = spy(createNewDisplay()); |
| 617 | doNothing().when(displayContent).updateDisplayInfo(); |
| 618 | return displayContent; |
| 619 | } |
| 620 | |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 621 | private void assertForAllWindowsOrder(List<WindowState> expectedWindowsBottomToTop) { |
| 622 | final LinkedList<WindowState> actualWindows = new LinkedList<>(); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 623 | |
| 624 | // Test forward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 625 | mDisplayContent.forAllWindows(actualWindows::addLast, false /* traverseTopToBottom */); |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 626 | assertThat("bottomToTop", actualWindows, is(expectedWindowsBottomToTop)); |
| 627 | |
| 628 | actualWindows.clear(); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 629 | |
| 630 | // Test backward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 631 | mDisplayContent.forAllWindows(actualWindows::addLast, true /* traverseTopToBottom */); |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 632 | assertThat("topToBottom", actualWindows, is(reverseList(expectedWindowsBottomToTop))); |
| 633 | } |
| 634 | |
| 635 | private static List<WindowState> reverseList(List<WindowState> list) { |
| 636 | final ArrayList<WindowState> result = new ArrayList<>(list); |
| 637 | Collections.reverse(result); |
| 638 | return result; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 639 | } |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 640 | |
| 641 | private MotionEvent createTapEvent(float x, float y, boolean isDownEvent) { |
| 642 | final long downTime = SystemClock.uptimeMillis(); |
| 643 | final long eventTime = SystemClock.uptimeMillis() + 100; |
| 644 | final int metaState = 0; |
| 645 | |
| 646 | return MotionEvent.obtain( |
| 647 | downTime, |
| 648 | eventTime, |
| 649 | isDownEvent ? MotionEvent.ACTION_DOWN : MotionEvent.ACTION_UP, |
| 650 | x, |
| 651 | y, |
| 652 | metaState); |
| 653 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 654 | } |