Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.window; |
| 18 | |
| 19 | import android.annotation.RequiresPermission; |
| 20 | import android.app.ActivityManager; |
| 21 | import android.app.ActivityTaskManager; |
| 22 | import android.os.RemoteException; |
| 23 | import android.util.Singleton; |
| 24 | |
| 25 | import java.util.List; |
| 26 | |
| 27 | /** |
| 28 | * Class for organizing specific types of windows like Tasks and DisplayAreas |
| 29 | * |
| 30 | * @hide |
| 31 | */ |
| 32 | public class WindowOrganizer { |
| 33 | |
| 34 | /** |
| 35 | * Apply multiple WindowContainer operations at once. |
| 36 | * @param t The transaction to apply. |
| 37 | * @hide |
| 38 | */ |
| 39 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
| 40 | public static void applyTransaction(WindowContainerTransaction t) throws RemoteException { |
| 41 | getWindowOrganizerController().applyTransaction(t); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Apply multiple WindowContainer operations at once. |
| 46 | * @param t The transaction to apply. |
| 47 | * @param callback This transaction will use the synchronization scheme described in |
| 48 | * BLASTSyncEngine.java. The SurfaceControl transaction containing the effects of this |
| 49 | * WindowContainer transaction will be passed to this callback when ready. |
| 50 | * @return An ID for the sync operation which will later be passed to transactionReady callback. |
| 51 | * This lets the caller differentiate overlapping sync operations. |
| 52 | * @hide |
| 53 | */ |
| 54 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
| 55 | public static int applySyncTransaction(WindowContainerTransaction t, |
| 56 | IWindowContainerTransactionCallback callback) throws RemoteException { |
| 57 | return getWindowOrganizerController().applySyncTransaction(t, callback); |
| 58 | } |
| 59 | |
| 60 | /** @hide */ |
| 61 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
| 62 | private static IWindowOrganizerController getWindowOrganizerController() { |
| 63 | return IWindowOrganizerControllerSingleton.get(); |
| 64 | } |
| 65 | |
| 66 | private static final Singleton<IWindowOrganizerController> IWindowOrganizerControllerSingleton = |
| 67 | new Singleton<IWindowOrganizerController>() { |
| 68 | @Override |
| 69 | protected IWindowOrganizerController create() { |
| 70 | try { |
| 71 | return ActivityTaskManager.getService().getWindowOrganizerController(); |
| 72 | } catch (RemoteException e) { |
| 73 | return null; |
| 74 | } |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | public static class TaskOrganizer { |
| 79 | |
| 80 | /** |
| 81 | * Register a TaskOrganizer to manage tasks as they enter the given windowing mode. |
| 82 | * If there was already a TaskOrganizer for this windowing mode it will be evicted |
| 83 | * and receive taskVanished callbacks in the process. |
| 84 | */ |
| 85 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
| 86 | public static void registerOrganizer(ITaskOrganizer organizer, int windowingMode) |
| 87 | throws RemoteException { |
| 88 | getController().registerTaskOrganizer(organizer, windowingMode); |
| 89 | } |
| 90 | |
| 91 | /** Unregisters a previously registered task organizer. */ |
| 92 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
| 93 | public static void unregisterOrganizer(ITaskOrganizer organizer) throws RemoteException { |
| 94 | getController().unregisterTaskOrganizer(organizer); |
| 95 | } |
| 96 | |
| 97 | /** Creates a persistent root task in WM for a particular windowing-mode. */ |
| 98 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
| 99 | public static ActivityManager.RunningTaskInfo createRootTask( |
| 100 | int displayId, int windowingMode) throws RemoteException { |
| 101 | return getController().createRootTask(displayId, windowingMode); |
| 102 | } |
| 103 | |
| 104 | /** Deletes a persistent root task in WM */ |
| 105 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
| 106 | public static boolean deleteRootTask(IWindowContainer task) throws RemoteException { |
| 107 | return getController().deleteRootTask(task); |
| 108 | } |
| 109 | |
| 110 | /** Gets direct child tasks (ordered from top-to-bottom) */ |
| 111 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
| 112 | public static List<ActivityManager.RunningTaskInfo> getChildTasks(IWindowContainer parent, |
| 113 | int[] activityTypes) throws RemoteException { |
| 114 | return getController().getChildTasks(parent, activityTypes); |
| 115 | } |
| 116 | |
| 117 | /** Gets all root tasks on a display (ordered from top-to-bottom) */ |
| 118 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
| 119 | public static List<ActivityManager.RunningTaskInfo> getRootTasks( |
| 120 | int displayId, int[] activityTypes) throws RemoteException { |
| 121 | return getController().getRootTasks(displayId, activityTypes); |
| 122 | } |
| 123 | |
| 124 | /** Get the root task which contains the current ime target */ |
| 125 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
| 126 | public static IWindowContainer getImeTarget(int display) throws RemoteException { |
| 127 | return getController().getImeTarget(display); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Set's the root task to launch new tasks into on a display. {@code null} means no launch |
| 132 | * root and thus new tasks just end up directly on the display. |
| 133 | */ |
| 134 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
| 135 | public static void setLaunchRoot(int displayId, IWindowContainer root) |
| 136 | throws RemoteException { |
| 137 | getController().setLaunchRoot(displayId, root); |
| 138 | } |
| 139 | |
| 140 | private static ITaskOrganizerController getController() { |
| 141 | return ITaskOrganizerControllerSingleton.get(); |
| 142 | } |
| 143 | |
| 144 | private static final Singleton<ITaskOrganizerController> ITaskOrganizerControllerSingleton = |
| 145 | new Singleton<ITaskOrganizerController>() { |
| 146 | @Override |
| 147 | protected ITaskOrganizerController create() { |
| 148 | try { |
| 149 | return getWindowOrganizerController().getTaskOrganizerController(); |
| 150 | } catch (RemoteException e) { |
| 151 | return null; |
| 152 | } |
| 153 | } |
| 154 | }; |
| 155 | |
| 156 | } |
| 157 | } |