Debian Codegraph @

core/java/android/window/WindowOrganizer.java

raw symbols SCIP
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)
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}, unless the caller is using
65 * {@link TaskFragmentOrganizer}, in which case it is allowed to change TaskFragment that is
66 * created by itself.
67 *
68 * @param t The transaction to apply.
69 * @param callback This transaction will use the synchronization scheme described in
70 * BLASTSyncEngine.java. The SurfaceControl transaction containing the effects of this
71 * WindowContainer transaction will be passed to this callback when ready.
72 * @return An ID for the sync operation which will later be passed to transactionReady callback.
73 * This lets the caller differentiate overlapping sync operations.
74 */
75 @RequiresPermission(value = android.Manifest.permission.MANAGE_ACTIVITY_TASKS,
76 conditional = true)
77 public int applySyncTransaction(@NonNull WindowContainerTransaction t,
78 @NonNull WindowContainerTransactionCallback callback) {
79 try {
80 return getWindowOrganizerController().applySyncTransaction(t, callback.mInterface);
81 } catch (RemoteException e) {
82 throw e.rethrowFromSystemServer();
83 }
84 }
85
86 /**
87 * Starts a new transition, don't use this to start an already created one.
88 * @param type The type of the transition. This is ignored if a transitionToken is provided.
89 * @param t The set of window operations that are part of this transition.
90 * @return A token identifying the transition. This will be the same as transitionToken if it
91 * was provided.
92 * @hide
93 */
94 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
95 @NonNull
96 public IBinder startNewTransition(int type, @Nullable WindowContainerTransaction t) {
97 try {
98 return getWindowOrganizerController().startNewTransition(type, t);
99 } catch (RemoteException e) {
100 throw e.rethrowFromSystemServer();
101 }
102 }
103
104 /**
105 * Starts an already created transition.
106 * @param transitionToken An existing transition to start.
107 * @hide
108 */
109 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
110 public void startTransition(@NonNull IBinder transitionToken,
111 @Nullable WindowContainerTransaction t) {
112 try {
113 getWindowOrganizerController().startTransition(transitionToken, t);
114 } catch (RemoteException e) {
115 throw e.rethrowFromSystemServer();
116 }
117 }
118
119 /**
120 * Finishes a running transition.
121 * @param transitionToken The transition to finish. Can't be null.
122 * @param t A set of window operations to apply before finishing.
123 * @param callback A sync callback (if provided). See {@link #applySyncTransaction}.
124 * @return An ID for the sync operation if performed. See {@link #applySyncTransaction}.
125 *
126 * @hide
127 */
128 @SuppressLint("ExecutorRegistration")
129 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
130 public int finishTransition(@NonNull IBinder transitionToken,
131 @Nullable WindowContainerTransaction t,
132 @Nullable WindowContainerTransactionCallback callback) {
133 try {
134 return getWindowOrganizerController().finishTransition(transitionToken, t,
135 callback != null ? callback.mInterface : null);
136 } catch (RemoteException e) {
137 throw e.rethrowFromSystemServer();
138 }
139 }
140
141 /**
142 * Start a legacy transition.
143 * @param type The type of the transition. This is ignored if a transitionToken is provided.
144 * @param adapter An existing transition to start. If null, a new transition is created.
145 * @param t The set of window operations that are part of this transition.
146 * @return true on success, false if a transition was already running.
147 * @hide
148 */
149 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
150 @NonNull
151 public int startLegacyTransition(int type, @NonNull RemoteAnimationAdapter adapter,
152 @NonNull WindowContainerTransactionCallback syncCallback,
153 @NonNull WindowContainerTransaction t) {
154 try {
155 return getWindowOrganizerController().startLegacyTransition(
156 type, adapter, syncCallback.mInterface, t);
157 } catch (RemoteException e) {
158 throw e.rethrowFromSystemServer();
159 }
160 }
161
162 /**
163 * Register an ITransitionPlayer to handle transition animations.
164 * @hide
165 */
166 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
167 public void registerTransitionPlayer(@Nullable ITransitionPlayer player) {
168 try {
169 getWindowOrganizerController().registerTransitionPlayer(player);
170 } catch (RemoteException e) {
171 throw e.rethrowFromSystemServer();
172 }
173 }
174
175 /**
176 * @see TransitionMetrics
177 * @hide
178 */
179 public static ITransitionMetricsReporter getTransitionMetricsReporter() {
180 try {
181 return getWindowOrganizerController().getTransitionMetricsReporter();
182 } catch (RemoteException e) {
183 throw e.rethrowFromSystemServer();
184 }
185 }
186
187 static IWindowOrganizerController getWindowOrganizerController() {
188 return IWindowOrganizerControllerSingleton.get();
189 }
190
191 private static final Singleton<IWindowOrganizerController> IWindowOrganizerControllerSingleton =
192 new Singleton<IWindowOrganizerController>() {
193 @Override
194 protected IWindowOrganizerController create() {
195 try {
196 return ActivityTaskManager.getService().getWindowOrganizerController();
197 } catch (RemoteException e) {
198 return null;
199 }
200 }
201 };
202 }