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 | |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 37 | public DisplayWindowController(Display display, WindowContainerListener listener) { |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 38 | super(listener, WindowManagerService.getInstance()); |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 39 | mDisplayId = display.getDisplayId(); |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 40 | |
| 41 | synchronized (mWindowMap) { |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 42 | final long callingIdentity = Binder.clearCallingIdentity(); |
| 43 | try { |
| 44 | mRoot.createDisplayContent(display, this /* controller */); |
| 45 | } finally { |
| 46 | Binder.restoreCallingIdentity(callingIdentity); |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 49 | if (mContainer == null) { |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 50 | throw new IllegalArgumentException("Trying to add display=" + display |
| 51 | + " dc=" + mRoot.getDisplayContent(mDisplayId)); |
Winson Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public void removeContainer() { |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 58 | 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 Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void onOverrideConfigurationChanged(Configuration overrideConfiguration) { |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 71 | // 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 Chung | 59a47ded | 2018-01-25 17:46:06 +0000 | [diff] [blame] | 74 | } |
| 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 | } |