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; |
| 24 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 25 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
Garfield Tan | b677660 | 2019-02-20 14:44:26 -0800 | [diff] [blame] | 26 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
| 30 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 32 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
wilsonshih | ca274ed | 2020-05-05 17:32:21 +0800 | [diff] [blame] | 34 | import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 35 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 36 | import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; |
| 37 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 38 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
wilsonshih | ca274ed | 2020-05-05 17:32:21 +0800 | [diff] [blame] | 39 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 40 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM; |
| 41 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM; |
| 42 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 43 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 44 | import static org.junit.Assert.assertEquals; |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 45 | import static org.junit.Assert.assertFalse; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 46 | import static org.junit.Assert.assertNotNull; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 47 | import static org.junit.Assert.assertNull; |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 48 | import static org.junit.Assert.assertTrue; |
Garfield Tan | b677660 | 2019-02-20 14:44:26 -0800 | [diff] [blame] | 49 | import static org.mockito.ArgumentMatchers.any; |
Riddle Hsu | a118b3a | 2018-10-11 22:05:06 +0800 | [diff] [blame] | 50 | import static org.mockito.ArgumentMatchers.anyInt; |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 51 | import static org.mockito.Mockito.reset; |
Garfield Tan | b677660 | 2019-02-20 14:44:26 -0800 | [diff] [blame] | 52 | import static org.mockito.Mockito.verify; |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 53 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 54 | import android.content.res.Configuration; |
Riddle Hsu | a118b3a | 2018-10-11 22:05:06 +0800 | [diff] [blame] | 55 | import android.graphics.Rect; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 56 | import android.platform.test.annotations.Presubmit; |
Garfield Tan | a3f1903 | 2019-11-19 18:04:50 -0800 | [diff] [blame] | 57 | import android.view.IWindowManager; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 58 | import android.view.Surface; |
| 59 | import android.view.WindowManager; |
| 60 | |
Yunfan Chen | c1caf6b | 2019-04-12 13:58:51 +0900 | [diff] [blame] | 61 | import androidx.test.filters.FlakyTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 62 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 63 | |
wilsonshih | ca274ed | 2020-05-05 17:32:21 +0800 | [diff] [blame] | 64 | import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; |
| 65 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 66 | import org.junit.Before; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 67 | import org.junit.Test; |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 68 | import org.junit.runner.RunWith; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 69 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 70 | /** |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 71 | * Tests for the {@link ActivityRecord} class. |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 72 | * |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 73 | * Build/Install/Run: |
Vishnu Nair | e6e2b0f | 2019-02-21 10:41:00 -0800 | [diff] [blame] | 74 | * atest WmTests:AppWindowTokenTests |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 75 | */ |
| 76 | @SmallTest |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 77 | @Presubmit |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 78 | @RunWith(WindowTestRunner.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 79 | public class AppWindowTokenTests extends WindowTestsBase { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 80 | |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 81 | ActivityStack mStack; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 82 | Task mTask; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 83 | ActivityRecord mActivity; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 84 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 85 | private final String mPackageName = getInstrumentation().getTargetContext().getPackageName(); |
| 86 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 87 | @Before |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 88 | public void setUp() throws Exception { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 89 | mStack = createTaskStackOnDisplay(mDisplayContent); |
| 90 | mTask = createTaskInStack(mStack, 0 /* userId */); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 91 | mActivity = WindowTestUtils.createTestActivityRecord(mDisplayContent); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 92 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 93 | mTask.addChild(mActivity, 0); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 96 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 97 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 98 | public void testAddWindow_Order() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 99 | assertEquals(0, mActivity.getChildCount()); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 100 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 101 | final WindowState win1 = createWindow(null, TYPE_APPLICATION, mActivity, "win1"); |
| 102 | final WindowState startingWin = createWindow(null, TYPE_APPLICATION_STARTING, mActivity, |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 103 | "startingWin"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 104 | final WindowState baseWin = createWindow(null, TYPE_BASE_APPLICATION, mActivity, "baseWin"); |
| 105 | final WindowState win4 = createWindow(null, TYPE_APPLICATION, mActivity, "win4"); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 106 | |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 107 | // Should not contain the windows that were added above. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 108 | assertEquals(4, mActivity.getChildCount()); |
| 109 | assertTrue(mActivity.mChildren.contains(win1)); |
| 110 | assertTrue(mActivity.mChildren.contains(startingWin)); |
| 111 | assertTrue(mActivity.mChildren.contains(baseWin)); |
| 112 | assertTrue(mActivity.mChildren.contains(win4)); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 113 | |
| 114 | // The starting window should be on-top of all other windows. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 115 | assertEquals(startingWin, mActivity.mChildren.peekLast()); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 116 | |
| 117 | // The base application window should be below all other windows. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 118 | assertEquals(baseWin, mActivity.mChildren.peekFirst()); |
| 119 | mActivity.removeImmediately(); |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 123 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 124 | public void testFindMainWindow() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 125 | assertNull(mActivity.findMainWindow()); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 126 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 127 | final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, mActivity, "window1"); |
| 128 | final WindowState window11 = createWindow(window1, FIRST_SUB_WINDOW, mActivity, "window11"); |
| 129 | final WindowState window12 = createWindow(window1, FIRST_SUB_WINDOW, mActivity, "window12"); |
| 130 | assertEquals(window1, mActivity.findMainWindow()); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 131 | window1.mAnimatingExit = true; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 132 | assertEquals(window1, mActivity.findMainWindow()); |
| 133 | final WindowState window2 = createWindow(null, TYPE_APPLICATION_STARTING, mActivity, |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 134 | "window2"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 135 | assertEquals(window2, mActivity.findMainWindow()); |
| 136 | mActivity.removeImmediately(); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 137 | } |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 138 | |
| 139 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 140 | @Presubmit |
Riddle Hsu | 84bc3d7 | 2019-12-19 19:24:07 +0800 | [diff] [blame] | 141 | public void testGetTopFullscreenOpaqueWindow() { |
| 142 | assertNull(mActivity.getTopFullscreenOpaqueWindow()); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 143 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 144 | final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, mActivity, "window1"); |
| 145 | final WindowState window11 = createWindow(null, TYPE_APPLICATION, mActivity, "window11"); |
| 146 | final WindowState window12 = createWindow(null, TYPE_APPLICATION, mActivity, "window12"); |
Riddle Hsu | 84bc3d7 | 2019-12-19 19:24:07 +0800 | [diff] [blame] | 147 | assertEquals(window12, mActivity.getTopFullscreenOpaqueWindow()); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 148 | window12.mAttrs.width = 500; |
Riddle Hsu | 84bc3d7 | 2019-12-19 19:24:07 +0800 | [diff] [blame] | 149 | assertEquals(window11, mActivity.getTopFullscreenOpaqueWindow()); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 150 | window11.mAttrs.width = 500; |
Riddle Hsu | 84bc3d7 | 2019-12-19 19:24:07 +0800 | [diff] [blame] | 151 | assertEquals(window1, mActivity.getTopFullscreenOpaqueWindow()); |
| 152 | window1.mAttrs.alpha = 0f; |
| 153 | assertNull(mActivity.getTopFullscreenOpaqueWindow()); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 154 | mActivity.removeImmediately(); |
Jorim Jaggi | 87fdbcb | 2017-08-17 13:41:11 +0200 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Test |
Wale Ogunwale | 815c7cb | 2019-05-02 08:04:01 -0700 | [diff] [blame] | 158 | @FlakyTest(bugId = 131005232) |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 159 | public void testLandscapeSeascapeRotationByApp() { |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 160 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( |
| 161 | TYPE_BASE_APPLICATION); |
| 162 | attrs.setTitle("AppWindow"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 163 | final WindowTestUtils.TestWindowState appWindow = createWindowState(attrs, mActivity); |
| 164 | mActivity.addWindow(appWindow); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 165 | |
| 166 | // Set initial orientation and update. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 167 | mActivity.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 168 | mDisplayContent.updateOrientation( |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 169 | mDisplayContent.getRequestedOverrideConfiguration(), |
| 170 | null /* freezeThisOneIfNeeded */, false /* forceUpdate */); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 171 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mDisplayContent.getLastOrientation()); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 172 | appWindow.mResizeReported = false; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 173 | |
| 174 | // 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] | 175 | mActivity.setOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 176 | mDisplayContent.updateOrientation( |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 177 | mDisplayContent.getRequestedOverrideConfiguration(), |
| 178 | null /* freezeThisOneIfNeeded */, false /* forceUpdate */); |
Yunfan Chen | 0530fe7 | 2019-02-12 15:05:49 +0900 | [diff] [blame] | 179 | // In this test, DC will not get config update. Set the waiting flag to false. |
| 180 | mDisplayContent.mWaitingForConfig = false; |
Riddle Hsu | 72d6dc3 | 2020-03-25 22:58:00 +0800 | [diff] [blame] | 181 | mWm.mRoot.performSurfacePlacement(); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 182 | assertEquals(SCREEN_ORIENTATION_REVERSE_LANDSCAPE, mDisplayContent.getLastOrientation()); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 183 | assertTrue(appWindow.mResizeReported); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 184 | appWindow.removeImmediately(); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 188 | public void testLandscapeSeascapeRotationByPolicy() { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 189 | // This instance has been spied in {@link TestDisplayContent}. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 190 | final DisplayRotation displayRotation = mDisplayContent.getDisplayRotation(); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 191 | |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 192 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( |
| 193 | TYPE_BASE_APPLICATION); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 194 | attrs.setTitle("RotationByPolicy"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 195 | final WindowTestUtils.TestWindowState appWindow = createWindowState(attrs, mActivity); |
| 196 | mActivity.addWindow(appWindow); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 197 | |
| 198 | // Set initial orientation and update. |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 199 | performRotation(displayRotation, Surface.ROTATION_90); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 200 | appWindow.mResizeReported = false; |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 201 | |
| 202 | // 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] | 203 | performRotation(displayRotation, Surface.ROTATION_270); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 204 | assertTrue(appWindow.mResizeReported); |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 205 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 206 | appWindow.removeImmediately(); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 207 | } |
Bryce Lee | 310de9e | 2017-03-15 10:18:21 -0700 | [diff] [blame] | 208 | |
Riddle Hsu | 5ce4bb3 | 2018-07-18 16:11:30 +0800 | [diff] [blame] | 209 | private void performRotation(DisplayRotation spiedRotation, int rotationToReport) { |
| 210 | doReturn(rotationToReport).when(spiedRotation).rotationForOrientation(anyInt(), anyInt()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 211 | mWm.updateRotation(false, false); |
Bryce Lee | 310de9e | 2017-03-15 10:18:21 -0700 | [diff] [blame] | 212 | } |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 213 | |
| 214 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 215 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 216 | public void testGetOrientation() { |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 217 | mActivity.setVisible(true); |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 218 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 219 | mActivity.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 220 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 221 | mActivity.setOccludesParent(false); |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 222 | // Can specify orientation if app doesn't occludes parent. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 223 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mActivity.getOrientation()); |
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(true); |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 226 | mActivity.setVisible(false); |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 227 | // 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] | 228 | assertEquals(SCREEN_ORIENTATION_UNSET, mActivity.getOrientation()); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 229 | // Can specify orientation if the current orientation candidate is orientation behind. |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 230 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 231 | mActivity.getOrientation(SCREEN_ORIENTATION_BEHIND)); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 232 | } |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 233 | |
| 234 | @Test |
Andrii Kulian | 6b3a371 | 2017-11-02 11:06:47 -0700 | [diff] [blame] | 235 | @Presubmit |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 236 | public void testKeyguardFlagsDuringRelaunch() { |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 237 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams( |
| 238 | TYPE_BASE_APPLICATION); |
| 239 | attrs.flags |= FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD; |
| 240 | attrs.setTitle("AppWindow"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 241 | final WindowTestUtils.TestWindowState appWindow = createWindowState(attrs, mActivity); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 242 | |
| 243 | // Add window with show when locked flag |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 244 | mActivity.addWindow(appWindow); |
| 245 | assertTrue(mActivity.containsShowWhenLockedWindow() && mActivity.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 246 | |
| 247 | // Start relaunching |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 248 | mActivity.startRelaunching(); |
| 249 | assertTrue(mActivity.containsShowWhenLockedWindow() && mActivity.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 250 | |
| 251 | // Remove window and make sure that we still report back flag |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 252 | mActivity.removeChild(appWindow); |
| 253 | assertTrue(mActivity.containsShowWhenLockedWindow() && mActivity.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 254 | |
| 255 | // Finish relaunching and ensure flag is now not reported |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 256 | mActivity.finishRelaunching(); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 257 | assertFalse( |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 258 | mActivity.containsShowWhenLockedWindow() || mActivity.containsDismissKeyguardWindow()); |
Bryce Lee | 081554b | 2017-05-25 07:52:12 -0700 | [diff] [blame] | 259 | } |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 260 | |
| 261 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 262 | public void testStuckExitingWindow() { |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 263 | final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, |
| 264 | "closingWindow"); |
| 265 | closingWindow.mAnimatingExit = true; |
| 266 | closingWindow.mRemoveOnExit = true; |
Issei Suzuki | 2bcbd68 | 2019-11-08 13:20:14 +0100 | [diff] [blame] | 267 | closingWindow.mActivityRecord.commitVisibility( |
| 268 | false /* visible */, true /* performLayout */); |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 269 | |
| 270 | // 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] | 271 | // by changing visibility of ActivityRecord |
Jorim Jaggi | ab9fcb2 | 2018-03-15 23:46:12 +0100 | [diff] [blame] | 272 | closingWindow.removeIfPossible(); |
| 273 | assertTrue(closingWindow.mRemoved); |
| 274 | } |
Riddle Hsu | a118b3a | 2018-10-11 22:05:06 +0800 | [diff] [blame] | 275 | |
| 276 | @Test |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 277 | public void testSetOrientation() { |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 278 | mActivity.setVisible(true); |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 279 | |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 280 | // Assert orientation is unspecified to start. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 281 | assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, mActivity.getOrientation()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 282 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 283 | mActivity.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 284 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, mActivity.getOrientation()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 285 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 286 | mDisplayContent.removeAppToken(mActivity.token); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 287 | // Assert orientation is unset to after container is removed. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 288 | assertEquals(SCREEN_ORIENTATION_UNSET, mActivity.getOrientation()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 289 | |
| 290 | // Reset display frozen state |
| 291 | mWm.mDisplayFrozen = false; |
| 292 | } |
| 293 | |
| 294 | @Test |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 295 | public void testReportOrientationChange() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 296 | mActivity.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
Garfield Tan | b677660 | 2019-02-20 14:44:26 -0800 | [diff] [blame] | 297 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 298 | mDisplayContent.getDisplayRotation().setFixedToUserRotation( |
Garfield Tan | a3f1903 | 2019-11-19 18:04:50 -0800 | [diff] [blame] | 299 | IWindowManager.FIXED_TO_USER_ROTATION_ENABLED); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 300 | reset(mTask); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 301 | mActivity.reportDescendantOrientationChangeIfNeeded(); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 302 | verify(mTask).onConfigurationChanged(any(Configuration.class)); |
Garfield Tan | b677660 | 2019-02-20 14:44:26 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | @Test |
Jeff Chang | 3b19efb | 2019-05-14 19:21:00 +0800 | [diff] [blame] | 306 | @FlakyTest(bugId = 131176283) |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 307 | public void testCreateRemoveStartingWindow() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 308 | mActivity.addStartingWindow(mPackageName, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 309 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 310 | false, false); |
| 311 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 312 | assertHasStartingWindow(mActivity); |
| 313 | mActivity.removeStartingWindow(); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 314 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 315 | assertNoStartingWindow(mActivity); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | @Test |
Yunfan Chen | c1caf6b | 2019-04-12 13:58:51 +0900 | [diff] [blame] | 319 | @FlakyTest(bugId = 130392471) |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 320 | public void testAddRemoveRace() { |
| 321 | // There was once a race condition between adding and removing starting windows |
| 322 | for (int i = 0; i < 1000; i++) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 323 | final ActivityRecord appToken = createIsolatedTestActivityRecord(); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 324 | |
| 325 | appToken.addStartingWindow(mPackageName, |
| 326 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 327 | false, false); |
| 328 | appToken.removeStartingWindow(); |
| 329 | waitUntilHandlersIdle(); |
| 330 | assertNoStartingWindow(appToken); |
| 331 | |
| 332 | appToken.getParent().getParent().removeImmediately(); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | @Test |
| 337 | public void testTransferStartingWindow() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 338 | final ActivityRecord activity1 = createIsolatedTestActivityRecord(); |
| 339 | final ActivityRecord activity2 = createIsolatedTestActivityRecord(); |
| 340 | activity1.addStartingWindow(mPackageName, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 341 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 342 | false, false); |
| 343 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 344 | activity2.addStartingWindow(mPackageName, |
| 345 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, activity1.appToken.asBinder(), |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 346 | true, true, false, true, false, false); |
| 347 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 348 | assertNoStartingWindow(activity1); |
| 349 | assertHasStartingWindow(activity2); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | @Test |
| 353 | public void testTransferStartingWindowWhileCreating() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 354 | final ActivityRecord activity1 = createIsolatedTestActivityRecord(); |
| 355 | final ActivityRecord activity2 = createIsolatedTestActivityRecord(); |
| 356 | ((TestWindowManagerPolicy) activity1.mWmService.mPolicy).setRunnableWhenAddingSplashScreen( |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 357 | () -> { |
| 358 | // Surprise, ...! Transfer window in the middle of the creation flow. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 359 | activity2.addStartingWindow(mPackageName, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 360 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 361 | activity1.appToken.asBinder(), true, true, false, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 362 | true, false, false); |
| 363 | }); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 364 | activity1.addStartingWindow(mPackageName, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 365 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 366 | false, false); |
| 367 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 368 | assertNoStartingWindow(activity1); |
| 369 | assertHasStartingWindow(activity2); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 370 | } |
| 371 | |
wilsonshih | ca274ed | 2020-05-05 17:32:21 +0800 | [diff] [blame] | 372 | @Test |
| 373 | public void testTransferStartingWindowCanAnimate() { |
| 374 | final ActivityRecord activity1 = createIsolatedTestActivityRecord(); |
| 375 | final ActivityRecord activity2 = createIsolatedTestActivityRecord(); |
| 376 | activity1.addStartingWindow(mPackageName, |
| 377 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 378 | false, false); |
| 379 | waitUntilHandlersIdle(); |
| 380 | activity2.addStartingWindow(mPackageName, |
| 381 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, activity1.appToken.asBinder(), |
| 382 | true, true, false, true, false, false); |
| 383 | waitUntilHandlersIdle(); |
| 384 | assertNoStartingWindow(activity1); |
| 385 | assertHasStartingWindow(activity2); |
| 386 | |
| 387 | // Assert that bottom activity is allowed to do animation. |
| 388 | doReturn(true).when(activity2).okToAnimate(); |
| 389 | doReturn(true).when(activity2).isAnimating(); |
| 390 | final OnAnimationFinishedCallback onAnimationFinishedCallback = |
| 391 | mock(OnAnimationFinishedCallback.class); |
| 392 | assertTrue(activity2.applyAnimation(null, TRANSIT_ACTIVITY_OPEN, true, false, |
| 393 | onAnimationFinishedCallback)); |
| 394 | } |
| 395 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 396 | private ActivityRecord createIsolatedTestActivityRecord() { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 397 | final ActivityStack taskStack = createTaskStackOnDisplay(mDisplayContent); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 398 | final Task task = createTaskInStack(taskStack, 0 /* userId */); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 399 | return createTestActivityRecordForGivenTask(task); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 400 | } |
| 401 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 402 | private ActivityRecord createTestActivityRecordForGivenTask(Task task) { |
| 403 | final ActivityRecord activity = |
| 404 | WindowTestUtils.createTestActivityRecord(mDisplayContent); |
| 405 | task.addChild(activity, 0); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 406 | waitUntilHandlersIdle(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 407 | return activity; |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | @Test |
| 411 | public void testTryTransferStartingWindowFromHiddenAboveToken() { |
| 412 | // Add two tasks on top of each other. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 413 | final ActivityRecord activityTop = createIsolatedTestActivityRecord(); |
| 414 | final ActivityRecord activityBottom = |
| 415 | createTestActivityRecordForGivenTask(activityTop.getTask()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 416 | |
| 417 | // Add a starting window. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 418 | activityTop.addStartingWindow(mPackageName, |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 419 | android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, |
| 420 | false, false); |
| 421 | waitUntilHandlersIdle(); |
| 422 | |
| 423 | // Make the top one invisible, and try transferring the starting window from the top to the |
| 424 | // bottom one. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 425 | activityTop.setVisibility(false, false); |
| 426 | activityBottom.transferStartingWindowFromHiddenAboveTokenIfNeeded(); |
Yunfan Chen | dcb1fcf | 2019-02-07 19:08:41 +0900 | [diff] [blame] | 427 | waitUntilHandlersIdle(); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 428 | |
| 429 | // Assert that the bottom window now has the starting window. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 430 | assertNoStartingWindow(activityTop); |
| 431 | assertHasStartingWindow(activityBottom); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 434 | @Test |
| 435 | public void testTransitionAnimationBounds() { |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 436 | removeGlobalMinSizeRestriction(); |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 437 | final Rect stackBounds = new Rect(0, 0, 1000, 600); |
| 438 | final Rect taskBounds = new Rect(100, 400, 600, 800); |
| 439 | mStack.setBounds(stackBounds); |
| 440 | mTask.setBounds(taskBounds); |
| 441 | |
| 442 | // Check that anim bounds for freeform window match task bounds |
| 443 | mTask.setWindowingMode(WINDOWING_MODE_FREEFORM); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 444 | assertEquals(mTask.getBounds(), mActivity.getAnimationBounds(STACK_CLIP_NONE)); |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 445 | |
| 446 | // STACK_CLIP_AFTER_ANIM should use task bounds since they will be clipped by |
| 447 | // bounds animation layer. |
| 448 | mTask.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 449 | assertEquals(mTask.getBounds(), mActivity.getAnimationBounds(STACK_CLIP_AFTER_ANIM)); |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 450 | |
| 451 | // STACK_CLIP_BEFORE_ANIM should use stack bounds since it won't be clipped later. |
| 452 | mTask.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 453 | assertEquals(mStack.getBounds(), mActivity.getAnimationBounds(STACK_CLIP_BEFORE_ANIM)); |
Evan Rosky | 641daea | 2019-04-24 14:45:24 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Tarandeep Singh | 69ab104 | 2019-07-30 13:30:03 -0700 | [diff] [blame] | 456 | @Test |
| 457 | public void testHasStartingWindow() { |
| 458 | final WindowManager.LayoutParams attrs = |
| 459 | new WindowManager.LayoutParams(TYPE_APPLICATION_STARTING); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 460 | final WindowTestUtils.TestWindowState startingWindow = createWindowState(attrs, mActivity); |
| 461 | mActivity.startingDisplayed = true; |
| 462 | mActivity.addWindow(startingWindow); |
| 463 | assertTrue("Starting window should be present", mActivity.hasStartingWindow()); |
| 464 | mActivity.startingDisplayed = false; |
| 465 | assertTrue("Starting window should be present", mActivity.hasStartingWindow()); |
Tarandeep Singh | 69ab104 | 2019-07-30 13:30:03 -0700 | [diff] [blame] | 466 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 467 | mActivity.removeChild(startingWindow); |
| 468 | assertFalse("Starting window should not be present", mActivity.hasStartingWindow()); |
Tarandeep Singh | 69ab104 | 2019-07-30 13:30:03 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 471 | private void assertHasStartingWindow(ActivityRecord atoken) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 472 | assertNotNull(atoken.startingSurface); |
chaviw | a8f07a7 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 473 | assertNotNull(atoken.mStartingData); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 474 | assertNotNull(atoken.startingWindow); |
| 475 | } |
| 476 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 477 | private void assertNoStartingWindow(ActivityRecord atoken) { |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 478 | assertNull(atoken.startingSurface); |
| 479 | assertNull(atoken.startingWindow); |
chaviw | a8f07a7 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 480 | assertNull(atoken.mStartingData); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 481 | atoken.forAllWindows(windowState -> { |
| 482 | assertFalse(windowState.getBaseType() == TYPE_APPLICATION_STARTING); |
| 483 | }, true); |
| 484 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 485 | } |