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