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; |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 30 | |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 31 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 32 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 33 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 34 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 35 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset; |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 36 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 37 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; |
| 38 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 39 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 40 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 41 | |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 42 | import static org.junit.Assert.assertEquals; |
Jorim Jaggi | 2a3002a | 2020-02-17 15:57:34 +0000 | [diff] [blame] | 43 | import static org.junit.Assert.assertFalse; |
Evan Rosky | 05ec886 | 2020-02-28 19:37:04 -0800 | [diff] [blame] | 44 | import static org.junit.Assert.assertNotEquals; |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 45 | import static org.junit.Assert.assertNotNull; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 46 | import static org.junit.Assert.assertTrue; |
| 47 | import static org.mockito.ArgumentMatchers.any; |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 48 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 49 | import static org.mockito.ArgumentMatchers.anyInt; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 50 | |
| 51 | import android.app.ActivityManager.RunningTaskInfo; |
| 52 | import android.app.ActivityManager.StackInfo; |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 53 | import android.app.PictureInPictureParams; |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 54 | import android.content.pm.ActivityInfo; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 55 | import android.content.res.Configuration; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 56 | import android.graphics.Rect; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 57 | import android.os.Binder; |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 58 | import android.os.IBinder; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 59 | import android.os.RemoteException; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 60 | import android.platform.test.annotations.Presubmit; |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 61 | import android.util.ArrayMap; |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 62 | import android.util.Rational; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 63 | import android.view.Display; |
Wale Ogunwale | 5794658 | 2020-03-21 14:29:07 -0700 | [diff] [blame] | 64 | import android.window.ITaskOrganizer; |
| 65 | import android.window.WindowContainerTransaction; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 66 | |
| 67 | import androidx.test.filters.SmallTest; |
| 68 | |
| 69 | import org.junit.Test; |
| 70 | import org.junit.runner.RunWith; |
| 71 | |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 72 | import java.util.ArrayList; |
| 73 | import java.util.List; |
| 74 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 75 | /** |
Wale Ogunwale | 5794658 | 2020-03-21 14:29:07 -0700 | [diff] [blame] | 76 | * Test class for {@link ITaskOrganizer} and {@link android.window.ITaskOrganizerController}. |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 77 | * |
| 78 | * Build/Install/Run: |
| 79 | * atest WmTests:TaskOrganizerTests |
| 80 | */ |
| 81 | @SmallTest |
| 82 | @Presubmit |
| 83 | @RunWith(WindowTestRunner.class) |
| 84 | public class TaskOrganizerTests extends WindowTestsBase { |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 85 | private ITaskOrganizer registerMockOrganizer(int windowingMode) { |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 86 | final ITaskOrganizer organizer = mock(ITaskOrganizer.class); |
| 87 | when(organizer.asBinder()).thenReturn(new Binder()); |
| 88 | |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 89 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer( |
| 90 | organizer, windowingMode); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 91 | |
| 92 | return organizer; |
| 93 | } |
| 94 | |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 95 | private ITaskOrganizer registerMockOrganizer() { |
| 96 | return registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); |
| 97 | } |
| 98 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 99 | @Test |
| 100 | public void testAppearVanish() throws RemoteException { |
| 101 | final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); |
| 102 | final Task task = createTaskInStack(stack, 0 /* userId */); |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 103 | final ITaskOrganizer organizer = registerMockOrganizer(); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 104 | |
| 105 | task.setTaskOrganizer(organizer); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 106 | verify(organizer).onTaskAppeared(any()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 107 | |
| 108 | task.removeImmediately(); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 109 | verify(organizer).onTaskVanished(any()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Test |
| 113 | public void testSwapOrganizer() throws RemoteException { |
| 114 | final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); |
| 115 | final Task task = createTaskInStack(stack, 0 /* userId */); |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 116 | final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); |
| 117 | final ITaskOrganizer organizer2 = registerMockOrganizer(WINDOWING_MODE_PINNED); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 118 | |
| 119 | task.setTaskOrganizer(organizer); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 120 | verify(organizer).onTaskAppeared(any()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 121 | task.setTaskOrganizer(organizer2); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 122 | verify(organizer).onTaskVanished(any()); |
| 123 | verify(organizer2).onTaskAppeared(any()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Test |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 127 | public void testSwapWindowingModes() throws RemoteException { |
| 128 | final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); |
| 129 | final Task task = createTaskInStack(stack, 0 /* userId */); |
| 130 | final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); |
| 131 | final ITaskOrganizer organizer2 = registerMockOrganizer(WINDOWING_MODE_PINNED); |
Rob Carr | ab17978 | 2020-03-10 12:50:30 -0700 | [diff] [blame] | 132 | |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 133 | stack.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 134 | verify(organizer).onTaskAppeared(any()); |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 135 | stack.setWindowingMode(WINDOWING_MODE_PINNED); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 136 | verify(organizer).onTaskVanished(any()); |
| 137 | verify(organizer2).onTaskAppeared(any()); |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | @Test |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 141 | public void testClearOrganizer() throws RemoteException { |
| 142 | final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); |
| 143 | final Task task = createTaskInStack(stack, 0 /* userId */); |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 144 | final ITaskOrganizer organizer = registerMockOrganizer(); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 145 | |
Robert Carr | 9fd095b | 2020-01-24 14:40:06 -0800 | [diff] [blame] | 146 | stack.setTaskOrganizer(organizer); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 147 | verify(organizer).onTaskAppeared(any()); |
| 148 | assertTrue(stack.isOrganized()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 149 | |
Robert Carr | 9fd095b | 2020-01-24 14:40:06 -0800 | [diff] [blame] | 150 | stack.setTaskOrganizer(null); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 151 | verify(organizer).onTaskVanished(any()); |
| 152 | assertFalse(stack.isOrganized()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | @Test |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 156 | public void testUnregisterOrganizer() throws RemoteException { |
| 157 | final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); |
| 158 | final Task task = createTaskInStack(stack, 0 /* userId */); |
| 159 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 160 | |
| 161 | stack.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 162 | verify(organizer).onTaskAppeared(any()); |
| 163 | assertTrue(stack.isOrganized()); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 164 | |
| 165 | mWm.mAtmService.mTaskOrganizerController.unregisterTaskOrganizer(organizer); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 166 | verify(organizer).onTaskVanished(any()); |
| 167 | assertFalse(stack.isOrganized()); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | @Test |
| 171 | public void testUnregisterOrganizerReturnsRegistrationToPrevious() throws RemoteException { |
| 172 | final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); |
| 173 | final Task task = createTaskInStack(stack, 0 /* userId */); |
| 174 | final ActivityStack stack2 = createTaskStackOnDisplay(mDisplayContent); |
| 175 | final Task task2 = createTaskInStack(stack2, 0 /* userId */); |
| 176 | final ActivityStack stack3 = createTaskStackOnDisplay(mDisplayContent); |
| 177 | final Task task3 = createTaskInStack(stack3, 0 /* userId */); |
| 178 | final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); |
| 179 | |
| 180 | // First organizer is registered, verify a task appears when changing windowing mode |
| 181 | stack.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 182 | verify(organizer, times(1)).onTaskAppeared(any()); |
| 183 | assertTrue(stack.isOrganized()); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 184 | |
| 185 | // Now we replace the registration and1 verify the new organizer receives tasks |
| 186 | // newly entering the windowing mode. |
| 187 | final ITaskOrganizer organizer2 = registerMockOrganizer(WINDOWING_MODE_MULTI_WINDOW); |
| 188 | stack2.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 189 | verify(organizer2).onTaskAppeared(any()); |
| 190 | assertTrue(stack2.isOrganized()); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 191 | |
| 192 | // Now we unregister the second one, the first one should automatically be reregistered |
| 193 | // so we verify that it's now seeing changes. |
| 194 | mWm.mAtmService.mTaskOrganizerController.unregisterTaskOrganizer(organizer2); |
| 195 | |
| 196 | stack3.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 197 | verify(organizer, times(2)).onTaskAppeared(any()); |
| 198 | assertTrue(stack3.isOrganized()); |
Robert Carr | 7d7c8ab | 2020-01-28 15:57:23 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | @Test |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 202 | public void testRegisterTaskOrganizerStackWindowingModeChanges() throws RemoteException { |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 203 | final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_PINNED); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 204 | |
| 205 | final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); |
| 206 | final Task task = createTaskInStack(stack, 0 /* userId */); |
| 207 | final Task task2 = createTaskInStack(stack, 0 /* userId */); |
| 208 | stack.setWindowingMode(WINDOWING_MODE_PINNED); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 209 | verify(organizer, times(1)).onTaskAppeared(any()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 210 | |
| 211 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 212 | verify(organizer, times(1)).onTaskVanished(any()); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 213 | } |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 214 | |
| 215 | @Test |
Winson Chung | 77338ab | 2020-03-09 16:32:34 -0700 | [diff] [blame] | 216 | public void testRegisterTaskOrganizerWithExistingTasks() throws RemoteException { |
| 217 | final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent); |
| 218 | final Task task = createTaskInStack(stack, 0 /* userId */); |
| 219 | stack.setWindowingMode(WINDOWING_MODE_PINNED); |
| 220 | |
| 221 | final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_PINNED); |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 222 | verify(organizer, times(1)).onTaskAppeared(any()); |
Winson Chung | 77338ab | 2020-03-09 16:32:34 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | @Test |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 226 | public void testTaskTransaction() { |
| 227 | removeGlobalMinSizeRestriction(); |
| 228 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
| 229 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 230 | final Task task = stack.getTopMostTask(); |
| 231 | WindowContainerTransaction t = new WindowContainerTransaction(); |
| 232 | Rect newBounds = new Rect(10, 10, 100, 100); |
| 233 | t.setBounds(task.mRemoteToken, new Rect(10, 10, 100, 100)); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 234 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 235 | assertEquals(newBounds, task.getBounds()); |
| 236 | } |
| 237 | |
| 238 | @Test |
| 239 | public void testStackTransaction() { |
| 240 | removeGlobalMinSizeRestriction(); |
| 241 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
| 242 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 243 | StackInfo info = |
| 244 | mWm.mAtmService.getStackInfo(WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD); |
| 245 | WindowContainerTransaction t = new WindowContainerTransaction(); |
| 246 | assertEquals(stack.mRemoteToken, info.stackToken); |
| 247 | Rect newBounds = new Rect(10, 10, 100, 100); |
| 248 | t.setBounds(info.stackToken, new Rect(10, 10, 100, 100)); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 249 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 250 | assertEquals(newBounds, stack.getBounds()); |
| 251 | } |
| 252 | |
| 253 | @Test |
Robert Carr | 2bed621 | 2020-02-20 16:55:07 -0800 | [diff] [blame] | 254 | public void testSetWindowingMode() { |
| 255 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
| 256 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 257 | final WindowContainerTransaction t = new WindowContainerTransaction(); |
| 258 | |
| 259 | t.setWindowingMode(stack.mRemoteToken, WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 260 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Robert Carr | 2bed621 | 2020-02-20 16:55:07 -0800 | [diff] [blame] | 261 | |
| 262 | assertEquals(WINDOWING_MODE_FULLSCREEN, stack.getWindowingMode()); |
| 263 | } |
| 264 | |
| 265 | @Test |
| 266 | public void testSetActivityWindowingMode() { |
| 267 | final ActivityRecord record = makePipableActivity(); |
| 268 | final ActivityStack stack = record.getStack(); |
| 269 | final WindowContainerTransaction t = new WindowContainerTransaction(); |
| 270 | |
| 271 | t.setWindowingMode(stack.mRemoteToken, WINDOWING_MODE_PINNED); |
| 272 | t.setActivityWindowingMode(stack.mRemoteToken, WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 273 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Robert Carr | 2bed621 | 2020-02-20 16:55:07 -0800 | [diff] [blame] | 274 | |
| 275 | assertEquals(WINDOWING_MODE_FULLSCREEN, record.getWindowingMode()); |
| 276 | assertEquals(WINDOWING_MODE_PINNED, stack.getWindowingMode()); |
| 277 | } |
| 278 | |
| 279 | @Test |
Robert Carr | f6878a4 | 2019-12-18 02:13:12 -0800 | [diff] [blame] | 280 | public void testContainerFocusableChanges() { |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 281 | removeGlobalMinSizeRestriction(); |
| 282 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
| 283 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 284 | final Task task = stack.getTopMostTask(); |
| 285 | WindowContainerTransaction t = new WindowContainerTransaction(); |
| 286 | assertTrue(task.isFocusable()); |
| 287 | t.setFocusable(stack.mRemoteToken, false); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 288 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 289 | assertFalse(task.isFocusable()); |
Robert Carr | f6878a4 | 2019-12-18 02:13:12 -0800 | [diff] [blame] | 290 | t.setFocusable(stack.mRemoteToken, true); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 291 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Robert Carr | f6878a4 | 2019-12-18 02:13:12 -0800 | [diff] [blame] | 292 | assertTrue(task.isFocusable()); |
| 293 | } |
| 294 | |
| 295 | @Test |
| 296 | public void testContainerHiddenChanges() { |
| 297 | removeGlobalMinSizeRestriction(); |
| 298 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
| 299 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 300 | WindowContainerTransaction t = new WindowContainerTransaction(); |
| 301 | assertTrue(stack.shouldBeVisible(null)); |
| 302 | t.setHidden(stack.mRemoteToken, true); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 303 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Robert Carr | f6878a4 | 2019-12-18 02:13:12 -0800 | [diff] [blame] | 304 | assertFalse(stack.shouldBeVisible(null)); |
| 305 | t.setHidden(stack.mRemoteToken, false); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 306 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Robert Carr | f6878a4 | 2019-12-18 02:13:12 -0800 | [diff] [blame] | 307 | assertTrue(stack.shouldBeVisible(null)); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | @Test |
Evan Rosky | 05ec886 | 2020-02-28 19:37:04 -0800 | [diff] [blame] | 311 | public void testOverrideConfigSize() { |
| 312 | removeGlobalMinSizeRestriction(); |
| 313 | final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot) |
| 314 | .setWindowingMode(WINDOWING_MODE_FREEFORM).build(); |
| 315 | final Task task = stack.getTopMostTask(); |
| 316 | WindowContainerTransaction t = new WindowContainerTransaction(); |
| 317 | t.setBounds(task.mRemoteToken, new Rect(10, 10, 100, 100)); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 318 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Evan Rosky | 05ec886 | 2020-02-28 19:37:04 -0800 | [diff] [blame] | 319 | final int origScreenWDp = task.getConfiguration().screenHeightDp; |
| 320 | final int origScreenHDp = task.getConfiguration().screenHeightDp; |
| 321 | t = new WindowContainerTransaction(); |
| 322 | // verify that setting config overrides on parent restricts children. |
| 323 | t.setScreenSizeDp(stack.mRemoteToken, origScreenWDp, origScreenHDp); |
| 324 | t.setBounds(task.mRemoteToken, new Rect(10, 10, 150, 200)); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 325 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Evan Rosky | 05ec886 | 2020-02-28 19:37:04 -0800 | [diff] [blame] | 326 | assertEquals(origScreenHDp, task.getConfiguration().screenHeightDp); |
| 327 | t = new WindowContainerTransaction(); |
| 328 | t.setScreenSizeDp(stack.mRemoteToken, Configuration.SCREEN_WIDTH_DP_UNDEFINED, |
| 329 | Configuration.SCREEN_HEIGHT_DP_UNDEFINED); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 330 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(t); |
Evan Rosky | 05ec886 | 2020-02-28 19:37:04 -0800 | [diff] [blame] | 331 | assertNotEquals(origScreenHDp, task.getConfiguration().screenHeightDp); |
| 332 | } |
| 333 | |
| 334 | @Test |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 335 | public void testCreateDeleteRootTasks() { |
| 336 | RunningTaskInfo info1 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
| 337 | Display.DEFAULT_DISPLAY, |
| 338 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 339 | assertEquals(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, |
| 340 | info1.configuration.windowConfiguration.getWindowingMode()); |
| 341 | assertEquals(ACTIVITY_TYPE_UNDEFINED, info1.topActivityType); |
| 342 | |
| 343 | RunningTaskInfo info2 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
| 344 | Display.DEFAULT_DISPLAY, |
| 345 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 346 | assertEquals(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, |
| 347 | info2.configuration.windowConfiguration.getWindowingMode()); |
| 348 | assertEquals(ACTIVITY_TYPE_UNDEFINED, info2.topActivityType); |
| 349 | |
| 350 | DisplayContent dc = mWm.mRoot.getDisplayContent(Display.DEFAULT_DISPLAY); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 351 | List<Task> infos = getTasksCreatedByOrganizer(dc); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 352 | assertEquals(2, infos.size()); |
| 353 | |
| 354 | assertTrue(mWm.mAtmService.mTaskOrganizerController.deleteRootTask(info1.token)); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 355 | infos = getTasksCreatedByOrganizer(dc); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 356 | assertEquals(1, infos.size()); |
| 357 | assertEquals(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, infos.get(0).getWindowingMode()); |
| 358 | } |
| 359 | |
| 360 | @Test |
| 361 | public void testTileAddRemoveChild() { |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 362 | ITaskOrganizer listener = new ITaskOrganizer.Stub() { |
| 363 | @Override |
| 364 | public void onTaskAppeared(RunningTaskInfo taskInfo) { } |
| 365 | |
| 366 | @Override |
| 367 | public void onTaskVanished(RunningTaskInfo container) { } |
| 368 | |
| 369 | @Override |
| 370 | public void onTaskInfoChanged(RunningTaskInfo info) throws RemoteException { |
| 371 | } |
| 372 | }; |
| 373 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer(listener, |
| 374 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 375 | RunningTaskInfo info1 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
| 376 | mDisplayContent.mDisplayId, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 377 | |
| 378 | final ActivityStack stack = createTaskStackOnDisplay( |
| 379 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, mDisplayContent); |
| 380 | assertEquals(mDisplayContent.getWindowingMode(), stack.getWindowingMode()); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 381 | WindowContainerTransaction wct = new WindowContainerTransaction(); |
| 382 | wct.reparent(stack.mRemoteToken, info1.token, true /* onTop */); |
| 383 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 384 | assertEquals(info1.configuration.windowConfiguration.getWindowingMode(), |
| 385 | stack.getWindowingMode()); |
| 386 | |
| 387 | // Info should reflect new membership |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 388 | List<Task> infos = getTasksCreatedByOrganizer(mDisplayContent); |
| 389 | info1 = infos.get(0).getTaskInfo(); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 390 | assertEquals(ACTIVITY_TYPE_STANDARD, info1.topActivityType); |
| 391 | |
| 392 | // Children inherit configuration |
| 393 | Rect newSize = new Rect(10, 10, 300, 300); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 394 | Task task1 = WindowContainer.fromBinder(info1.token.asBinder()).asTask(); |
| 395 | Configuration c = new Configuration(task1.getRequestedOverrideConfiguration()); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 396 | c.windowConfiguration.setBounds(newSize); |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 397 | doNothing().when(stack).adjustForMinimalTaskDimensions(any(), any()); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 398 | task1.onRequestedOverrideConfigurationChanged(c); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 399 | assertEquals(newSize, stack.getBounds()); |
| 400 | |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 401 | wct = new WindowContainerTransaction(); |
| 402 | wct.reparent(stack.mRemoteToken, null, true /* onTop */); |
| 403 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 404 | assertEquals(mDisplayContent.getWindowingMode(), stack.getWindowingMode()); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 405 | infos = getTasksCreatedByOrganizer(mDisplayContent); |
| 406 | info1 = infos.get(0).getTaskInfo(); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 407 | assertEquals(ACTIVITY_TYPE_UNDEFINED, info1.topActivityType); |
| 408 | } |
| 409 | |
| 410 | @Test |
| 411 | public void testTaskInfoCallback() { |
| 412 | final ArrayList<RunningTaskInfo> lastReportedTiles = new ArrayList<>(); |
| 413 | final boolean[] called = {false}; |
| 414 | ITaskOrganizer listener = new ITaskOrganizer.Stub() { |
| 415 | @Override |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 416 | public void onTaskAppeared(RunningTaskInfo taskInfo) { } |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 417 | |
| 418 | @Override |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 419 | public void onTaskVanished(RunningTaskInfo container) { } |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 420 | |
| 421 | @Override |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 422 | public void onTaskInfoChanged(RunningTaskInfo info) throws RemoteException { |
| 423 | lastReportedTiles.add(info); |
| 424 | called[0] = true; |
| 425 | } |
| 426 | }; |
| 427 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer(listener, |
| 428 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 429 | RunningTaskInfo info1 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
| 430 | mDisplayContent.mDisplayId, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 431 | lastReportedTiles.clear(); |
| 432 | called[0] = false; |
| 433 | |
| 434 | final ActivityStack stack = createTaskStackOnDisplay( |
| 435 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, mDisplayContent); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 436 | Task task1 = WindowContainer.fromBinder(info1.token.asBinder()).asTask(); |
| 437 | WindowContainerTransaction wct = new WindowContainerTransaction(); |
| 438 | wct.reparent(stack.mRemoteToken, info1.token, true /* onTop */); |
| 439 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 440 | assertTrue(called[0]); |
| 441 | assertEquals(ACTIVITY_TYPE_STANDARD, lastReportedTiles.get(0).topActivityType); |
| 442 | |
| 443 | lastReportedTiles.clear(); |
| 444 | called[0] = false; |
| 445 | final ActivityStack stack2 = createTaskStackOnDisplay( |
| 446 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME, mDisplayContent); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 447 | wct = new WindowContainerTransaction(); |
| 448 | wct.reparent(stack2.mRemoteToken, info1.token, true /* onTop */); |
| 449 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 450 | assertTrue(called[0]); |
| 451 | assertEquals(ACTIVITY_TYPE_HOME, lastReportedTiles.get(0).topActivityType); |
| 452 | |
| 453 | lastReportedTiles.clear(); |
| 454 | called[0] = false; |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 455 | task1.positionChildAt(POSITION_TOP, stack, false /* includingParents */); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 456 | assertTrue(called[0]); |
| 457 | assertEquals(ACTIVITY_TYPE_STANDARD, lastReportedTiles.get(0).topActivityType); |
| 458 | |
| 459 | lastReportedTiles.clear(); |
| 460 | called[0] = false; |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 461 | wct = new WindowContainerTransaction(); |
| 462 | wct.reparent(stack.mRemoteToken, null, true /* onTop */); |
| 463 | wct.reparent(stack2.mRemoteToken, null, true /* onTop */); |
| 464 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 465 | assertTrue(called[0]); |
| 466 | assertEquals(ACTIVITY_TYPE_UNDEFINED, lastReportedTiles.get(0).topActivityType); |
| 467 | } |
| 468 | |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 469 | @Test |
| 470 | public void testHierarchyTransaction() { |
| 471 | final ArrayMap<IBinder, RunningTaskInfo> lastReportedTiles = new ArrayMap<>(); |
| 472 | ITaskOrganizer listener = new ITaskOrganizer.Stub() { |
| 473 | @Override |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 474 | public void onTaskAppeared(RunningTaskInfo taskInfo) { } |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 475 | |
| 476 | @Override |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 477 | public void onTaskVanished(RunningTaskInfo container) { } |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 478 | |
| 479 | @Override |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 480 | public void onTaskInfoChanged(RunningTaskInfo info) { |
| 481 | lastReportedTiles.put(info.token.asBinder(), info); |
| 482 | } |
| 483 | }; |
| 484 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer( |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 485 | listener, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 486 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer( |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 487 | listener, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 488 | RunningTaskInfo info1 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 489 | mDisplayContent.mDisplayId, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 490 | RunningTaskInfo info2 = mWm.mAtmService.mTaskOrganizerController.createRootTask( |
| 491 | mDisplayContent.mDisplayId, WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 492 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 493 | final int initialRootTaskCount = mWm.mAtmService.mTaskOrganizerController.getRootTasks( |
| 494 | mDisplayContent.mDisplayId, null /* activityTypes */).size(); |
| 495 | |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 496 | final ActivityStack stack = createTaskStackOnDisplay( |
| 497 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, mDisplayContent); |
| 498 | final ActivityStack stack2 = createTaskStackOnDisplay( |
| 499 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME, mDisplayContent); |
| 500 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 501 | // Check getRootTasks works |
| 502 | List<RunningTaskInfo> roots = mWm.mAtmService.mTaskOrganizerController.getRootTasks( |
| 503 | mDisplayContent.mDisplayId, null /* activityTypes */); |
| 504 | assertEquals(initialRootTaskCount + 2, roots.size()); |
| 505 | |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 506 | lastReportedTiles.clear(); |
| 507 | WindowContainerTransaction wct = new WindowContainerTransaction(); |
| 508 | wct.reparent(stack.mRemoteToken, info1.token, true /* onTop */); |
| 509 | wct.reparent(stack2.mRemoteToken, info2.token, true /* onTop */); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 510 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 511 | assertFalse(lastReportedTiles.isEmpty()); |
| 512 | assertEquals(ACTIVITY_TYPE_STANDARD, |
| 513 | lastReportedTiles.get(info1.token.asBinder()).topActivityType); |
| 514 | assertEquals(ACTIVITY_TYPE_HOME, |
| 515 | lastReportedTiles.get(info2.token.asBinder()).topActivityType); |
| 516 | |
| 517 | lastReportedTiles.clear(); |
| 518 | wct = new WindowContainerTransaction(); |
| 519 | wct.reparent(stack2.mRemoteToken, info1.token, false /* onTop */); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 520 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 521 | assertFalse(lastReportedTiles.isEmpty()); |
| 522 | // Standard should still be on top of tile 1, so no change there |
| 523 | assertFalse(lastReportedTiles.containsKey(info1.token.asBinder())); |
| 524 | // But tile 2 has no children, so should become undefined |
| 525 | assertEquals(ACTIVITY_TYPE_UNDEFINED, |
| 526 | lastReportedTiles.get(info2.token.asBinder()).topActivityType); |
| 527 | |
| 528 | // Check the getChildren call |
| 529 | List<RunningTaskInfo> children = |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 530 | mWm.mAtmService.mTaskOrganizerController.getChildTasks(info1.token, |
| 531 | null /* activityTypes */); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 532 | assertEquals(2, children.size()); |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 533 | children = mWm.mAtmService.mTaskOrganizerController.getChildTasks(info2.token, |
| 534 | null /* activityTypes */); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 535 | assertEquals(0, children.size()); |
| 536 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 537 | // Check that getRootTasks doesn't include children of tiles |
| 538 | roots = mWm.mAtmService.mTaskOrganizerController.getRootTasks(mDisplayContent.mDisplayId, |
| 539 | null /* activityTypes */); |
| 540 | assertEquals(initialRootTaskCount, roots.size()); |
| 541 | |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 542 | lastReportedTiles.clear(); |
| 543 | wct = new WindowContainerTransaction(); |
| 544 | wct.reorder(stack2.mRemoteToken, true /* onTop */); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 545 | mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 546 | // Home should now be on top. No change occurs in second tile, so not reported |
| 547 | assertEquals(1, lastReportedTiles.size()); |
| 548 | assertEquals(ACTIVITY_TYPE_HOME, |
| 549 | lastReportedTiles.get(info1.token.asBinder()).topActivityType); |
| 550 | } |
| 551 | |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 552 | private List<Task> getTasksCreatedByOrganizer(DisplayContent dc) { |
| 553 | ArrayList<Task> out = new ArrayList<>(); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 554 | for (int i = dc.getStackCount() - 1; i >= 0; --i) { |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame^] | 555 | final Task t = dc.getStackAt(i); |
| 556 | if (t.mCreatedByOrganizer) out.add(t); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 557 | } |
| 558 | return out; |
| 559 | } |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 560 | |
| 561 | @Test |
| 562 | public void testTrivialBLASTCallback() throws RemoteException { |
| 563 | final ActivityStack stackController1 = createTaskStackOnDisplay(mDisplayContent); |
| 564 | final Task task = createTaskInStack(stackController1, 0 /* userId */); |
| 565 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 566 | |
Robert Carr | 8ccc4fc | 2020-03-13 10:48:49 -0700 | [diff] [blame] | 567 | spyOn(task); |
| 568 | doReturn(true).when(task).isVisible(); |
| 569 | |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 570 | BLASTSyncEngine bse = new BLASTSyncEngine(); |
| 571 | |
| 572 | BLASTSyncEngine.TransactionReadyListener transactionListener = |
| 573 | mock(BLASTSyncEngine.TransactionReadyListener.class); |
| 574 | |
| 575 | int id = bse.startSyncSet(transactionListener); |
| 576 | bse.addToSyncSet(id, task); |
| 577 | bse.setReady(id); |
| 578 | // Since this task has no windows the sync is trivial and completes immediately. |
| 579 | verify(transactionListener) |
| 580 | .transactionReady(anyInt(), any()); |
| 581 | } |
| 582 | |
| 583 | @Test |
Robert Carr | 8ccc4fc | 2020-03-13 10:48:49 -0700 | [diff] [blame] | 584 | public void testOverlappingBLASTCallback() throws RemoteException { |
| 585 | final ActivityStack stackController1 = createTaskStackOnDisplay(mDisplayContent); |
| 586 | final Task task = createTaskInStack(stackController1, 0 /* userId */); |
| 587 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 588 | |
| 589 | spyOn(task); |
| 590 | doReturn(true).when(task).isVisible(); |
| 591 | final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); |
| 592 | makeWindowVisible(w); |
| 593 | |
| 594 | BLASTSyncEngine bse = new BLASTSyncEngine(); |
| 595 | |
| 596 | BLASTSyncEngine.TransactionReadyListener transactionListener = |
| 597 | mock(BLASTSyncEngine.TransactionReadyListener.class); |
| 598 | |
| 599 | int id = bse.startSyncSet(transactionListener); |
| 600 | assertEquals(true, bse.addToSyncSet(id, task)); |
| 601 | bse.setReady(id); |
| 602 | |
| 603 | int id2 = bse.startSyncSet(transactionListener); |
| 604 | // We should be rejected from the second sync since we are already |
| 605 | // in one. |
| 606 | assertEquals(false, bse.addToSyncSet(id2, task)); |
| 607 | w.finishDrawing(null); |
| 608 | assertEquals(true, bse.addToSyncSet(id2, task)); |
| 609 | bse.setReady(id2); |
| 610 | } |
| 611 | |
| 612 | @Test |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 613 | public void testBLASTCallbackWithWindow() { |
| 614 | final ActivityStack stackController1 = createTaskStackOnDisplay(mDisplayContent); |
| 615 | final Task task = createTaskInStack(stackController1, 0 /* userId */); |
| 616 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 617 | final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); |
Rob Carr | cba6a72 | 2020-03-10 12:41:06 -0700 | [diff] [blame] | 618 | makeWindowVisible(w); |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 619 | |
| 620 | BLASTSyncEngine bse = new BLASTSyncEngine(); |
| 621 | |
| 622 | BLASTSyncEngine.TransactionReadyListener transactionListener = |
| 623 | mock(BLASTSyncEngine.TransactionReadyListener.class); |
| 624 | |
| 625 | int id = bse.startSyncSet(transactionListener); |
| 626 | bse.addToSyncSet(id, task); |
| 627 | bse.setReady(id); |
| 628 | // Since we have a window we have to wait for it to draw to finish sync. |
| 629 | verify(transactionListener, never()) |
| 630 | .transactionReady(anyInt(), any()); |
| 631 | w.finishDrawing(null); |
| 632 | verify(transactionListener) |
| 633 | .transactionReady(anyInt(), any()); |
| 634 | } |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 635 | |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 636 | @Test |
Rob Carr | cba6a72 | 2020-03-10 12:41:06 -0700 | [diff] [blame] | 637 | public void testBLASTCallbackWithInvisibleWindow() { |
| 638 | final ActivityStack stackController1 = createTaskStackOnDisplay(mDisplayContent); |
| 639 | final Task task = createTaskInStack(stackController1, 0 /* userId */); |
| 640 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 641 | final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); |
| 642 | |
| 643 | BLASTSyncEngine bse = new BLASTSyncEngine(); |
| 644 | |
| 645 | BLASTSyncEngine.TransactionReadyListener transactionListener = |
| 646 | mock(BLASTSyncEngine.TransactionReadyListener.class); |
| 647 | |
| 648 | int id = bse.startSyncSet(transactionListener); |
| 649 | bse.addToSyncSet(id, task); |
| 650 | bse.setReady(id); |
| 651 | |
| 652 | // Since the window was invisible, the Task had no visible leaves and the sync should |
| 653 | // complete as soon as we call setReady. |
| 654 | verify(transactionListener) |
| 655 | .transactionReady(anyInt(), any()); |
| 656 | } |
| 657 | |
| 658 | @Test |
Rob Carr | 2537651 | 2020-03-09 15:23:19 -0700 | [diff] [blame] | 659 | public void testBLASTCallbackWithChildWindow() { |
| 660 | final ActivityStack stackController1 = createTaskStackOnDisplay(mDisplayContent); |
| 661 | final Task task = createTaskInStack(stackController1, 0 /* userId */); |
| 662 | final ITaskOrganizer organizer = registerMockOrganizer(); |
| 663 | final WindowState w = createAppWindow(task, TYPE_APPLICATION, "Enlightened Window"); |
| 664 | final WindowState child = createWindow(w, TYPE_APPLICATION, "Other Window"); |
| 665 | |
| 666 | w.mActivityRecord.setVisible(true); |
| 667 | makeWindowVisible(w, child); |
| 668 | |
| 669 | BLASTSyncEngine bse = new BLASTSyncEngine(); |
| 670 | |
| 671 | BLASTSyncEngine.TransactionReadyListener transactionListener = |
| 672 | mock(BLASTSyncEngine.TransactionReadyListener.class); |
| 673 | |
| 674 | int id = bse.startSyncSet(transactionListener); |
| 675 | assertEquals(true, bse.addToSyncSet(id, task)); |
| 676 | bse.setReady(id); |
| 677 | w.finishDrawing(null); |
| 678 | |
| 679 | // Since we have a child window we still shouldn't be done. |
| 680 | verify(transactionListener, never()) |
| 681 | .transactionReady(anyInt(), any()); |
| 682 | reset(transactionListener); |
| 683 | |
| 684 | child.finishDrawing(null); |
| 685 | // Ah finally! Done |
| 686 | verify(transactionListener) |
| 687 | .transactionReady(anyInt(), any()); |
| 688 | } |
| 689 | |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 690 | class StubOrganizer extends ITaskOrganizer.Stub { |
| 691 | RunningTaskInfo mInfo; |
| 692 | |
| 693 | @Override |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 694 | public void onTaskAppeared(RunningTaskInfo info) { |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 695 | mInfo = info; |
| 696 | } |
| 697 | @Override |
Wale Ogunwale | dec3408 | 2020-03-22 09:45:00 -0700 | [diff] [blame] | 698 | public void onTaskVanished(RunningTaskInfo info) { |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 699 | } |
| 700 | @Override |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 701 | public void onTaskInfoChanged(RunningTaskInfo info) { |
| 702 | } |
| 703 | }; |
| 704 | |
| 705 | private ActivityRecord makePipableActivity() { |
| 706 | final ActivityRecord record = createActivityRecord(mDisplayContent, |
| 707 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
| 708 | record.info.flags |= ActivityInfo.FLAG_SUPPORTS_PICTURE_IN_PICTURE; |
| 709 | spyOn(record); |
| 710 | doReturn(true).when(record).checkEnterPictureInPictureState(any(), anyBoolean()); |
| 711 | return record; |
| 712 | } |
| 713 | |
| 714 | @Test |
| 715 | public void testEnterPipParams() { |
| 716 | final StubOrganizer o = new StubOrganizer(); |
| 717 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer(o, WINDOWING_MODE_PINNED); |
| 718 | final ActivityRecord record = makePipableActivity(); |
| 719 | |
| 720 | final PictureInPictureParams p = |
| 721 | new PictureInPictureParams.Builder().setAspectRatio(new Rational(1, 2)).build(); |
| 722 | assertTrue(mWm.mAtmService.enterPictureInPictureMode(record.token, p)); |
| 723 | waitUntilHandlersIdle(); |
| 724 | assertNotNull(o.mInfo); |
| 725 | assertNotNull(o.mInfo.pictureInPictureParams); |
| 726 | } |
| 727 | |
| 728 | @Test |
| 729 | public void testChangePipParams() { |
| 730 | class ChangeSavingOrganizer extends StubOrganizer { |
| 731 | RunningTaskInfo mChangedInfo; |
| 732 | @Override |
| 733 | public void onTaskInfoChanged(RunningTaskInfo info) { |
| 734 | mChangedInfo = info; |
| 735 | } |
| 736 | } |
| 737 | ChangeSavingOrganizer o = new ChangeSavingOrganizer(); |
| 738 | mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer(o, WINDOWING_MODE_PINNED); |
| 739 | |
| 740 | final ActivityRecord record = makePipableActivity(); |
| 741 | final PictureInPictureParams p = |
| 742 | new PictureInPictureParams.Builder().setAspectRatio(new Rational(1, 2)).build(); |
| 743 | assertTrue(mWm.mAtmService.enterPictureInPictureMode(record.token, p)); |
| 744 | waitUntilHandlersIdle(); |
| 745 | assertNotNull(o.mInfo); |
| 746 | assertNotNull(o.mInfo.pictureInPictureParams); |
| 747 | |
| 748 | final PictureInPictureParams p2 = |
| 749 | new PictureInPictureParams.Builder().setAspectRatio(new Rational(3, 4)).build(); |
| 750 | mWm.mAtmService.setPictureInPictureParams(record.token, p2); |
| 751 | waitUntilHandlersIdle(); |
| 752 | assertNotNull(o.mChangedInfo); |
| 753 | assertNotNull(o.mChangedInfo.pictureInPictureParams); |
| 754 | final Rational ratio = o.mChangedInfo.pictureInPictureParams.getAspectRatioRational(); |
| 755 | assertEquals(3, ratio.getNumerator()); |
| 756 | assertEquals(4, ratio.getDenominator()); |
| 757 | } |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 758 | } |