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 | |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 19 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 20 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
| 21 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 22 | import static android.os.Build.VERSION_CODES.P; |
| 23 | import static android.os.Build.VERSION_CODES.Q; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 24 | import static android.view.Display.DEFAULT_DISPLAY; |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 25 | import static android.view.DisplayCutout.BOUNDS_POSITION_LEFT; |
| 26 | import static android.view.DisplayCutout.BOUNDS_POSITION_TOP; |
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 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 34 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; |
| 35 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 36 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 37 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; |
| 38 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
| 39 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; |
| 40 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.same; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 41 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; |
| 42 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; |
| 43 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 44 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 45 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 46 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 47 | import static org.hamcrest.Matchers.is; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 48 | import static org.junit.Assert.assertEquals; |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 49 | import static org.junit.Assert.assertFalse; |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 50 | import static org.junit.Assert.assertNotNull; |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 51 | import static org.junit.Assert.assertNull; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 52 | import static org.junit.Assert.assertThat; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 53 | import static org.junit.Assert.assertTrue; |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame^] | 54 | import static org.mockito.ArgumentMatchers.eq; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 55 | |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 56 | import android.annotation.SuppressLint; |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame^] | 57 | import android.app.WindowConfiguration; |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 58 | import android.content.res.Configuration; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 59 | import android.graphics.Rect; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 60 | import android.os.SystemClock; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 61 | import android.platform.test.annotations.Presubmit; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 62 | import android.util.DisplayMetrics; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 63 | import android.view.DisplayCutout; |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame^] | 64 | import android.view.DisplayInfo; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 65 | import android.view.Gravity; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 66 | import android.view.MotionEvent; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 67 | import android.view.Surface; |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame^] | 68 | import android.view.ViewRootImpl; |
| 69 | import android.view.test.InsetsModeSession; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 70 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 71 | import androidx.test.filters.FlakyTest; |
| 72 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 73 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 74 | import com.android.dx.mockito.inline.extended.ExtendedMockito; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 75 | import com.android.server.wm.utils.WmDisplayCutout; |
| 76 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 77 | import org.junit.Test; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 78 | import org.mockito.ArgumentCaptor; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 79 | |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 80 | import java.util.ArrayList; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 81 | import java.util.Arrays; |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 82 | import java.util.Collections; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 83 | import java.util.LinkedList; |
| 84 | import java.util.List; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Tests for the {@link DisplayContent} class. |
| 88 | * |
| 89 | * Build/Install/Run: |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 90 | * atest FrameworksServicesTests:DisplayContentTests |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 91 | */ |
| 92 | @SmallTest |
| 93 | @Presubmit |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 94 | public class DisplayContentTests extends WindowTestsBase { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 95 | |
| 96 | @Test |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 97 | @FlakyTest(bugId = 77772044) |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 98 | public void testForAllWindows() { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 99 | final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 100 | mDisplayContent, "exiting app"); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 101 | final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken; |
| 102 | exitingAppToken.mIsExiting = true; |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 103 | exitingAppToken.getTask().mStack.mExitingAppTokens.add(exitingAppToken); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 104 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 105 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 106 | mWallpaperWindow, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 107 | exitingAppWindow, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 108 | mChildAppWindowBelow, |
| 109 | mAppWindow, |
| 110 | mChildAppWindowAbove, |
| 111 | mDockedDividerWindow, |
| 112 | mStatusBarWindow, |
| 113 | mNavBarWindow, |
| 114 | mImeWindow, |
| 115 | mImeDialogWindow)); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 119 | public void testForAllWindows_WithAppImeTarget() { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 120 | final WindowState imeAppTarget = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 121 | createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget"); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 122 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 123 | mDisplayContent.mInputMethodTarget = imeAppTarget; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 124 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 125 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 126 | mWallpaperWindow, |
| 127 | mChildAppWindowBelow, |
| 128 | mAppWindow, |
| 129 | mChildAppWindowAbove, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 130 | imeAppTarget, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 131 | mImeWindow, |
| 132 | mImeDialogWindow, |
| 133 | mDockedDividerWindow, |
| 134 | mStatusBarWindow, |
| 135 | mNavBarWindow)); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 136 | } |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 137 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 138 | @Test |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 139 | public void testForAllWindows_WithChildWindowImeTarget() throws Exception { |
| 140 | mDisplayContent.mInputMethodTarget = mChildAppWindowAbove; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 141 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 142 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 143 | mWallpaperWindow, |
| 144 | mChildAppWindowBelow, |
| 145 | mAppWindow, |
| 146 | mChildAppWindowAbove, |
| 147 | mImeWindow, |
| 148 | mImeDialogWindow, |
| 149 | mDockedDividerWindow, |
| 150 | mStatusBarWindow, |
| 151 | mNavBarWindow)); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 152 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 153 | |
| 154 | @Test |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 155 | public void testForAllWindows_WithStatusBarImeTarget() throws Exception { |
| 156 | mDisplayContent.mInputMethodTarget = mStatusBarWindow; |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 157 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 158 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 159 | mWallpaperWindow, |
| 160 | mChildAppWindowBelow, |
| 161 | mAppWindow, |
| 162 | mChildAppWindowAbove, |
| 163 | mDockedDividerWindow, |
| 164 | mStatusBarWindow, |
| 165 | mImeWindow, |
| 166 | mImeDialogWindow, |
| 167 | mNavBarWindow)); |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 171 | public void testForAllWindows_WithInBetweenWindowToken() { |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 172 | // This window is set-up to be z-ordered between some windows that go in the same token like |
| 173 | // the nav bar and status bar. |
| 174 | final WindowState voiceInteractionWindow = createWindow(null, TYPE_VOICE_INTERACTION, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 175 | mDisplayContent, "voiceInteractionWindow"); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 176 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 177 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 178 | mWallpaperWindow, |
| 179 | mChildAppWindowBelow, |
| 180 | mAppWindow, |
| 181 | mChildAppWindowAbove, |
| 182 | mDockedDividerWindow, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 183 | voiceInteractionWindow, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 184 | mStatusBarWindow, |
| 185 | mNavBarWindow, |
| 186 | mImeWindow, |
| 187 | mImeDialogWindow)); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 188 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 189 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 190 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 191 | public void testComputeImeTarget() { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 192 | // Verify that an app window can be an ime target. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 193 | final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin"); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 194 | appWin.setHasSurface(true); |
| 195 | assertTrue(appWin.canBeImeTarget()); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 196 | WindowState imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 197 | assertEquals(appWin, imeTarget); |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 198 | appWin.mHidden = false; |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 199 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 200 | // Verify that an child window can be an ime target. |
| 201 | final WindowState childWin = createWindow(appWin, |
| 202 | TYPE_APPLICATION_ATTACHED_DIALOG, "childWin"); |
| 203 | childWin.setHasSurface(true); |
| 204 | assertTrue(childWin.canBeImeTarget()); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 205 | imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 206 | assertEquals(childWin, imeTarget); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 207 | } |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 208 | |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 209 | /** |
| 210 | * This tests stack movement between displays and proper stack's, task's and app token's display |
| 211 | * container references updates. |
| 212 | */ |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 213 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 214 | public void testMoveStackBetweenDisplays() { |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 215 | // Create a second display. |
| 216 | final DisplayContent dc = createNewDisplay(); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 217 | |
| 218 | // Add stack with activity. |
| 219 | final TaskStack stack = createTaskStackOnDisplay(dc); |
| 220 | assertEquals(dc.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 221 | assertEquals(dc, stack.getParent().getParent()); |
| 222 | assertEquals(dc, stack.getDisplayContent()); |
| 223 | |
| 224 | final Task task = createTaskInStack(stack, 0 /* userId */); |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 225 | final WindowTestUtils.TestAppWindowToken token = WindowTestUtils.createTestAppWindowToken( |
| 226 | dc); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 227 | task.addChild(token, 0); |
| 228 | assertEquals(dc, task.getDisplayContent()); |
| 229 | assertEquals(dc, token.getDisplayContent()); |
| 230 | |
| 231 | // Move stack to first display. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 232 | mDisplayContent.moveStackToDisplay(stack, true /* onTop */); |
| 233 | assertEquals(mDisplayContent.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 234 | assertEquals(mDisplayContent, stack.getParent().getParent()); |
| 235 | assertEquals(mDisplayContent, stack.getDisplayContent()); |
| 236 | assertEquals(mDisplayContent, task.getDisplayContent()); |
| 237 | assertEquals(mDisplayContent, token.getDisplayContent()); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 238 | } |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 239 | |
| 240 | /** |
| 241 | * This tests override configuration updates for display content. |
| 242 | */ |
| 243 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 244 | public void testDisplayOverrideConfigUpdate() { |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 245 | final Configuration currentOverrideConfig = |
| 246 | mDisplayContent.getRequestedOverrideConfiguration(); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 247 | |
| 248 | // Create new, slightly changed override configuration and apply it to the display. |
| 249 | final Configuration newOverrideConfig = new Configuration(currentOverrideConfig); |
| 250 | newOverrideConfig.densityDpi += 120; |
| 251 | newOverrideConfig.fontScale += 0.3; |
| 252 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 253 | mWm.setNewDisplayOverrideConfiguration(newOverrideConfig, mDisplayContent); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 254 | |
| 255 | // Check that override config is applied. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 256 | assertEquals(newOverrideConfig, mDisplayContent.getRequestedOverrideConfiguration()); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /** |
| 260 | * This tests global configuration updates when default display config is updated. |
| 261 | */ |
| 262 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 263 | public void testDefaultDisplayOverrideConfigUpdate() { |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 264 | DisplayContent defaultDisplay = mWm.mRoot.getDisplayContent(DEFAULT_DISPLAY); |
| 265 | final Configuration currentConfig = defaultDisplay.getConfiguration(); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 266 | |
| 267 | // Create new, slightly changed override configuration and apply it to the display. |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 268 | final Configuration newOverrideConfig = new Configuration(currentConfig); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 269 | newOverrideConfig.densityDpi += 120; |
| 270 | newOverrideConfig.fontScale += 0.3; |
| 271 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 272 | mWm.setNewDisplayOverrideConfiguration(newOverrideConfig, defaultDisplay); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 273 | |
| 274 | // 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] | 275 | Configuration globalConfig = mWm.mRoot.getConfiguration(); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 276 | assertEquals(newOverrideConfig.densityDpi, globalConfig.densityDpi); |
| 277 | assertEquals(newOverrideConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 278 | |
| 279 | // Return back to original values. |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 280 | mWm.setNewDisplayOverrideConfiguration(currentConfig, defaultDisplay); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 281 | globalConfig = mWm.mRoot.getConfiguration(); |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 282 | assertEquals(currentConfig.densityDpi, globalConfig.densityDpi); |
| 283 | assertEquals(currentConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 284 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 285 | |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 286 | /** |
| 287 | * Tests tapping on a stack in different display results in window gaining focus. |
| 288 | */ |
| 289 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 290 | public void testInputEventBringsCorrectDisplayInFocus() { |
| 291 | DisplayContent dc0 = mWm.getDefaultDisplayContentLocked(); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 292 | // Create a second display |
| 293 | final DisplayContent dc1 = createNewDisplay(); |
| 294 | |
| 295 | // Add stack with activity. |
| 296 | final TaskStack stack0 = createTaskStackOnDisplay(dc0); |
| 297 | final Task task0 = createTaskInStack(stack0, 0 /* userId */); |
| 298 | final WindowTestUtils.TestAppWindowToken token = |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 299 | WindowTestUtils.createTestAppWindowToken(dc0); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 300 | task0.addChild(token, 0); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 301 | dc0.configureDisplayPolicy(); |
| 302 | assertNotNull(dc0.mTapDetector); |
| 303 | |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 304 | final TaskStack stack1 = createTaskStackOnDisplay(dc1); |
| 305 | final Task task1 = createTaskInStack(stack1, 0 /* userId */); |
| 306 | final WindowTestUtils.TestAppWindowToken token1 = |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 307 | WindowTestUtils.createTestAppWindowToken(dc0); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 308 | task1.addChild(token1, 0); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 309 | dc1.configureDisplayPolicy(); |
| 310 | assertNotNull(dc1.mTapDetector); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 311 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 312 | // tap on primary display. |
| 313 | tapOnDisplay(dc0); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 314 | // Check focus is on primary display. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 315 | assertEquals(mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus, |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 316 | dc0.findFocusedWindow()); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 317 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 318 | // Tap on secondary display. |
| 319 | tapOnDisplay(dc1); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 320 | // Check focus is on secondary. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 321 | assertEquals(mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus, |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 322 | dc1.findFocusedWindow()); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 323 | } |
| 324 | |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 325 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 326 | public void testFocusedWindowMultipleDisplays() { |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 327 | doTestFocusedWindowMultipleDisplays(false /* perDisplayFocusEnabled */, Q); |
| 328 | } |
| 329 | |
| 330 | @Test |
| 331 | public void testFocusedWindowMultipleDisplaysPerDisplayFocusEnabled() { |
| 332 | doTestFocusedWindowMultipleDisplays(true /* perDisplayFocusEnabled */, Q); |
| 333 | } |
| 334 | |
| 335 | @Test |
| 336 | public void testFocusedWindowMultipleDisplaysPerDisplayFocusEnabledLegacyApp() { |
| 337 | doTestFocusedWindowMultipleDisplays(true /* perDisplayFocusEnabled */, P); |
| 338 | } |
| 339 | |
| 340 | private void doTestFocusedWindowMultipleDisplays(boolean perDisplayFocusEnabled, |
| 341 | int targetSdk) { |
| 342 | mWm.mPerDisplayFocusEnabled = perDisplayFocusEnabled; |
| 343 | |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame] | 344 | // Create a focusable window and check that focus is calculated correctly |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 345 | final WindowState window1 = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 346 | createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1"); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 347 | window1.mAppToken.mTargetSdk = targetSdk; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 348 | updateFocusedWindow(); |
| 349 | assertTrue(window1.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 350 | assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 351 | |
| 352 | // Check that a new display doesn't affect focus |
| 353 | final DisplayContent dc = createNewDisplay(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 354 | updateFocusedWindow(); |
| 355 | assertTrue(window1.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 356 | assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 357 | |
| 358 | // Add a window to the second display, and it should be focused |
| 359 | final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2"); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 360 | window2.mAppToken.mTargetSdk = targetSdk; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 361 | updateFocusedWindow(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 362 | assertTrue(window2.isFocused()); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 363 | assertEquals(perDisplayFocusEnabled && targetSdk >= Q, window1.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 364 | assertEquals(window2, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 365 | |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 366 | // Move the first window to top including parents, and make sure focus is updated |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 367 | window1.getParent().positionChildAt(POSITION_TOP, window1, true); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 368 | updateFocusedWindow(); |
| 369 | assertTrue(window1.isFocused()); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 370 | assertEquals(perDisplayFocusEnabled && targetSdk >= Q, window2.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 371 | assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
Adrian Roos | 4163d62 | 2018-05-22 16:56:35 +0200 | [diff] [blame] | 372 | } |
| 373 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 374 | /** |
| 375 | * This tests setting the maximum ui width on a display. |
| 376 | */ |
| 377 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 378 | public void testMaxUiWidth() { |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 379 | // Prevent base display metrics for test from being updated to the value of real display. |
| 380 | final DisplayContent displayContent = createDisplayNoUpdateDisplayInfo(); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 381 | final int baseWidth = 1440; |
| 382 | final int baseHeight = 2560; |
| 383 | final int baseDensity = 300; |
| 384 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 385 | displayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 386 | |
| 387 | final int maxWidth = 300; |
| 388 | final int resultingHeight = (maxWidth * baseHeight) / baseWidth; |
| 389 | final int resultingDensity = (maxWidth * baseDensity) / baseWidth; |
| 390 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 391 | displayContent.setMaxUiWidth(maxWidth); |
| 392 | verifySizes(displayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 393 | |
| 394 | // Assert setting values again does not change; |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 395 | displayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
| 396 | verifySizes(displayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 397 | |
| 398 | final int smallerWidth = 200; |
| 399 | final int smallerHeight = 400; |
| 400 | final int smallerDensity = 100; |
| 401 | |
| 402 | // Specify smaller dimension, verify that it is honored |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 403 | displayContent.updateBaseDisplayMetrics(smallerWidth, smallerHeight, smallerDensity); |
| 404 | verifySizes(displayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 405 | |
| 406 | // 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] | 407 | displayContent.setMaxUiWidth(maxWidth); |
| 408 | verifySizes(displayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 411 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 412 | public void testDisplayCutout_rot0() { |
| 413 | synchronized (mWm.getWindowManagerLock()) { |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 414 | final DisplayContent dc = createNewDisplay(); |
| 415 | dc.mInitialDisplayWidth = 200; |
| 416 | dc.mInitialDisplayHeight = 400; |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 417 | Rect r = new Rect(80, 0, 120, 10); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 418 | final DisplayCutout cutout = new WmDisplayCutout( |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 419 | 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] | 420 | .computeSafeInsets(200, 400).getDisplayCutout(); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 421 | |
| 422 | dc.mInitialDisplayCutout = cutout; |
| 423 | dc.setRotation(Surface.ROTATION_0); |
| 424 | dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo. |
| 425 | |
| 426 | assertEquals(cutout, dc.getDisplayInfo().displayCutout); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 431 | public void testDisplayCutout_rot90() { |
| 432 | synchronized (mWm.getWindowManagerLock()) { |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 433 | // Prevent mInitialDisplayCutout from being updated from real display (e.g. null |
| 434 | // if the device has no cutout). |
| 435 | final DisplayContent dc = createDisplayNoUpdateDisplayInfo(); |
| 436 | // Rotation may use real display info to compute bound, so here also uses the |
| 437 | // same width and height. |
| 438 | final int displayWidth = dc.mInitialDisplayWidth; |
| 439 | final int displayHeight = dc.mInitialDisplayHeight; |
| 440 | final int cutoutWidth = 40; |
| 441 | final int cutoutHeight = 10; |
| 442 | final int left = (displayWidth - cutoutWidth) / 2; |
| 443 | final int top = 0; |
| 444 | final int right = (displayWidth + cutoutWidth) / 2; |
| 445 | final int bottom = cutoutHeight; |
| 446 | |
| 447 | final Rect r1 = new Rect(left, top, right, bottom); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 448 | final DisplayCutout cutout = new WmDisplayCutout( |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 449 | fromBoundingRect(r1.left, r1.top, r1.right, r1.bottom, BOUNDS_POSITION_TOP), |
| 450 | null) |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 451 | .computeSafeInsets(displayWidth, displayHeight).getDisplayCutout(); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 452 | |
| 453 | dc.mInitialDisplayCutout = cutout; |
| 454 | dc.setRotation(Surface.ROTATION_90); |
| 455 | dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo. |
| 456 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 457 | // ----o---------- ------------- |
| 458 | // | | | | | |
| 459 | // | ------o | o--- |
| 460 | // | | | | |
| 461 | // | | -> | | |
| 462 | // | | ---o |
| 463 | // | | | |
| 464 | // | | ------------- |
| 465 | final Rect r = new Rect(top, left, bottom, right); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 466 | assertEquals(new WmDisplayCutout( |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 467 | 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] | 468 | .computeSafeInsets(displayHeight, displayWidth) |
| 469 | .getDisplayCutout(), dc.getDisplayInfo().displayCutout); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
| 473 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 474 | public void testLayoutSeq_assignedDuringLayout() { |
| 475 | synchronized (mWm.getWindowManagerLock()) { |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 476 | |
| 477 | final DisplayContent dc = createNewDisplay(); |
| 478 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
| 479 | |
| 480 | dc.setLayoutNeeded(); |
| 481 | dc.performLayout(true /* initial */, false /* updateImeWindows */); |
| 482 | |
| 483 | assertThat(win.mLayoutSeq, is(dc.mLayoutSeq)); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | @Test |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 488 | @SuppressLint("InlinedApi") |
| 489 | public void testOrientationDefinedByKeyguard() { |
| 490 | final DisplayContent dc = createNewDisplay(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 491 | |
| 492 | // When display content is created its configuration is not yet initialized, which could |
| 493 | // cause unnecessary configuration propagation, so initialize it here. |
| 494 | final Configuration config = new Configuration(); |
| 495 | dc.computeScreenConfiguration(config); |
| 496 | dc.onRequestedOverrideConfigurationChanged(config); |
| 497 | |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 498 | // Create a window that requests landscape orientation. It will define device orientation |
| 499 | // by default. |
| 500 | final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
| 501 | window.mAppToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 502 | |
| 503 | final WindowState keyguard = createWindow(null, TYPE_STATUS_BAR, dc, "keyguard"); |
| 504 | keyguard.mHasSurface = true; |
| 505 | keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 506 | |
| 507 | assertEquals("Screen orientation must be defined by the app window by default", |
| 508 | SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation()); |
| 509 | |
| 510 | keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_PORTRAIT; |
| 511 | assertEquals("Visible keyguard must influence device orientation", |
| 512 | SCREEN_ORIENTATION_PORTRAIT, dc.getOrientation()); |
| 513 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 514 | mWm.setKeyguardGoingAway(true); |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 515 | assertEquals("Keyguard that is going away must not influence device orientation", |
| 516 | SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation()); |
| 517 | } |
| 518 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 519 | @Test |
| 520 | public void testDisableDisplayInfoOverrideFromWindowManager() { |
| 521 | final DisplayContent dc = createNewDisplay(); |
| 522 | |
| 523 | assertTrue(dc.mShouldOverrideDisplayConfiguration); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 524 | mWm.dontOverrideDisplayInfo(dc.getDisplayId()); |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 525 | |
| 526 | assertFalse(dc.mShouldOverrideDisplayConfiguration); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 527 | verify(mWm.mDisplayManagerInternal, times(1)) |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 528 | .setDisplayInfoOverrideFromWindowManager(dc.getDisplayId(), null); |
| 529 | } |
| 530 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 531 | @Test |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 532 | public void testClearLastFocusWhenReparentingFocusedWindow() { |
| 533 | final DisplayContent defaultDisplay = mWm.getDefaultDisplayContentLocked(); |
| 534 | final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, |
| 535 | defaultDisplay, "window"); |
| 536 | defaultDisplay.mLastFocus = window; |
| 537 | mDisplayContent.mCurrentFocus = window; |
| 538 | mDisplayContent.reParentWindowToken(window.mToken); |
| 539 | |
| 540 | assertNull(defaultDisplay.mLastFocus); |
| 541 | } |
| 542 | |
| 543 | @Test |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 544 | public void testGetPreferredOptionsPanelGravityFromDifferentDisplays() { |
| 545 | final DisplayContent portraitDisplay = createNewDisplay(); |
| 546 | portraitDisplay.mInitialDisplayHeight = 2000; |
| 547 | portraitDisplay.mInitialDisplayWidth = 1000; |
| 548 | |
| 549 | portraitDisplay.setRotation(Surface.ROTATION_0); |
| 550 | assertFalse(isOptionsPanelAtRight(portraitDisplay.getDisplayId())); |
| 551 | portraitDisplay.setRotation(Surface.ROTATION_90); |
| 552 | assertTrue(isOptionsPanelAtRight(portraitDisplay.getDisplayId())); |
| 553 | |
| 554 | final DisplayContent landscapeDisplay = createNewDisplay(); |
| 555 | landscapeDisplay.mInitialDisplayHeight = 1000; |
| 556 | landscapeDisplay.mInitialDisplayWidth = 2000; |
| 557 | |
| 558 | landscapeDisplay.setRotation(Surface.ROTATION_0); |
| 559 | assertTrue(isOptionsPanelAtRight(landscapeDisplay.getDisplayId())); |
| 560 | landscapeDisplay.setRotation(Surface.ROTATION_90); |
| 561 | assertFalse(isOptionsPanelAtRight(landscapeDisplay.getDisplayId())); |
| 562 | } |
| 563 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 564 | @Test |
| 565 | public void testInputMethodTargetUpdateWhenSwitchingOnDisplays() { |
| 566 | final DisplayContent newDisplay = createNewDisplay(); |
| 567 | |
| 568 | final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin"); |
| 569 | final WindowState appWin1 = createWindow(null, TYPE_APPLICATION, newDisplay, "appWin1"); |
| 570 | appWin.setHasSurface(true); |
| 571 | appWin1.setHasSurface(true); |
| 572 | |
| 573 | // Set current input method window on default display, make sure the input method target |
| 574 | // is appWin & null on the other display. |
| 575 | mDisplayContent.setInputMethodWindowLocked(mImeWindow); |
| 576 | newDisplay.setInputMethodWindowLocked(null); |
| 577 | assertTrue("appWin should be IME target window", |
| 578 | appWin.equals(mDisplayContent.mInputMethodTarget)); |
| 579 | assertNull("newDisplay Ime target: ", newDisplay.mInputMethodTarget); |
| 580 | |
| 581 | // Switch input method window on new display & make sure the input method target also |
| 582 | // switched as expected. |
| 583 | newDisplay.setInputMethodWindowLocked(mImeWindow); |
| 584 | mDisplayContent.setInputMethodWindowLocked(null); |
| 585 | assertTrue("appWin1 should be IME target window", |
| 586 | appWin1.equals(newDisplay.mInputMethodTarget)); |
| 587 | assertNull("default display Ime target: ", mDisplayContent.mInputMethodTarget); |
| 588 | } |
| 589 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 590 | @Test |
| 591 | public void testOnDescendantOrientationRequestChanged() { |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 592 | final DisplayContent dc = createNewDisplay(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 593 | mWm.mAtmService.mRootActivityContainer = mock(RootActivityContainer.class); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 594 | final int newOrientation = dc.getLastOrientation() == SCREEN_ORIENTATION_LANDSCAPE |
| 595 | ? SCREEN_ORIENTATION_PORTRAIT |
| 596 | : SCREEN_ORIENTATION_LANDSCAPE; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 597 | |
| 598 | final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
| 599 | window.getTask().mTaskRecord = mock(TaskRecord.class, ExtendedMockito.RETURNS_DEEP_STUBS); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 600 | window.mAppToken.setOrientation(newOrientation); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 601 | |
| 602 | ActivityRecord activityRecord = mock(ActivityRecord.class); |
| 603 | |
| 604 | assertTrue("Display should rotate to handle orientation request by default.", |
| 605 | dc.onDescendantOrientationChanged(window.mToken.token, activityRecord)); |
| 606 | |
| 607 | final ArgumentCaptor<Configuration> captor = ArgumentCaptor.forClass(Configuration.class); |
| 608 | verify(mWm.mAtmService).updateDisplayOverrideConfigurationLocked(captor.capture(), |
| 609 | same(activityRecord), anyBoolean(), eq(dc.getDisplayId())); |
| 610 | final Configuration newDisplayConfig = captor.getValue(); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 611 | assertEquals(Configuration.ORIENTATION_PORTRAIT, newDisplayConfig.orientation); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | @Test |
| 615 | public void testOnDescendantOrientationRequestChanged_FrozenToUserRotation() { |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 616 | final DisplayContent dc = createNewDisplay(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 617 | dc.getDisplayRotation().setFixedToUserRotation(true); |
| 618 | mWm.mAtmService.mRootActivityContainer = mock(RootActivityContainer.class); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 619 | final int newOrientation = dc.getLastOrientation() == SCREEN_ORIENTATION_LANDSCAPE |
| 620 | ? SCREEN_ORIENTATION_PORTRAIT |
| 621 | : SCREEN_ORIENTATION_LANDSCAPE; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 622 | |
| 623 | final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
| 624 | window.getTask().mTaskRecord = mock(TaskRecord.class, ExtendedMockito.RETURNS_DEEP_STUBS); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 625 | window.mAppToken.setOrientation(newOrientation); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 626 | |
| 627 | ActivityRecord activityRecord = mock(ActivityRecord.class); |
| 628 | |
| 629 | assertFalse("Display shouldn't rotate to handle orientation request if fixed to" |
| 630 | + " user rotation.", |
| 631 | dc.onDescendantOrientationChanged(window.mToken.token, activityRecord)); |
| 632 | verify(mWm.mAtmService, never()).updateDisplayOverrideConfigurationLocked(any(), |
| 633 | eq(activityRecord), anyBoolean(), eq(dc.getDisplayId())); |
| 634 | } |
| 635 | |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame^] | 636 | @Test |
| 637 | public void testComputeImeParent_app() throws Exception { |
| 638 | try (final InsetsModeSession session = |
| 639 | new InsetsModeSession(ViewRootImpl.NEW_INSETS_MODE_IME)) { |
| 640 | final DisplayContent dc = createNewDisplay(); |
| 641 | dc.mInputMethodTarget = createWindow(null, TYPE_BASE_APPLICATION, "app"); |
| 642 | assertEquals(dc.mInputMethodTarget.mAppToken.getSurfaceControl(), |
| 643 | dc.computeImeParent()); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | @Test |
| 648 | public void testComputeImeParent_app_notFullscreen() throws Exception { |
| 649 | try (final InsetsModeSession session = |
| 650 | new InsetsModeSession(ViewRootImpl.NEW_INSETS_MODE_IME)) { |
| 651 | final DisplayContent dc = createNewDisplay(); |
| 652 | dc.mInputMethodTarget = createWindow(null, TYPE_STATUS_BAR, "app"); |
| 653 | dc.mInputMethodTarget.setWindowingMode( |
| 654 | WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 655 | assertEquals(dc.getWindowingLayer(), dc.computeImeParent()); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | @Test |
| 660 | public void testComputeImeParent_noApp() throws Exception { |
| 661 | try (final InsetsModeSession session = |
| 662 | new InsetsModeSession(ViewRootImpl.NEW_INSETS_MODE_IME)) { |
| 663 | final DisplayContent dc = createNewDisplay(); |
| 664 | dc.mInputMethodTarget = createWindow(null, TYPE_STATUS_BAR, "statusBar"); |
| 665 | assertEquals(dc.getWindowingLayer(), dc.computeImeParent()); |
| 666 | } |
| 667 | } |
| 668 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 669 | private boolean isOptionsPanelAtRight(int displayId) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 670 | return (mWm.getPreferredOptionsPanelGravity(displayId) & Gravity.RIGHT) == Gravity.RIGHT; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 671 | } |
| 672 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 673 | private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth, |
| 674 | int expectedBaseHeight, int expectedBaseDensity) { |
| 675 | assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth); |
| 676 | assertEquals(displayContent.mBaseDisplayHeight, expectedBaseHeight); |
| 677 | assertEquals(displayContent.mBaseDisplayDensity, expectedBaseDensity); |
| 678 | } |
| 679 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 680 | private void updateFocusedWindow() { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 681 | synchronized (mWm.mGlobalLock) { |
| 682 | mWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 686 | /** |
| 687 | * Create DisplayContent that does not update display base/initial values from device to keep |
| 688 | * the values set by test. |
| 689 | */ |
| 690 | private DisplayContent createDisplayNoUpdateDisplayInfo() { |
| 691 | final DisplayContent displayContent = spy(createNewDisplay()); |
| 692 | doNothing().when(displayContent).updateDisplayInfo(); |
| 693 | return displayContent; |
| 694 | } |
| 695 | |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 696 | private void assertForAllWindowsOrder(List<WindowState> expectedWindowsBottomToTop) { |
| 697 | final LinkedList<WindowState> actualWindows = new LinkedList<>(); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 698 | |
| 699 | // Test forward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 700 | mDisplayContent.forAllWindows(actualWindows::addLast, false /* traverseTopToBottom */); |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 701 | assertThat("bottomToTop", actualWindows, is(expectedWindowsBottomToTop)); |
| 702 | |
| 703 | actualWindows.clear(); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 704 | |
| 705 | // Test backward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 706 | mDisplayContent.forAllWindows(actualWindows::addLast, true /* traverseTopToBottom */); |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 707 | assertThat("topToBottom", actualWindows, is(reverseList(expectedWindowsBottomToTop))); |
| 708 | } |
| 709 | |
| 710 | private static List<WindowState> reverseList(List<WindowState> list) { |
| 711 | final ArrayList<WindowState> result = new ArrayList<>(list); |
| 712 | Collections.reverse(result); |
| 713 | return result; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 714 | } |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 715 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 716 | private void tapOnDisplay(final DisplayContent dc) { |
| 717 | final DisplayMetrics dm = dc.getDisplayMetrics(); |
| 718 | final float x = dm.widthPixels / 2; |
| 719 | final float y = dm.heightPixels / 2; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 720 | final long downTime = SystemClock.uptimeMillis(); |
| 721 | final long eventTime = SystemClock.uptimeMillis() + 100; |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 722 | // sending ACTION_DOWN |
| 723 | final MotionEvent downEvent = MotionEvent.obtain( |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 724 | downTime, |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 725 | downTime, |
| 726 | MotionEvent.ACTION_DOWN, |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 727 | x, |
| 728 | y, |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 729 | 0 /*metaState*/); |
| 730 | downEvent.setDisplayId(dc.getDisplayId()); |
| 731 | dc.mTapDetector.onPointerEvent(downEvent); |
| 732 | |
| 733 | // sending ACTION_UP |
| 734 | final MotionEvent upEvent = MotionEvent.obtain( |
| 735 | downTime, |
| 736 | eventTime, |
| 737 | MotionEvent.ACTION_UP, |
| 738 | x, |
| 739 | y, |
| 740 | 0 /*metaState*/); |
| 741 | upEvent.setDisplayId(dc.getDisplayId()); |
| 742 | dc.mTapDetector.onPointerEvent(upEvent); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 743 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 744 | } |