Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 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 | |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame^] | 19 | import android.annotation.NonNull; |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 20 | import android.annotation.RequiresPermission; |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame^] | 21 | import android.annotation.TestApi; |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 22 | import android.app.ActivityTaskManager; |
| 23 | import android.os.RemoteException; |
| 24 | import android.util.Singleton; |
| 25 | |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 26 | /** |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame^] | 27 | * Base class for organizing specific types of windows like Tasks and DisplayAreas |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 28 | * |
| 29 | * @hide |
| 30 | */ |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame^] | 31 | @TestApi |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 32 | public class WindowOrganizer { |
| 33 | |
| 34 | /** |
| 35 | * Apply multiple WindowContainer operations at once. |
| 36 | * @param t The transaction to apply. |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 37 | */ |
| 38 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame^] | 39 | public static void applyTransaction(@NonNull WindowContainerTransaction t) { |
| 40 | try { |
| 41 | getWindowOrganizerController().applyTransaction(t); |
| 42 | } catch (RemoteException e) { |
| 43 | throw e.rethrowFromSystemServer(); |
| 44 | } |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Apply multiple WindowContainer operations at once. |
| 49 | * @param t The transaction to apply. |
| 50 | * @param callback This transaction will use the synchronization scheme described in |
| 51 | * BLASTSyncEngine.java. The SurfaceControl transaction containing the effects of this |
| 52 | * WindowContainer transaction will be passed to this callback when ready. |
| 53 | * @return An ID for the sync operation which will later be passed to transactionReady callback. |
| 54 | * This lets the caller differentiate overlapping sync operations. |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 55 | */ |
| 56 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame^] | 57 | public int applySyncTransaction(@NonNull WindowContainerTransaction t, |
| 58 | @NonNull WindowContainerTransactionCallback callback) { |
| 59 | try { |
| 60 | return getWindowOrganizerController().applySyncTransaction(t, callback.mInterface); |
| 61 | } catch (RemoteException e) { |
| 62 | throw e.rethrowFromSystemServer(); |
| 63 | } |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 66 | @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS) |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame^] | 67 | static IWindowOrganizerController getWindowOrganizerController() { |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 68 | return IWindowOrganizerControllerSingleton.get(); |
| 69 | } |
| 70 | |
| 71 | private static final Singleton<IWindowOrganizerController> IWindowOrganizerControllerSingleton = |
| 72 | new Singleton<IWindowOrganizerController>() { |
| 73 | @Override |
| 74 | protected IWindowOrganizerController create() { |
| 75 | try { |
| 76 | return ActivityTaskManager.getService().getWindowOrganizerController(); |
| 77 | } catch (RemoteException e) { |
| 78 | return null; |
| 79 | } |
| 80 | } |
| 81 | }; |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 82 | } |