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