Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame^] | 19 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY; |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 20 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
| 21 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 22 | |
| 23 | import android.content.res.Configuration; |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame^] | 24 | import android.os.Binder; |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 25 | import android.util.Slog; |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame^] | 26 | import android.view.Display; |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 27 | |
| 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 | */ |
| 32 | public 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 Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame^] | 42 | 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 Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 52 | if (mContainer == null) { |
| 53 | throw new IllegalArgumentException("Trying to add displayId=" + displayId); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void removeContainer() { |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame^] | 60 | 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 Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void onOverrideConfigurationChanged(Configuration overrideConfiguration) { |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame^] | 73 | // 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 Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 76 | } |
| 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 | } |