|
165 | 165 | /** {@hide} */ |
166 | 166 | public class WindowManagerService extends IWindowManager.Stub |
167 | 167 | implements Watchdog.Monitor, WindowManagerPolicy.WindowManagerFuncs, |
168 | | - DisplayManagerService.WindowManagerFuncs { |
| 168 | + DisplayManagerService.WindowManagerFuncs, DisplayManager.DisplayListener { |
169 | 169 | static final String TAG = "WindowManager"; |
170 | 170 | static final boolean DEBUG = false; |
171 | 171 | static final boolean DEBUG_ADD_REMOVE = false; |
@@ -782,9 +782,15 @@ private WindowManagerService(Context context, PowerManagerService pm, |
782 | 782 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
783 | 783 | com.android.internal.R.bool.config_sf_limitedAlpha); |
784 | 784 | mDisplayManagerService = displayManager; |
785 | | - mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); |
786 | 785 | mHeadless = displayManager.isHeadless(); |
787 | 786 |
|
| 787 | + mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); |
| 788 | + mDisplayManager.registerDisplayListener(this, null); |
| 789 | + Display[] displays = mDisplayManager.getDisplays(); |
| 790 | + for (Display display : displays) { |
| 791 | + createDisplayContent(display); |
| 792 | + } |
| 793 | + |
788 | 794 | mKeyguardDisableHandler = new KeyguardDisableHandler(mContext, mPolicy); |
789 | 795 |
|
790 | 796 | mPowerManager = pm; |
@@ -1120,6 +1126,10 @@ private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
1120 | 1126 | if (win.mAppToken != null && addToToken) { |
1121 | 1127 | win.mAppToken.allAppWindows.add(win); |
1122 | 1128 | } |
| 1129 | + |
| 1130 | + if (windows.size() == 1) { |
| 1131 | + mDisplayManagerService.setDisplayHasContent(win.getDisplayId(), true); |
| 1132 | + } |
1123 | 1133 | } |
1124 | 1134 |
|
1125 | 1135 | /** TODO(cmautner): Is this the same as {@link WindowState#canReceiveKeys()} */ |
@@ -2408,6 +2418,9 @@ private void removeWindowInnerLocked(Session session, WindowState win) { |
2408 | 2418 |
|
2409 | 2419 | final WindowList windows = win.getWindowList(); |
2410 | 2420 | windows.remove(win); |
| 2421 | + if (windows.isEmpty()) { |
| 2422 | + mDisplayManagerService.setDisplayHasContent(win.getDisplayId(), false); |
| 2423 | + } |
2411 | 2424 | mPendingRemove.remove(win); |
2412 | 2425 | mWindowsChanged = true; |
2413 | 2426 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win); |
@@ -7194,6 +7207,10 @@ final class H extends Handler { |
7194 | 7207 | public static final int NOTIFY_WINDOW_TRANSITION = 29; |
7195 | 7208 | public static final int NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED = 30; |
7196 | 7209 |
|
| 7210 | + public static final int DO_DISPLAY_ADDED = 31; |
| 7211 | + public static final int DO_DISPLAY_REMOVED = 32; |
| 7212 | + public static final int DO_DISPLAY_CHANGED = 33; |
| 7213 | + |
7197 | 7214 | public static final int ANIMATOR_WHAT_OFFSET = 100000; |
7198 | 7215 | public static final int SET_TRANSPARENT_REGION = ANIMATOR_WHAT_OFFSET + 1; |
7199 | 7216 | public static final int CLEAR_PENDING_ACTIONS = ANIMATOR_WHAT_OFFSET + 2; |
@@ -7631,25 +7648,46 @@ public void handleMessage(Message msg) { |
7631 | 7648 | } |
7632 | 7649 | break; |
7633 | 7650 | } |
| 7651 | + |
7634 | 7652 | case NOTIFY_ROTATION_CHANGED: { |
7635 | 7653 | final int displayId = msg.arg1; |
7636 | 7654 | final int rotation = msg.arg2; |
7637 | 7655 | handleNotifyRotationChanged(displayId, rotation); |
7638 | 7656 | break; |
7639 | 7657 | } |
| 7658 | + |
7640 | 7659 | case NOTIFY_WINDOW_TRANSITION: { |
7641 | 7660 | final int transition = msg.arg1; |
7642 | 7661 | WindowInfo info = (WindowInfo) msg.obj; |
7643 | 7662 | handleNotifyWindowTranstion(transition, info); |
7644 | 7663 | break; |
7645 | 7664 | } |
| 7665 | + |
7646 | 7666 | case NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED: { |
7647 | 7667 | final int displayId = msg.arg1; |
7648 | 7668 | final boolean immediate = (msg.arg2 == 1); |
7649 | 7669 | Rect rectangle = (Rect) msg.obj; |
7650 | 7670 | handleNotifyRectangleOnScreenRequested(displayId, rectangle, immediate); |
7651 | 7671 | break; |
7652 | 7672 | } |
| 7673 | + |
| 7674 | + case DO_DISPLAY_ADDED: |
| 7675 | + synchronized (mWindowMap) { |
| 7676 | + handleDisplayAddedLocked(msg.arg1); |
| 7677 | + } |
| 7678 | + break; |
| 7679 | + |
| 7680 | + case DO_DISPLAY_REMOVED: |
| 7681 | + synchronized (mWindowMap) { |
| 7682 | + handleDisplayRemovedLocked(msg.arg1); |
| 7683 | + } |
| 7684 | + break; |
| 7685 | + |
| 7686 | + case DO_DISPLAY_CHANGED: |
| 7687 | + synchronized (mWindowMap) { |
| 7688 | + handleDisplayChangedLocked(msg.arg1); |
| 7689 | + } |
| 7690 | + break; |
7653 | 7691 | } |
7654 | 7692 | if (DEBUG_WINDOW_TRACE) { |
7655 | 7693 | Slog.v(TAG, "handleMessage: exit"); |
@@ -8866,8 +8904,6 @@ private final void performLayoutAndPlaceSurfacesLockedInner(boolean recoveringMe |
8866 | 8904 | final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo(); |
8867 | 8905 | final int defaultDw = defaultInfo.logicalWidth; |
8868 | 8906 | final int defaultDh = defaultInfo.logicalHeight; |
8869 | | - final int defaultInnerDw = defaultInfo.appWidth; |
8870 | | - final int defaultInnerDh = defaultInfo.appHeight; |
8871 | 8907 |
|
8872 | 8908 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
8873 | 8909 | ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
@@ -9441,6 +9477,7 @@ void setHoldScreenLocked(final Session newHoldScreen) { |
9441 | 9477 | } |
9442 | 9478 | } |
9443 | 9479 |
|
| 9480 | + @Override |
9444 | 9481 | public void requestTraversal() { |
9445 | 9482 | synchronized (mWindowMap) { |
9446 | 9483 | requestTraversalLocked(); |
@@ -10465,7 +10502,7 @@ void dumpWindowsNoHeaderLocked(PrintWriter pw, boolean dumpAll, |
10465 | 10502 |
|
10466 | 10503 | boolean dumpWindows(PrintWriter pw, String name, String[] args, |
10467 | 10504 | int opti, boolean dumpAll) { |
10468 | | - ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 10505 | + WindowList windows = new WindowList(); |
10469 | 10506 | if ("visible".equals(name)) { |
10470 | 10507 | synchronized(mWindowMap) { |
10471 | 10508 | final AllWindowsIterator iterator = new AllWindowsIterator(REVERSE_ITERATOR); |
@@ -10673,6 +10710,14 @@ void debugLayoutRepeats(final String msg, int pendingLayoutChanges) { |
10673 | 10710 | } |
10674 | 10711 | } |
10675 | 10712 |
|
| 10713 | + public void createDisplayContent(final Display display) { |
| 10714 | + if (display == null) { |
| 10715 | + throw new IllegalArgumentException("getDisplayContent: display must not be null"); |
| 10716 | + } |
| 10717 | + final DisplayContent displayContent = new DisplayContent(display); |
| 10718 | + mDisplayContents.put(display.getDisplayId(), displayContent); |
| 10719 | + } |
| 10720 | + |
10676 | 10721 | public DisplayContent getDisplayContent(final int displayId) { |
10677 | 10722 | DisplayContent displayContent = mDisplayContents.get(displayId); |
10678 | 10723 | if (displayContent == null) { |
@@ -10780,4 +10825,40 @@ public DisplayInfo getDefaultDisplayInfo() { |
10780 | 10825 | public WindowList getWindowList(final Display display) { |
10781 | 10826 | return getDisplayContent(display.getDisplayId()).getWindowList(); |
10782 | 10827 | } |
| 10828 | + |
| 10829 | + @Override |
| 10830 | + public void onDisplayAdded(int displayId) { |
| 10831 | + mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_ADDED, displayId, 0)); |
| 10832 | + } |
| 10833 | + |
| 10834 | + private void handleDisplayAddedLocked(int displayId) { |
| 10835 | + createDisplayContent(mDisplayManager.getDisplay(displayId)); |
| 10836 | + } |
| 10837 | + |
| 10838 | + @Override |
| 10839 | + public void onDisplayRemoved(int displayId) { |
| 10840 | + mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_REMOVED, displayId, 0)); |
| 10841 | + } |
| 10842 | + |
| 10843 | + private void handleDisplayRemovedLocked(int displayId) { |
| 10844 | + final DisplayContent displayContent = getDisplayContent(displayId); |
| 10845 | + mDisplayContents.delete(displayId); |
| 10846 | + WindowList windows = displayContent.getWindowList(); |
| 10847 | + for (int i = windows.size() - 1; i >= 0; --i) { |
| 10848 | + final WindowState win = windows.get(i); |
| 10849 | + removeWindowLocked(win.mSession, win); |
| 10850 | + } |
| 10851 | + } |
| 10852 | + |
| 10853 | + @Override |
| 10854 | + public void onDisplayChanged(int displayId) { |
| 10855 | + mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_CHANGED, displayId, 0)); |
| 10856 | + } |
| 10857 | + |
| 10858 | + private void handleDisplayChangedLocked(int displayId) { |
| 10859 | + final DisplayContent displayContent = getDisplayContent(displayId); |
| 10860 | + if (displayContent != null) { |
| 10861 | + displayContent.updateDisplayInfo(); |
| 10862 | + } |
| 10863 | + } |
10783 | 10864 | } |
0 commit comments