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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 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; |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 27 | import static android.view.DisplayCutout.BOUNDS_POSITION_LEFT; |
| 28 | import static android.view.DisplayCutout.BOUNDS_POSITION_TOP; |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 29 | import static android.view.DisplayCutout.fromBoundingRect; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
| 31 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 33 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 34 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 35 | |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 36 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 37 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 38 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 39 | import static org.hamcrest.Matchers.is; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 40 | import static org.junit.Assert.assertEquals; |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 41 | import static org.junit.Assert.assertFalse; |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 42 | import static org.junit.Assert.assertNotNull; |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame^] | 43 | import static org.junit.Assert.assertNull; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 44 | import static org.junit.Assert.assertThat; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 45 | import static org.junit.Assert.assertTrue; |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 46 | import static org.mockito.Mockito.doNothing; |
| 47 | import static org.mockito.Mockito.spy; |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 48 | import static org.mockito.Mockito.times; |
| 49 | import static org.mockito.Mockito.verify; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 50 | |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 51 | import android.annotation.SuppressLint; |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 52 | import android.content.res.Configuration; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 53 | import android.graphics.Rect; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 54 | import android.os.SystemClock; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 55 | import android.platform.test.annotations.Presubmit; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 56 | import android.util.DisplayMetrics; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 57 | import android.view.DisplayCutout; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 58 | import android.view.Gravity; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 59 | import android.view.MotionEvent; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 60 | import android.view.Surface; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 61 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 62 | import androidx.test.filters.FlakyTest; |
| 63 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 64 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 65 | import com.android.server.wm.utils.WmDisplayCutout; |
| 66 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 67 | import org.junit.Test; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 68 | |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 69 | import java.util.ArrayList; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 70 | import java.util.Arrays; |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 71 | import java.util.Collections; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 72 | import java.util.LinkedList; |
| 73 | import java.util.List; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Tests for the {@link DisplayContent} class. |
| 77 | * |
| 78 | * Build/Install/Run: |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 79 | * atest FrameworksServicesTests:DisplayContentTests |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 80 | */ |
| 81 | @SmallTest |
| 82 | @Presubmit |
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) |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 87 | public void testForAllWindows() { |
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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 108 | public void testForAllWindows_WithAppImeTarget() { |
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 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame^] | 112 | mDisplayContent.mInputMethodTarget = imeAppTarget; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 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 |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame^] | 128 | public void testForAllWindows_WithChildWindowImeTarget() throws Exception { |
| 129 | mDisplayContent.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 |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame^] | 144 | public void testForAllWindows_WithStatusBarImeTarget() throws Exception { |
| 145 | mDisplayContent.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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 160 | public void testForAllWindows_WithInBetweenWindowToken() { |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 180 | public void testComputeImeTarget() { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 203 | public void testMoveStackBetweenDisplays() { |
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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 233 | public void testDisplayOverrideConfigUpdate() { |
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 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 242 | mWm.setNewDisplayOverrideConfiguration(newOverrideConfig, displayId); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 252 | public void testDefaultDisplayOverrideConfigUpdate() { |
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 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 260 | mWm.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. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 263 | Configuration globalConfig = mWm.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. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 268 | mWm.setNewDisplayOverrideConfiguration(currentConfig, DEFAULT_DISPLAY); |
| 269 | globalConfig = mWm.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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 278 | public void testInputEventBringsCorrectDisplayInFocus() { |
| 279 | DisplayContent dc0 = mWm.getDefaultDisplayContentLocked(); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 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); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 289 | dc0.configureDisplayPolicy(); |
| 290 | assertNotNull(dc0.mTapDetector); |
| 291 | |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 292 | final TaskStack stack1 = createTaskStackOnDisplay(dc1); |
| 293 | final Task task1 = createTaskInStack(stack1, 0 /* userId */); |
| 294 | final WindowTestUtils.TestAppWindowToken token1 = |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 295 | WindowTestUtils.createTestAppWindowToken(dc0); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 296 | task1.addChild(token1, 0); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 297 | dc1.configureDisplayPolicy(); |
| 298 | assertNotNull(dc1.mTapDetector); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 299 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 300 | // tap on primary display. |
| 301 | tapOnDisplay(dc0); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 302 | // Check focus is on primary display. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 303 | assertEquals(mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus, |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 304 | dc0.findFocusedWindow()); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 305 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 306 | // Tap on secondary display. |
| 307 | tapOnDisplay(dc1); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 308 | // Check focus is on secondary. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 309 | assertEquals(mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus, |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 310 | dc1.findFocusedWindow()); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 311 | } |
| 312 | |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 313 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 314 | public void testFocusedWindowMultipleDisplays() { |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame] | 315 | // Create a focusable window and check that focus is calculated correctly |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 316 | final WindowState window1 = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 317 | createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1"); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 318 | updateFocusedWindow(); |
| 319 | assertTrue(window1.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 320 | assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 321 | |
| 322 | // Check that a new display doesn't affect focus |
| 323 | final DisplayContent dc = createNewDisplay(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 324 | updateFocusedWindow(); |
| 325 | assertTrue(window1.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 326 | assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 327 | |
| 328 | // Add a window to the second display, and it should be focused |
| 329 | final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2"); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 330 | updateFocusedWindow(); |
| 331 | assertTrue(window1.isFocused()); |
| 332 | assertTrue(window2.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 333 | assertEquals(window2, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 334 | |
| 335 | // Move the first window to the to including parents, and make sure focus is updated |
| 336 | window1.getParent().positionChildAt(POSITION_TOP, window1, true); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 337 | updateFocusedWindow(); |
| 338 | assertTrue(window1.isFocused()); |
| 339 | assertTrue(window2.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 340 | assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
Adrian Roos | 4163d62 | 2018-05-22 16:56:35 +0200 | [diff] [blame] | 341 | } |
| 342 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 343 | /** |
| 344 | * This tests setting the maximum ui width on a display. |
| 345 | */ |
| 346 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 347 | public void testMaxUiWidth() { |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 348 | // Prevent base display metrics for test from being updated to the value of real display. |
| 349 | final DisplayContent displayContent = createDisplayNoUpdateDisplayInfo(); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 350 | final int baseWidth = 1440; |
| 351 | final int baseHeight = 2560; |
| 352 | final int baseDensity = 300; |
| 353 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 354 | displayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 355 | |
| 356 | final int maxWidth = 300; |
| 357 | final int resultingHeight = (maxWidth * baseHeight) / baseWidth; |
| 358 | final int resultingDensity = (maxWidth * baseDensity) / baseWidth; |
| 359 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 360 | displayContent.setMaxUiWidth(maxWidth); |
| 361 | verifySizes(displayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 362 | |
| 363 | // Assert setting values again does not change; |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 364 | displayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
| 365 | verifySizes(displayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 366 | |
| 367 | final int smallerWidth = 200; |
| 368 | final int smallerHeight = 400; |
| 369 | final int smallerDensity = 100; |
| 370 | |
| 371 | // Specify smaller dimension, verify that it is honored |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 372 | displayContent.updateBaseDisplayMetrics(smallerWidth, smallerHeight, smallerDensity); |
| 373 | verifySizes(displayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 374 | |
| 375 | // 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] | 376 | displayContent.setMaxUiWidth(maxWidth); |
| 377 | verifySizes(displayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 380 | /** |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 381 | * This test enforces that alwaysOnTop stack is placed at proper position. |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 382 | */ |
| 383 | @Test |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 384 | public void testAlwaysOnTopStackLocation() { |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 385 | final TaskStack alwaysOnTopStack = createStackControllerOnStackOnDisplay( |
| 386 | WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer; |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 387 | final Task task = createTaskInStack(alwaysOnTopStack, 0 /* userId */); |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 388 | alwaysOnTopStack.setAlwaysOnTop(true); |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 389 | mDisplayContent.positionStackAt(POSITION_TOP, alwaysOnTopStack, |
| 390 | false /* includingParents */); |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 391 | assertTrue(alwaysOnTopStack.isAlwaysOnTop()); |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 392 | // Ensure always on top state is synced to the children of the stack. |
| 393 | assertTrue(alwaysOnTopStack.getTopChild().isAlwaysOnTop()); |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 394 | assertEquals(alwaysOnTopStack, mDisplayContent.getTopStack()); |
| 395 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 396 | final TaskStack pinnedStack = createStackControllerOnStackOnDisplay( |
| 397 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer; |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 398 | assertEquals(pinnedStack, mDisplayContent.getPinnedStack()); |
| 399 | assertEquals(pinnedStack, mDisplayContent.getTopStack()); |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 400 | |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 401 | final TaskStack anotherAlwaysOnTopStack = createStackControllerOnStackOnDisplay( |
| 402 | WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 403 | anotherAlwaysOnTopStack.setAlwaysOnTop(true); |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 404 | mDisplayContent.positionStackAt(POSITION_TOP, anotherAlwaysOnTopStack, |
| 405 | false /* includingParents */); |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 406 | assertTrue(anotherAlwaysOnTopStack.isAlwaysOnTop()); |
| 407 | int topPosition = mDisplayContent.getStacks().size() - 1; |
| 408 | // Ensure the new alwaysOnTop stack is put below the pinned stack, but on top of the |
| 409 | // existing alwaysOnTop stack. |
| 410 | assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 1)); |
| 411 | |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 412 | final TaskStack nonAlwaysOnTopStack = createStackControllerOnStackOnDisplay( |
| 413 | WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 414 | assertEquals(mDisplayContent, nonAlwaysOnTopStack.getDisplayContent()); |
| 415 | topPosition = mDisplayContent.getStacks().size() - 1; |
| 416 | // Ensure the non-alwaysOnTop stack is put below the three alwaysOnTop stacks, but above the |
| 417 | // existing other non-alwaysOnTop stacks. |
| 418 | assertEquals(nonAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 3)); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 419 | |
| 420 | anotherAlwaysOnTopStack.setAlwaysOnTop(false); |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 421 | mDisplayContent.positionStackAt(POSITION_TOP, anotherAlwaysOnTopStack, |
| 422 | false /* includingParents */); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 423 | assertFalse(anotherAlwaysOnTopStack.isAlwaysOnTop()); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 424 | // Ensure, when always on top is turned off for a stack, the stack is put just below all |
| 425 | // other always on top stacks. |
| 426 | assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 2)); |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 427 | anotherAlwaysOnTopStack.setAlwaysOnTop(true); |
| 428 | |
| 429 | // Ensure always on top state changes properly when windowing mode changes. |
| 430 | anotherAlwaysOnTopStack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 431 | assertFalse(anotherAlwaysOnTopStack.isAlwaysOnTop()); |
| 432 | assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 2)); |
| 433 | anotherAlwaysOnTopStack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 434 | assertTrue(anotherAlwaysOnTopStack.isAlwaysOnTop()); |
| 435 | assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 1)); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 438 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 439 | public void testDisplayCutout_rot0() { |
| 440 | synchronized (mWm.getWindowManagerLock()) { |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 441 | final DisplayContent dc = createNewDisplay(); |
| 442 | dc.mInitialDisplayWidth = 200; |
| 443 | dc.mInitialDisplayHeight = 400; |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 444 | Rect r = new Rect(80, 0, 120, 10); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 445 | final DisplayCutout cutout = new WmDisplayCutout( |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 446 | fromBoundingRect(r.left, r.top, r.right, r.bottom, BOUNDS_POSITION_TOP), null) |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 447 | .computeSafeInsets(200, 400).getDisplayCutout(); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 448 | |
| 449 | dc.mInitialDisplayCutout = cutout; |
| 450 | dc.setRotation(Surface.ROTATION_0); |
| 451 | dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo. |
| 452 | |
| 453 | assertEquals(cutout, dc.getDisplayInfo().displayCutout); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 458 | public void testDisplayCutout_rot90() { |
| 459 | synchronized (mWm.getWindowManagerLock()) { |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 460 | // Prevent mInitialDisplayCutout from being updated from real display (e.g. null |
| 461 | // if the device has no cutout). |
| 462 | final DisplayContent dc = createDisplayNoUpdateDisplayInfo(); |
| 463 | // Rotation may use real display info to compute bound, so here also uses the |
| 464 | // same width and height. |
| 465 | final int displayWidth = dc.mInitialDisplayWidth; |
| 466 | final int displayHeight = dc.mInitialDisplayHeight; |
| 467 | final int cutoutWidth = 40; |
| 468 | final int cutoutHeight = 10; |
| 469 | final int left = (displayWidth - cutoutWidth) / 2; |
| 470 | final int top = 0; |
| 471 | final int right = (displayWidth + cutoutWidth) / 2; |
| 472 | final int bottom = cutoutHeight; |
| 473 | |
| 474 | final Rect r1 = new Rect(left, top, right, bottom); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 475 | final DisplayCutout cutout = new WmDisplayCutout( |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 476 | fromBoundingRect(r1.left, r1.top, r1.right, r1.bottom, BOUNDS_POSITION_TOP), |
| 477 | null) |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 478 | .computeSafeInsets(displayWidth, displayHeight).getDisplayCutout(); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 479 | |
| 480 | dc.mInitialDisplayCutout = cutout; |
| 481 | dc.setRotation(Surface.ROTATION_90); |
| 482 | dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo. |
| 483 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 484 | // ----o---------- ------------- |
| 485 | // | | | | | |
| 486 | // | ------o | o--- |
| 487 | // | | | | |
| 488 | // | | -> | | |
| 489 | // | | ---o |
| 490 | // | | | |
| 491 | // | | ------------- |
| 492 | final Rect r = new Rect(top, left, bottom, right); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 493 | assertEquals(new WmDisplayCutout( |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 494 | fromBoundingRect(r.left, r.top, r.right, r.bottom, BOUNDS_POSITION_LEFT), null) |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 495 | .computeSafeInsets(displayHeight, displayWidth) |
| 496 | .getDisplayCutout(), dc.getDisplayInfo().displayCutout); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
| 500 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 501 | public void testLayoutSeq_assignedDuringLayout() { |
| 502 | synchronized (mWm.getWindowManagerLock()) { |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 503 | |
| 504 | final DisplayContent dc = createNewDisplay(); |
| 505 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
| 506 | |
| 507 | dc.setLayoutNeeded(); |
| 508 | dc.performLayout(true /* initial */, false /* updateImeWindows */); |
| 509 | |
| 510 | assertThat(win.mLayoutSeq, is(dc.mLayoutSeq)); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | @Test |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 515 | @SuppressLint("InlinedApi") |
| 516 | public void testOrientationDefinedByKeyguard() { |
| 517 | final DisplayContent dc = createNewDisplay(); |
| 518 | // Create a window that requests landscape orientation. It will define device orientation |
| 519 | // by default. |
| 520 | final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
| 521 | window.mAppToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 522 | |
| 523 | final WindowState keyguard = createWindow(null, TYPE_STATUS_BAR, dc, "keyguard"); |
| 524 | keyguard.mHasSurface = true; |
| 525 | keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 526 | |
| 527 | assertEquals("Screen orientation must be defined by the app window by default", |
| 528 | SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation()); |
| 529 | |
| 530 | keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_PORTRAIT; |
| 531 | assertEquals("Visible keyguard must influence device orientation", |
| 532 | SCREEN_ORIENTATION_PORTRAIT, dc.getOrientation()); |
| 533 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 534 | mWm.setKeyguardGoingAway(true); |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 535 | assertEquals("Keyguard that is going away must not influence device orientation", |
| 536 | SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation()); |
| 537 | } |
| 538 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 539 | @Test |
| 540 | public void testDisableDisplayInfoOverrideFromWindowManager() { |
| 541 | final DisplayContent dc = createNewDisplay(); |
| 542 | |
| 543 | assertTrue(dc.mShouldOverrideDisplayConfiguration); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 544 | mWm.dontOverrideDisplayInfo(dc.getDisplayId()); |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 545 | |
| 546 | assertFalse(dc.mShouldOverrideDisplayConfiguration); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 547 | verify(mWm.mDisplayManagerInternal, times(1)) |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 548 | .setDisplayInfoOverrideFromWindowManager(dc.getDisplayId(), null); |
| 549 | } |
| 550 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 551 | @Test |
| 552 | public void testGetPreferredOptionsPanelGravityFromDifferentDisplays() { |
| 553 | final DisplayContent portraitDisplay = createNewDisplay(); |
| 554 | portraitDisplay.mInitialDisplayHeight = 2000; |
| 555 | portraitDisplay.mInitialDisplayWidth = 1000; |
| 556 | |
| 557 | portraitDisplay.setRotation(Surface.ROTATION_0); |
| 558 | assertFalse(isOptionsPanelAtRight(portraitDisplay.getDisplayId())); |
| 559 | portraitDisplay.setRotation(Surface.ROTATION_90); |
| 560 | assertTrue(isOptionsPanelAtRight(portraitDisplay.getDisplayId())); |
| 561 | |
| 562 | final DisplayContent landscapeDisplay = createNewDisplay(); |
| 563 | landscapeDisplay.mInitialDisplayHeight = 1000; |
| 564 | landscapeDisplay.mInitialDisplayWidth = 2000; |
| 565 | |
| 566 | landscapeDisplay.setRotation(Surface.ROTATION_0); |
| 567 | assertTrue(isOptionsPanelAtRight(landscapeDisplay.getDisplayId())); |
| 568 | landscapeDisplay.setRotation(Surface.ROTATION_90); |
| 569 | assertFalse(isOptionsPanelAtRight(landscapeDisplay.getDisplayId())); |
| 570 | } |
| 571 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame^] | 572 | @Test |
| 573 | public void testInputMethodTargetUpdateWhenSwitchingOnDisplays() { |
| 574 | final DisplayContent newDisplay = createNewDisplay(); |
| 575 | |
| 576 | final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin"); |
| 577 | final WindowState appWin1 = createWindow(null, TYPE_APPLICATION, newDisplay, "appWin1"); |
| 578 | appWin.setHasSurface(true); |
| 579 | appWin1.setHasSurface(true); |
| 580 | |
| 581 | // Set current input method window on default display, make sure the input method target |
| 582 | // is appWin & null on the other display. |
| 583 | mDisplayContent.setInputMethodWindowLocked(mImeWindow); |
| 584 | newDisplay.setInputMethodWindowLocked(null); |
| 585 | assertTrue("appWin should be IME target window", |
| 586 | appWin.equals(mDisplayContent.mInputMethodTarget)); |
| 587 | assertNull("newDisplay Ime target: ", newDisplay.mInputMethodTarget); |
| 588 | |
| 589 | // Switch input method window on new display & make sure the input method target also |
| 590 | // switched as expected. |
| 591 | newDisplay.setInputMethodWindowLocked(mImeWindow); |
| 592 | mDisplayContent.setInputMethodWindowLocked(null); |
| 593 | assertTrue("appWin1 should be IME target window", |
| 594 | appWin1.equals(newDisplay.mInputMethodTarget)); |
| 595 | assertNull("default display Ime target: ", mDisplayContent.mInputMethodTarget); |
| 596 | } |
| 597 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 598 | private boolean isOptionsPanelAtRight(int displayId) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 599 | return (mWm.getPreferredOptionsPanelGravity(displayId) & Gravity.RIGHT) == Gravity.RIGHT; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 600 | } |
| 601 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 602 | private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth, |
| 603 | int expectedBaseHeight, int expectedBaseDensity) { |
| 604 | assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth); |
| 605 | assertEquals(displayContent.mBaseDisplayHeight, expectedBaseHeight); |
| 606 | assertEquals(displayContent.mBaseDisplayDensity, expectedBaseDensity); |
| 607 | } |
| 608 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 609 | private void updateFocusedWindow() { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 610 | synchronized (mWm.mGlobalLock) { |
| 611 | mWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 615 | /** |
| 616 | * Create DisplayContent that does not update display base/initial values from device to keep |
| 617 | * the values set by test. |
| 618 | */ |
| 619 | private DisplayContent createDisplayNoUpdateDisplayInfo() { |
| 620 | final DisplayContent displayContent = spy(createNewDisplay()); |
| 621 | doNothing().when(displayContent).updateDisplayInfo(); |
| 622 | return displayContent; |
| 623 | } |
| 624 | |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 625 | private void assertForAllWindowsOrder(List<WindowState> expectedWindowsBottomToTop) { |
| 626 | final LinkedList<WindowState> actualWindows = new LinkedList<>(); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 627 | |
| 628 | // Test forward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 629 | mDisplayContent.forAllWindows(actualWindows::addLast, false /* traverseTopToBottom */); |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 630 | assertThat("bottomToTop", actualWindows, is(expectedWindowsBottomToTop)); |
| 631 | |
| 632 | actualWindows.clear(); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 633 | |
| 634 | // Test backward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 635 | mDisplayContent.forAllWindows(actualWindows::addLast, true /* traverseTopToBottom */); |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 636 | assertThat("topToBottom", actualWindows, is(reverseList(expectedWindowsBottomToTop))); |
| 637 | } |
| 638 | |
| 639 | private static List<WindowState> reverseList(List<WindowState> list) { |
| 640 | final ArrayList<WindowState> result = new ArrayList<>(list); |
| 641 | Collections.reverse(result); |
| 642 | return result; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 643 | } |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 644 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 645 | private void tapOnDisplay(final DisplayContent dc) { |
| 646 | final DisplayMetrics dm = dc.getDisplayMetrics(); |
| 647 | final float x = dm.widthPixels / 2; |
| 648 | final float y = dm.heightPixels / 2; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 649 | final long downTime = SystemClock.uptimeMillis(); |
| 650 | final long eventTime = SystemClock.uptimeMillis() + 100; |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 651 | // sending ACTION_DOWN |
| 652 | final MotionEvent downEvent = MotionEvent.obtain( |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 653 | downTime, |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 654 | downTime, |
| 655 | MotionEvent.ACTION_DOWN, |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 656 | x, |
| 657 | y, |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 658 | 0 /*metaState*/); |
| 659 | downEvent.setDisplayId(dc.getDisplayId()); |
| 660 | dc.mTapDetector.onPointerEvent(downEvent); |
| 661 | |
| 662 | // sending ACTION_UP |
| 663 | final MotionEvent upEvent = MotionEvent.obtain( |
| 664 | downTime, |
| 665 | eventTime, |
| 666 | MotionEvent.ACTION_UP, |
| 667 | x, |
| 668 | y, |
| 669 | 0 /*metaState*/); |
| 670 | upEvent.setDisplayId(dc.getDisplayId()); |
| 671 | dc.mTapDetector.onPointerEvent(upEvent); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 672 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 673 | } |