blob: 0e1283899eeacdc06d657efe2f06290673642f48 [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
37 public DisplayWindowController(int displayId, WindowContainerListener listener) {
38 super(listener, WindowManagerService.getInstance());
39 mDisplayId = displayId;
40
41 synchronized (mWindowMap) {
Bryce Leef19cbe22018-02-02 15:09:21 -080042 final Display display = mService.mDisplayManager.getDisplay(displayId);
43 if (display != null) {
44 final long callingIdentity = Binder.clearCallingIdentity();
45 try {
46 mRoot.createDisplayContent(display, this /* controller */);
47 } finally {
48 Binder.restoreCallingIdentity(callingIdentity);
49 }
50 }
51
Winson Chung59a47ded2018-01-25 17:46:06 +000052 if (mContainer == null) {
53 throw new IllegalArgumentException("Trying to add displayId=" + displayId);
54 }
55 }
56 }
57
58 @Override
59 public void removeContainer() {
Bryce Leef19cbe22018-02-02 15:09:21 -080060 synchronized (mWindowMap) {
61 if(mContainer == null) {
62 if (DEBUG_DISPLAY) Slog.i(TAG_WM, "removeDisplay: could not find displayId="
63 + mDisplayId);
64 return;
65 }
66 mContainer.removeIfPossible();
67 super.removeContainer();
68 }
Winson Chung59a47ded2018-01-25 17:46:06 +000069 }
70
71 @Override
72 public void onOverrideConfigurationChanged(Configuration overrideConfiguration) {
Bryce Leef19cbe22018-02-02 15:09:21 -080073 // TODO: The container receives override configuration changes through other means. enabling
74 // callbacks through the controller causes layout issues. Investigate consolidating
75 // override configuration propagation to just here.
Winson Chung59a47ded2018-01-25 17:46:06 +000076 }
77
78 /**
79 * Positions the task stack at the given position in the task stack container.
80 */
81 public void positionChildAt(StackWindowController child, int position) {
82 synchronized (mWindowMap) {
83 if (DEBUG_STACK) Slog.i(TAG_WM, "positionTaskStackAt: positioning stack=" + child
84 + " at " + position);
85 if (mContainer == null) {
86 if (DEBUG_STACK) Slog.i(TAG_WM,
87 "positionTaskStackAt: could not find display=" + mContainer);
88 return;
89 }
90 if (child.mContainer == null) {
91 if (DEBUG_STACK) Slog.i(TAG_WM,
92 "positionTaskStackAt: could not find stack=" + this);
93 return;
94 }
95 mContainer.positionStackAt(position, child.mContainer);
96 }
97 }
98
99 @Override
100 public String toString() {
101 return "{DisplayWindowController displayId=" + mDisplayId + "}";
102 }
103}