blob: ba8ec69f36055c1c7c0998871288b1414f48b4ff [file] [log] [blame]
Winson Chung59a47ded2018-01-25 17:46:06 +00001/*
2 * Copyright (C) 2018 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
Bryce Leef19cbe22018-02-02 15:09:21 -080019import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Winson Chung59a47ded2018-01-25 17:46:06 +000020import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
21import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
22
23import android.content.res.Configuration;
Bryce Leef19cbe22018-02-02 15:09:21 -080024import android.os.Binder;
Winson Chung59a47ded2018-01-25 17:46:06 +000025import android.util.Slog;
Bryce Leef19cbe22018-02-02 15:09:21 -080026import android.view.Display;
Winson Chung59a47ded2018-01-25 17:46:06 +000027
28/**
29 * Controller for the display container. This is created by activity manager to link activity
30 * displays to the display content they use in window manager.
31 */
32public class DisplayWindowController
33 extends WindowContainerController<DisplayContent, WindowContainerListener> {
34
35 private final int mDisplayId;
36
Wale Ogunwale45477b52018-03-06 12:24:19 -080037 public DisplayWindowController(Display display, WindowContainerListener listener) {
Winson Chung59a47ded2018-01-25 17:46:06 +000038 super(listener, WindowManagerService.getInstance());
Wale Ogunwale45477b52018-03-06 12:24:19 -080039 mDisplayId = display.getDisplayId();
Winson Chung59a47ded2018-01-25 17:46:06 +000040
41 synchronized (mWindowMap) {
Wale Ogunwale45477b52018-03-06 12:24:19 -080042 final long callingIdentity = Binder.clearCallingIdentity();
43 try {
44 mRoot.createDisplayContent(display, this /* controller */);
45 } finally {
46 Binder.restoreCallingIdentity(callingIdentity);
Bryce Leef19cbe22018-02-02 15:09:21 -080047 }
48
Winson Chung59a47ded2018-01-25 17:46:06 +000049 if (mContainer == null) {
Wale Ogunwale45477b52018-03-06 12:24:19 -080050 throw new IllegalArgumentException("Trying to add display=" + display
51 + " dc=" + mRoot.getDisplayContent(mDisplayId));
Winson Chung59a47ded2018-01-25 17:46:06 +000052 }
53 }
54 }
55
56 @Override
57 public void removeContainer() {
Bryce Leef19cbe22018-02-02 15:09:21 -080058 synchronized (mWindowMap) {
59 if(mContainer == null) {
60 if (DEBUG_DISPLAY) Slog.i(TAG_WM, "removeDisplay: could not find displayId="
61 + mDisplayId);
62 return;
63 }
64 mContainer.removeIfPossible();
65 super.removeContainer();
66 }
Winson Chung59a47ded2018-01-25 17:46:06 +000067 }
68
69 @Override
70 public void onOverrideConfigurationChanged(Configuration overrideConfiguration) {
Bryce Leef19cbe22018-02-02 15:09:21 -080071 // TODO: The container receives override configuration changes through other means. enabling
72 // callbacks through the controller causes layout issues. Investigate consolidating
73 // override configuration propagation to just here.
Winson Chung59a47ded2018-01-25 17:46:06 +000074 }
75
76 /**
77 * Positions the task stack at the given position in the task stack container.
78 */
79 public void positionChildAt(StackWindowController child, int position) {
80 synchronized (mWindowMap) {
81 if (DEBUG_STACK) Slog.i(TAG_WM, "positionTaskStackAt: positioning stack=" + child
82 + " at " + position);
83 if (mContainer == null) {
84 if (DEBUG_STACK) Slog.i(TAG_WM,
85 "positionTaskStackAt: could not find display=" + mContainer);
86 return;
87 }
88 if (child.mContainer == null) {
89 if (DEBUG_STACK) Slog.i(TAG_WM,
90 "positionTaskStackAt: could not find stack=" + this);
91 return;
92 }
93 mContainer.positionStackAt(position, child.mContainer);
94 }
95 }
96
97 @Override
98 public String toString() {
99 return "{DisplayWindowController displayId=" + mDisplayId + "}";
100 }
101}