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