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