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