1 /* 2 * Copyright (C) 2021 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 com.android.server.wm; 18 19 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; 20 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; 21 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; 22 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; 23 import static android.window.DisplayAreaOrganizer.FEATURE_DEFAULT_TASK_CONTAINER; 24 import static android.window.DisplayAreaOrganizer.FEATURE_IME_PLACEHOLDER; 25 import static android.window.DisplayAreaOrganizer.FEATURE_VENDOR_FIRST; 26 27 import java.util.ArrayList; 28 import java.util.List; 29 30 /** 31 * Provider for platform-default car display area policy for reference design. 32 */ 33 public class CarDisplayAreaPolicyProvider implements DisplayAreaPolicy.Provider { 34 35 /** 36 * This display area is mandatory to be defined. This is where the applications will be 37 * launched. 38 */ 39 private static final int DEFAULT_APP_TASK_CONTAINER = FEATURE_DEFAULT_TASK_CONTAINER; 40 41 /** 42 * The display partition to launch applications by default. This contains {@link 43 * #DEFAULT_APP_TASK_CONTAINER}. 44 */ 45 private static final int FOREGROUND_DISPLAY_AREA_ROOT = FEATURE_VENDOR_FIRST + 1; 46 47 /** 48 * Background applications task container. 49 */ 50 private static final int BACKGROUND_TASK_CONTAINER = FEATURE_VENDOR_FIRST + 2; 51 private static final int FEATURE_TASKDISPLAYAREA_PARENT = FEATURE_VENDOR_FIRST + 3; 52 53 /** 54 * Control bar task container. 55 * 56 * Currently we are launching CarLauncher activity in this TDA. This is because the audio card 57 * implementation today is using fragments. If that changes in future then we can use the window 58 * instead to display that view instead of fragments that need an activity. 59 */ 60 private static final int CONTROL_BAR_DISPLAY_AREA = FEATURE_VENDOR_FIRST + 4; 61 62 /** 63 * Feature to display the title bar. 64 */ 65 private static final int FEATURE_TITLE_BAR = FEATURE_VENDOR_FIRST + 5; 66 67 private static final int FEATURE_VOICE_PLATE = FEATURE_VENDOR_FIRST + 6; 68 69 @Override instantiate(WindowManagerService wmService, DisplayContent content, RootDisplayArea root, DisplayArea.Tokens imeContainer)70 public DisplayAreaPolicy instantiate(WindowManagerService wmService, DisplayContent content, 71 RootDisplayArea root, DisplayArea.Tokens imeContainer) { 72 73 if (!content.isDefaultDisplay) { 74 return new DisplayAreaPolicy.DefaultProvider().instantiate(wmService, content, root, 75 imeContainer); 76 } 77 78 TaskDisplayArea backgroundTaskDisplayArea = new TaskDisplayArea(content, wmService, 79 "BackgroundTaskDisplayArea", BACKGROUND_TASK_CONTAINER, 80 /* createdByOrganizer= */ false, /* canHostHomeTask= */ false); 81 82 TaskDisplayArea controlBarDisplayArea = new TaskDisplayArea(content, wmService, 83 "ControlBarTaskDisplayArea", CONTROL_BAR_DISPLAY_AREA, 84 /* createdByOrganizer= */ false, /* canHostHomeTask= */ false); 85 86 TaskDisplayArea voicePlateTaskDisplayArea = new TaskDisplayArea(content, wmService, 87 "VoicePlateTaskDisplayArea", FEATURE_VOICE_PLATE, 88 /* createdByOrganizer= */ false, /* canHostHomeTask= */ false); 89 90 List<TaskDisplayArea> backgroundTdaList = new ArrayList<>(); 91 backgroundTdaList.add(voicePlateTaskDisplayArea); 92 backgroundTdaList.add(backgroundTaskDisplayArea); 93 backgroundTdaList.add(controlBarDisplayArea); 94 95 // Root 96 DisplayAreaPolicyBuilder.HierarchyBuilder rootHierarchy = 97 new DisplayAreaPolicyBuilder.HierarchyBuilder(root) 98 .setTaskDisplayAreas(backgroundTdaList) 99 .addFeature(new DisplayAreaPolicyBuilder.Feature.Builder(wmService.mPolicy, 100 "ImePlaceholder", FEATURE_IME_PLACEHOLDER) 101 .and(TYPE_INPUT_METHOD, TYPE_INPUT_METHOD_DIALOG) 102 .build()) 103 // to make sure there are 2 children under root. 104 // TODO: replace when b/188102153 is resolved to set this to top. 105 .addFeature(new DisplayAreaPolicyBuilder.Feature.Builder(wmService.mPolicy, 106 "TaskDisplayAreaParent", FEATURE_TASKDISPLAYAREA_PARENT) 107 .and(TYPE_APPLICATION) 108 .build()); 109 110 // Default application launches here 111 RootDisplayArea defaultAppsRoot = new DisplayAreaGroup(wmService, 112 "FeatureForegroundApplication", FOREGROUND_DISPLAY_AREA_ROOT); 113 TaskDisplayArea defaultAppTaskDisplayArea = new TaskDisplayArea(content, wmService, 114 "DefaultApplicationTaskDisplayArea", DEFAULT_APP_TASK_CONTAINER); 115 List<TaskDisplayArea> firstTdaList = new ArrayList<>(); 116 firstTdaList.add(defaultAppTaskDisplayArea); 117 DisplayAreaPolicyBuilder.HierarchyBuilder applicationHierarchy = 118 new DisplayAreaPolicyBuilder.HierarchyBuilder(defaultAppsRoot) 119 .setTaskDisplayAreas(firstTdaList) 120 .setImeContainer(imeContainer) 121 .addFeature(new DisplayAreaPolicyBuilder.Feature.Builder(wmService.mPolicy, 122 "ImePlaceholder", FEATURE_IME_PLACEHOLDER) 123 .and(TYPE_INPUT_METHOD, TYPE_INPUT_METHOD_DIALOG) 124 .build()) 125 .addFeature(new DisplayAreaPolicyBuilder.Feature.Builder(wmService.mPolicy, 126 "TitleBar", FEATURE_TITLE_BAR) 127 .and(TYPE_APPLICATION_OVERLAY) 128 .build()); 129 130 return new DisplayAreaPolicyBuilder() 131 .setRootHierarchy(rootHierarchy) 132 .addDisplayAreaGroupHierarchy(applicationHierarchy) 133 .build(wmService); 134 } 135 } 136