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