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