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