blob: 0ec0c7b53875ad896523fde05bb07312fb3701e6 [file] [log] [blame]
Adrian Roos22a20a82019-10-23 19:05:33 +02001/*
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 com.android.server.wm;
18
Adrian Roos639ce072020-02-06 16:45:18 -080019import android.content.res.Resources;
20import android.text.TextUtils;
21
Adrian Roos22a20a82019-10-23 19:05:33 +020022import com.android.server.wm.DisplayContent.TaskContainers;
23
24/**
25 * Policy that manages DisplayAreas.
26 */
27public abstract class DisplayAreaPolicy {
28 protected final WindowManagerService mWmService;
29 protected final DisplayContent mContent;
30
31 /**
32 * The root DisplayArea. Attach all DisplayAreas to this area (directly or indirectly).
33 */
34 protected final DisplayArea.Root mRoot;
35
36 /**
37 * The IME container. The IME's windows are automatically added to this container.
38 */
39 protected final DisplayArea<? extends WindowContainer> mImeContainer;
40
41 /**
42 * The Tasks container. Tasks etc. are automatically added to this container.
43 */
Adrian Roos81163582020-01-08 23:21:16 +010044 protected final DisplayArea<? extends ActivityStack> mTaskContainers;
Adrian Roos22a20a82019-10-23 19:05:33 +020045
Adrian Roos639ce072020-02-06 16:45:18 -080046 /**
47 * Construct a new {@link DisplayAreaPolicy}
48 *
49 * @param wmService the window manager service instance
50 * @param content the display content for which the policy applies
51 * @param root the root display area under which the policy operates
52 * @param imeContainer the ime container that the policy must attach
53 * @param taskContainers the task container that the policy must attach
54 *
55 * @see #attachDisplayAreas()
56 */
57 protected DisplayAreaPolicy(WindowManagerService wmService,
Adrian Roos22a20a82019-10-23 19:05:33 +020058 DisplayContent content, DisplayArea.Root root,
Adrian Roos81163582020-01-08 23:21:16 +010059 DisplayArea<? extends WindowContainer> imeContainer,
60 DisplayArea<? extends ActivityStack> taskContainers) {
Adrian Roos22a20a82019-10-23 19:05:33 +020061 mWmService = wmService;
62 mContent = content;
63 mRoot = root;
64 mImeContainer = imeContainer;
65 mTaskContainers = taskContainers;
66 }
67
68 /**
69 * Called to ask the policy to set up the DisplayArea hierarchy. At a minimum this must:
70 *
71 * - attach mImeContainer to mRoot (or one of its descendants)
72 * - attach mTaskStacks to mRoot (or one of its descendants)
73 *
74 * Additionally, this is the right place to set up any other DisplayAreas as desired.
75 */
76 public abstract void attachDisplayAreas();
77
78 /**
79 * Called to ask the policy to attach the given WindowToken to the DisplayArea hierarchy.
80 *
81 * This must attach the token to mRoot (or one of its descendants).
82 */
83 public abstract void addWindow(WindowToken token);
84
Adrian Roos81163582020-01-08 23:21:16 +010085 /** Provider for platform-default display area policy. */
86 static final class DefaultProvider implements DisplayAreaPolicy.Provider {
87 @Override
88 public DisplayAreaPolicy instantiate(WindowManagerService wmService,
89 DisplayContent content, DisplayArea.Root root,
Adrian Roos22a20a82019-10-23 19:05:33 +020090 DisplayArea<? extends WindowContainer> imeContainer,
91 TaskContainers taskContainers) {
Adrian Roos81163582020-01-08 23:21:16 +010092 return new DisplayAreaPolicyBuilder()
93 .build(wmService, content, root, imeContainer, taskContainers);
Adrian Roos639ce072020-02-06 16:45:18 -080094 }
95 }
96
97 /**
98 * Provider for {@link DisplayAreaPolicy} instances.
99 *
100 * By implementing this interface and overriding the
101 * {@code config_deviceSpecificDisplayAreaPolicyProvider}, a device-specific implementations
102 * of {@link DisplayAreaPolicy} can be supplied.
103 */
104 public interface Provider {
105 /**
106 * Instantiate a new DisplayAreaPolicy.
107 *
108 * @see DisplayAreaPolicy#DisplayAreaPolicy
109 */
110 DisplayAreaPolicy instantiate(WindowManagerService wmService,
111 DisplayContent content, DisplayArea.Root root,
112 DisplayArea<? extends WindowContainer> imeContainer,
113 TaskContainers taskContainers);
114
115 /**
116 * Instantiate the device-specific {@link Provider}.
117 */
118 static Provider fromResources(Resources res) {
119 String name = res.getString(
120 com.android.internal.R.string.config_deviceSpecificDisplayAreaPolicyProvider);
121 if (TextUtils.isEmpty(name)) {
Adrian Roos81163582020-01-08 23:21:16 +0100122 return new DisplayAreaPolicy.DefaultProvider();
Adrian Roos639ce072020-02-06 16:45:18 -0800123 }
124 try {
125 return (Provider) Class.forName(name).newInstance();
126 } catch (ReflectiveOperationException | ClassCastException e) {
127 throw new IllegalStateException("Couldn't instantiate class " + name
128 + " for config_deviceSpecificDisplayAreaPolicyProvider:"
129 + " make sure it has a public zero-argument constructor"
130 + " and implements DisplayAreaPolicy.Provider", e);
131 }
132 }
Adrian Roos22a20a82019-10-23 19:05:33 +0200133 }
134}