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.CallSuper; 20 import android.annotation.NonNull; 21 import android.annotation.RequiresPermission; 22 import android.annotation.TestApi; 23 import android.os.RemoteException; 24 import android.view.SurfaceControl; 25 26 import java.util.List; 27 import java.util.concurrent.Executor; 28 29 /** 30 * Interface for WindowManager to delegate control of display areas. 31 * @hide 32 */ 33 @TestApi 34 public class DisplayAreaOrganizer extends WindowOrganizer { 35 36 /** 37 * Key to specify the {@link com.android.server.wm.RootDisplayArea} to attach a window to. 38 * It will be used by the function passed in from 39 * {@link com.android.server.wm.DisplayAreaPolicyBuilder#setSelectRootForWindowFunc(BiFunction)} 40 * to find the Root DA to attach the window. 41 * @hide 42 */ 43 public static final String KEY_ROOT_DISPLAY_AREA_ID = "root_display_area_id"; 44 45 /** 46 * The value in display area indicating that no value has been set. 47 */ 48 public static final int FEATURE_UNDEFINED = -1; 49 50 /** 51 * The Root display area on a display 52 */ 53 public static final int FEATURE_SYSTEM_FIRST = 0; 54 55 /** 56 * The Root display area on a display 57 */ 58 public static final int FEATURE_ROOT = FEATURE_SYSTEM_FIRST; 59 60 /** 61 * Display area hosting the default task container. 62 */ 63 public static final int FEATURE_DEFAULT_TASK_CONTAINER = FEATURE_SYSTEM_FIRST + 1; 64 65 /** 66 * Display area hosting non-activity window tokens. 67 */ 68 public static final int FEATURE_WINDOW_TOKENS = FEATURE_SYSTEM_FIRST + 2; 69 70 /** 71 * Display area for one handed feature 72 */ 73 public static final int FEATURE_ONE_HANDED = FEATURE_SYSTEM_FIRST + 3; 74 75 /** 76 * Display area that can be magnified in 77 * {@link Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW}. It contains all windows 78 * below {@link WindowManager.LayoutParams#TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY}. 79 */ 80 public static final int FEATURE_WINDOWED_MAGNIFICATION = FEATURE_SYSTEM_FIRST + 4; 81 82 /** 83 * Display area that can be magnified in 84 * {@link Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN}. This is different from 85 * {@link #FEATURE_WINDOWED_MAGNIFICATION} that the whole display will be magnified. 86 * @hide 87 */ 88 public static final int FEATURE_FULLSCREEN_MAGNIFICATION = FEATURE_SYSTEM_FIRST + 5; 89 90 /** 91 * Display area for hiding display cutout feature 92 * @hide 93 */ 94 public static final int FEATURE_HIDE_DISPLAY_CUTOUT = FEATURE_SYSTEM_FIRST + 6; 95 96 /** 97 * Display area that the IME container can be placed in. Should be enabled on every root 98 * hierarchy if IME container may be reparented to that hierarchy when the IME target changed. 99 * @hide 100 */ 101 public static final int FEATURE_IME_PLACEHOLDER = FEATURE_SYSTEM_FIRST + 7; 102 103 /** 104 * Display area for one handed background layer, which preventing when user 105 * turning the Dark theme on, they can not clearly identify the screen has entered 106 * one handed mode. 107 * @hide 108 */ 109 public static final int FEATURE_ONE_HANDED_BACKGROUND_PANEL = FEATURE_SYSTEM_FIRST + 8; 110 111 /** 112 * The last boundary of display area for system features 113 */ 114 public static final int FEATURE_SYSTEM_LAST = 10_000; 115 116 /** 117 * Vendor specific display area definition can start with this value. 118 */ 119 public static final int FEATURE_VENDOR_FIRST = FEATURE_SYSTEM_LAST + 1; 120 121 /** 122 * Last possible vendor specific display area id. 123 * @hide 124 */ 125 public static final int FEATURE_VENDOR_LAST = FEATURE_VENDOR_FIRST + 10_000; 126 127 /** 128 * Task display areas that can be created at runtime start with this value. 129 * @see #createTaskDisplayArea(int, int, String) 130 * @hide 131 */ 132 public static final int FEATURE_RUNTIME_TASK_CONTAINER_FIRST = FEATURE_VENDOR_LAST + 1; 133 134 // Callbacks WM Core are posted on this executor if it isn't null, otherwise direct calls are 135 // made on the incoming binder call. 136 private final Executor mExecutor; 137 138 /** @hide */ DisplayAreaOrganizer(@onNull Executor executor)139 public DisplayAreaOrganizer(@NonNull Executor executor) { 140 mExecutor = executor; 141 } 142 143 /** 144 * Gets the executor to run callbacks on. 145 * @hide 146 */ 147 @NonNull getExecutor()148 public Executor getExecutor() { 149 return mExecutor; 150 } 151 152 /** 153 * Registers a DisplayAreaOrganizer to manage display areas for a given feature. A feature can 154 * not be registered by multiple organizers at the same time. 155 * 156 * @return a list of display areas that should be managed by the organizer. 157 * @throws IllegalStateException if the feature has already been registered. 158 */ 159 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 160 @CallSuper 161 @NonNull registerOrganizer(int displayAreaFeature)162 public List<DisplayAreaAppearedInfo> registerOrganizer(int displayAreaFeature) { 163 try { 164 return getController().registerOrganizer(mInterface, displayAreaFeature).getList(); 165 } catch (RemoteException e) { 166 throw e.rethrowFromSystemServer(); 167 } 168 } 169 170 /** 171 * @hide 172 */ 173 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 174 @CallSuper unregisterOrganizer()175 public void unregisterOrganizer() { 176 try { 177 getController().unregisterOrganizer(mInterface); 178 } catch (RemoteException e) { 179 throw e.rethrowFromSystemServer(); 180 } 181 } 182 183 /** 184 * Creates a persistent {@link com.android.server.wm.TaskDisplayArea}. 185 * 186 * The new created TDA is organized by the organizer, and will be deleted on calling 187 * {@link #deleteTaskDisplayArea(WindowContainerToken)} or {@link #unregisterOrganizer()}. 188 * 189 * @param displayId the display to create the new TDA in. 190 * @param parentFeatureId the parent to create the new TDA in. If it is a 191 * {@link com.android.server.wm.RootDisplayArea}, the new TDA will be 192 * placed as the topmost TDA. If it is another TDA, the new TDA will be 193 * placed as the topmost child. 194 * Caller can use {@link #FEATURE_ROOT} as the root of the logical 195 * display, or {@link #FEATURE_DEFAULT_TASK_CONTAINER} as the default 196 * TDA. 197 * @param name the name for the new task display area. 198 * @return the new created task display area. 199 * @throws IllegalArgumentException if failed to create a new task display area. 200 * @hide 201 */ 202 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 203 @CallSuper 204 @NonNull createTaskDisplayArea(int displayId, int parentFeatureId, @NonNull String name)205 public DisplayAreaAppearedInfo createTaskDisplayArea(int displayId, int parentFeatureId, 206 @NonNull String name) { 207 try { 208 return getController().createTaskDisplayArea( 209 mInterface, displayId, parentFeatureId, name); 210 } catch (RemoteException e) { 211 throw e.rethrowFromSystemServer(); 212 } 213 } 214 215 /** 216 * Deletes a persistent task display area. It can only be one that created by an organizer. 217 * 218 * @throws IllegalArgumentException if failed to delete the task display area. 219 * @hide 220 */ 221 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) 222 @CallSuper deleteTaskDisplayArea(@onNull WindowContainerToken taskDisplayArea)223 public void deleteTaskDisplayArea(@NonNull WindowContainerToken taskDisplayArea) { 224 try { 225 getController().deleteTaskDisplayArea(taskDisplayArea); 226 } catch (RemoteException e) { 227 throw e.rethrowFromSystemServer(); 228 } 229 } 230 231 /** 232 * Called when a DisplayArea of the registered window type can be controlled by this organizer. 233 * It will not be called for the DisplayAreas that exist when {@link #registerOrganizer(int)} is 234 * called. 235 */ onDisplayAreaAppeared(@onNull DisplayAreaInfo displayAreaInfo, @NonNull SurfaceControl leash)236 public void onDisplayAreaAppeared(@NonNull DisplayAreaInfo displayAreaInfo, 237 @NonNull SurfaceControl leash) {} 238 onDisplayAreaVanished(@onNull DisplayAreaInfo displayAreaInfo)239 public void onDisplayAreaVanished(@NonNull DisplayAreaInfo displayAreaInfo) {} 240 241 /** 242 * @hide 243 */ onDisplayAreaInfoChanged(@onNull DisplayAreaInfo displayAreaInfo)244 public void onDisplayAreaInfoChanged(@NonNull DisplayAreaInfo displayAreaInfo) {} 245 246 private final IDisplayAreaOrganizer mInterface = new IDisplayAreaOrganizer.Stub() { 247 248 @Override 249 public void onDisplayAreaAppeared(@NonNull DisplayAreaInfo displayAreaInfo, 250 @NonNull SurfaceControl leash) { 251 mExecutor.execute( 252 () -> DisplayAreaOrganizer.this.onDisplayAreaAppeared(displayAreaInfo, leash)); 253 } 254 255 @Override 256 public void onDisplayAreaVanished(@NonNull DisplayAreaInfo displayAreaInfo) { 257 mExecutor.execute( 258 () -> DisplayAreaOrganizer.this.onDisplayAreaVanished(displayAreaInfo)); 259 } 260 261 @Override 262 public void onDisplayAreaInfoChanged(@NonNull DisplayAreaInfo displayAreaInfo) { 263 mExecutor.execute( 264 () -> DisplayAreaOrganizer.this.onDisplayAreaInfoChanged(displayAreaInfo)); 265 } 266 }; 267 268 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS) getController()269 private IDisplayAreaOrganizerController getController() { 270 try { 271 return getWindowOrganizerController().getDisplayAreaOrganizerController(); 272 } catch (RemoteException e) { 273 return null; 274 } 275 } 276 } 277