Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -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 | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 22 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
Riddle Hsu | 0c1b0d1 | 2020-05-27 23:15:39 +0800 | [diff] [blame] | 24 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 25 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 26 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
Garfield Tan | b677660 | 2019-02-20 14:44:26 -0800 | [diff] [blame] | 27 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
| 31 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 32 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 33 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
wilsonshih | ca274ed | 2020-05-05 17:32:21 +0800 | [diff] [blame] | 35 | import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 36 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 37 | import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; |
| 38 | |
Riddle Hsu | ffc1246 | 2020-05-27 17:43:25 +0800 | [diff] [blame] | 39 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doCallRealMethod; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 40 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Louis Chang | 242be90 | 2020-06-03 12:24:45 +0800 | [diff] [blame] | 41 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 42 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM; |
| 43 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM; |
| 44 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 45 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 46 | import static org.junit.Assert.assertEquals; |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 47 | import static org.junit.Assert.assertFalse; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 48 | import static org.junit.Assert.assertNotNull; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 49 | import static org.junit.Assert.assertNull; |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 50 | import static org.junit.Assert.assertTrue; |
Garfield Tan | b677660 | 2019-02-20 14:44:26 -0800 | [diff] [blame] | 51 | import static org.mockito.ArgumentMatchers.any; |
Riddle Hsu | ffc1246 | 2020-05-27 17:43:25 +0800 | [diff] [blame] | 52 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Riddle Hsu | a118b3a | 2018-10-11 22:05:06 +0800 | [diff] [blame] | 53 | import static org.mockito.ArgumentMatchers.anyInt; |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 54 | import static org.mockito.Mockito.reset; |
Garfield Tan | b677660 | 2019-02-20 14:44:26 -0800 | [diff] [blame] | 55 | import static org.mockito.Mockito.verify; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 56 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 57 | import android.content.res.Configuration; |
Riddle Hsu | a71f8e0 | 2020-05-05 23:07:59 +0800 | [diff] [blame] | 58 | import android.graphics.Point; |
Riddle Hsu | a118b3a | 2018-10-11 22:05:06 +0800 | [diff] [blame] | 59 | import android.graphics.Rect; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 60 | import android.platform.test.annotations.Presubmit; |
Garfield Tan | a3f1903 | 2019-11-19 18:04:50 -0800 | [diff] [blame] | 61 | import android.view.IWindowManager; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 62 | import android.view.Surface; |
| 63 | import android.view.WindowManager; |
| 64 | |
Yunfan Chen | c1caf6b | 2019-04-12 13:58:51 +0900 | [diff] [blame] | 65 | import androidx.test.filters.FlakyTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 66 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 67 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 68 | import org.junit.Before; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 69 | import org.junit.Test; |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 70 | import org.junit.runner.RunWith; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 71 | |
Issei Suzuki | 737b7f1 | 2020-05-25 14:54:06 +0200 | [diff] [blame] | 72 | import java.util.ArrayList; |
| 73 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 74 | /** |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 75 | * Tests for the {@link ActivityRecord} class. |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 76 | * |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 77 | * Build/Install/Run: |
Vishnu Nair | e6e2b0f | 2019-02-21 10:41:00 -0800 | [diff] [blame] | 78 | * atest WmTests:AppWindowTokenTests |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 79 | */ |
| 80 | @SmallTest |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 81 | @Presubmit |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 82 | @RunWith(WindowTestRunner.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 83 | public class AppWindowTokenTests extends WindowTestsBase { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 84 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 85 | ActivityStack mStack; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 86 | Task mTask; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 87 | ActivityRecord mActivity; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 88 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 89 | private final String mPackageName = getInstrumentation().getTargetContext().getPackageName(); |
| 90 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 91 | @Before |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 92 | public void setUp() throws Exception { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 93 | mStack = createTaskStackOnDisplay(mDisplayContent); |
| 94 | mTask = createTaskInStack(mStack, 0 /* userId */); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 95 | mActivity = WindowTestUtils.createTestActivityRecord(mDisplayContent); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 96 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 97 | mTask.addChild(mActivity, 0); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 100 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 101 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 102 | public void testAddWindow_Order() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 103 | assertEquals(0, mActivity.getChildCount()); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 104 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 105 | final WindowState win1 = createWindow(null, TYPE_APPLICATION, mActivity, "win1"); |
| 106 | final WindowState startingWin = createWindow(null, TYPE_APPLICATION_STARTING, mActivity, |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 107 | "startingWin"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 108 | final WindowState baseWin = createWindow(null, TYPE_BASE_APPLICATION, mActivity, "baseWin"); |
| 109 | final WindowState win4 = createWindow(null, TYPE_APPLICATION, mActivity, "win4"); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 110 | |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 111 | // Should not contain the windows that were added above. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 112 | assertEquals(4, mActivity.getChildCount()); |
| 113 | assertTrue(mActivity.mChildren.contains(win1)); |
| 114 | assertTrue(mActivity.mChildren.contains(startingWin)); |
| 115 | assertTrue(mActivity.mChildren.contains(baseWin)); |
| 116 | assertTrue(mActivity.mChildren.contains(win4)); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 117 | |
| 118 | // The starting window should be on-top of all other windows. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 119 | assertEquals(startingWin, mActivity.mChildren.peekLast()); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 120 | |
| 121 | // The base application window should be below all other windows. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 122 | assertEquals(baseWin, mActivity.mChildren.peekFirst()); |
| 123 | mActivity.removeImmediately(); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 127 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 128 | public void testFindMainWindow() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 129 | assertNull(mActivity.findMainWindow()); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 130 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 131 | final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, mActivity, "window1"); |
| 132 | final WindowState window11 = createWindow(window1, FIRST_SUB_WINDOW, mActivity, "window11"); |
| 133 | final WindowState window12 = createWindow(window1, FIRST_SUB_WINDOW, mActivity, "window12"); |
| 134 | assertEquals(window1, mActivity.findMainWindow()); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 135 | window1.mAnimatingExit = true; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 136 | assertEquals(window1, mActivity.findMainWindow()); |
| 137 | final WindowState window2 = createWindow(null, TYPE_APPLICATION_STARTING, mActivity, |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 138 | "window2"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 139 | assertEquals(window2, mActivity.findMainWindow()); |
| 140 | mActivity.removeImmediately(); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 141 | } |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 142 | |
| 143 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 144 | @Presubmit |
Riddle Hsu | 84bc3d7 | 2019-12-19 19:24:07 +0800 | [diff] [blame] | 145 | public void testGetTopFullscreenOpaqueWindow() { |
| 146 | assertNull(mActivity.getTopFullscreenOpaqueWindow()); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 147 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 148 | final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, mActivity, "window1"); |
| 149 | final WindowState window11 = createWindow(null, TYPE_APPLICATION, mActivity, "window11"); |
| 150 | final WindowState window12 = createWindow(null, TYPE_APPLICATION, mActivity, "window12"); |
Riddle Hsu | 84bc3d7 | 2019-12-19 19:24:07 +0800 | [diff] [blame] | 151 | assertEquals(window12, mActivity.getTopFullscreenOpaqueWindow()); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 152 | window12.mAttrs.width = 500; |
Riddle Hsu | 84bc3d7 | 2019-12-19 19:24:07 +0800 | [diff] [blame] | 153 | assertEquals(window11, mActivity.getTopFullscreenOpaqueWindow()); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 154 | window11.mAttrs.width = 500; |
Riddle Hsu | 84bc3d7 | 2019-12-19 19:24:07 +0800 | [diff] [blame] | 155 | assertEquals(window1, mActivity.getTopFullscreenOpaqueWindow()); |
| 156 | window1.mAttrs.alpha = 0f; |
| 157 | assertNull(mActivity.getTopFullscreenOpaqueWindow()); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 158 | mActivity.removeImmediately(); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | @Test |
Wale Ogunwale | 815c7cb | 2019-05-02 08:04:01 -0700 | [diff] [blame] | 162 | @FlakyTest(bugId = 131005232) |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 163 | public void testLandscapeSeascapeRotationByApp() { |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 164 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( |
| 165 | TYPE_BASE_APPLICATION); |
| 166 | attrs.setTitle("AppWindow"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 167 | final WindowTestUtils.TestWindowState appWindow = createWindowState(attrs, mActivity); |
| 168 | mActivity.addWindow(appWindow); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 169 | |
| 170 | // Set initial orientation and update. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 171 | mActivity.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 172 | mDisplayContent.updateOrientation( |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 173 | mDisplayContent.getRequestedOverrideConfiguration(), |
| 174 | null /* freezeThisOneIfNeeded */, false /* forceUpdate */); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 175 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mDisplayContent.getLastOrientation()); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 176 | appWindow.mResizeReported = false; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 177 | |
| 178 | // Update the orientation to perform 180 degree rotation and check that resize was reported. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 179 | mActivity.setOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 180 | mDisplayContent.updateOrientation( |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 181 | mDisplayContent.getRequestedOverrideConfiguration(), |
| 182 | null /* freezeThisOneIfNeeded */, false /* forceUpdate */); |
Yunfan Chen | 0530fe7 | 2019-02-12 15:05:49 +0900 | [diff] [blame] | 183 | // In this test, DC will not get config update. Set the waiting flag to false. |
| 184 | mDisplayContent.mWaitingForConfig = false; |
Riddle Hsu | 72d6dc3 | 2020-03-25 22:58:00 +0800 | [diff] [blame] | 185 | mWm.mRoot.performSurfacePlacement(); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 186 | assertEquals(SCREEN_ORIENTATION_REVERSE_LANDSCAPE, mDisplayContent.getLastOrientation()); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 187 | assertTrue(appWindow.mResizeReported); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 188 | appWindow.removeImmediately(); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 192 | public void testLandscapeSeascapeRotationByPolicy() { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 193 | // This instance has been spied in {@link TestDisplayContent}. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 194 | final DisplayRotation displayRotation = mDisplayContent.getDisplayRotation(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 195 | |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 196 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( |
| 197 | TYPE_BASE_APPLICATION); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 198 | attrs.setTitle("RotationByPolicy"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 199 | final WindowTestUtils.TestWindowState appWindow = createWindowState(attrs, mActivity); |
| 200 | mActivity.addWindow(appWindow); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 201 | |
| 202 | // Set initial orientation and update. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 203 | performRotation(displayRotation, Surface.ROTATION_90); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 204 | appWindow.mResizeReported = false; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 205 | |
| 206 | // Update the rotation to perform 180 degree rotation and check that resize was reported. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 207 | performRotation(displayRotation, Surface.ROTATION_270); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 208 | assertTrue(appWindow.mResizeReported); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 209 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 210 | appWindow.removeImmediately(); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 211 | } |
Bryce Lee | 310de9e | 2017-03-15 10:18:21 -0700 | [diff] [blame] | 212 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 213 | private void performRotation(DisplayRotation spiedRotation, int rotationToReport) { |
| 214 | doReturn(rotationToReport).when(spiedRotation).rotationForOrientation(anyInt(), anyInt()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 215 | mWm.updateRotation(false, false); |
Bryce Lee | 310de9e | 2017-03-15 10:18:21 -0700 | [diff] [blame] | 216 | } |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 217 | |
| 218 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 219 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 220 | public void testGetOrientation() { |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 221 | mActivity.setVisible(true); |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 222 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 223 | mActivity.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 224 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 225 | mActivity.setOccludesParent(false); |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 226 | // Can specify orientation if app doesn't occludes parent. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 227 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mActivity.getOrientation()); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 228 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 229 | mActivity.setOccludesParent(true); |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 230 | mActivity.setVisible(false); |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 231 | // Can not specify orientation if app isn't visible even though it occludes parent. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 232 | assertEquals(SCREEN_ORIENTATION_UNSET, mActivity.getOrientation()); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 233 | // Can specify orientation if the current orientation candidate is orientation behind. |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 234 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 235 | mActivity.getOrientation(SCREEN_ORIENTATION_BEHIND)); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 236 | } |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 237 | |
| 238 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 239 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 240 | public void testKeyguardFlagsDuringRelaunch() { |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 241 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( |
| 242 | TYPE_BASE_APPLICATION); |
| 243 | attrs.flags |= FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD; |
| 244 | attrs.setTitle("AppWindow"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 245 | final WindowTestUtils.TestWindowState appWindow = createWindowState(attrs, mActivity); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 246 | |
| 247 | // Add window with show when locked flag |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 248 | mActivity.addWindow(appWindow); |
| 249 | assertTrue(mActivity.containsShowWhenLockedWindow() && mActivity.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 250 | |
| 251 | // Start relaunching |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 252 | mActivity.startRelaunching(); |
| 253 | assertTrue(mActivity.containsShowWhenLockedWindow() && mActivity.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 254 | |
| 255 | // Remove window and make sure that we still report back flag |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 256 | mActivity.removeChild(appWindow); |
| 257 | assertTrue(mActivity.containsShowWhenLockedWindow() && mActivity.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 258 | |
| 259 | // Finish relaunching and ensure flag is now not reported |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 260 | mActivity.finishRelaunching(); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 261 | assertFalse( |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 262 | mActivity.containsShowWhenLockedWindow() || mActivity.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 263 | } |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 264 | |
| 265 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 266 | public void testStuckExitingWindow() { |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 267 | final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, |
| 268 | "closingWindow"); |
| 269 | closingWindow.mAnimatingExit = true; |
| 270 | closingWindow.mRemoveOnExit = true; |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 271 | closingWindow.mActivityRecord.commitVisibility( |
| 272 | false /* visible */, true /* performLayout */); |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 273 | |
| 274 | // We pretended that we were running an exit animation, but that should have been cleared up |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 275 | // by changing visibility of ActivityRecord |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 276 | closingWindow.removeIfPossible(); |
| 277 | assertTrue(closingWindow.mRemoved); |
| 278 | } |
Riddle Hsu | a118b3a | 2018-10-11 22:05:06 +0800 | [diff] [blame] | 279 | |
| 280 | @Test |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 281 | public void testSetOrientation() { |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 282 | mActivity.setVisible(true); |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 283 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 284 | // Assert orientation is unspecified to start. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 285 | assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, mActivity.getOrientation()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 286 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 287 | mActivity.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 288 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mActivity.getOrientation()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 289 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 290 | mDisplayContent.removeAppToken(mActivity.token); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 291 | // Assert orientation is unset to after container is removed. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 292 | assertEquals(SCREEN_ORIENTATION_UNSET, mActivity.getOrientation()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 293 | |
| 294 | // Reset display frozen state |
| 295 | mWm.mDisplayFrozen = false; |
| 296 | } |
| 297 | |
| 298 | @Test |
Riddle Hsu | 0c1b0d1 | 2020-05-27 23:15:39 +0800 | [diff] [blame] | 299 | public void testRespectTopFullscreenOrientation() { |
| 300 | final Configuration displayConfig = mActivity.mDisplayContent.getConfiguration(); |
| 301 | final Configuration activityConfig = mActivity.getConfiguration(); |
| 302 | mActivity.setOrientation(SCREEN_ORIENTATION_PORTRAIT); |
| 303 | |
| 304 | assertEquals(Configuration.ORIENTATION_PORTRAIT, displayConfig.orientation); |
| 305 | assertEquals(Configuration.ORIENTATION_PORTRAIT, activityConfig.orientation); |
| 306 | |
| 307 | final ActivityRecord topActivity = WindowTestUtils.createTestActivityRecord(mStack); |
| 308 | topActivity.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 309 | |
| 310 | assertEquals(Configuration.ORIENTATION_LANDSCAPE, displayConfig.orientation); |
| 311 | // Although the activity requested portrait, it is not the top activity that determines |
| 312 | // the display orientation. So it should be able to inherit the orientation from parent. |
| 313 | // Otherwise its configuration will be inconsistent that its orientation is portrait but |
| 314 | // other screen configurations are in landscape, e.g. screenWidthDp, screenHeightDp, and |
| 315 | // window configuration. |
| 316 | assertEquals(Configuration.ORIENTATION_LANDSCAPE, activityConfig.orientation); |
| 317 | } |
| 318 | |
| 319 | @Test |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 320 | public void testReportOrientationChange() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 321 | mActivity.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
Garfield Tan | b677660 | 2019-02-20 14:44:26 -0800 | [diff] [blame] | 322 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 323 | mDisplayContent.getDisplayRotation().setFixedToUserRotation( |
Garfield Tan | a3f1903 | 2019-11-19 18:04:50 -0800 | [diff] [blame] | 324 | IWindowManager.FIXED_TO_USER_ROTATION_ENABLED); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 325 | reset(mTask); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 326 | mActivity.reportDescendantOrientationChangeIfNeeded(); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 327 | verify(mTask).onConfigurationChanged(any(Configuration.class)); |
Garfield Tan | b677660 | 2019-02-20 14:44:26 -0800 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | @Test |
Jeff Chang | 3b19efb | 2019-05-14 19:21:00 +0800 | [diff] [blame] | 331 | @FlakyTest(bugId = 131176283) |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 332 | public void testCreateRemoveStartingWindow() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 333 | mActivity.addStartingWindow(mPackageName, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 334 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 335 | false); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 336 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 337 | assertHasStartingWindow(mActivity); |
| 338 | mActivity.removeStartingWindow(); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 339 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 340 | assertNoStartingWindow(mActivity); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | @Test |
| 344 | public void testAddRemoveRace() { |
| 345 | // There was once a race condition between adding and removing starting windows |
Yunfan Chen | 4c6a8fc | 2020-05-13 14:47:38 +0900 | [diff] [blame] | 346 | final ActivityRecord appToken = mAppWindow.mActivityRecord; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 347 | for (int i = 0; i < 1000; i++) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 348 | appToken.addStartingWindow(mPackageName, |
| 349 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 350 | false); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 351 | appToken.removeStartingWindow(); |
| 352 | waitUntilHandlersIdle(); |
| 353 | assertNoStartingWindow(appToken); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
| 357 | @Test |
| 358 | public void testTransferStartingWindow() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 359 | final ActivityRecord activity1 = createIsolatedTestActivityRecord(); |
| 360 | final ActivityRecord activity2 = createIsolatedTestActivityRecord(); |
| 361 | activity1.addStartingWindow(mPackageName, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 362 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 363 | false); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 364 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 365 | activity2.addStartingWindow(mPackageName, |
| 366 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, activity1.appToken.asBinder(), |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 367 | true, true, false, true, false); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 368 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 369 | assertNoStartingWindow(activity1); |
| 370 | assertHasStartingWindow(activity2); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | @Test |
| 374 | public void testTransferStartingWindowWhileCreating() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 375 | final ActivityRecord activity1 = createIsolatedTestActivityRecord(); |
| 376 | final ActivityRecord activity2 = createIsolatedTestActivityRecord(); |
| 377 | ((TestWindowManagerPolicy) activity1.mWmService.mPolicy).setRunnableWhenAddingSplashScreen( |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 378 | () -> { |
| 379 | // Surprise, ...! Transfer window in the middle of the creation flow. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 380 | activity2.addStartingWindow(mPackageName, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 381 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 382 | activity1.appToken.asBinder(), true, true, false, |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 383 | true, false); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 384 | }); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 385 | activity1.addStartingWindow(mPackageName, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 386 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 387 | false); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 388 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 389 | assertNoStartingWindow(activity1); |
| 390 | assertHasStartingWindow(activity2); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 391 | } |
| 392 | |
wilsonshih | ca274ed | 2020-05-05 17:32:21 +0800 | [diff] [blame] | 393 | @Test |
| 394 | public void testTransferStartingWindowCanAnimate() { |
| 395 | final ActivityRecord activity1 = createIsolatedTestActivityRecord(); |
| 396 | final ActivityRecord activity2 = createIsolatedTestActivityRecord(); |
| 397 | activity1.addStartingWindow(mPackageName, |
| 398 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 399 | false); |
wilsonshih | ca274ed | 2020-05-05 17:32:21 +0800 | [diff] [blame] | 400 | waitUntilHandlersIdle(); |
| 401 | activity2.addStartingWindow(mPackageName, |
| 402 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, activity1.appToken.asBinder(), |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 403 | true, true, false, true, false); |
wilsonshih | ca274ed | 2020-05-05 17:32:21 +0800 | [diff] [blame] | 404 | waitUntilHandlersIdle(); |
| 405 | assertNoStartingWindow(activity1); |
| 406 | assertHasStartingWindow(activity2); |
| 407 | |
| 408 | // Assert that bottom activity is allowed to do animation. |
Issei Suzuki | 737b7f1 | 2020-05-25 14:54:06 +0200 | [diff] [blame] | 409 | ArrayList<WindowContainer> sources = new ArrayList<>(); |
| 410 | sources.add(activity2); |
wilsonshih | ca274ed | 2020-05-05 17:32:21 +0800 | [diff] [blame] | 411 | doReturn(true).when(activity2).okToAnimate(); |
| 412 | doReturn(true).when(activity2).isAnimating(); |
Issei Suzuki | 737b7f1 | 2020-05-25 14:54:06 +0200 | [diff] [blame] | 413 | assertTrue(activity2.applyAnimation(null, TRANSIT_ACTIVITY_OPEN, true, false, sources)); |
wilsonshih | ca274ed | 2020-05-05 17:32:21 +0800 | [diff] [blame] | 414 | } |
| 415 | |
Riddle Hsu | ffc1246 | 2020-05-27 17:43:25 +0800 | [diff] [blame] | 416 | @Test |
| 417 | public void testTransferStartingWindowFromFinishingActivity() { |
| 418 | mActivity.addStartingWindow(mPackageName, android.R.style.Theme, null /* compatInfo */, |
| 419 | "Test", 0 /* labelRes */, 0 /* icon */, 0 /* logo */, 0 /* windowFlags */, |
| 420 | null /* transferFrom */, true /* newTask */, true /* taskSwitch */, |
| 421 | false /* processRunning */, false /* allowTaskSnapshot */, |
| 422 | false /* activityCreate */); |
| 423 | waitUntilHandlersIdle(); |
| 424 | assertHasStartingWindow(mActivity); |
| 425 | mActivity.mStartingWindowState = ActivityRecord.STARTING_WINDOW_SHOWN; |
| 426 | |
| 427 | doCallRealMethod().when(mStack).startActivityLocked( |
| 428 | any(), any(), anyBoolean(), anyBoolean(), any()); |
| 429 | // Make mVisibleSetFromTransferredStartingWindow true. |
| 430 | final ActivityRecord middle = new ActivityTestsBase.ActivityBuilder(mWm.mAtmService) |
| 431 | .setTask(mTask).build(); |
| 432 | mStack.startActivityLocked(middle, null /* focusedTopActivity */, |
| 433 | false /* newTask */, false /* keepCurTransition */, null /* options */); |
| 434 | middle.makeFinishingLocked(); |
| 435 | |
| 436 | assertNull(mActivity.startingWindow); |
| 437 | assertHasStartingWindow(middle); |
| 438 | |
| 439 | final ActivityRecord top = new ActivityTestsBase.ActivityBuilder(mWm.mAtmService) |
| 440 | .setTask(mTask).build(); |
| 441 | // Expect the visibility should be updated to true when transferring starting window from |
| 442 | // a visible activity. |
| 443 | top.setVisible(false); |
| 444 | // The finishing middle should be able to transfer starting window to top. |
| 445 | mStack.startActivityLocked(top, null /* focusedTopActivity */, |
| 446 | false /* newTask */, false /* keepCurTransition */, null /* options */); |
| 447 | |
| 448 | assertNull(middle.startingWindow); |
| 449 | assertHasStartingWindow(top); |
| 450 | assertTrue(top.isVisible()); |
| 451 | // The activity was visible by mVisibleSetFromTransferredStartingWindow, so after its |
| 452 | // starting window is transferred, it should restore to invisible. |
| 453 | assertFalse(middle.isVisible()); |
| 454 | } |
| 455 | |
Louis Chang | 242be90 | 2020-06-03 12:24:45 +0800 | [diff] [blame] | 456 | @Test |
| 457 | public void testTransferStartingWindowSetFixedRotation() { |
| 458 | mWm.mIsFixedRotationTransformEnabled = true; |
| 459 | final ActivityRecord topActivity = createTestActivityRecordForGivenTask(mTask); |
| 460 | mTask.positionChildAt(topActivity, POSITION_TOP); |
| 461 | mActivity.addStartingWindow(mPackageName, |
| 462 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 463 | false); |
| 464 | waitUntilHandlersIdle(); |
| 465 | |
| 466 | // Make activities to have different rotation from it display and set fixed rotation |
| 467 | // transform to activity1. |
| 468 | int rotation = (mDisplayContent.getRotation() + 1) % 4; |
| 469 | mDisplayContent.setFixedRotationLaunchingApp(mActivity, rotation); |
| 470 | doReturn(rotation).when(mDisplayContent) |
| 471 | .rotationForActivityInDifferentOrientation(topActivity); |
| 472 | |
| 473 | // Make sure the fixed rotation transform linked to activity2 when adding starting window |
| 474 | // on activity2. |
| 475 | topActivity.addStartingWindow(mPackageName, |
| 476 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, mActivity.appToken.asBinder(), |
| 477 | false, false, false, true, false); |
| 478 | waitUntilHandlersIdle(); |
| 479 | assertTrue(topActivity.hasFixedRotationTransform()); |
| 480 | } |
| 481 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 482 | private ActivityRecord createIsolatedTestActivityRecord() { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 483 | final ActivityStack taskStack = createTaskStackOnDisplay(mDisplayContent); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 484 | final Task task = createTaskInStack(taskStack, 0 /* userId */); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 485 | return createTestActivityRecordForGivenTask(task); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 486 | } |
| 487 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 488 | private ActivityRecord createTestActivityRecordForGivenTask(Task task) { |
| 489 | final ActivityRecord activity = |
| 490 | WindowTestUtils.createTestActivityRecord(mDisplayContent); |
| 491 | task.addChild(activity, 0); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 492 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 493 | return activity; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | @Test |
| 497 | public void testTryTransferStartingWindowFromHiddenAboveToken() { |
| 498 | // Add two tasks on top of each other. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 499 | final ActivityRecord activityTop = createIsolatedTestActivityRecord(); |
| 500 | final ActivityRecord activityBottom = |
| 501 | createTestActivityRecordForGivenTask(activityTop.getTask()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 502 | |
| 503 | // Add a starting window. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 504 | activityTop.addStartingWindow(mPackageName, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 505 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 506 | false); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 507 | waitUntilHandlersIdle(); |
| 508 | |
| 509 | // Make the top one invisible, and try transferring the starting window from the top to the |
| 510 | // bottom one. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 511 | activityTop.setVisibility(false, false); |
| 512 | activityBottom.transferStartingWindowFromHiddenAboveTokenIfNeeded(); |
Yunfan Chen | dcb1fcf | 2019-02-07 19:08:41 +0900 | [diff] [blame] | 513 | waitUntilHandlersIdle(); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 514 | |
| 515 | // Assert that the bottom window now has the starting window. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 516 | assertNoStartingWindow(activityTop); |
| 517 | assertHasStartingWindow(activityBottom); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 518 | } |
| 519 | |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 520 | @Test |
| 521 | public void testTransitionAnimationBounds() { |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 522 | removeGlobalMinSizeRestriction(); |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 523 | final Rect stackBounds = new Rect(0, 0, 1000, 600); |
| 524 | final Rect taskBounds = new Rect(100, 400, 600, 800); |
Riddle Hsu | a71f8e0 | 2020-05-05 23:07:59 +0800 | [diff] [blame] | 525 | // Set the bounds and windowing mode to window configuration directly, otherwise the |
| 526 | // testing setups may be discarded by configuration resolving. |
| 527 | mStack.getWindowConfiguration().setBounds(stackBounds); |
| 528 | mTask.getWindowConfiguration().setBounds(taskBounds); |
| 529 | mActivity.getWindowConfiguration().setBounds(taskBounds); |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 530 | |
| 531 | // Check that anim bounds for freeform window match task bounds |
Riddle Hsu | a71f8e0 | 2020-05-05 23:07:59 +0800 | [diff] [blame] | 532 | mTask.getWindowConfiguration().setWindowingMode(WINDOWING_MODE_FREEFORM); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 533 | assertEquals(mTask.getBounds(), mActivity.getAnimationBounds(STACK_CLIP_NONE)); |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 534 | |
| 535 | // STACK_CLIP_AFTER_ANIM should use task bounds since they will be clipped by |
| 536 | // bounds animation layer. |
Riddle Hsu | a71f8e0 | 2020-05-05 23:07:59 +0800 | [diff] [blame] | 537 | mTask.getWindowConfiguration().setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 538 | assertEquals(mTask.getBounds(), mActivity.getAnimationBounds(STACK_CLIP_AFTER_ANIM)); |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 539 | |
Riddle Hsu | a71f8e0 | 2020-05-05 23:07:59 +0800 | [diff] [blame] | 540 | // Even the activity is smaller than task and it is not aligned to the top-left corner of |
| 541 | // task, the animation bounds the same as task and position should be zero because in real |
| 542 | // case the letterbox will fill the remaining area in task. |
| 543 | final Rect halfBounds = new Rect(taskBounds); |
| 544 | halfBounds.scale(0.5f); |
| 545 | mActivity.getWindowConfiguration().setBounds(halfBounds); |
| 546 | final Point animationPosition = new Point(); |
| 547 | mActivity.getAnimationPosition(animationPosition); |
| 548 | |
| 549 | assertEquals(taskBounds, mActivity.getAnimationBounds(STACK_CLIP_AFTER_ANIM)); |
| 550 | assertEquals(new Point(0, 0), animationPosition); |
| 551 | |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 552 | // STACK_CLIP_BEFORE_ANIM should use stack bounds since it won't be clipped later. |
Riddle Hsu | a71f8e0 | 2020-05-05 23:07:59 +0800 | [diff] [blame] | 553 | mTask.getWindowConfiguration().setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 554 | assertEquals(mStack.getBounds(), mActivity.getAnimationBounds(STACK_CLIP_BEFORE_ANIM)); |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Tarandeep Singh | 69ab104 | 2019-07-30 13:30:03 -0700 | [diff] [blame] | 557 | @Test |
| 558 | public void testHasStartingWindow() { |
| 559 | final WindowManager.LayoutParams attrs = |
| 560 | new WindowManager.LayoutParams(TYPE_APPLICATION_STARTING); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 561 | final WindowTestUtils.TestWindowState startingWindow = createWindowState(attrs, mActivity); |
| 562 | mActivity.startingDisplayed = true; |
| 563 | mActivity.addWindow(startingWindow); |
| 564 | assertTrue("Starting window should be present", mActivity.hasStartingWindow()); |
| 565 | mActivity.startingDisplayed = false; |
| 566 | assertTrue("Starting window should be present", mActivity.hasStartingWindow()); |
Tarandeep Singh | 69ab104 | 2019-07-30 13:30:03 -0700 | [diff] [blame] | 567 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 568 | mActivity.removeChild(startingWindow); |
| 569 | assertFalse("Starting window should not be present", mActivity.hasStartingWindow()); |
Tarandeep Singh | 69ab104 | 2019-07-30 13:30:03 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 572 | private void assertHasStartingWindow(ActivityRecord atoken) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 573 | assertNotNull(atoken.startingSurface); |
chaviw | a8f07a7 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 574 | assertNotNull(atoken.mStartingData); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 575 | assertNotNull(atoken.startingWindow); |
| 576 | } |
| 577 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 578 | private void assertNoStartingWindow(ActivityRecord atoken) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 579 | assertNull(atoken.startingSurface); |
| 580 | assertNull(atoken.startingWindow); |
chaviw | a8f07a7 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 581 | assertNull(atoken.mStartingData); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 582 | atoken.forAllWindows(windowState -> { |
| 583 | assertFalse(windowState.getBaseType() == TYPE_APPLICATION_STARTING); |
| 584 | }, true); |
| 585 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 586 | } |