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