blob: ff40ddac134ede107442f154a3724511fbd82eb4 [file] [log] [blame]
Wale Ogunwale568f9f412020-03-21 22:27:35 -07001/*
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
17package android.window;
18
Wale Ogunwaleadf116e2020-03-27 16:36:01 -070019import android.annotation.NonNull;
chaviw5ef1e932020-04-21 12:55:37 -070020import android.annotation.Nullable;
Wale Ogunwale568f9f412020-03-21 22:27:35 -070021import android.annotation.RequiresPermission;
Wale Ogunwaleadf116e2020-03-27 16:36:01 -070022import android.annotation.TestApi;
Wale Ogunwale568f9f412020-03-21 22:27:35 -070023import android.app.ActivityTaskManager;
24import android.os.RemoteException;
25import android.util.Singleton;
chaviw5ef1e932020-04-21 12:55:37 -070026import android.view.SurfaceControl;
Wale Ogunwale568f9f412020-03-21 22:27:35 -070027
Wale Ogunwale568f9f412020-03-21 22:27:35 -070028/**
Wale Ogunwaleadf116e2020-03-27 16:36:01 -070029 * Base class for organizing specific types of windows like Tasks and DisplayAreas
Wale Ogunwale568f9f412020-03-21 22:27:35 -070030 *
31 * @hide
32 */
Wale Ogunwaleadf116e2020-03-27 16:36:01 -070033@TestApi
Wale Ogunwale568f9f412020-03-21 22:27:35 -070034public class WindowOrganizer {
35
36 /**
37 * Apply multiple WindowContainer operations at once.
38 * @param t The transaction to apply.
Wale Ogunwale568f9f412020-03-21 22:27:35 -070039 */
40 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
Wale Ogunwaleadf116e2020-03-27 16:36:01 -070041 public static void applyTransaction(@NonNull WindowContainerTransaction t) {
42 try {
43 getWindowOrganizerController().applyTransaction(t);
44 } catch (RemoteException e) {
45 throw e.rethrowFromSystemServer();
46 }
Wale Ogunwale568f9f412020-03-21 22:27:35 -070047 }
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.
Wale Ogunwale568f9f412020-03-21 22:27:35 -070057 */
58 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
Wale Ogunwaleadf116e2020-03-27 16:36:01 -070059 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 }
Wale Ogunwale568f9f412020-03-21 22:27:35 -070066 }
67
chaviw5ef1e932020-04-21 12:55:37 -070068 /**
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)
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
Wale Ogunwale568f9f412020-03-21 22:27:35 -070090 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
Wale Ogunwaleadf116e2020-03-27 16:36:01 -070091 static IWindowOrganizerController getWindowOrganizerController() {
Wale Ogunwale568f9f412020-03-21 22:27:35 -070092 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 };
Wale Ogunwale568f9f412020-03-21 22:27:35 -0700106}