|
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; |
@@ -1109,6 +1115,10 @@ private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
1109 | 1115 | if (win.mAppToken != null && addToToken) { |
1110 | 1116 | win.mAppToken.allAppWindows.add(win); |
1111 | 1117 | } |
| 1118 | + |
| 1119 | + if (windows.size() == 1) { |
| 1120 | + mDisplayManagerService.setDisplayHasContent(win.getDisplayId(), true); |
| 1121 | + } |
1112 | 1122 | } |
1113 | 1123 |
|
1114 | 1124 | /** TODO(cmautner): Is this the same as {@link WindowState#canReceiveKeys()} */ |
@@ -2397,6 +2407,9 @@ private void removeWindowInnerLocked(Session session, WindowState win) { |
2397 | 2407 |
|
2398 | 2408 | final WindowList windows = win.getWindowList(); |
2399 | 2409 | windows.remove(win); |
| 2410 | + if (windows.isEmpty()) { |
| 2411 | + mDisplayManagerService.setDisplayHasContent(win.getDisplayId(), false); |
| 2412 | + } |
2400 | 2413 | mPendingRemove.remove(win); |
2401 | 2414 | mWindowsChanged = true; |
2402 | 2415 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win); |
@@ -7183,6 +7196,10 @@ final class H extends Handler { |
7183 | 7196 | public static final int NOTIFY_WINDOW_TRANSITION = 29; |
7184 | 7197 | public static final int NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED = 30; |
7185 | 7198 |
|
| 7199 | + public static final int DO_DISPLAY_ADDED = 31; |
| 7200 | + public static final int DO_DISPLAY_REMOVED = 32; |
| 7201 | + public static final int DO_DISPLAY_CHANGED = 33; |
| 7202 | + |
7186 | 7203 | public static final int ANIMATOR_WHAT_OFFSET = 100000; |
7187 | 7204 | public static final int SET_TRANSPARENT_REGION = ANIMATOR_WHAT_OFFSET + 1; |
7188 | 7205 | public static final int CLEAR_PENDING_ACTIONS = ANIMATOR_WHAT_OFFSET + 2; |
@@ -7620,25 +7637,46 @@ public void handleMessage(Message msg) { |
7620 | 7637 | } |
7621 | 7638 | break; |
7622 | 7639 | } |
| 7640 | + |
7623 | 7641 | case NOTIFY_ROTATION_CHANGED: { |
7624 | 7642 | final int displayId = msg.arg1; |
7625 | 7643 | final int rotation = msg.arg2; |
7626 | 7644 | handleNotifyRotationChanged(displayId, rotation); |
7627 | 7645 | break; |
7628 | 7646 | } |
| 7647 | + |
7629 | 7648 | case NOTIFY_WINDOW_TRANSITION: { |
7630 | 7649 | final int transition = msg.arg1; |
7631 | 7650 | WindowInfo info = (WindowInfo) msg.obj; |
7632 | 7651 | handleNotifyWindowTranstion(transition, info); |
7633 | 7652 | break; |
7634 | 7653 | } |
| 7654 | + |
7635 | 7655 | case NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED: { |
7636 | 7656 | final int displayId = msg.arg1; |
7637 | 7657 | final boolean immediate = (msg.arg2 == 1); |
7638 | 7658 | Rect rectangle = (Rect) msg.obj; |
7639 | 7659 | handleNotifyRectangleOnScreenRequested(displayId, rectangle, immediate); |
7640 | 7660 | break; |
7641 | 7661 | } |
| 7662 | + |
| 7663 | + case DO_DISPLAY_ADDED: |
| 7664 | + synchronized (mWindowMap) { |
| 7665 | + handleDisplayAddedLocked(msg.arg1); |
| 7666 | + } |
| 7667 | + break; |
| 7668 | + |
| 7669 | + case DO_DISPLAY_REMOVED: |
| 7670 | + synchronized (mWindowMap) { |
| 7671 | + handleDisplayRemovedLocked(msg.arg1); |
| 7672 | + } |
| 7673 | + break; |
| 7674 | + |
| 7675 | + case DO_DISPLAY_CHANGED: |
| 7676 | + synchronized (mWindowMap) { |
| 7677 | + handleDisplayChangedLocked(msg.arg1); |
| 7678 | + } |
| 7679 | + break; |
7642 | 7680 | } |
7643 | 7681 | if (DEBUG_WINDOW_TRACE) { |
7644 | 7682 | Slog.v(TAG, "handleMessage: exit"); |
@@ -8855,8 +8893,6 @@ private final void performLayoutAndPlaceSurfacesLockedInner(boolean recoveringMe |
8855 | 8893 | final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo(); |
8856 | 8894 | final int defaultDw = defaultInfo.logicalWidth; |
8857 | 8895 | final int defaultDh = defaultInfo.logicalHeight; |
8858 | | - final int defaultInnerDw = defaultInfo.appWidth; |
8859 | | - final int defaultInnerDh = defaultInfo.appHeight; |
8860 | 8896 |
|
8861 | 8897 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
8862 | 8898 | ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
@@ -9430,6 +9466,7 @@ void setHoldScreenLocked(final Session newHoldScreen) { |
9430 | 9466 | } |
9431 | 9467 | } |
9432 | 9468 |
|
| 9469 | + @Override |
9433 | 9470 | public void requestTraversal() { |
9434 | 9471 | synchronized (mWindowMap) { |
9435 | 9472 | requestTraversalLocked(); |
@@ -10454,7 +10491,7 @@ void dumpWindowsNoHeaderLocked(PrintWriter pw, boolean dumpAll, |
10454 | 10491 |
|
10455 | 10492 | boolean dumpWindows(PrintWriter pw, String name, String[] args, |
10456 | 10493 | int opti, boolean dumpAll) { |
10457 | | - ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 10494 | + WindowList windows = new WindowList(); |
10458 | 10495 | if ("visible".equals(name)) { |
10459 | 10496 | synchronized(mWindowMap) { |
10460 | 10497 | final AllWindowsIterator iterator = new AllWindowsIterator(REVERSE_ITERATOR); |
@@ -10662,6 +10699,14 @@ void debugLayoutRepeats(final String msg, int pendingLayoutChanges) { |
10662 | 10699 | } |
10663 | 10700 | } |
10664 | 10701 |
|
| 10702 | + public void createDisplayContent(final Display display) { |
| 10703 | + if (display == null) { |
| 10704 | + throw new IllegalArgumentException("getDisplayContent: display must not be null"); |
| 10705 | + } |
| 10706 | + final DisplayContent displayContent = new DisplayContent(display); |
| 10707 | + mDisplayContents.put(display.getDisplayId(), displayContent); |
| 10708 | + } |
| 10709 | + |
10665 | 10710 | public DisplayContent getDisplayContent(final int displayId) { |
10666 | 10711 | DisplayContent displayContent = mDisplayContents.get(displayId); |
10667 | 10712 | if (displayContent == null) { |
@@ -10769,4 +10814,40 @@ public DisplayInfo getDefaultDisplayInfo() { |
10769 | 10814 | public WindowList getWindowList(final Display display) { |
10770 | 10815 | return getDisplayContent(display.getDisplayId()).getWindowList(); |
10771 | 10816 | } |
| 10817 | + |
| 10818 | + @Override |
| 10819 | + public void onDisplayAdded(int displayId) { |
| 10820 | + mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_ADDED, displayId, 0)); |
| 10821 | + } |
| 10822 | + |
| 10823 | + private void handleDisplayAddedLocked(int displayId) { |
| 10824 | + createDisplayContent(mDisplayManager.getDisplay(displayId)); |
| 10825 | + } |
| 10826 | + |
| 10827 | + @Override |
| 10828 | + public void onDisplayRemoved(int displayId) { |
| 10829 | + mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_REMOVED, displayId, 0)); |
| 10830 | + } |
| 10831 | + |
| 10832 | + private void handleDisplayRemovedLocked(int displayId) { |
| 10833 | + final DisplayContent displayContent = getDisplayContent(displayId); |
| 10834 | + mDisplayContents.delete(displayId); |
| 10835 | + WindowList windows = displayContent.getWindowList(); |
| 10836 | + for (int i = windows.size() - 1; i >= 0; --i) { |
| 10837 | + final WindowState win = windows.get(i); |
| 10838 | + removeWindowLocked(win.mSession, win); |
| 10839 | + } |
| 10840 | + } |
| 10841 | + |
| 10842 | + @Override |
| 10843 | + public void onDisplayChanged(int displayId) { |
| 10844 | + mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_CHANGED, displayId, 0)); |
| 10845 | + } |
| 10846 | + |
| 10847 | + private void handleDisplayChangedLocked(int displayId) { |
| 10848 | + final DisplayContent displayContent = getDisplayContent(displayId); |
| 10849 | + if (displayContent != null) { |
| 10850 | + displayContent.updateDisplayInfo(); |
| 10851 | + } |
| 10852 | + } |
10772 | 10853 | } |
0 commit comments