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