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