• 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.TestApi;
23 import android.app.ActivityTaskManager;
24 import android.os.RemoteException;
25 import android.util.Singleton;
26 import android.view.SurfaceControl;
27 
28 /**
29  * Base class for organizing specific types of windows like Tasks and DisplayAreas
30  *
31  * @hide
32  */
33 @TestApi
34 public class WindowOrganizer {
35 
36     /**
37      * Apply multiple WindowContainer operations at once.
38      * @param t The transaction to apply.
39      */
40     @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
applyTransaction(@onNull WindowContainerTransaction t)41     public static void applyTransaction(@NonNull WindowContainerTransaction t) {
42         try {
43             getWindowOrganizerController().applyTransaction(t);
44         } catch (RemoteException e) {
45             throw e.rethrowFromSystemServer();
46         }
47     }
48 
49     /**
50      * Apply multiple WindowContainer operations at once.
51      * @param t The transaction to apply.
52      * @param callback This transaction will use the synchronization scheme described in
53      *        BLASTSyncEngine.java. The SurfaceControl transaction containing the effects of this
54      *        WindowContainer transaction will be passed to this callback when ready.
55      * @return An ID for the sync operation which will later be passed to transactionReady callback.
56      *         This lets the caller differentiate overlapping sync operations.
57      */
58     @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
applySyncTransaction(@onNull WindowContainerTransaction t, @NonNull WindowContainerTransactionCallback callback)59     public int applySyncTransaction(@NonNull WindowContainerTransaction t,
60             @NonNull WindowContainerTransactionCallback callback) {
61         try {
62             return getWindowOrganizerController().applySyncTransaction(t, callback.mInterface);
63         } catch (RemoteException e) {
64             throw e.rethrowFromSystemServer();
65         }
66     }
67 
68     /**
69      * Take a screenshot for a specified Window
70      * @param token The token for the WindowContainer that should get a screenshot taken.
71      * @return A SurfaceControl where the screenshot will be attached, or null if failed.
72      *
73      * @hide
74      */
75     @Nullable
76     @RequiresPermission(android.Manifest.permission.READ_FRAME_BUFFER)
takeScreenshot(@onNull WindowContainerToken token)77     public static SurfaceControl takeScreenshot(@NonNull WindowContainerToken token) {
78         try {
79             SurfaceControl surfaceControl = new SurfaceControl();
80             if (getWindowOrganizerController().takeScreenshot(token, surfaceControl)) {
81                 return surfaceControl;
82             } else {
83                 return null;
84             }
85         } catch (RemoteException e) {
86             throw e.rethrowFromSystemServer();
87         }
88     }
89 
90     @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
getWindowOrganizerController()91     static IWindowOrganizerController getWindowOrganizerController() {
92         return IWindowOrganizerControllerSingleton.get();
93     }
94 
95     private static final Singleton<IWindowOrganizerController> IWindowOrganizerControllerSingleton =
96             new Singleton<IWindowOrganizerController>() {
97                 @Override
98                 protected IWindowOrganizerController create() {
99                     try {
100                         return ActivityTaskManager.getService().getWindowOrganizerController();
101                     } catch (RemoteException e) {
102                         return null;
103                     }
104                 }
105             };
106 }
107