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.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.RequiresPermission; 22 import android.annotation.SuppressLint; 23 import android.annotation.TestApi; 24 import android.app.ActivityTaskManager; 25 import android.os.IBinder; 26 import android.os.RemoteException; 27 import android.util.Singleton; 28 import android.view.RemoteAnimationAdapter; 29 30 /** 31 * Base class for organizing specific types of windows like Tasks and DisplayAreas 32 * 33 * @hide 34 */ 35 @TestApi 36 public class WindowOrganizer { 37 38 /** 39 * Apply multiple WindowContainer operations at once. 40 * 41 * Note that using this API requires the caller to hold 42 * {@link android.Manifest.permission#MANAGE_ACTIVITY_TASKS}, unless the caller is using 43 * {@link TaskFragmentOrganizer}, in which case it is allowed to change TaskFragment that is 44 * created by itself. 45 * 46 * @param t The transaction to apply. 47 */ 48 @RequiresPermission(value = android.Manifest.permission.MANAGE_ACTIVITY_TASKS, 49 conditional = true) applyTransaction(@onNull WindowContainerTransaction t)50 public void applyTransaction(@NonNull WindowContainerTransaction t) { 51 try { 52 if (!t.isEmpty()) { 53 getWindowOrganizerController().applyTransaction(t); 54 } 55 } catch (RemoteException e) { 56 throw e.rethrowFromSystemServer(); 57 } 58 } 59 60 /** 61 * Apply multiple WindowContainer operations at once. 62 * 63 * Note that using this API requires the caller to hold 64 * {@link android.Manifest.permission#MANAGE_ACTIVITY_TASKS}. 65 * 66 * @param t The transaction to apply. 67 * @param callback This transaction will use the synchronization scheme described in 68 * BLASTSyncEngine.java. The SurfaceControl transaction containing the effects of this 69 * WindowContainer transaction will be passed to this callback when ready. 70 * @return An ID for the sync operation which will later be passed to transactionReady callback. 71 * This lets the caller differentiate overlapping sync operations. 72 */ 73 @RequiresPermission(value = android.Manifest.permission.MANAGE_ACTIVITY_TASKS) applySyncTransaction(@onNull WindowContainerTransaction t, @NonNull WindowContainerTransactionCallback callback)74 public int applySyncTransaction(@NonNull WindowContainerTransaction t, 75 @NonNull WindowContainerTransactionCallback callback) { 76 try { 77 return getWindowOrganizerController().applySyncTransaction(t, callback.mInterface); 78 } catch (RemoteException e) { 79 throw e.rethrowFromSystemServer(); 80 } 81 } 82 83 /** 84 * Starts a new transition, don't use this to start an already created one. 85 * @param type The type of the transition. This is ignored if a transitionToken is provided. 86 * @param t The set of window operations that are part of this transition. 87 * @return A token identifying the transition. This will be the same as transitionToken if it 88 * was provided. 89 * @hide 90 */ 91 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 92 @NonNull startNewTransition(int type, @Nullable WindowContainerTransaction t)93 public IBinder startNewTransition(int type, @Nullable WindowContainerTransaction t) { 94 try { 95 return getWindowOrganizerController().startNewTransition(type, t); 96 } catch (RemoteException e) { 97 throw e.rethrowFromSystemServer(); 98 } 99 } 100 101 /** 102 * Starts an already created transition. 103 * @param transitionToken An existing transition to start. 104 * @hide 105 */ 106 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) startTransition(@onNull IBinder transitionToken, @Nullable WindowContainerTransaction t)107 public void startTransition(@NonNull IBinder transitionToken, 108 @Nullable WindowContainerTransaction t) { 109 try { 110 getWindowOrganizerController().startTransition(transitionToken, t); 111 } catch (RemoteException e) { 112 throw e.rethrowFromSystemServer(); 113 } 114 } 115 116 /** 117 * Finishes a running transition. 118 * @param transitionToken The transition to finish. Can't be null. 119 * @param t A set of window operations to apply before finishing. 120 * @param callback A sync callback (if provided). See {@link #applySyncTransaction}. 121 * @return An ID for the sync operation if performed. See {@link #applySyncTransaction}. 122 * 123 * @hide 124 */ 125 @SuppressLint("ExecutorRegistration") 126 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) finishTransition(@onNull IBinder transitionToken, @Nullable WindowContainerTransaction t, @Nullable WindowContainerTransactionCallback callback)127 public int finishTransition(@NonNull IBinder transitionToken, 128 @Nullable WindowContainerTransaction t, 129 @Nullable WindowContainerTransactionCallback callback) { 130 try { 131 return getWindowOrganizerController().finishTransition(transitionToken, t, 132 callback != null ? callback.mInterface : null); 133 } catch (RemoteException e) { 134 throw e.rethrowFromSystemServer(); 135 } 136 } 137 138 /** 139 * Start a legacy transition. 140 * @param type The type of the transition. This is ignored if a transitionToken is provided. 141 * @param adapter An existing transition to start. If null, a new transition is created. 142 * @param t The set of window operations that are part of this transition. 143 * @return true on success, false if a transition was already running. 144 * @hide 145 */ 146 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 147 @NonNull startLegacyTransition(int type, @NonNull RemoteAnimationAdapter adapter, @NonNull WindowContainerTransactionCallback syncCallback, @NonNull WindowContainerTransaction t)148 public int startLegacyTransition(int type, @NonNull RemoteAnimationAdapter adapter, 149 @NonNull WindowContainerTransactionCallback syncCallback, 150 @NonNull WindowContainerTransaction t) { 151 try { 152 return getWindowOrganizerController().startLegacyTransition( 153 type, adapter, syncCallback.mInterface, t); 154 } catch (RemoteException e) { 155 throw e.rethrowFromSystemServer(); 156 } 157 } 158 159 /** 160 * Register an ITransitionPlayer to handle transition animations. 161 * @hide 162 */ 163 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) registerTransitionPlayer(@ullable ITransitionPlayer player)164 public void registerTransitionPlayer(@Nullable ITransitionPlayer player) { 165 try { 166 getWindowOrganizerController().registerTransitionPlayer(player); 167 } catch (RemoteException e) { 168 throw e.rethrowFromSystemServer(); 169 } 170 } 171 172 /** 173 * @see TransitionMetrics 174 * @hide 175 */ getTransitionMetricsReporter()176 public static ITransitionMetricsReporter getTransitionMetricsReporter() { 177 try { 178 return getWindowOrganizerController().getTransitionMetricsReporter(); 179 } catch (RemoteException e) { 180 throw e.rethrowFromSystemServer(); 181 } 182 } 183 getWindowOrganizerController()184 static IWindowOrganizerController getWindowOrganizerController() { 185 return IWindowOrganizerControllerSingleton.get(); 186 } 187 188 private static final Singleton<IWindowOrganizerController> IWindowOrganizerControllerSingleton = 189 new Singleton<IWindowOrganizerController>() { 190 @Override 191 protected IWindowOrganizerController create() { 192 try { 193 return ActivityTaskManager.getService().getWindowOrganizerController(); 194 } catch (RemoteException e) { 195 return null; 196 } 197 } 198 }; 199 } 200