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 29 /** 30 * Base class for organizing specific types of windows like Tasks and DisplayAreas 31 * 32 * @hide 33 */ 34 @TestApi 35 public class WindowOrganizer { 36 37 /** 38 * Apply multiple WindowContainer operations at once. 39 * @param t The transaction to apply. 40 */ 41 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 42 public void applyTransaction(@NonNull WindowContainerTransaction t) { 43 try { 44 if (!t.isEmpty()) { 45 getWindowOrganizerController().applyTransaction(t); 46 } 47 } catch (RemoteException e) { 48 throw e.rethrowFromSystemServer(); 49 } 50 } 51 52 /** 53 * Apply multiple WindowContainer operations at once. 54 * @param t The transaction to apply. 55 * @param callback This transaction will use the synchronization scheme described in 56 * BLASTSyncEngine.java. The SurfaceControl transaction containing the effects of this 57 * WindowContainer transaction will be passed to this callback when ready. 58 * @return An ID for the sync operation which will later be passed to transactionReady callback. 59 * This lets the caller differentiate overlapping sync operations. 60 */ 61 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 62 public int applySyncTransaction(@NonNull WindowContainerTransaction t, 63 @NonNull WindowContainerTransactionCallback callback) { 64 try { 65 return getWindowOrganizerController().applySyncTransaction(t, callback.mInterface); 66 } catch (RemoteException e) { 67 throw e.rethrowFromSystemServer(); 68 } 69 } 70 71 /** 72 * Start a transition. 73 * @param type The type of the transition. This is ignored if a transitionToken is provided. 74 * @param transitionToken An existing transition to start. If null, a new transition is created. 75 * @param t The set of window operations that are part of this transition. 76 * @return A token identifying the transition. This will be the same as transitionToken if it 77 * was provided. 78 * @hide 79 */ 80 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 81 @NonNull 82 public IBinder startTransition(int type, @Nullable IBinder transitionToken, 83 @Nullable WindowContainerTransaction t) { 84 try { 85 return getWindowOrganizerController().startTransition(type, transitionToken, t); 86 } catch (RemoteException e) { 87 throw e.rethrowFromSystemServer(); 88 } 89 } 90 91 /** 92 * Finishes a running transition. 93 * @param transitionToken The transition to finish. Can't be null. 94 * @param t A set of window operations to apply before finishing. 95 * @param callback A sync callback (if provided). See {@link #applySyncTransaction}. 96 * @return An ID for the sync operation if performed. See {@link #applySyncTransaction}. 97 * 98 * @hide 99 */ 100 @SuppressLint("ExecutorRegistration") 101 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 102 public int finishTransition(@NonNull IBinder transitionToken, 103 @Nullable WindowContainerTransaction t, 104 @Nullable WindowContainerTransactionCallback callback) { 105 try { 106 return getWindowOrganizerController().finishTransition(transitionToken, t, 107 callback != null ? callback.mInterface : null); 108 } catch (RemoteException e) { 109 throw e.rethrowFromSystemServer(); 110 } 111 } 112 113 /** 114 * Register an ITransitionPlayer to handle transition animations. 115 * @hide 116 */ 117 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 118 public void registerTransitionPlayer(@Nullable ITransitionPlayer player) { 119 try { 120 getWindowOrganizerController().registerTransitionPlayer(player); 121 } catch (RemoteException e) { 122 throw e.rethrowFromSystemServer(); 123 } 124 } 125 126 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 127 IWindowOrganizerController getWindowOrganizerController() { 128 return IWindowOrganizerControllerSingleton.get(); 129 } 130 131 private static final Singleton<IWindowOrganizerController> IWindowOrganizerControllerSingleton = 132 new Singleton<IWindowOrganizerController>() { 133 @Override 134 protected IWindowOrganizerController create() { 135 try { 136 return ActivityTaskManager.getService().getWindowOrganizerController(); 137 } catch (RemoteException e) { 138 return null; 139 } 140 } 141 }; 142 } 143