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