Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 1 | /* |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 2 | * Copyright (C) 2020 The Android Open Source Project |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 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 |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
| 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 24 | import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 27 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 28 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 29 | import static android.content.res.Configuration.SCREEN_HEIGHT_DP_UNDEFINED; |
| 30 | import static android.content.res.Configuration.SCREEN_WIDTH_DP_UNDEFINED; |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 32 | |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 33 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 34 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 35 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 36 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 37 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset; |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 38 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 39 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; |
| 40 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 41 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 42 | import static com.android.server.wm.DisplayArea.Type.ABOVE_TASKS; |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 43 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 44 | |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 45 | import static org.junit.Assert.assertEquals; |
Jorim Jaggi | 2a3002a | 2020-02-17 15:57:34 +0000 | [diff] [blame] | 46 | import static org.junit.Assert.assertFalse; |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 47 | import static org.junit.Assert.assertNotNull; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 48 | import static org.junit.Assert.assertTrue; |
| 49 | import static org.mockito.ArgumentMatchers.any; |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 50 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 51 | import static org.mockito.ArgumentMatchers.anyInt; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 52 | |
Winson Chung | 1df39e2 | 2020-04-09 14:30:55 -0700 | [diff] [blame] | 53 | import android.app.ActivityManager; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 54 | import android.app.ActivityManager.RunningTaskInfo; |
| 55 | import android.app.ActivityManager.StackInfo; |
Winson Chung | a1f869d | 2020-03-21 23:02:48 -0700 | [diff] [blame] | 56 | import android.app.IRequestFinishCallback; |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 57 | import android.app.PictureInPictureParams; |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 58 | import android.content.pm.ActivityInfo; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 59 | import android.content.res.Configuration; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 60 | import android.graphics.Rect; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 61 | import android.os.Binder; |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 62 | import android.os.IBinder; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 63 | import android.os.RemoteException; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 64 | import android.platform.test.annotations.Presubmit; |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 65 | import android.util.ArrayMap; |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 66 | import android.util.Rational; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 67 | import android.view.Display; |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 68 | import android.view.SurfaceControl; |
Wale Ogunwale | 5794658 | 2020-03-21 14:29:07 -0700 | [diff] [blame] | 69 | import android.window.ITaskOrganizer; |
chaviw | 5452169 | 2020-06-12 14:34:30 -0700 | [diff] [blame] | 70 | import android.window.IWindowContainerTransactionCallback; |
Wale Ogunwale | 5794658 | 2020-03-21 14:29:07 -0700 | [diff] [blame] | 71 | import android.window.WindowContainerTransaction; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 72 | |
| 73 | import androidx.test.filters.SmallTest; |
| 74 | |
Winson Chung | 1b5d055 | 2020-04-06 19:28:49 -0700 | [diff] [blame] | 75 | import org.junit.Before; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 76 | import org.junit.Test; |
| 77 | import org.junit.runner.RunWith; |
| 78 | |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 79 | import java.util.ArrayList; |
| 80 | import java.util.List; |
| 81 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 82 | /** |
Wale Ogunwale | 5794658 | 2020-03-21 14:29:07 -0700 | [diff] [blame] | 83 | * Test class for {@link ITaskOrganizer} and {@link android.window.ITaskOrganizerController}. |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 84 | * |
| 85 | * Build/Install/Run: |
Wale Ogunwale | 20ab6d4 | 2020-04-13 07:30:59 -0700 | [diff] [blame] | 86 | * atest WmTests:WindowOrganizerTests |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 87 | */ |
| 88 | @SmallTest |
| 89 | @Presubmit |
| 90 | @RunWith(WindowTestRunner.class) |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 91 | public class WindowOrganizerTests extends WindowTestsBase { |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 92 | private ITaskOrganizer registerMockOrganizer(int windowingMode) { |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 93 | final ITaskOrganizer organizer = mock(ITaskOrganizer.class); |
| 94 | when(organizer.asBinder()).thenReturn(new Binder()); |
| 95 | |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 96 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer( |
| 97 | organizer, windowingMode); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 98 | |
| 99 | return organizer; |
| 100 | } |
| 101 | |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 102 | private ITaskOrganizer registerMockOrganizer() { |
| 103 | return registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); |
| 104 | } |
| 105 | |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 106 | Task createTask(ActivityStack stack, boolean fakeDraw) { |
| 107 | final Task task = createTaskInStack(stack, 0); |
| 108 | |
| 109 | if (fakeDraw) { |
| 110 | task.setHasBeenVisible(true); |
| 111 | } |
| 112 | return task; |
| 113 | } |
| 114 | |
| 115 | Task createTask(ActivityStack stack) { |
| 116 | // Fake draw notifications for most of our tests. |
| 117 | return createTask(stack, true); |
| 118 | } |
| 119 | |
| 120 | ActivityStack createStack() { |
| 121 | return createTaskStackOnDisplay(mDisplayContent); |
| 122 | } |
| 123 | |
Winson Chung | 1b5d055 | 2020-04-06 19:28:49 -0700 | [diff] [blame] | 124 | @Before |
| 125 | public void setUp() { |
| 126 | // We defer callbacks since we need to adjust task surface visibility, but for these tests, |
| 127 | // just run the callbacks synchronously |
| 128 | mWm.mAtmService.mTaskOrganizerController.setDeferTaskOrgCallbacksConsumer((r) -> r.run()); |
| 129 | } |
| 130 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 131 | @Test |
| 132 | public void testAppearVanish() throws RemoteException { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 133 | final ActivityStack stack = createStack(); |
| 134 | final Task task = createTask(stack); |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 135 | final ITaskOrganizer organizer = registerMockOrganizer(); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 136 | |
| 137 | task.setTaskOrganizer(organizer); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 138 | verify(organizer).onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
| 139 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 140 | |
| 141 | task.removeImmediately(); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 142 | verify(organizer).onTaskVanished(any()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | @Test |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 146 | public void testAppearWaitsForVisibility() throws RemoteException { |
| 147 | final ActivityStack stack = createStack(); |
| 148 | final Task task = createTask(stack, false); |
| 149 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 150 | |
| 151 | task.setTaskOrganizer(organizer); |
| 152 | |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 153 | verify(organizer, never()) |
| 154 | .onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 155 | task.setHasBeenVisible(true); |
| 156 | assertTrue(stack.getHasBeenVisible()); |
| 157 | |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 158 | verify(organizer).onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 159 | |
| 160 | task.removeImmediately(); |
| 161 | verify(organizer).onTaskVanished(any()); |
| 162 | } |
| 163 | |
| 164 | @Test |
| 165 | public void testNoVanishedIfNoAppear() throws RemoteException { |
| 166 | final ActivityStack stack = createStack(); |
| 167 | final Task task = createTask(stack, false /* hasBeenVisible */); |
| 168 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 169 | |
| 170 | // In this test we skip making the Task visible, and verify |
| 171 | // that even though a TaskOrganizer is set remove doesn't emit |
| 172 | // a vanish callback, because we never emitted appear. |
| 173 | task.setTaskOrganizer(organizer); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 174 | verify(organizer, never()) |
| 175 | .onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 176 | task.removeImmediately(); |
| 177 | verify(organizer, never()).onTaskVanished(any()); |
| 178 | } |
| 179 | |
| 180 | @Test |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 181 | public void testSwapOrganizer() throws RemoteException { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 182 | final ActivityStack stack = createStack(); |
| 183 | final Task task = createTask(stack); |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 184 | final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); |
| 185 | final ITaskOrganizer organizer2 = registerMockOrganizer(WINDOWING_MODE_PINNED); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 186 | |
| 187 | task.setTaskOrganizer(organizer); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 188 | verify(organizer).onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 189 | task.setTaskOrganizer(organizer2); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 190 | verify(organizer).onTaskVanished(any()); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 191 | verify(organizer2).onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Test |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 195 | public void testSwapWindowingModes() throws RemoteException { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 196 | final ActivityStack stack = createStack(); |
| 197 | final Task task = createTask(stack); |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 198 | final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); |
| 199 | final ITaskOrganizer organizer2 = registerMockOrganizer(WINDOWING_MODE_PINNED); |
Rob Carr | ab17978 | 2020-03-10 12:50:30 -0700 | [diff] [blame] | 200 | |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 201 | stack.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 202 | verify(organizer).onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 203 | stack.setWindowingMode(WINDOWING_MODE_PINNED); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 204 | verify(organizer).onTaskVanished(any()); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 205 | verify(organizer2).onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | @Test |
Louis Chang | 9d35a3a | 2020-04-06 17:23:02 +0800 | [diff] [blame] | 209 | public void testTaskNoDraw() throws RemoteException { |
| 210 | final ActivityStack stack = createStack(); |
| 211 | final Task task = createTask(stack, false /* fakeDraw */); |
| 212 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 213 | |
| 214 | stack.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 215 | verify(organizer, never()) |
| 216 | .onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Louis Chang | 9d35a3a | 2020-04-06 17:23:02 +0800 | [diff] [blame] | 217 | assertTrue(stack.isOrganized()); |
| 218 | |
| 219 | mWm.mAtmService.mTaskOrganizerController.unregisterTaskOrganizer(organizer); |
| 220 | verify(organizer, never()).onTaskVanished(any()); |
| 221 | assertFalse(stack.isOrganized()); |
| 222 | } |
| 223 | |
| 224 | @Test |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 225 | public void testClearOrganizer() throws RemoteException { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 226 | final ActivityStack stack = createStack(); |
| 227 | final Task task = createTask(stack); |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 228 | final ITaskOrganizer organizer = registerMockOrganizer(); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 229 | |
Robert Carr | 9fd095b | 2020-01-24 14:40:06 -0800 | [diff] [blame] | 230 | stack.setTaskOrganizer(organizer); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 231 | verify(organizer).onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 232 | assertTrue(stack.isOrganized()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 233 | |
Robert Carr | 9fd095b | 2020-01-24 14:40:06 -0800 | [diff] [blame] | 234 | stack.setTaskOrganizer(null); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 235 | verify(organizer).onTaskVanished(any()); |
| 236 | assertFalse(stack.isOrganized()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | @Test |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 240 | public void testUnregisterOrganizer() throws RemoteException { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 241 | final ActivityStack stack = createStack(); |
| 242 | final Task task = createTask(stack); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 243 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 244 | |
| 245 | stack.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 246 | verify(organizer).onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 247 | assertTrue(stack.isOrganized()); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 248 | |
| 249 | mWm.mAtmService.mTaskOrganizerController.unregisterTaskOrganizer(organizer); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 250 | verify(organizer).onTaskVanished(any()); |
| 251 | assertFalse(stack.isOrganized()); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | @Test |
| 255 | public void testUnregisterOrganizerReturnsRegistrationToPrevious() throws RemoteException { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 256 | final ActivityStack stack = createStack(); |
| 257 | final Task task = createTask(stack); |
| 258 | final ActivityStack stack2 = createStack(); |
| 259 | final Task task2 = createTask(stack2); |
| 260 | final ActivityStack stack3 = createStack(); |
| 261 | final Task task3 = createTask(stack3); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 262 | final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); |
| 263 | |
| 264 | // First organizer is registered, verify a task appears when changing windowing mode |
| 265 | stack.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 266 | verify(organizer, times(1)) |
| 267 | .onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 268 | assertTrue(stack.isOrganized()); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 269 | |
| 270 | // Now we replace the registration and1 verify the new organizer receives tasks |
| 271 | // newly entering the windowing mode. |
| 272 | final ITaskOrganizer organizer2 = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); |
| 273 | stack2.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
Wale Ogunwale | 20ab6d4 | 2020-04-13 07:30:59 -0700 | [diff] [blame] | 274 | // One each for task and task2 |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 275 | verify(organizer2, times(2)) |
| 276 | .onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Wale Ogunwale | 20ab6d4 | 2020-04-13 07:30:59 -0700 | [diff] [blame] | 277 | verify(organizer2, times(0)).onTaskVanished(any()); |
| 278 | // One for task |
| 279 | verify(organizer).onTaskVanished(any()); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 280 | assertTrue(stack2.isOrganized()); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 281 | |
| 282 | // Now we unregister the second one, the first one should automatically be reregistered |
| 283 | // so we verify that it's now seeing changes. |
| 284 | mWm.mAtmService.mTaskOrganizerController.unregisterTaskOrganizer(organizer2); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 285 | verify(organizer, times(3)) |
| 286 | .onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Wale Ogunwale | 20ab6d4 | 2020-04-13 07:30:59 -0700 | [diff] [blame] | 287 | verify(organizer2, times(2)).onTaskVanished(any()); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 288 | |
| 289 | stack3.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 290 | verify(organizer, times(4)) |
| 291 | .onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Wale Ogunwale | 20ab6d4 | 2020-04-13 07:30:59 -0700 | [diff] [blame] | 292 | verify(organizer2, times(2)).onTaskVanished(any()); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 293 | assertTrue(stack3.isOrganized()); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | @Test |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 297 | public void testRegisterTaskOrganizerStackWindowingModeChanges() throws RemoteException { |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 298 | final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_PINNED); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 299 | |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 300 | final ActivityStack stack = createStack(); |
| 301 | final Task task = createTask(stack); |
| 302 | final Task task2 = createTask(stack); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 303 | stack.setWindowingMode(WINDOWING_MODE_PINNED); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 304 | verify(organizer, times(1)) |
| 305 | .onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 306 | |
| 307 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 308 | verify(organizer, times(1)).onTaskVanished(any()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 309 | } |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 310 | |
| 311 | @Test |
Winson Chung | 77338ab | 2020-03-09 16:32:34 -0700 | [diff] [blame] | 312 | public void testRegisterTaskOrganizerWithExistingTasks() throws RemoteException { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 313 | final ActivityStack stack = createStack(); |
| 314 | final Task task = createTask(stack); |
Winson Chung | 77338ab | 2020-03-09 16:32:34 -0700 | [diff] [blame] | 315 | stack.setWindowingMode(WINDOWING_MODE_PINNED); |
| 316 | |
| 317 | final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_PINNED); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 318 | verify(organizer, times(1)) |
| 319 | .onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Winson Chung | 77338ab | 2020-03-09 16:32:34 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | @Test |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 323 | public void testTaskTransaction() { |
| 324 | removeGlobalMinSizeRestriction(); |
| 325 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
| 326 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 327 | final Task task = stack.getTopMostTask(); |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 328 | testTransaction(task); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | @Test |
| 332 | public void testStackTransaction() { |
| 333 | removeGlobalMinSizeRestriction(); |
| 334 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
| 335 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 336 | StackInfo info = |
| 337 | mWm.mAtmService.getStackInfo(WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 338 | assertEquals(stack.mRemoteToken.toWindowContainerToken(), info.stackToken); |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 339 | testTransaction(stack); |
| 340 | } |
| 341 | |
| 342 | @Test |
| 343 | public void testDisplayAreaTransaction() { |
| 344 | removeGlobalMinSizeRestriction(); |
| 345 | final DisplayArea displayArea = new DisplayArea<>(mWm, ABOVE_TASKS, "DisplayArea"); |
| 346 | testTransaction(displayArea); |
| 347 | } |
| 348 | |
| 349 | private void testTransaction(WindowContainer wc) { |
| 350 | WindowContainerTransaction t = new WindowContainerTransaction(); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 351 | Rect newBounds = new Rect(10, 10, 100, 100); |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 352 | t.setBounds(wc.mRemoteToken.toWindowContainerToken(), new Rect(10, 10, 100, 100)); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 353 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 354 | assertEquals(newBounds, wc.getBounds()); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | @Test |
Robert Carr | 2bed621 | 2020-02-20 16:55:07 -0800 | [diff] [blame] | 358 | public void testSetWindowingMode() { |
| 359 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 360 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 361 | testSetWindowingMode(stack); |
| 362 | |
| 363 | final DisplayArea displayArea = new DisplayArea<>(mWm, ABOVE_TASKS, "DisplayArea"); |
| 364 | displayArea.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 365 | testSetWindowingMode(displayArea); |
| 366 | } |
| 367 | |
| 368 | private void testSetWindowingMode(WindowContainer wc) { |
Robert Carr | 2bed621 | 2020-02-20 16:55:07 -0800 | [diff] [blame] | 369 | final WindowContainerTransaction t = new WindowContainerTransaction(); |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 370 | t.setWindowingMode(wc.mRemoteToken.toWindowContainerToken(), WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 371 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 372 | assertEquals(WINDOWING_MODE_FULLSCREEN, wc.getWindowingMode()); |
Robert Carr | 2bed621 | 2020-02-20 16:55:07 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | @Test |
| 376 | public void testSetActivityWindowingMode() { |
| 377 | final ActivityRecord record = makePipableActivity(); |
| 378 | final ActivityStack stack = record.getStack(); |
| 379 | final WindowContainerTransaction t = new WindowContainerTransaction(); |
| 380 | |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 381 | t.setWindowingMode(stack.mRemoteToken.toWindowContainerToken(), WINDOWING_MODE_PINNED); |
| 382 | t.setActivityWindowingMode( |
| 383 | stack.mRemoteToken.toWindowContainerToken(), WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 384 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Robert Carr | 2bed621 | 2020-02-20 16:55:07 -0800 | [diff] [blame] | 385 | |
| 386 | assertEquals(WINDOWING_MODE_FULLSCREEN, record.getWindowingMode()); |
| 387 | assertEquals(WINDOWING_MODE_PINNED, stack.getWindowingMode()); |
| 388 | } |
| 389 | |
| 390 | @Test |
Robert Carr | f6878a4 | 2019-12-18 02:13:12 -0800 | [diff] [blame] | 391 | public void testContainerFocusableChanges() { |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 392 | removeGlobalMinSizeRestriction(); |
| 393 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
| 394 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 395 | final Task task = stack.getTopMostTask(); |
| 396 | WindowContainerTransaction t = new WindowContainerTransaction(); |
| 397 | assertTrue(task.isFocusable()); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 398 | t.setFocusable(stack.mRemoteToken.toWindowContainerToken(), false); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 399 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 400 | assertFalse(task.isFocusable()); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 401 | t.setFocusable(stack.mRemoteToken.toWindowContainerToken(), true); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 402 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Robert Carr | f6878a4 | 2019-12-18 02:13:12 -0800 | [diff] [blame] | 403 | assertTrue(task.isFocusable()); |
| 404 | } |
| 405 | |
| 406 | @Test |
| 407 | public void testContainerHiddenChanges() { |
| 408 | removeGlobalMinSizeRestriction(); |
| 409 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
| 410 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 411 | WindowContainerTransaction t = new WindowContainerTransaction(); |
| 412 | assertTrue(stack.shouldBeVisible(null)); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 413 | t.setHidden(stack.mRemoteToken.toWindowContainerToken(), true); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 414 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Robert Carr | f6878a4 | 2019-12-18 02:13:12 -0800 | [diff] [blame] | 415 | assertFalse(stack.shouldBeVisible(null)); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 416 | t.setHidden(stack.mRemoteToken.toWindowContainerToken(), false); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 417 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Robert Carr | f6878a4 | 2019-12-18 02:13:12 -0800 | [diff] [blame] | 418 | assertTrue(stack.shouldBeVisible(null)); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | @Test |
Evan Rosky | 05ec886 | 2020-02-28 19:37:04 -0800 | [diff] [blame] | 422 | public void testOverrideConfigSize() { |
| 423 | removeGlobalMinSizeRestriction(); |
| 424 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
| 425 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 426 | final Task task = stack.getTopMostTask(); |
| 427 | WindowContainerTransaction t = new WindowContainerTransaction(); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 428 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Evan Rosky | 05ec886 | 2020-02-28 19:37:04 -0800 | [diff] [blame] | 429 | final int origScreenWDp = task.getConfiguration().screenHeightDp; |
| 430 | final int origScreenHDp = task.getConfiguration().screenHeightDp; |
| 431 | t = new WindowContainerTransaction(); |
| 432 | // verify that setting config overrides on parent restricts children. |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 433 | t.setScreenSizeDp(stack.mRemoteToken |
Evan Rosky | c440b4e | 2020-04-17 15:11:22 -0700 | [diff] [blame] | 434 | .toWindowContainerToken(), origScreenWDp, origScreenHDp / 2); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 435 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Evan Rosky | c440b4e | 2020-04-17 15:11:22 -0700 | [diff] [blame] | 436 | assertEquals(origScreenHDp / 2, task.getConfiguration().screenHeightDp); |
Evan Rosky | 05ec886 | 2020-02-28 19:37:04 -0800 | [diff] [blame] | 437 | t = new WindowContainerTransaction(); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 438 | t.setScreenSizeDp(stack.mRemoteToken.toWindowContainerToken(), SCREEN_WIDTH_DP_UNDEFINED, |
| 439 | SCREEN_HEIGHT_DP_UNDEFINED); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 440 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Evan Rosky | c440b4e | 2020-04-17 15:11:22 -0700 | [diff] [blame] | 441 | assertEquals(origScreenHDp, task.getConfiguration().screenHeightDp); |
Evan Rosky | 05ec886 | 2020-02-28 19:37:04 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | @Test |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 445 | public void testCreateDeleteRootTasks() { |
| 446 | RunningTaskInfo info1 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
| 447 | Display.DEFAULT_DISPLAY, |
| 448 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 449 | assertEquals(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, |
| 450 | info1.configuration.windowConfiguration.getWindowingMode()); |
| 451 | assertEquals(ACTIVITY_TYPE_UNDEFINED, info1.topActivityType); |
| 452 | |
| 453 | RunningTaskInfo info2 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
| 454 | Display.DEFAULT_DISPLAY, |
| 455 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 456 | assertEquals(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, |
| 457 | info2.configuration.windowConfiguration.getWindowingMode()); |
| 458 | assertEquals(ACTIVITY_TYPE_UNDEFINED, info2.topActivityType); |
| 459 | |
| 460 | DisplayContent dc = mWm.mRoot.getDisplayContent(Display.DEFAULT_DISPLAY); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 461 | List<Task> infos = getTasksCreatedByOrganizer(dc); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 462 | assertEquals(2, infos.size()); |
| 463 | |
| 464 | assertTrue(mWm.mAtmService.mTaskOrganizerController.deleteRootTask(info1.token)); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 465 | infos = getTasksCreatedByOrganizer(dc); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 466 | assertEquals(1, infos.size()); |
| 467 | assertEquals(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, infos.get(0).getWindowingMode()); |
| 468 | } |
| 469 | |
| 470 | @Test |
| 471 | public void testTileAddRemoveChild() { |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 472 | ITaskOrganizer listener = new ITaskOrganizer.Stub() { |
| 473 | @Override |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 474 | public void onTaskAppeared(RunningTaskInfo taskInfo, SurfaceControl leash) { } |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 475 | |
| 476 | @Override |
| 477 | public void onTaskVanished(RunningTaskInfo container) { } |
| 478 | |
| 479 | @Override |
| 480 | public void onTaskInfoChanged(RunningTaskInfo info) throws RemoteException { |
| 481 | } |
Winson Chung | a1f869d | 2020-03-21 23:02:48 -0700 | [diff] [blame] | 482 | |
| 483 | @Override |
| 484 | public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { |
| 485 | } |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 486 | }; |
| 487 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer(listener, |
| 488 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 489 | RunningTaskInfo info1 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
| 490 | mDisplayContent.mDisplayId, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 491 | |
| 492 | final ActivityStack stack = createTaskStackOnDisplay( |
| 493 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, mDisplayContent); |
| 494 | assertEquals(mDisplayContent.getWindowingMode(), stack.getWindowingMode()); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 495 | WindowContainerTransaction wct = new WindowContainerTransaction(); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 496 | wct.reparent(stack.mRemoteToken.toWindowContainerToken(), info1.token, true /* onTop */); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 497 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 498 | assertEquals(info1.configuration.windowConfiguration.getWindowingMode(), |
| 499 | stack.getWindowingMode()); |
| 500 | |
| 501 | // Info should reflect new membership |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 502 | List<Task> infos = getTasksCreatedByOrganizer(mDisplayContent); |
| 503 | info1 = infos.get(0).getTaskInfo(); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 504 | assertEquals(ACTIVITY_TYPE_STANDARD, info1.topActivityType); |
| 505 | |
| 506 | // Children inherit configuration |
| 507 | Rect newSize = new Rect(10, 10, 300, 300); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 508 | Task task1 = WindowContainer.fromBinder(info1.token.asBinder()).asTask(); |
| 509 | Configuration c = new Configuration(task1.getRequestedOverrideConfiguration()); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 510 | c.windowConfiguration.setBounds(newSize); |
Riddle Hsu | dd49c63 | 2020-04-30 22:39:51 +0800 | [diff] [blame] | 511 | doNothing().when(stack).adjustForMinimalTaskDimensions(any(), any(), any()); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 512 | task1.onRequestedOverrideConfigurationChanged(c); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 513 | assertEquals(newSize, stack.getBounds()); |
| 514 | |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 515 | wct = new WindowContainerTransaction(); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 516 | wct.reparent(stack.mRemoteToken.toWindowContainerToken(), null, true /* onTop */); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 517 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 518 | assertEquals(mDisplayContent.getWindowingMode(), stack.getWindowingMode()); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 519 | infos = getTasksCreatedByOrganizer(mDisplayContent); |
| 520 | info1 = infos.get(0).getTaskInfo(); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 521 | assertEquals(ACTIVITY_TYPE_UNDEFINED, info1.topActivityType); |
| 522 | } |
| 523 | |
| 524 | @Test |
| 525 | public void testTaskInfoCallback() { |
| 526 | final ArrayList<RunningTaskInfo> lastReportedTiles = new ArrayList<>(); |
| 527 | final boolean[] called = {false}; |
| 528 | ITaskOrganizer listener = new ITaskOrganizer.Stub() { |
| 529 | @Override |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 530 | public void onTaskAppeared(RunningTaskInfo taskInfo, SurfaceControl leash) { } |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 531 | |
| 532 | @Override |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 533 | public void onTaskVanished(RunningTaskInfo container) { } |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 534 | |
| 535 | @Override |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 536 | public void onTaskInfoChanged(RunningTaskInfo info) throws RemoteException { |
| 537 | lastReportedTiles.add(info); |
| 538 | called[0] = true; |
| 539 | } |
Winson Chung | a1f869d | 2020-03-21 23:02:48 -0700 | [diff] [blame] | 540 | |
| 541 | @Override |
| 542 | public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { |
| 543 | } |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 544 | }; |
| 545 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer(listener, |
| 546 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 547 | RunningTaskInfo info1 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
| 548 | mDisplayContent.mDisplayId, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 549 | lastReportedTiles.clear(); |
| 550 | called[0] = false; |
| 551 | |
| 552 | final ActivityStack stack = createTaskStackOnDisplay( |
| 553 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, mDisplayContent); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 554 | Task task1 = WindowContainer.fromBinder(info1.token.asBinder()).asTask(); |
| 555 | WindowContainerTransaction wct = new WindowContainerTransaction(); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 556 | wct.reparent(stack.mRemoteToken.toWindowContainerToken(), info1.token, true /* onTop */); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 557 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 558 | assertTrue(called[0]); |
| 559 | assertEquals(ACTIVITY_TYPE_STANDARD, lastReportedTiles.get(0).topActivityType); |
| 560 | |
| 561 | lastReportedTiles.clear(); |
| 562 | called[0] = false; |
| 563 | final ActivityStack stack2 = createTaskStackOnDisplay( |
| 564 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME, mDisplayContent); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 565 | wct = new WindowContainerTransaction(); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 566 | wct.reparent(stack2.mRemoteToken.toWindowContainerToken(), info1.token, true /* onTop */); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 567 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 568 | assertTrue(called[0]); |
| 569 | assertEquals(ACTIVITY_TYPE_HOME, lastReportedTiles.get(0).topActivityType); |
| 570 | |
| 571 | lastReportedTiles.clear(); |
| 572 | called[0] = false; |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 573 | task1.positionChildAt(POSITION_TOP, stack, false /* includingParents */); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 574 | assertTrue(called[0]); |
| 575 | assertEquals(ACTIVITY_TYPE_STANDARD, lastReportedTiles.get(0).topActivityType); |
| 576 | |
| 577 | lastReportedTiles.clear(); |
| 578 | called[0] = false; |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 579 | wct = new WindowContainerTransaction(); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 580 | wct.reparent(stack.mRemoteToken.toWindowContainerToken(), null, true /* onTop */); |
| 581 | wct.reparent(stack2.mRemoteToken.toWindowContainerToken(), null, true /* onTop */); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 582 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 583 | assertTrue(called[0]); |
| 584 | assertEquals(ACTIVITY_TYPE_UNDEFINED, lastReportedTiles.get(0).topActivityType); |
| 585 | } |
| 586 | |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 587 | @Test |
| 588 | public void testHierarchyTransaction() { |
| 589 | final ArrayMap<IBinder, RunningTaskInfo> lastReportedTiles = new ArrayMap<>(); |
| 590 | ITaskOrganizer listener = new ITaskOrganizer.Stub() { |
| 591 | @Override |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 592 | public void onTaskAppeared(RunningTaskInfo taskInfo, SurfaceControl leash) { } |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 593 | |
| 594 | @Override |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 595 | public void onTaskVanished(RunningTaskInfo container) { } |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 596 | |
| 597 | @Override |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 598 | public void onTaskInfoChanged(RunningTaskInfo info) { |
| 599 | lastReportedTiles.put(info.token.asBinder(), info); |
| 600 | } |
Winson Chung | a1f869d | 2020-03-21 23:02:48 -0700 | [diff] [blame] | 601 | |
| 602 | @Override |
| 603 | public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { |
| 604 | } |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 605 | }; |
| 606 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer( |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 607 | listener, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 608 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer( |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 609 | listener, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 610 | RunningTaskInfo info1 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 611 | mDisplayContent.mDisplayId, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 612 | RunningTaskInfo info2 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
| 613 | mDisplayContent.mDisplayId, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 614 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 615 | final int initialRootTaskCount = mWm.mAtmService.mTaskOrganizerController.getRootTasks( |
| 616 | mDisplayContent.mDisplayId, null /* activityTypes */).size(); |
| 617 | |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 618 | final ActivityStack stack = createTaskStackOnDisplay( |
| 619 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, mDisplayContent); |
| 620 | final ActivityStack stack2 = createTaskStackOnDisplay( |
| 621 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME, mDisplayContent); |
| 622 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 623 | // Check getRootTasks works |
| 624 | List<RunningTaskInfo> roots = mWm.mAtmService.mTaskOrganizerController.getRootTasks( |
| 625 | mDisplayContent.mDisplayId, null /* activityTypes */); |
| 626 | assertEquals(initialRootTaskCount + 2, roots.size()); |
| 627 | |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 628 | lastReportedTiles.clear(); |
| 629 | WindowContainerTransaction wct = new WindowContainerTransaction(); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 630 | wct.reparent(stack.mRemoteToken.toWindowContainerToken(), info1.token, true /* onTop */); |
| 631 | wct.reparent(stack2.mRemoteToken.toWindowContainerToken(), info2.token, true /* onTop */); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 632 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 633 | assertFalse(lastReportedTiles.isEmpty()); |
| 634 | assertEquals(ACTIVITY_TYPE_STANDARD, |
| 635 | lastReportedTiles.get(info1.token.asBinder()).topActivityType); |
| 636 | assertEquals(ACTIVITY_TYPE_HOME, |
| 637 | lastReportedTiles.get(info2.token.asBinder()).topActivityType); |
| 638 | |
| 639 | lastReportedTiles.clear(); |
| 640 | wct = new WindowContainerTransaction(); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 641 | wct.reparent(stack2.mRemoteToken.toWindowContainerToken(), info1.token, false /* onTop */); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 642 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 643 | assertFalse(lastReportedTiles.isEmpty()); |
| 644 | // Standard should still be on top of tile 1, so no change there |
| 645 | assertFalse(lastReportedTiles.containsKey(info1.token.asBinder())); |
| 646 | // But tile 2 has no children, so should become undefined |
| 647 | assertEquals(ACTIVITY_TYPE_UNDEFINED, |
| 648 | lastReportedTiles.get(info2.token.asBinder()).topActivityType); |
| 649 | |
| 650 | // Check the getChildren call |
| 651 | List<RunningTaskInfo> children = |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 652 | mWm.mAtmService.mTaskOrganizerController.getChildTasks(info1.token, |
| 653 | null /* activityTypes */); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 654 | assertEquals(2, children.size()); |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 655 | children = mWm.mAtmService.mTaskOrganizerController.getChildTasks(info2.token, |
| 656 | null /* activityTypes */); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 657 | assertEquals(0, children.size()); |
| 658 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 659 | // Check that getRootTasks doesn't include children of tiles |
| 660 | roots = mWm.mAtmService.mTaskOrganizerController.getRootTasks(mDisplayContent.mDisplayId, |
| 661 | null /* activityTypes */); |
| 662 | assertEquals(initialRootTaskCount, roots.size()); |
| 663 | |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 664 | lastReportedTiles.clear(); |
| 665 | wct = new WindowContainerTransaction(); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 666 | wct.reorder(stack2.mRemoteToken.toWindowContainerToken(), true /* onTop */); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 667 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 668 | // Home should now be on top. No change occurs in second tile, so not reported |
| 669 | assertEquals(1, lastReportedTiles.size()); |
| 670 | assertEquals(ACTIVITY_TYPE_HOME, |
| 671 | lastReportedTiles.get(info1.token.asBinder()).topActivityType); |
| 672 | } |
| 673 | |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 674 | private List<Task> getTasksCreatedByOrganizer(DisplayContent dc) { |
| 675 | ArrayList<Task> out = new ArrayList<>(); |
Andrii Kulian | f9df4a8 | 2020-03-31 12:09:27 -0700 | [diff] [blame] | 676 | for (int tdaNdx = dc.getTaskDisplayAreaCount() - 1; tdaNdx >= 0; --tdaNdx) { |
| 677 | final TaskDisplayArea taskDisplayArea = dc.getTaskDisplayAreaAt(tdaNdx); |
| 678 | for (int sNdx = taskDisplayArea.getStackCount() - 1; sNdx >= 0; --sNdx) { |
| 679 | final Task t = taskDisplayArea.getStackAt(sNdx); |
| 680 | if (t.mCreatedByOrganizer) out.add(t); |
| 681 | } |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 682 | } |
| 683 | return out; |
| 684 | } |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 685 | |
| 686 | @Test |
| 687 | public void testTrivialBLASTCallback() throws RemoteException { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 688 | final ActivityStack stackController1 = createStack(); |
| 689 | final Task task = createTask(stackController1); |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 690 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 691 | |
Robert Carr | 8ccc4fc | 2020-03-13 10:48:49 -0700 | [diff] [blame] | 692 | spyOn(task); |
| 693 | doReturn(true).when(task).isVisible(); |
| 694 | |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 695 | BLASTSyncEngine bse = new BLASTSyncEngine(); |
| 696 | |
| 697 | BLASTSyncEngine.TransactionReadyListener transactionListener = |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 698 | mock(BLASTSyncEngine.TransactionReadyListener.class); |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 699 | |
| 700 | int id = bse.startSyncSet(transactionListener); |
| 701 | bse.addToSyncSet(id, task); |
| 702 | bse.setReady(id); |
| 703 | // Since this task has no windows the sync is trivial and completes immediately. |
| 704 | verify(transactionListener) |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 705 | .onTransactionReady(anyInt(), any()); |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | @Test |
Robert Carr | 8ccc4fc | 2020-03-13 10:48:49 -0700 | [diff] [blame] | 709 | public void testOverlappingBLASTCallback() throws RemoteException { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 710 | final ActivityStack stackController1 = createStack(); |
| 711 | final Task task = createTask(stackController1); |
Robert Carr | 8ccc4fc | 2020-03-13 10:48:49 -0700 | [diff] [blame] | 712 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 713 | |
| 714 | spyOn(task); |
| 715 | doReturn(true).when(task).isVisible(); |
| 716 | final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); |
| 717 | makeWindowVisible(w); |
| 718 | |
| 719 | BLASTSyncEngine bse = new BLASTSyncEngine(); |
| 720 | |
| 721 | BLASTSyncEngine.TransactionReadyListener transactionListener = |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 722 | mock(BLASTSyncEngine.TransactionReadyListener.class); |
Robert Carr | 8ccc4fc | 2020-03-13 10:48:49 -0700 | [diff] [blame] | 723 | |
| 724 | int id = bse.startSyncSet(transactionListener); |
| 725 | assertEquals(true, bse.addToSyncSet(id, task)); |
| 726 | bse.setReady(id); |
| 727 | |
| 728 | int id2 = bse.startSyncSet(transactionListener); |
| 729 | // We should be rejected from the second sync since we are already |
| 730 | // in one. |
| 731 | assertEquals(false, bse.addToSyncSet(id2, task)); |
chaviw | 5452169 | 2020-06-12 14:34:30 -0700 | [diff] [blame] | 732 | finishAndNotifyDrawing(w); |
Robert Carr | 8ccc4fc | 2020-03-13 10:48:49 -0700 | [diff] [blame] | 733 | assertEquals(true, bse.addToSyncSet(id2, task)); |
| 734 | bse.setReady(id2); |
| 735 | } |
| 736 | |
| 737 | @Test |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 738 | public void testBLASTCallbackWithWindow() { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 739 | final ActivityStack stackController1 = createStack(); |
| 740 | final Task task = createTask(stackController1); |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 741 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 742 | final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); |
Rob Carr | cba6a72 | 2020-03-10 12:41:06 -0700 | [diff] [blame] | 743 | makeWindowVisible(w); |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 744 | |
| 745 | BLASTSyncEngine bse = new BLASTSyncEngine(); |
| 746 | |
| 747 | BLASTSyncEngine.TransactionReadyListener transactionListener = |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 748 | mock(BLASTSyncEngine.TransactionReadyListener.class); |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 749 | |
| 750 | int id = bse.startSyncSet(transactionListener); |
| 751 | bse.addToSyncSet(id, task); |
| 752 | bse.setReady(id); |
| 753 | // Since we have a window we have to wait for it to draw to finish sync. |
| 754 | verify(transactionListener, never()) |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 755 | .onTransactionReady(anyInt(), any()); |
chaviw | 5452169 | 2020-06-12 14:34:30 -0700 | [diff] [blame] | 756 | finishAndNotifyDrawing(w); |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 757 | verify(transactionListener) |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 758 | .onTransactionReady(anyInt(), any()); |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 759 | } |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 760 | |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 761 | @Test |
Robert Carr | 6a08d32 | 2020-05-19 10:21:55 -0700 | [diff] [blame] | 762 | public void testBLASTCallbackNoDoubleAdd() { |
| 763 | final ActivityStack stackController1 = createStack(); |
| 764 | final Task task = createTask(stackController1); |
| 765 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 766 | final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); |
| 767 | makeWindowVisible(w); |
| 768 | |
| 769 | BLASTSyncEngine bse = new BLASTSyncEngine(); |
| 770 | |
| 771 | BLASTSyncEngine.TransactionReadyListener transactionListener = |
| 772 | mock(BLASTSyncEngine.TransactionReadyListener.class); |
| 773 | |
| 774 | int id = bse.startSyncSet(transactionListener); |
| 775 | assertTrue(bse.addToSyncSet(id, w)); |
| 776 | assertFalse(bse.addToSyncSet(id, w)); |
| 777 | |
| 778 | // Clean-up |
| 779 | bse.setReady(id); |
| 780 | } |
| 781 | |
| 782 | |
| 783 | @Test |
Rob Carr | cba6a72 | 2020-03-10 12:41:06 -0700 | [diff] [blame] | 784 | public void testBLASTCallbackWithInvisibleWindow() { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 785 | final ActivityStack stackController1 = createStack(); |
| 786 | final Task task = createTask(stackController1); |
Rob Carr | cba6a72 | 2020-03-10 12:41:06 -0700 | [diff] [blame] | 787 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 788 | final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); |
| 789 | |
| 790 | BLASTSyncEngine bse = new BLASTSyncEngine(); |
| 791 | |
| 792 | BLASTSyncEngine.TransactionReadyListener transactionListener = |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 793 | mock(BLASTSyncEngine.TransactionReadyListener.class); |
Rob Carr | cba6a72 | 2020-03-10 12:41:06 -0700 | [diff] [blame] | 794 | |
| 795 | int id = bse.startSyncSet(transactionListener); |
| 796 | bse.addToSyncSet(id, task); |
| 797 | bse.setReady(id); |
| 798 | |
| 799 | // Since the window was invisible, the Task had no visible leaves and the sync should |
| 800 | // complete as soon as we call setReady. |
| 801 | verify(transactionListener) |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 802 | .onTransactionReady(anyInt(), any()); |
Rob Carr | cba6a72 | 2020-03-10 12:41:06 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | @Test |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 806 | public void testBLASTCallbackWithChildWindow() { |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 807 | final ActivityStack stackController1 = createStack(); |
| 808 | final Task task = createTask(stackController1); |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 809 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 810 | final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); |
| 811 | final WindowState child = createWindow(w, TYPE_APPLICATION, "Other Window"); |
| 812 | |
| 813 | w.mActivityRecord.setVisible(true); |
| 814 | makeWindowVisible(w, child); |
| 815 | |
| 816 | BLASTSyncEngine bse = new BLASTSyncEngine(); |
| 817 | |
| 818 | BLASTSyncEngine.TransactionReadyListener transactionListener = |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 819 | mock(BLASTSyncEngine.TransactionReadyListener.class); |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 820 | |
| 821 | int id = bse.startSyncSet(transactionListener); |
| 822 | assertEquals(true, bse.addToSyncSet(id, task)); |
| 823 | bse.setReady(id); |
chaviw | 5452169 | 2020-06-12 14:34:30 -0700 | [diff] [blame] | 824 | finishAndNotifyDrawing(w); |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 825 | |
| 826 | // Since we have a child window we still shouldn't be done. |
| 827 | verify(transactionListener, never()) |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 828 | .onTransactionReady(anyInt(), any()); |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 829 | reset(transactionListener); |
| 830 | |
chaviw | 5452169 | 2020-06-12 14:34:30 -0700 | [diff] [blame] | 831 | finishAndNotifyDrawing(child); |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 832 | // Ah finally! Done |
| 833 | verify(transactionListener) |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 834 | .onTransactionReady(anyInt(), any()); |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 837 | class StubOrganizer extends ITaskOrganizer.Stub { |
| 838 | RunningTaskInfo mInfo; |
| 839 | |
| 840 | @Override |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 841 | public void onTaskAppeared(RunningTaskInfo info, SurfaceControl leash) { |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 842 | mInfo = info; |
| 843 | } |
| 844 | @Override |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 845 | public void onTaskVanished(RunningTaskInfo info) { |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 846 | } |
| 847 | @Override |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 848 | public void onTaskInfoChanged(RunningTaskInfo info) { |
| 849 | } |
Winson Chung | a1f869d | 2020-03-21 23:02:48 -0700 | [diff] [blame] | 850 | @Override |
| 851 | public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { |
| 852 | } |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 853 | }; |
| 854 | |
| 855 | private ActivityRecord makePipableActivity() { |
| 856 | final ActivityRecord record = createActivityRecord(mDisplayContent, |
| 857 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
| 858 | record.info.flags |= ActivityInfo.FLAG_SUPPORTS_PICTURE_IN_PICTURE; |
| 859 | spyOn(record); |
| 860 | doReturn(true).when(record).checkEnterPictureInPictureState(any(), anyBoolean()); |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 861 | |
Evan Rosky | 2af969c | 2020-05-08 16:26:31 +0000 | [diff] [blame] | 862 | record.getTask().setHasBeenVisible(true); |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 863 | return record; |
| 864 | } |
| 865 | |
| 866 | @Test |
| 867 | public void testEnterPipParams() { |
| 868 | final StubOrganizer o = new StubOrganizer(); |
| 869 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer(o, WINDOWING_MODE_PINNED); |
| 870 | final ActivityRecord record = makePipableActivity(); |
| 871 | |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 872 | final PictureInPictureParams p = new PictureInPictureParams.Builder() |
| 873 | .setAspectRatio(new Rational(1, 2)).build(); |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 874 | assertTrue(mWm.mAtmService.enterPictureInPictureMode(record.token, p)); |
| 875 | waitUntilHandlersIdle(); |
| 876 | assertNotNull(o.mInfo); |
| 877 | assertNotNull(o.mInfo.pictureInPictureParams); |
| 878 | } |
| 879 | |
| 880 | @Test |
| 881 | public void testChangePipParams() { |
| 882 | class ChangeSavingOrganizer extends StubOrganizer { |
| 883 | RunningTaskInfo mChangedInfo; |
| 884 | @Override |
| 885 | public void onTaskInfoChanged(RunningTaskInfo info) { |
| 886 | mChangedInfo = info; |
| 887 | } |
| 888 | } |
| 889 | ChangeSavingOrganizer o = new ChangeSavingOrganizer(); |
| 890 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer(o, WINDOWING_MODE_PINNED); |
| 891 | |
| 892 | final ActivityRecord record = makePipableActivity(); |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 893 | final PictureInPictureParams p = new PictureInPictureParams.Builder() |
| 894 | .setAspectRatio(new Rational(1, 2)).build(); |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 895 | assertTrue(mWm.mAtmService.enterPictureInPictureMode(record.token, p)); |
| 896 | waitUntilHandlersIdle(); |
| 897 | assertNotNull(o.mInfo); |
| 898 | assertNotNull(o.mInfo.pictureInPictureParams); |
| 899 | |
chaviw | 6630d85 | 2020-04-15 19:06:56 -0700 | [diff] [blame] | 900 | final PictureInPictureParams p2 = new PictureInPictureParams.Builder() |
| 901 | .setAspectRatio(new Rational(3, 4)).build(); |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 902 | mWm.mAtmService.setPictureInPictureParams(record.token, p2); |
| 903 | waitUntilHandlersIdle(); |
| 904 | assertNotNull(o.mChangedInfo); |
| 905 | assertNotNull(o.mChangedInfo.pictureInPictureParams); |
| 906 | final Rational ratio = o.mChangedInfo.pictureInPictureParams.getAspectRatioRational(); |
| 907 | assertEquals(3, ratio.getNumerator()); |
| 908 | assertEquals(4, ratio.getDenominator()); |
| 909 | } |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 910 | |
| 911 | @Test |
Winson Chung | 1df39e2 | 2020-04-09 14:30:55 -0700 | [diff] [blame] | 912 | public void testChangeTaskDescription() { |
| 913 | class ChangeSavingOrganizer extends StubOrganizer { |
| 914 | RunningTaskInfo mChangedInfo; |
| 915 | @Override |
| 916 | public void onTaskInfoChanged(RunningTaskInfo info) { |
| 917 | mChangedInfo = info; |
| 918 | } |
| 919 | } |
| 920 | ChangeSavingOrganizer o = new ChangeSavingOrganizer(); |
| 921 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer(o, |
| 922 | WINDOWING_MODE_MULTI_WINDOW); |
| 923 | |
| 924 | final ActivityStack stack = createStack(); |
| 925 | final Task task = createTask(stack); |
| 926 | final ActivityRecord record = WindowTestUtils.createActivityRecordInTask( |
| 927 | stack.mDisplayContent, task); |
| 928 | |
| 929 | stack.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
| 930 | record.setTaskDescription(new ActivityManager.TaskDescription("TestDescription")); |
| 931 | waitUntilHandlersIdle(); |
| 932 | assertEquals("TestDescription", o.mChangedInfo.taskDescription.getLabel()); |
| 933 | } |
| 934 | |
| 935 | @Test |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 936 | public void testPreventDuplicateAppear() throws RemoteException { |
| 937 | final ActivityStack stack = createStack(); |
| 938 | final Task task = createTask(stack); |
| 939 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 940 | |
| 941 | task.setTaskOrganizer(organizer); |
| 942 | // setHasBeenVisible was already called once by the set-up code. |
| 943 | task.setHasBeenVisible(true); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 944 | verify(organizer, times(1)) |
| 945 | .onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 946 | |
Wale Ogunwale | 20ab6d4 | 2020-04-13 07:30:59 -0700 | [diff] [blame] | 947 | task.setTaskOrganizer(null); |
| 948 | verify(organizer, times(1)).onTaskVanished(any()); |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 949 | task.setTaskOrganizer(organizer); |
chaviw | 7de5000 | 2020-04-27 12:33:30 -0700 | [diff] [blame] | 950 | verify(organizer, times(2)) |
| 951 | .onTaskAppeared(any(RunningTaskInfo.class), any(SurfaceControl.class)); |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 952 | |
| 953 | task.removeImmediately(); |
Wale Ogunwale | 20ab6d4 | 2020-04-13 07:30:59 -0700 | [diff] [blame] | 954 | verify(organizer, times(2)).onTaskVanished(any()); |
Robert Carr | de96c8a | 2020-03-24 15:22:21 -0700 | [diff] [blame] | 955 | } |
Winson Chung | a1f869d | 2020-03-21 23:02:48 -0700 | [diff] [blame] | 956 | |
| 957 | @Test |
| 958 | public void testInterceptBackPressedOnTaskRoot() throws RemoteException { |
| 959 | final ActivityStack stack = createStack(); |
| 960 | final Task task = createTask(stack); |
| 961 | final ActivityRecord activity = WindowTestUtils.createActivityRecordInTask( |
| 962 | stack.mDisplayContent, task); |
| 963 | final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); |
| 964 | |
| 965 | // Setup the task to be controlled by the MW mode organizer |
| 966 | stack.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
| 967 | assertTrue(stack.isOrganized()); |
| 968 | |
| 969 | // Verify a back pressed does not call the organizer |
| 970 | mWm.mAtmService.onBackPressedOnTaskRoot(activity.token, |
| 971 | new IRequestFinishCallback.Default()); |
| 972 | verify(organizer, never()).onBackPressedOnTaskRoot(any()); |
| 973 | |
| 974 | // Enable intercepting back |
| 975 | mWm.mAtmService.mTaskOrganizerController.setInterceptBackPressedOnTaskRoot(organizer, |
| 976 | true); |
| 977 | |
| 978 | // Verify now that the back press does call the organizer |
| 979 | mWm.mAtmService.onBackPressedOnTaskRoot(activity.token, |
| 980 | new IRequestFinishCallback.Default()); |
| 981 | verify(organizer, times(1)).onBackPressedOnTaskRoot(any()); |
| 982 | } |
chaviw | 5452169 | 2020-06-12 14:34:30 -0700 | [diff] [blame] | 983 | |
| 984 | @Test |
| 985 | public void testBLASTCallbackWithMultipleWindows() throws Exception { |
| 986 | final ActivityStack stackController = createStack(); |
| 987 | final Task task = createTask(stackController); |
| 988 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 989 | final WindowState w1 = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window 1"); |
| 990 | final WindowState w2 = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window 2"); |
| 991 | makeWindowVisible(w1); |
| 992 | makeWindowVisible(w2); |
| 993 | |
| 994 | IWindowContainerTransactionCallback mockCallback = |
| 995 | mock(IWindowContainerTransactionCallback.class); |
| 996 | int id = mWm.mAtmService.mWindowOrganizerController.startSyncWithOrganizer(mockCallback); |
| 997 | |
| 998 | mWm.mAtmService.mWindowOrganizerController.addToSyncSet(id, task); |
| 999 | mWm.mAtmService.mWindowOrganizerController.setSyncReady(id); |
| 1000 | |
| 1001 | // Since we have a window we have to wait for it to draw to finish sync. |
| 1002 | verify(mockCallback, never()).onTransactionReady(anyInt(), any()); |
| 1003 | assertTrue(w1.useBLASTSync()); |
| 1004 | assertTrue(w2.useBLASTSync()); |
| 1005 | finishAndNotifyDrawing(w1); |
| 1006 | |
| 1007 | // Even though one Window finished drawing, both windows should still be using blast sync |
| 1008 | assertTrue(w1.useBLASTSync()); |
| 1009 | assertTrue(w2.useBLASTSync()); |
| 1010 | |
| 1011 | finishAndNotifyDrawing(w2); |
| 1012 | verify(mockCallback).onTransactionReady(anyInt(), any()); |
| 1013 | assertFalse(w1.useBLASTSync()); |
| 1014 | assertFalse(w2.useBLASTSync()); |
| 1015 | } |
| 1016 | |
| 1017 | private void finishAndNotifyDrawing(WindowState ws) { |
| 1018 | ws.finishDrawing(null); |
| 1019 | ws.notifyBlastSyncTransaction(); |
| 1020 | } |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 1021 | } |