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