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 | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 22 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER; |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 23 | import static android.os.Build.VERSION_CODES.P; |
| 24 | import static android.os.Build.VERSION_CODES.Q; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 25 | import static android.view.Display.DEFAULT_DISPLAY; |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 26 | import static android.view.DisplayCutout.BOUNDS_POSITION_LEFT; |
| 27 | import static android.view.DisplayCutout.BOUNDS_POSITION_TOP; |
Adrian Roos | 2426421 | 2018-02-19 16:26:15 +0100 | [diff] [blame] | 28 | import static android.view.DisplayCutout.fromBoundingRect; |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 29 | import static android.view.View.SYSTEM_UI_FLAG_FULLSCREEN; |
| 30 | import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 31 | import static android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 32 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; |
| 33 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 34 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
| 35 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 36 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
| 37 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 38 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 39 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 40 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 41 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 42 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 43 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 44 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; |
| 45 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 46 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
Riddle Hsu | 6d6f67c | 2019-03-14 16:54:26 +0800 | [diff] [blame] | 47 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 48 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
| 49 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 50 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 51 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.same; |
Riddle Hsu | 6d6f67c | 2019-03-14 16:54:26 +0800 | [diff] [blame] | 52 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 53 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; |
| 54 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 55 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 56 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 57 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 58 | import static org.hamcrest.Matchers.is; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 59 | import static org.junit.Assert.assertEquals; |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 60 | import static org.junit.Assert.assertFalse; |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 61 | import static org.junit.Assert.assertNotNull; |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 62 | import static org.junit.Assert.assertNull; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 63 | import static org.junit.Assert.assertThat; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 64 | import static org.junit.Assert.assertTrue; |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 65 | import static org.mockito.ArgumentMatchers.eq; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 66 | |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 67 | import android.annotation.SuppressLint; |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 68 | import android.app.WindowConfiguration; |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 69 | import android.content.res.Configuration; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 70 | import android.graphics.Rect; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 71 | import android.graphics.Region; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 72 | import android.metrics.LogMaker; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 73 | import android.os.SystemClock; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 74 | import android.platform.test.annotations.Presubmit; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 75 | import android.util.DisplayMetrics; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 76 | import android.view.DisplayCutout; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 77 | import android.view.Gravity; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 78 | import android.view.ISystemGestureExclusionListener; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 79 | import android.view.MotionEvent; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 80 | import android.view.Surface; |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 81 | import android.view.ViewRootImpl; |
| 82 | import android.view.test.InsetsModeSession; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 83 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 84 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 85 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 86 | import com.android.internal.logging.MetricsLogger; |
| 87 | import com.android.internal.logging.nano.MetricsProto; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 88 | import com.android.server.wm.utils.WmDisplayCutout; |
| 89 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 90 | import org.junit.Test; |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 91 | import org.junit.runner.RunWith; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 92 | import org.mockito.ArgumentCaptor; |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 93 | import org.mockito.Mockito; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 94 | |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 95 | import java.util.ArrayList; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 96 | import java.util.Arrays; |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 97 | import java.util.Collections; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 98 | import java.util.LinkedList; |
| 99 | import java.util.List; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * Tests for the {@link DisplayContent} class. |
| 103 | * |
| 104 | * Build/Install/Run: |
Yunfan Chen | 6dd9a62 | 2019-02-18 15:12:33 +0900 | [diff] [blame] | 105 | * atest WmTests:DisplayContentTests |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 106 | */ |
| 107 | @SmallTest |
| 108 | @Presubmit |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 109 | @RunWith(WindowTestRunner.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 110 | public class DisplayContentTests extends WindowTestsBase { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 111 | |
| 112 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 113 | public void testForAllWindows() { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 114 | final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 115 | mDisplayContent, "exiting app"); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 116 | final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken; |
Yunfan Chen | 6dd9a62 | 2019-02-18 15:12:33 +0900 | [diff] [blame] | 117 | // Wait until everything in animation handler get executed to prevent the exiting window |
| 118 | // from being removed during WindowSurfacePlacer Traversal. |
| 119 | waitUntilHandlersIdle(); |
| 120 | |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 121 | exitingAppToken.mIsExiting = true; |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 122 | exitingAppToken.getTask().mStack.mExitingAppTokens.add(exitingAppToken); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 123 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 124 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 125 | mWallpaperWindow, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 126 | exitingAppWindow, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 127 | mChildAppWindowBelow, |
| 128 | mAppWindow, |
| 129 | mChildAppWindowAbove, |
| 130 | mDockedDividerWindow, |
| 131 | mStatusBarWindow, |
| 132 | mNavBarWindow, |
| 133 | mImeWindow, |
| 134 | mImeDialogWindow)); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 138 | public void testForAllWindows_WithAppImeTarget() { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 139 | final WindowState imeAppTarget = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 140 | createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget"); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 141 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 142 | mDisplayContent.mInputMethodTarget = imeAppTarget; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 143 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 144 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 145 | mWallpaperWindow, |
| 146 | mChildAppWindowBelow, |
| 147 | mAppWindow, |
| 148 | mChildAppWindowAbove, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 149 | imeAppTarget, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 150 | mImeWindow, |
| 151 | mImeDialogWindow, |
| 152 | mDockedDividerWindow, |
| 153 | mStatusBarWindow, |
| 154 | mNavBarWindow)); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 155 | } |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 156 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 157 | @Test |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 158 | public void testForAllWindows_WithChildWindowImeTarget() throws Exception { |
| 159 | mDisplayContent.mInputMethodTarget = mChildAppWindowAbove; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -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 | mImeWindow, |
| 167 | mImeDialogWindow, |
| 168 | mDockedDividerWindow, |
| 169 | mStatusBarWindow, |
| 170 | mNavBarWindow)); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 171 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 172 | |
| 173 | @Test |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 174 | public void testForAllWindows_WithStatusBarImeTarget() throws Exception { |
| 175 | mDisplayContent.mInputMethodTarget = mStatusBarWindow; |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 176 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 177 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 178 | mWallpaperWindow, |
| 179 | mChildAppWindowBelow, |
| 180 | mAppWindow, |
| 181 | mChildAppWindowAbove, |
| 182 | mDockedDividerWindow, |
| 183 | mStatusBarWindow, |
| 184 | mImeWindow, |
| 185 | mImeDialogWindow, |
| 186 | mNavBarWindow)); |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 190 | public void testForAllWindows_WithInBetweenWindowToken() { |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 191 | // This window is set-up to be z-ordered between some windows that go in the same token like |
| 192 | // the nav bar and status bar. |
| 193 | final WindowState voiceInteractionWindow = createWindow(null, TYPE_VOICE_INTERACTION, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 194 | mDisplayContent, "voiceInteractionWindow"); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 195 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 196 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 197 | mWallpaperWindow, |
| 198 | mChildAppWindowBelow, |
| 199 | mAppWindow, |
| 200 | mChildAppWindowAbove, |
| 201 | mDockedDividerWindow, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 202 | voiceInteractionWindow, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 203 | mStatusBarWindow, |
| 204 | mNavBarWindow, |
| 205 | mImeWindow, |
| 206 | mImeDialogWindow)); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 207 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 208 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 209 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 210 | public void testComputeImeTarget() { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 211 | // Verify that an app window can be an ime target. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 212 | final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin"); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 213 | appWin.setHasSurface(true); |
| 214 | assertTrue(appWin.canBeImeTarget()); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 215 | WindowState imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 216 | assertEquals(appWin, imeTarget); |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 217 | appWin.mHidden = false; |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 218 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 219 | // Verify that an child window can be an ime target. |
| 220 | final WindowState childWin = createWindow(appWin, |
| 221 | TYPE_APPLICATION_ATTACHED_DIALOG, "childWin"); |
| 222 | childWin.setHasSurface(true); |
| 223 | assertTrue(childWin.canBeImeTarget()); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 224 | imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 225 | assertEquals(childWin, imeTarget); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 226 | } |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 227 | |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 228 | /** |
| 229 | * This tests stack movement between displays and proper stack's, task's and app token's display |
| 230 | * container references updates. |
| 231 | */ |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 232 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 233 | public void testMoveStackBetweenDisplays() { |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 234 | // Create a second display. |
| 235 | final DisplayContent dc = createNewDisplay(); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 236 | |
| 237 | // Add stack with activity. |
| 238 | final TaskStack stack = createTaskStackOnDisplay(dc); |
| 239 | assertEquals(dc.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 240 | assertEquals(dc, stack.getParent().getParent()); |
| 241 | assertEquals(dc, stack.getDisplayContent()); |
| 242 | |
| 243 | final Task task = createTaskInStack(stack, 0 /* userId */); |
Wale Ogunwale | 3198da4 | 2019-10-10 14:45:03 +0200 | [diff] [blame^] | 244 | final ActivityRecord token = WindowTestUtils.createTestAppWindowToken(dc); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 245 | task.addChild(token, 0); |
| 246 | assertEquals(dc, task.getDisplayContent()); |
| 247 | assertEquals(dc, token.getDisplayContent()); |
| 248 | |
| 249 | // Move stack to first display. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 250 | mDisplayContent.moveStackToDisplay(stack, true /* onTop */); |
| 251 | assertEquals(mDisplayContent.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 252 | assertEquals(mDisplayContent, stack.getParent().getParent()); |
| 253 | assertEquals(mDisplayContent, stack.getDisplayContent()); |
| 254 | assertEquals(mDisplayContent, task.getDisplayContent()); |
| 255 | assertEquals(mDisplayContent, token.getDisplayContent()); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 256 | } |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 257 | |
| 258 | /** |
| 259 | * This tests override configuration updates for display content. |
| 260 | */ |
| 261 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 262 | public void testDisplayOverrideConfigUpdate() { |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 263 | final Configuration currentOverrideConfig = |
| 264 | mDisplayContent.getRequestedOverrideConfiguration(); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 265 | |
| 266 | // Create new, slightly changed override configuration and apply it to the display. |
| 267 | final Configuration newOverrideConfig = new Configuration(currentOverrideConfig); |
| 268 | newOverrideConfig.densityDpi += 120; |
| 269 | newOverrideConfig.fontScale += 0.3; |
| 270 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 271 | mWm.setNewDisplayOverrideConfiguration(newOverrideConfig, mDisplayContent); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 272 | |
| 273 | // Check that override config is applied. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 274 | assertEquals(newOverrideConfig, mDisplayContent.getRequestedOverrideConfiguration()); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /** |
| 278 | * This tests global configuration updates when default display config is updated. |
| 279 | */ |
| 280 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 281 | public void testDefaultDisplayOverrideConfigUpdate() { |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 282 | DisplayContent defaultDisplay = mWm.mRoot.getDisplayContent(DEFAULT_DISPLAY); |
| 283 | final Configuration currentConfig = defaultDisplay.getConfiguration(); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 284 | |
| 285 | // Create new, slightly changed override configuration and apply it to the display. |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 286 | final Configuration newOverrideConfig = new Configuration(currentConfig); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 287 | newOverrideConfig.densityDpi += 120; |
| 288 | newOverrideConfig.fontScale += 0.3; |
| 289 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 290 | mWm.setNewDisplayOverrideConfiguration(newOverrideConfig, defaultDisplay); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 291 | |
| 292 | // 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] | 293 | Configuration globalConfig = mWm.mRoot.getConfiguration(); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 294 | assertEquals(newOverrideConfig.densityDpi, globalConfig.densityDpi); |
| 295 | assertEquals(newOverrideConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 296 | |
| 297 | // Return back to original values. |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 298 | mWm.setNewDisplayOverrideConfiguration(currentConfig, defaultDisplay); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 299 | globalConfig = mWm.mRoot.getConfiguration(); |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 300 | assertEquals(currentConfig.densityDpi, globalConfig.densityDpi); |
| 301 | assertEquals(currentConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 302 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 303 | |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 304 | /** |
| 305 | * Tests tapping on a stack in different display results in window gaining focus. |
| 306 | */ |
| 307 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 308 | public void testInputEventBringsCorrectDisplayInFocus() { |
| 309 | DisplayContent dc0 = mWm.getDefaultDisplayContentLocked(); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 310 | // Create a second display |
| 311 | final DisplayContent dc1 = createNewDisplay(); |
| 312 | |
| 313 | // Add stack with activity. |
| 314 | final TaskStack stack0 = createTaskStackOnDisplay(dc0); |
| 315 | final Task task0 = createTaskInStack(stack0, 0 /* userId */); |
Wale Ogunwale | 3198da4 | 2019-10-10 14:45:03 +0200 | [diff] [blame^] | 316 | final ActivityRecord token = |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 317 | WindowTestUtils.createTestAppWindowToken(dc0); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 318 | task0.addChild(token, 0); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 319 | dc0.configureDisplayPolicy(); |
| 320 | assertNotNull(dc0.mTapDetector); |
| 321 | |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 322 | final TaskStack stack1 = createTaskStackOnDisplay(dc1); |
| 323 | final Task task1 = createTaskInStack(stack1, 0 /* userId */); |
Wale Ogunwale | 3198da4 | 2019-10-10 14:45:03 +0200 | [diff] [blame^] | 324 | final ActivityRecord token1 = |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 325 | WindowTestUtils.createTestAppWindowToken(dc0); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 326 | task1.addChild(token1, 0); |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 327 | dc1.configureDisplayPolicy(); |
| 328 | assertNotNull(dc1.mTapDetector); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 329 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 330 | // tap on primary display. |
| 331 | tapOnDisplay(dc0); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 332 | // Check focus is on primary display. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 333 | assertEquals(mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus, |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 334 | dc0.findFocusedWindow()); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 335 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 336 | // Tap on secondary display. |
| 337 | tapOnDisplay(dc1); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 338 | // Check focus is on secondary. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 339 | assertEquals(mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus, |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 340 | dc1.findFocusedWindow()); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 341 | } |
| 342 | |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 343 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 344 | public void testFocusedWindowMultipleDisplays() { |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 345 | doTestFocusedWindowMultipleDisplays(false /* perDisplayFocusEnabled */, Q); |
| 346 | } |
| 347 | |
| 348 | @Test |
| 349 | public void testFocusedWindowMultipleDisplaysPerDisplayFocusEnabled() { |
| 350 | doTestFocusedWindowMultipleDisplays(true /* perDisplayFocusEnabled */, Q); |
| 351 | } |
| 352 | |
| 353 | @Test |
| 354 | public void testFocusedWindowMultipleDisplaysPerDisplayFocusEnabledLegacyApp() { |
| 355 | doTestFocusedWindowMultipleDisplays(true /* perDisplayFocusEnabled */, P); |
| 356 | } |
| 357 | |
| 358 | private void doTestFocusedWindowMultipleDisplays(boolean perDisplayFocusEnabled, |
| 359 | int targetSdk) { |
| 360 | mWm.mPerDisplayFocusEnabled = perDisplayFocusEnabled; |
| 361 | |
Andrii Kulian | 0214ed9 | 2017-05-16 13:44:05 -0700 | [diff] [blame] | 362 | // Create a focusable window and check that focus is calculated correctly |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 363 | final WindowState window1 = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 364 | createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1"); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 365 | window1.mAppToken.mTargetSdk = targetSdk; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 366 | updateFocusedWindow(); |
| 367 | assertTrue(window1.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 368 | assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 369 | |
| 370 | // Check that a new display doesn't affect focus |
| 371 | final DisplayContent dc = createNewDisplay(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 372 | updateFocusedWindow(); |
| 373 | assertTrue(window1.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 374 | assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 375 | |
| 376 | // Add a window to the second display, and it should be focused |
| 377 | final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2"); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 378 | window2.mAppToken.mTargetSdk = targetSdk; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 379 | updateFocusedWindow(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 380 | assertTrue(window2.isFocused()); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 381 | assertEquals(perDisplayFocusEnabled && targetSdk >= Q, window1.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 382 | assertEquals(window2, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 383 | |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 384 | // 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] | 385 | window1.getParent().positionChildAt(POSITION_TOP, window1, true); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 386 | updateFocusedWindow(); |
| 387 | assertTrue(window1.isFocused()); |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 388 | assertEquals(perDisplayFocusEnabled && targetSdk >= Q, window2.isFocused()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 389 | assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus); |
Louis Chang | a9350fe | 2019-04-25 17:14:20 +0800 | [diff] [blame] | 390 | |
| 391 | // Make sure top focused display not changed if there is a focused app. |
| 392 | window1.mAppToken.hiddenRequested = true; |
| 393 | window1.getDisplayContent().setFocusedApp(window1.mAppToken); |
| 394 | updateFocusedWindow(); |
| 395 | assertTrue(!window1.isFocused()); |
| 396 | assertEquals(window1.getDisplayId(), |
| 397 | mWm.mRoot.getTopFocusedDisplayContent().getDisplayId()); |
Adrian Roos | 4163d62 | 2018-05-22 16:56:35 +0200 | [diff] [blame] | 398 | } |
| 399 | |
Riddle Hsu | b2297ad | 2019-07-26 23:37:25 -0600 | [diff] [blame] | 400 | @Test |
| 401 | public void testShouldWaitForSystemDecorWindowsOnBoot_OnDefaultDisplay() { |
| 402 | mWm.mSystemBooted = true; |
| 403 | final DisplayContent defaultDisplay = mWm.getDefaultDisplayContentLocked(); |
| 404 | final WindowState[] windows = createNotDrawnWindowsOn(defaultDisplay, |
| 405 | TYPE_WALLPAPER, TYPE_APPLICATION); |
| 406 | |
| 407 | // Verify waiting for windows to be drawn. |
| 408 | assertTrue(defaultDisplay.shouldWaitForSystemDecorWindowsOnBoot()); |
| 409 | |
| 410 | // Verify not waiting for drawn windows. |
| 411 | makeWindowsDrawn(windows); |
| 412 | assertFalse(defaultDisplay.shouldWaitForSystemDecorWindowsOnBoot()); |
| 413 | } |
| 414 | |
| 415 | @Test |
| 416 | public void testShouldWaitForSystemDecorWindowsOnBoot_OnSecondaryDisplay() { |
| 417 | mWm.mSystemBooted = true; |
| 418 | final DisplayContent secondaryDisplay = createNewDisplay(); |
| 419 | final WindowState[] windows = createNotDrawnWindowsOn(secondaryDisplay, |
| 420 | TYPE_WALLPAPER, TYPE_APPLICATION); |
| 421 | |
| 422 | // Verify not waiting for display without system decorations. |
| 423 | doReturn(false).when(secondaryDisplay).supportsSystemDecorations(); |
| 424 | assertFalse(secondaryDisplay.shouldWaitForSystemDecorWindowsOnBoot()); |
| 425 | |
| 426 | // Verify waiting for non-drawn windows on display with system decorations. |
| 427 | reset(secondaryDisplay); |
| 428 | doReturn(true).when(secondaryDisplay).supportsSystemDecorations(); |
| 429 | assertTrue(secondaryDisplay.shouldWaitForSystemDecorWindowsOnBoot()); |
| 430 | |
| 431 | // Verify not waiting for drawn windows on display with system decorations. |
| 432 | makeWindowsDrawn(windows); |
| 433 | assertFalse(secondaryDisplay.shouldWaitForSystemDecorWindowsOnBoot()); |
| 434 | } |
| 435 | |
| 436 | private WindowState[] createNotDrawnWindowsOn(DisplayContent displayContent, int... types) { |
| 437 | final WindowState[] windows = new WindowState[types.length]; |
| 438 | for (int i = 0; i < types.length; i++) { |
| 439 | final int type = types[i]; |
| 440 | windows[i] = createWindow(null /* parent */, type, displayContent, "window-" + type); |
| 441 | windows[i].mHasSurface = false; |
| 442 | } |
| 443 | return windows; |
| 444 | } |
| 445 | |
| 446 | private static void makeWindowsDrawn(WindowState[] windows) { |
| 447 | for (WindowState window : windows) { |
| 448 | window.mHasSurface = true; |
| 449 | window.mWinAnimator.mDrawState = WindowStateAnimator.HAS_DRAWN; |
| 450 | } |
| 451 | } |
| 452 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 453 | /** |
| 454 | * This tests setting the maximum ui width on a display. |
| 455 | */ |
| 456 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 457 | public void testMaxUiWidth() { |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 458 | // Prevent base display metrics for test from being updated to the value of real display. |
| 459 | final DisplayContent displayContent = createDisplayNoUpdateDisplayInfo(); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 460 | final int baseWidth = 1440; |
| 461 | final int baseHeight = 2560; |
| 462 | final int baseDensity = 300; |
| 463 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 464 | displayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 465 | |
| 466 | final int maxWidth = 300; |
| 467 | final int resultingHeight = (maxWidth * baseHeight) / baseWidth; |
| 468 | final int resultingDensity = (maxWidth * baseDensity) / baseWidth; |
| 469 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 470 | displayContent.setMaxUiWidth(maxWidth); |
| 471 | verifySizes(displayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 472 | |
| 473 | // Assert setting values again does not change; |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 474 | displayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
| 475 | verifySizes(displayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 476 | |
| 477 | final int smallerWidth = 200; |
| 478 | final int smallerHeight = 400; |
| 479 | final int smallerDensity = 100; |
| 480 | |
| 481 | // Specify smaller dimension, verify that it is honored |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 482 | displayContent.updateBaseDisplayMetrics(smallerWidth, smallerHeight, smallerDensity); |
| 483 | verifySizes(displayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 484 | |
| 485 | // 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] | 486 | displayContent.setMaxUiWidth(maxWidth); |
| 487 | verifySizes(displayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 490 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 491 | public void testDisplayCutout_rot0() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 492 | final DisplayContent dc = createNewDisplay(); |
| 493 | dc.mInitialDisplayWidth = 200; |
| 494 | dc.mInitialDisplayHeight = 400; |
| 495 | final Rect r = new Rect(80, 0, 120, 10); |
| 496 | final DisplayCutout cutout = new WmDisplayCutout( |
| 497 | fromBoundingRect(r.left, r.top, r.right, r.bottom, BOUNDS_POSITION_TOP), null) |
| 498 | .computeSafeInsets(200, 400).getDisplayCutout(); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 499 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 500 | dc.mInitialDisplayCutout = cutout; |
| 501 | dc.getDisplayRotation().setRotation(Surface.ROTATION_0); |
| 502 | dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo. |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 503 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 504 | assertEquals(cutout, dc.getDisplayInfo().displayCutout); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 508 | public void testDisplayCutout_rot90() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 509 | // Prevent mInitialDisplayCutout from being updated from real display (e.g. null |
| 510 | // if the device has no cutout). |
| 511 | final DisplayContent dc = createDisplayNoUpdateDisplayInfo(); |
| 512 | // Rotation may use real display info to compute bound, so here also uses the |
| 513 | // same width and height. |
| 514 | final int displayWidth = dc.mInitialDisplayWidth; |
| 515 | final int displayHeight = dc.mInitialDisplayHeight; |
| 516 | final int cutoutWidth = 40; |
| 517 | final int cutoutHeight = 10; |
| 518 | final int left = (displayWidth - cutoutWidth) / 2; |
| 519 | final int top = 0; |
| 520 | final int right = (displayWidth + cutoutWidth) / 2; |
| 521 | final int bottom = cutoutHeight; |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 522 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 523 | final Rect r1 = new Rect(left, top, right, bottom); |
| 524 | final DisplayCutout cutout = new WmDisplayCutout( |
| 525 | fromBoundingRect(r1.left, r1.top, r1.right, r1.bottom, BOUNDS_POSITION_TOP), null) |
| 526 | .computeSafeInsets(displayWidth, displayHeight).getDisplayCutout(); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 527 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 528 | dc.mInitialDisplayCutout = cutout; |
| 529 | dc.getDisplayRotation().setRotation(Surface.ROTATION_90); |
| 530 | dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo. |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 531 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 532 | // ----o---------- ------------- |
| 533 | // | | | | | |
| 534 | // | ------o | o--- |
| 535 | // | | | | |
| 536 | // | | -> | | |
| 537 | // | | ---o |
| 538 | // | | | |
| 539 | // | | ------------- |
| 540 | final Rect r = new Rect(top, left, bottom, right); |
| 541 | assertEquals(new WmDisplayCutout( |
| 542 | fromBoundingRect(r.left, r.top, r.right, r.bottom, BOUNDS_POSITION_LEFT), null) |
| 543 | .computeSafeInsets(displayHeight, displayWidth).getDisplayCutout(), |
| 544 | dc.getDisplayInfo().displayCutout); |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 548 | public void testLayoutSeq_assignedDuringLayout() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 549 | final DisplayContent dc = createNewDisplay(); |
| 550 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 551 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 552 | dc.setLayoutNeeded(); |
| 553 | dc.performLayout(true /* initial */, false /* updateImeWindows */); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 554 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 555 | assertThat(win.mLayoutSeq, is(dc.mLayoutSeq)); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | @Test |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 559 | @SuppressLint("InlinedApi") |
| 560 | public void testOrientationDefinedByKeyguard() { |
| 561 | final DisplayContent dc = createNewDisplay(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 562 | |
| 563 | // When display content is created its configuration is not yet initialized, which could |
| 564 | // cause unnecessary configuration propagation, so initialize it here. |
| 565 | final Configuration config = new Configuration(); |
| 566 | dc.computeScreenConfiguration(config); |
| 567 | dc.onRequestedOverrideConfigurationChanged(config); |
| 568 | |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 569 | // Create a window that requests landscape orientation. It will define device orientation |
| 570 | // by default. |
| 571 | final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); |
| 572 | window.mAppToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 573 | |
| 574 | final WindowState keyguard = createWindow(null, TYPE_STATUS_BAR, dc, "keyguard"); |
| 575 | keyguard.mHasSurface = true; |
| 576 | keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 577 | |
| 578 | assertEquals("Screen orientation must be defined by the app window by default", |
| 579 | SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation()); |
| 580 | |
| 581 | keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_PORTRAIT; |
| 582 | assertEquals("Visible keyguard must influence device orientation", |
| 583 | SCREEN_ORIENTATION_PORTRAIT, dc.getOrientation()); |
| 584 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 585 | mWm.setKeyguardGoingAway(true); |
Andrii Kulian | 92c9a94 | 2017-10-10 00:41:41 -0700 | [diff] [blame] | 586 | assertEquals("Keyguard that is going away must not influence device orientation", |
| 587 | SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation()); |
| 588 | } |
| 589 | |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 590 | @Test |
Tiger Huang | 86e6d07 | 2019-05-02 20:23:47 +0800 | [diff] [blame] | 591 | public void testOrientationForAspectRatio() { |
| 592 | final DisplayContent dc = createNewDisplay(); |
| 593 | |
| 594 | // When display content is created its configuration is not yet initialized, which could |
| 595 | // cause unnecessary configuration propagation, so initialize it here. |
| 596 | final Configuration config = new Configuration(); |
| 597 | dc.computeScreenConfiguration(config); |
| 598 | dc.onRequestedOverrideConfigurationChanged(config); |
| 599 | |
| 600 | // Create a window that requests a fixed orientation. It will define device orientation |
| 601 | // by default. |
| 602 | final WindowState window = createWindow(null /* parent */, TYPE_APPLICATION_OVERLAY, dc, |
| 603 | "window"); |
| 604 | window.mHasSurface = true; |
| 605 | window.mAttrs.screenOrientation = SCREEN_ORIENTATION_LANDSCAPE; |
| 606 | |
| 607 | // -------------------------------- |
| 608 | // Test non-close-to-square display |
| 609 | // -------------------------------- |
| 610 | dc.mBaseDisplayWidth = 1000; |
| 611 | dc.mBaseDisplayHeight = (int) (dc.mBaseDisplayWidth * dc.mCloseToSquareMaxAspectRatio * 2f); |
| 612 | dc.configureDisplayPolicy(); |
| 613 | |
| 614 | assertEquals("Screen orientation must be defined by the window by default.", |
| 615 | window.mAttrs.screenOrientation, dc.getOrientation()); |
| 616 | |
| 617 | // ---------------------------- |
| 618 | // Test close-to-square display |
| 619 | // ---------------------------- |
| 620 | dc.mBaseDisplayHeight = dc.mBaseDisplayWidth; |
| 621 | dc.configureDisplayPolicy(); |
| 622 | |
| 623 | assertEquals("Screen orientation must be SCREEN_ORIENTATION_USER.", |
| 624 | SCREEN_ORIENTATION_USER, dc.getOrientation()); |
| 625 | } |
| 626 | |
| 627 | @Test |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 628 | public void testDisableDisplayInfoOverrideFromWindowManager() { |
| 629 | final DisplayContent dc = createNewDisplay(); |
| 630 | |
| 631 | assertTrue(dc.mShouldOverrideDisplayConfiguration); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 632 | mWm.dontOverrideDisplayInfo(dc.getDisplayId()); |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 633 | |
| 634 | assertFalse(dc.mShouldOverrideDisplayConfiguration); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 635 | verify(mWm.mDisplayManagerInternal, times(1)) |
Andrii Kulian | f0379de | 2018-03-14 16:24:07 -0700 | [diff] [blame] | 636 | .setDisplayInfoOverrideFromWindowManager(dc.getDisplayId(), null); |
| 637 | } |
| 638 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 639 | @Test |
Riddle Hsu | 85bd04b | 2018-11-17 00:34:36 +0800 | [diff] [blame] | 640 | public void testClearLastFocusWhenReparentingFocusedWindow() { |
| 641 | final DisplayContent defaultDisplay = mWm.getDefaultDisplayContentLocked(); |
| 642 | final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, |
| 643 | defaultDisplay, "window"); |
| 644 | defaultDisplay.mLastFocus = window; |
| 645 | mDisplayContent.mCurrentFocus = window; |
| 646 | mDisplayContent.reParentWindowToken(window.mToken); |
| 647 | |
| 648 | assertNull(defaultDisplay.mLastFocus); |
| 649 | } |
| 650 | |
| 651 | @Test |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 652 | public void testGetPreferredOptionsPanelGravityFromDifferentDisplays() { |
| 653 | final DisplayContent portraitDisplay = createNewDisplay(); |
| 654 | portraitDisplay.mInitialDisplayHeight = 2000; |
| 655 | portraitDisplay.mInitialDisplayWidth = 1000; |
| 656 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 657 | portraitDisplay.getDisplayRotation().setRotation(Surface.ROTATION_0); |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 658 | assertFalse(isOptionsPanelAtRight(portraitDisplay.getDisplayId())); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 659 | portraitDisplay.getDisplayRotation().setRotation(Surface.ROTATION_90); |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 660 | assertTrue(isOptionsPanelAtRight(portraitDisplay.getDisplayId())); |
| 661 | |
| 662 | final DisplayContent landscapeDisplay = createNewDisplay(); |
| 663 | landscapeDisplay.mInitialDisplayHeight = 1000; |
| 664 | landscapeDisplay.mInitialDisplayWidth = 2000; |
| 665 | |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 666 | landscapeDisplay.getDisplayRotation().setRotation(Surface.ROTATION_0); |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 667 | assertTrue(isOptionsPanelAtRight(landscapeDisplay.getDisplayId())); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 668 | landscapeDisplay.getDisplayRotation().setRotation(Surface.ROTATION_90); |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 669 | assertFalse(isOptionsPanelAtRight(landscapeDisplay.getDisplayId())); |
| 670 | } |
| 671 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 672 | @Test |
| 673 | public void testInputMethodTargetUpdateWhenSwitchingOnDisplays() { |
| 674 | final DisplayContent newDisplay = createNewDisplay(); |
| 675 | |
| 676 | final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin"); |
| 677 | final WindowState appWin1 = createWindow(null, TYPE_APPLICATION, newDisplay, "appWin1"); |
| 678 | appWin.setHasSurface(true); |
| 679 | appWin1.setHasSurface(true); |
| 680 | |
| 681 | // Set current input method window on default display, make sure the input method target |
| 682 | // is appWin & null on the other display. |
| 683 | mDisplayContent.setInputMethodWindowLocked(mImeWindow); |
| 684 | newDisplay.setInputMethodWindowLocked(null); |
Wale Ogunwale | 3198da4 | 2019-10-10 14:45:03 +0200 | [diff] [blame^] | 685 | assertEquals("appWin should be IME target window", |
| 686 | appWin, mDisplayContent.mInputMethodTarget); |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 687 | assertNull("newDisplay Ime target: ", newDisplay.mInputMethodTarget); |
| 688 | |
| 689 | // Switch input method window on new display & make sure the input method target also |
| 690 | // switched as expected. |
| 691 | newDisplay.setInputMethodWindowLocked(mImeWindow); |
| 692 | mDisplayContent.setInputMethodWindowLocked(null); |
Wale Ogunwale | 3198da4 | 2019-10-10 14:45:03 +0200 | [diff] [blame^] | 693 | assertEquals("appWin1 should be IME target window", appWin1, newDisplay.mInputMethodTarget); |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 694 | assertNull("default display Ime target: ", mDisplayContent.mInputMethodTarget); |
| 695 | } |
| 696 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 697 | @Test |
| 698 | public void testOnDescendantOrientationRequestChanged() { |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 699 | final DisplayContent dc = createNewDisplay(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 700 | dc.getDisplayRotation().setFixedToUserRotation( |
| 701 | DisplayRotation.FIXED_TO_USER_ROTATION_DISABLED); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 702 | final int newOrientation = dc.getLastOrientation() == SCREEN_ORIENTATION_LANDSCAPE |
| 703 | ? SCREEN_ORIENTATION_PORTRAIT |
| 704 | : SCREEN_ORIENTATION_LANDSCAPE; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 705 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 706 | final ActivityStack stack = |
| 707 | new ActivityTestsBase.StackBuilder(mWm.mAtmService.mRootActivityContainer) |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 708 | .setDisplay(dc.mActivityDisplay).build(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 709 | final ActivityRecord activity = stack.topTask().getTopActivity(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 710 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 711 | activity.setRequestedOrientation(newOrientation); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 712 | |
| 713 | final ArgumentCaptor<Configuration> captor = ArgumentCaptor.forClass(Configuration.class); |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 714 | verify(dc.mActivityDisplay).updateDisplayOverrideConfigurationLocked(captor.capture(), |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 715 | same(activity), anyBoolean(), same(null)); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 716 | final Configuration newDisplayConfig = captor.getValue(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 717 | final int expectedOrientation = newOrientation == SCREEN_ORIENTATION_PORTRAIT |
| 718 | ? Configuration.ORIENTATION_PORTRAIT |
| 719 | : Configuration.ORIENTATION_LANDSCAPE; |
| 720 | assertEquals(expectedOrientation, newDisplayConfig.orientation); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | @Test |
| 724 | public void testOnDescendantOrientationRequestChanged_FrozenToUserRotation() { |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 725 | final DisplayContent dc = createNewDisplay(); |
Garfield Tan | 7fbca05 | 2019-02-19 10:45:35 -0800 | [diff] [blame] | 726 | dc.getDisplayRotation().setFixedToUserRotation( |
| 727 | DisplayRotation.FIXED_TO_USER_ROTATION_ENABLED); |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 728 | final int newOrientation = dc.getLastOrientation() == SCREEN_ORIENTATION_LANDSCAPE |
| 729 | ? SCREEN_ORIENTATION_PORTRAIT |
| 730 | : SCREEN_ORIENTATION_LANDSCAPE; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 731 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 732 | final ActivityStack stack = |
| 733 | new ActivityTestsBase.StackBuilder(mWm.mAtmService.mRootActivityContainer) |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 734 | .setDisplay(dc.mActivityDisplay).build(); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 735 | final ActivityRecord activity = stack.topTask().getTopActivity(); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 736 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 737 | activity.setRequestedOrientation(newOrientation); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 738 | |
Riddle Hsu | d1549d2 | 2019-10-07 17:00:47 +0800 | [diff] [blame] | 739 | verify(dc.mActivityDisplay, never()).updateDisplayOverrideConfigurationLocked(any(), |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 740 | eq(activity), anyBoolean(), same(null)); |
| 741 | assertEquals(dc.getDisplayRotation().getUserRotation(), dc.getRotation()); |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 742 | } |
| 743 | |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 744 | @Test |
| 745 | public void testComputeImeParent_app() throws Exception { |
| 746 | try (final InsetsModeSession session = |
| 747 | new InsetsModeSession(ViewRootImpl.NEW_INSETS_MODE_IME)) { |
| 748 | final DisplayContent dc = createNewDisplay(); |
| 749 | dc.mInputMethodTarget = createWindow(null, TYPE_BASE_APPLICATION, "app"); |
| 750 | assertEquals(dc.mInputMethodTarget.mAppToken.getSurfaceControl(), |
| 751 | dc.computeImeParent()); |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | @Test |
| 756 | public void testComputeImeParent_app_notFullscreen() throws Exception { |
| 757 | try (final InsetsModeSession session = |
| 758 | new InsetsModeSession(ViewRootImpl.NEW_INSETS_MODE_IME)) { |
| 759 | final DisplayContent dc = createNewDisplay(); |
| 760 | dc.mInputMethodTarget = createWindow(null, TYPE_STATUS_BAR, "app"); |
| 761 | dc.mInputMethodTarget.setWindowingMode( |
| 762 | WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 763 | assertEquals(dc.getWindowingLayer(), dc.computeImeParent()); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | @Test |
Riddle Hsu | 6d6f67c | 2019-03-14 16:54:26 +0800 | [diff] [blame] | 768 | public void testComputeImeParent_app_notMatchParentBounds() { |
| 769 | spyOn(mAppWindow.mAppToken); |
| 770 | doReturn(false).when(mAppWindow.mAppToken).matchParentBounds(); |
| 771 | mDisplayContent.mInputMethodTarget = mAppWindow; |
| 772 | // The surface parent of IME should be the display instead of app window. |
| 773 | assertEquals(mDisplayContent.getWindowingLayer(), mDisplayContent.computeImeParent()); |
| 774 | } |
| 775 | |
| 776 | @Test |
Tarandeep Singh | a6f3561 | 2019-01-11 19:50:46 -0800 | [diff] [blame] | 777 | public void testComputeImeParent_noApp() throws Exception { |
| 778 | try (final InsetsModeSession session = |
| 779 | new InsetsModeSession(ViewRootImpl.NEW_INSETS_MODE_IME)) { |
| 780 | final DisplayContent dc = createNewDisplay(); |
| 781 | dc.mInputMethodTarget = createWindow(null, TYPE_STATUS_BAR, "statusBar"); |
| 782 | assertEquals(dc.getWindowingLayer(), dc.computeImeParent()); |
| 783 | } |
| 784 | } |
| 785 | |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 786 | @Test |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 787 | public void testUpdateSystemGestureExclusion() throws Exception { |
| 788 | final DisplayContent dc = createNewDisplay(); |
| 789 | final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, dc, "win"); |
| 790 | win.getAttrs().flags |= FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR; |
| 791 | win.setSystemGestureExclusion(Collections.singletonList(new Rect(10, 20, 30, 40))); |
| 792 | |
| 793 | dc.setLayoutNeeded(); |
| 794 | dc.performLayout(true /* initial */, false /* updateImeWindows */); |
| 795 | |
| 796 | win.setHasSurface(true); |
| 797 | dc.updateSystemGestureExclusion(); |
| 798 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 799 | final boolean[] invoked = { false }; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 800 | final ISystemGestureExclusionListener.Stub verifier = |
| 801 | new ISystemGestureExclusionListener.Stub() { |
| 802 | @Override |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 803 | public void onSystemGestureExclusionChanged(int displayId, Region actual, |
| 804 | Region unrestricted) { |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 805 | Region expected = Region.obtain(); |
| 806 | expected.set(10, 20, 30, 40); |
| 807 | assertEquals(expected, actual); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 808 | invoked[0] = true; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 809 | } |
| 810 | }; |
| 811 | try { |
| 812 | dc.registerSystemGestureExclusionListener(verifier); |
| 813 | } finally { |
| 814 | dc.unregisterSystemGestureExclusionListener(verifier); |
| 815 | } |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 816 | assertTrue("SystemGestureExclusionListener was not invoked", invoked[0]); |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | @Test |
| 820 | public void testCalculateSystemGestureExclusion() throws Exception { |
| 821 | final DisplayContent dc = createNewDisplay(); |
| 822 | final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, dc, "win"); |
| 823 | win.getAttrs().flags |= FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR; |
| 824 | win.setSystemGestureExclusion(Collections.singletonList(new Rect(10, 20, 30, 40))); |
| 825 | |
| 826 | final WindowState win2 = createWindow(null, TYPE_APPLICATION, dc, "win2"); |
| 827 | win2.getAttrs().flags |= FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR; |
| 828 | win2.setSystemGestureExclusion(Collections.singletonList(new Rect(20, 30, 40, 50))); |
| 829 | |
| 830 | dc.setLayoutNeeded(); |
| 831 | dc.performLayout(true /* initial */, false /* updateImeWindows */); |
| 832 | |
| 833 | win.setHasSurface(true); |
| 834 | win2.setHasSurface(true); |
| 835 | |
| 836 | final Region expected = Region.obtain(); |
| 837 | expected.set(20, 30, 40, 50); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 838 | assertEquals(expected, calculateSystemGestureExclusion(dc)); |
| 839 | } |
| 840 | |
| 841 | private Region calculateSystemGestureExclusion(DisplayContent dc) { |
| 842 | Region out = Region.obtain(); |
| 843 | Region unrestricted = Region.obtain(); |
| 844 | dc.calculateSystemGestureExclusion(out, unrestricted); |
| 845 | return out; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | @Test |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 849 | public void testCalculateSystemGestureExclusion_modal() throws Exception { |
| 850 | final DisplayContent dc = createNewDisplay(); |
| 851 | final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, dc, "base"); |
| 852 | win.getAttrs().flags |= FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR; |
| 853 | win.setSystemGestureExclusion(Collections.singletonList(new Rect(0, 0, 1000, 1000))); |
| 854 | |
| 855 | final WindowState win2 = createWindow(null, TYPE_APPLICATION, dc, "modal"); |
| 856 | win2.getAttrs().flags |= FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR; |
| 857 | win2.getAttrs().privateFlags |= PRIVATE_FLAG_NO_MOVE_ANIMATION; |
| 858 | win2.getAttrs().width = 10; |
| 859 | win2.getAttrs().height = 10; |
| 860 | win2.setSystemGestureExclusion(Collections.emptyList()); |
| 861 | |
| 862 | dc.setLayoutNeeded(); |
| 863 | dc.performLayout(true /* initial */, false /* updateImeWindows */); |
| 864 | |
| 865 | win.setHasSurface(true); |
| 866 | win2.setHasSurface(true); |
| 867 | |
| 868 | final Region expected = Region.obtain(); |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 869 | assertEquals(expected, calculateSystemGestureExclusion(dc)); |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | @Test |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 873 | public void testCalculateSystemGestureExclusion_immersiveStickyLegacyWindow() throws Exception { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 874 | mWm.mSystemGestureExcludedByPreQStickyImmersive = true; |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 875 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 876 | final DisplayContent dc = createNewDisplay(); |
| 877 | final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, dc, "win"); |
| 878 | win.getAttrs().flags |= FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR; |
| 879 | win.getAttrs().layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
| 880 | win.getAttrs().privateFlags |= PRIVATE_FLAG_NO_MOVE_ANIMATION; |
| 881 | win.getAttrs().subtreeSystemUiVisibility = win.mSystemUiVisibility = |
| 882 | SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 883 | | SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
| 884 | win.mAppToken.mTargetSdk = P; |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 885 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 886 | dc.setLayoutNeeded(); |
| 887 | dc.performLayout(true /* initial */, false /* updateImeWindows */); |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 888 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 889 | win.setHasSurface(true); |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 890 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 891 | final Region expected = Region.obtain(); |
| 892 | expected.set(dc.getBounds()); |
| 893 | assertEquals(expected, calculateSystemGestureExclusion(dc)); |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 894 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 895 | win.setHasSurface(false); |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | @Test |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 899 | public void testOrientationChangeLogging() { |
| 900 | MetricsLogger mockLogger = mock(MetricsLogger.class); |
| 901 | Configuration oldConfig = new Configuration(); |
| 902 | oldConfig.orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 903 | |
| 904 | Configuration newConfig = new Configuration(); |
| 905 | newConfig.orientation = Configuration.ORIENTATION_PORTRAIT; |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 906 | final DisplayContent displayContent = createNewDisplay(); |
Susi Kharraz-Post | 9893b8c | 2019-02-12 14:21:29 -0500 | [diff] [blame] | 907 | Mockito.doReturn(mockLogger).when(displayContent).getMetricsLogger(); |
| 908 | Mockito.doReturn(oldConfig).doReturn(newConfig).when(displayContent).getConfiguration(); |
| 909 | |
| 910 | displayContent.onConfigurationChanged(newConfig); |
| 911 | |
| 912 | ArgumentCaptor<LogMaker> logMakerCaptor = ArgumentCaptor.forClass(LogMaker.class); |
| 913 | verify(mockLogger).write(logMakerCaptor.capture()); |
| 914 | assertThat(logMakerCaptor.getValue().getCategory(), |
| 915 | is(MetricsProto.MetricsEvent.ACTION_PHONE_ORIENTATION_CHANGED)); |
| 916 | assertThat(logMakerCaptor.getValue().getSubtype(), |
| 917 | is(Configuration.ORIENTATION_PORTRAIT)); |
| 918 | } |
| 919 | |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 920 | private boolean isOptionsPanelAtRight(int displayId) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 921 | return (mWm.getPreferredOptionsPanelGravity(displayId) & Gravity.RIGHT) == Gravity.RIGHT; |
Riddle Hsu | a4d6fa2 | 2018-08-11 00:50:39 +0800 | [diff] [blame] | 922 | } |
| 923 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 924 | private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth, |
| 925 | int expectedBaseHeight, int expectedBaseDensity) { |
| 926 | assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth); |
| 927 | assertEquals(displayContent.mBaseDisplayHeight, expectedBaseHeight); |
| 928 | assertEquals(displayContent.mBaseDisplayDensity, expectedBaseDensity); |
| 929 | } |
| 930 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 931 | private void updateFocusedWindow() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 932 | mWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateInputWindows */); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 933 | } |
| 934 | |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 935 | /** |
| 936 | * Create DisplayContent that does not update display base/initial values from device to keep |
| 937 | * the values set by test. |
| 938 | */ |
| 939 | private DisplayContent createDisplayNoUpdateDisplayInfo() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 940 | final DisplayContent displayContent = createNewDisplay(); |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 941 | doNothing().when(displayContent).updateDisplayInfo(); |
| 942 | return displayContent; |
| 943 | } |
| 944 | |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 945 | private void assertForAllWindowsOrder(List<WindowState> expectedWindowsBottomToTop) { |
| 946 | final LinkedList<WindowState> actualWindows = new LinkedList<>(); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 947 | |
| 948 | // Test forward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 949 | mDisplayContent.forAllWindows(actualWindows::addLast, false /* traverseTopToBottom */); |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 950 | assertThat("bottomToTop", actualWindows, is(expectedWindowsBottomToTop)); |
| 951 | |
| 952 | actualWindows.clear(); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 953 | |
| 954 | // Test backward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 955 | mDisplayContent.forAllWindows(actualWindows::addLast, true /* traverseTopToBottom */); |
Adrian Roos | 0f9368c | 2018-04-08 10:59:08 -0700 | [diff] [blame] | 956 | assertThat("topToBottom", actualWindows, is(reverseList(expectedWindowsBottomToTop))); |
| 957 | } |
| 958 | |
| 959 | private static List<WindowState> reverseList(List<WindowState> list) { |
| 960 | final ArrayList<WindowState> result = new ArrayList<>(list); |
| 961 | Collections.reverse(result); |
| 962 | return result; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 963 | } |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 964 | |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 965 | private void tapOnDisplay(final DisplayContent dc) { |
| 966 | final DisplayMetrics dm = dc.getDisplayMetrics(); |
| 967 | final float x = dm.widthPixels / 2; |
| 968 | final float y = dm.heightPixels / 2; |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 969 | final long downTime = SystemClock.uptimeMillis(); |
| 970 | final long eventTime = SystemClock.uptimeMillis() + 100; |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 971 | // sending ACTION_DOWN |
| 972 | final MotionEvent downEvent = MotionEvent.obtain( |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 973 | downTime, |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 974 | downTime, |
| 975 | MotionEvent.ACTION_DOWN, |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 976 | x, |
| 977 | y, |
Arthur Hung | be5ce21 | 2018-09-13 18:41:56 +0800 | [diff] [blame] | 978 | 0 /*metaState*/); |
| 979 | downEvent.setDisplayId(dc.getDisplayId()); |
| 980 | dc.mTapDetector.onPointerEvent(downEvent); |
| 981 | |
| 982 | // sending ACTION_UP |
| 983 | final MotionEvent upEvent = MotionEvent.obtain( |
| 984 | downTime, |
| 985 | eventTime, |
| 986 | MotionEvent.ACTION_UP, |
| 987 | x, |
| 988 | y, |
| 989 | 0 /*metaState*/); |
| 990 | upEvent.setDisplayId(dc.getDisplayId()); |
| 991 | dc.mTapDetector.onPointerEvent(upEvent); |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 992 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 993 | } |