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