@@ -2092,6 +2092,11 @@ public int addWindow(Session session, IWindow client, int seq,
20922092 throw new IllegalStateException ("Display has not been initialialized" );
20932093 }
20942094
2095+ final DisplayContent displayContent = getDisplayContentLocked (displayId );
2096+ if (displayContent == null ) {
2097+ return WindowManagerGlobal .ADD_INVALID_DISPLAY ;
2098+ }
2099+
20952100 if (mWindowMap .containsKey (client .asBinder ())) {
20962101 Slog .w (TAG , "Window " + client + " is already added" );
20972102 return WindowManagerGlobal .ADD_DUPLICATE_ADD ;
@@ -2174,7 +2179,6 @@ public int addWindow(Session session, IWindow client, int seq,
21742179 }
21752180 }
21762181
2177- final DisplayContent displayContent = getDisplayContentLocked (displayId );
21782182 win = new WindowState (this , session , client , token ,
21792183 attachedWindow , seq , attrs , viewVisibility , displayContent );
21802184 if (win .mDeathRecipient == null ) {
@@ -5704,6 +5708,7 @@ public void setStrictModeVisualIndicatorPreference(String value) {
57045708 * @param width the width of the target bitmap
57055709 * @param height the height of the target bitmap
57065710 */
5711+ @ Override
57075712 public Bitmap screenshotApplications (IBinder appToken , int displayId , int width , int height ) {
57085713 if (!checkCallingPermission (android .Manifest .permission .READ_FRAME_BUFFER ,
57095714 "screenshotApplications()" )) {
@@ -5723,6 +5728,9 @@ public Bitmap screenshotApplications(IBinder appToken, int displayId, int width,
57235728 long ident = Binder .clearCallingIdentity ();
57245729
57255730 final DisplayContent displayContent = getDisplayContentLocked (displayId );
5731+ if (displayContent == null ) {
5732+ return null ;
5733+ }
57265734 final DisplayInfo displayInfo = displayContent .getDisplayInfo ();
57275735 dw = displayInfo .logicalWidth ;
57285736 dh = displayInfo .logicalHeight ;
@@ -6465,6 +6473,7 @@ boolean viewServerWindowCommand(Socket client, String command, String parameters
64656473 return success ;
64666474 }
64676475
6476+ @ Override
64686477 public void addDisplayContentChangeListener (int displayId ,
64696478 IDisplayContentChangeListener listener ) {
64706479 if (!checkCallingPermission (android .Manifest .permission .RETRIEVE_WINDOW_INFO ,
@@ -6473,14 +6482,17 @@ public void addDisplayContentChangeListener(int displayId,
64736482 }
64746483 synchronized (mWindowMap ) {
64756484 DisplayContent displayContent = getDisplayContentLocked (displayId );
6476- if (displayContent .mDisplayContentChangeListeners == null ) {
6477- displayContent .mDisplayContentChangeListeners =
6478- new RemoteCallbackList <IDisplayContentChangeListener >();
6479- displayContent .mDisplayContentChangeListeners .register (listener );
6485+ if (displayContent != null ) {
6486+ if (displayContent .mDisplayContentChangeListeners == null ) {
6487+ displayContent .mDisplayContentChangeListeners =
6488+ new RemoteCallbackList <IDisplayContentChangeListener >();
6489+ displayContent .mDisplayContentChangeListeners .register (listener );
6490+ }
64806491 }
64816492 }
64826493 }
64836494
6495+ @ Override
64846496 public void removeDisplayContentChangeListener (int displayId ,
64856497 IDisplayContentChangeListener listener ) {
64866498 if (!checkCallingPermission (android .Manifest .permission .RETRIEVE_WINDOW_INFO ,
@@ -6489,11 +6501,13 @@ public void removeDisplayContentChangeListener(int displayId,
64896501 }
64906502 synchronized (mWindowMap ) {
64916503 DisplayContent displayContent = getDisplayContentLocked (displayId );
6492- if (displayContent .mDisplayContentChangeListeners != null ) {
6493- displayContent .mDisplayContentChangeListeners .unregister (listener );
6494- if (displayContent .mDisplayContentChangeListeners
6495- .getRegisteredCallbackCount () == 0 ) {
6496- displayContent .mDisplayContentChangeListeners = null ;
6504+ if (displayContent != null ) {
6505+ if (displayContent .mDisplayContentChangeListeners != null ) {
6506+ displayContent .mDisplayContentChangeListeners .unregister (listener );
6507+ if (displayContent .mDisplayContentChangeListeners
6508+ .getRegisteredCallbackCount () == 0 ) {
6509+ displayContent .mDisplayContentChangeListeners = null ;
6510+ }
64976511 }
64986512 }
64996513 }
@@ -7149,7 +7163,6 @@ public void displayReady() {
71497163
71507164 synchronized (mWindowMap ) {
71517165 final DisplayContent displayContent = getDefaultDisplayContentLocked ();
7152- final Display display = displayContent .getDisplay ();
71537166 readForcedDisplaySizeAndDensityLocked (displayContent );
71547167
71557168 mDisplayReady = true ;
@@ -7173,24 +7186,25 @@ public void displayReady() {
71737186 }
71747187 }
71757188
7176- public void displayReady (int displayId ) {
7189+ private void displayReady (int displayId ) {
71777190 synchronized (mWindowMap ) {
71787191 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7179- final DisplayInfo displayInfo ;
7180- mAnimator .addDisplayLocked (displayId );
7181- synchronized (displayContent .mDisplaySizeLock ) {
7182- // Bootstrap the default logical display from the display manager.
7183- displayInfo = displayContent .getDisplayInfo ();
7184- DisplayInfo newDisplayInfo = mDisplayManagerService .getDisplayInfo (displayId );
7185- if (newDisplayInfo != null ) {
7186- displayInfo .copyFrom (newDisplayInfo );
7192+ if (displayContent != null ) {
7193+ mAnimator .addDisplayLocked (displayId );
7194+ synchronized (displayContent .mDisplaySizeLock ) {
7195+ // Bootstrap the default logical display from the display manager.
7196+ final DisplayInfo displayInfo = displayContent .getDisplayInfo ();
7197+ DisplayInfo newDisplayInfo = mDisplayManagerService .getDisplayInfo (displayId );
7198+ if (newDisplayInfo != null ) {
7199+ displayInfo .copyFrom (newDisplayInfo );
7200+ }
7201+ displayContent .mInitialDisplayWidth = displayInfo .logicalWidth ;
7202+ displayContent .mInitialDisplayHeight = displayInfo .logicalHeight ;
7203+ displayContent .mInitialDisplayDensity = displayInfo .logicalDensityDpi ;
7204+ displayContent .mBaseDisplayWidth = displayContent .mInitialDisplayWidth ;
7205+ displayContent .mBaseDisplayHeight = displayContent .mInitialDisplayHeight ;
7206+ displayContent .mBaseDisplayDensity = displayContent .mInitialDisplayDensity ;
71877207 }
7188- displayContent .mInitialDisplayWidth = displayInfo .logicalWidth ;
7189- displayContent .mInitialDisplayHeight = displayInfo .logicalHeight ;
7190- displayContent .mInitialDisplayDensity = displayInfo .logicalDensityDpi ;
7191- displayContent .mBaseDisplayWidth = displayContent .mInitialDisplayWidth ;
7192- displayContent .mBaseDisplayHeight = displayContent .mInitialDisplayHeight ;
7193- displayContent .mBaseDisplayDensity = displayContent .mInitialDisplayDensity ;
71947208 }
71957209 }
71967210 }
@@ -7831,12 +7845,15 @@ public void getInitialDisplaySize(int displayId, Point size) {
78317845 // TODO(cmautner): Access to DisplayContent should be locked on mWindowMap. Doing that
78327846 // could lead to deadlock since this is called from ActivityManager.
78337847 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7834- synchronized (displayContent .mDisplaySizeLock ) {
7835- size .x = displayContent .mInitialDisplayWidth ;
7836- size .y = displayContent .mInitialDisplayHeight ;
7848+ if (displayContent != null ) {
7849+ synchronized (displayContent .mDisplaySizeLock ) {
7850+ size .x = displayContent .mInitialDisplayWidth ;
7851+ size .y = displayContent .mInitialDisplayHeight ;
7852+ }
78377853 }
78387854 }
78397855
7856+ @ Override
78407857 public void setForcedDisplaySize (int displayId , int width , int height ) {
78417858 synchronized (mWindowMap ) {
78427859 // Set some sort of reasonable bounds on the size of the display that we
@@ -7845,14 +7862,15 @@ public void setForcedDisplaySize(int displayId, int width, int height) {
78457862 final int MIN_HEIGHT = 200 ;
78467863 final int MAX_SCALE = 2 ;
78477864 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7848-
7849- width = Math .min (Math .max (width , MIN_WIDTH ),
7850- displayContent .mInitialDisplayWidth * MAX_SCALE );
7851- height = Math .min (Math .max (height , MIN_HEIGHT ),
7852- displayContent .mInitialDisplayHeight * MAX_SCALE );
7853- setForcedDisplaySizeLocked (displayContent , width , height );
7854- Settings .Global .putString (mContext .getContentResolver (),
7855- Settings .Global .DISPLAY_SIZE_FORCED , width + "," + height );
7865+ if (displayContent != null ) {
7866+ width = Math .min (Math .max (width , MIN_WIDTH ),
7867+ displayContent .mInitialDisplayWidth * MAX_SCALE );
7868+ height = Math .min (Math .max (height , MIN_HEIGHT ),
7869+ displayContent .mInitialDisplayHeight * MAX_SCALE );
7870+ setForcedDisplaySizeLocked (displayContent , width , height );
7871+ Settings .Global .putString (mContext .getContentResolver (),
7872+ Settings .Global .DISPLAY_SIZE_FORCED , width + "," + height );
7873+ }
78567874 }
78577875 }
78587876
@@ -7895,6 +7913,7 @@ private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayC
78957913 }
78967914 }
78977915
7916+ // displayContent must not be null
78987917 private void setForcedDisplaySizeLocked (DisplayContent displayContent , int width , int height ) {
78997918 Slog .i (TAG , "Using new display size: " + width + "x" + height );
79007919
@@ -7905,25 +7924,32 @@ private void setForcedDisplaySizeLocked(DisplayContent displayContent, int width
79057924 reconfigureDisplayLocked (displayContent );
79067925 }
79077926
7927+ @ Override
79087928 public void clearForcedDisplaySize (int displayId ) {
79097929 synchronized (mWindowMap ) {
79107930 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7911- setForcedDisplaySizeLocked (displayContent , displayContent .mInitialDisplayWidth ,
7912- displayContent .mInitialDisplayHeight );
7913- Settings .Global .putString (mContext .getContentResolver (),
7914- Settings .Global .DISPLAY_SIZE_FORCED , "" );
7931+ if (displayContent != null ) {
7932+ setForcedDisplaySizeLocked (displayContent , displayContent .mInitialDisplayWidth ,
7933+ displayContent .mInitialDisplayHeight );
7934+ Settings .Global .putString (mContext .getContentResolver (),
7935+ Settings .Global .DISPLAY_SIZE_FORCED , "" );
7936+ }
79157937 }
79167938 }
79177939
7940+ @ Override
79187941 public void setForcedDisplayDensity (int displayId , int density ) {
79197942 synchronized (mWindowMap ) {
79207943 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7921- setForcedDisplayDensityLocked (displayContent , density );
7922- Settings .Global .putString (mContext .getContentResolver (),
7923- Settings .Global .DISPLAY_DENSITY_FORCED , Integer .toString (density ));
7944+ if (displayContent != null ) {
7945+ setForcedDisplayDensityLocked (displayContent , density );
7946+ Settings .Global .putString (mContext .getContentResolver (),
7947+ Settings .Global .DISPLAY_DENSITY_FORCED , Integer .toString (density ));
7948+ }
79247949 }
79257950 }
79267951
7952+ // displayContent must not be null
79277953 private void setForcedDisplayDensityLocked (DisplayContent displayContent , int density ) {
79287954 Slog .i (TAG , "Using new display density: " + density );
79297955
@@ -7933,15 +7959,19 @@ private void setForcedDisplayDensityLocked(DisplayContent displayContent, int de
79337959 reconfigureDisplayLocked (displayContent );
79347960 }
79357961
7962+ @ Override
79367963 public void clearForcedDisplayDensity (int displayId ) {
79377964 synchronized (mWindowMap ) {
79387965 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7939- setForcedDisplayDensityLocked (displayContent , displayContent .mInitialDisplayDensity );
7940- Settings .Global .putString (mContext .getContentResolver (),
7941- Settings .Global .DISPLAY_DENSITY_FORCED , "" );
7966+ if (displayContent != null ) {
7967+ setForcedDisplayDensityLocked (displayContent , displayContent .mInitialDisplayDensity );
7968+ Settings .Global .putString (mContext .getContentResolver (),
7969+ Settings .Global .DISPLAY_DENSITY_FORCED , "" );
7970+ }
79427971 }
79437972 }
79447973
7974+ // displayContent must not be null
79457975 private void reconfigureDisplayLocked (DisplayContent displayContent ) {
79467976 // TODO: Multidisplay: for now only use with default display.
79477977 mPolicy .setInitialDisplaySize (displayContent .getDisplay (),
@@ -9711,7 +9741,9 @@ private boolean copyAnimToLayoutParamsLocked() {
97119741 for (int i = 0 ; i < count ; ++i ) {
97129742 final DisplayContent displayContent =
97139743 getDisplayContentLocked (pendingLayouts .keyAt (i ));
9714- displayContent .pendingLayoutChanges |= pendingLayouts .valueAt (i );
9744+ if (displayContent != null ) {
9745+ displayContent .pendingLayoutChanges |= pendingLayouts .valueAt (i );
9746+ }
97159747 }
97169748
97179749 mWindowDetachedWallpaper = animToLayout .mWindowDetachedWallpaper ;
@@ -10837,11 +10869,20 @@ public void createDisplayContentLocked(final Display display) {
1083710869 mDisplayContents .put (display .getDisplayId (), displayContent );
1083810870 }
1083910871
10872+ /**
10873+ * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
10874+ * there is a Display for the displayId.
10875+ * @param displayId The display the caller is interested in.
10876+ * @return The DisplayContent associated with displayId or null if there is no Display for it.
10877+ */
1084010878 public DisplayContent getDisplayContentLocked (final int displayId ) {
1084110879 DisplayContent displayContent = mDisplayContents .get (displayId );
1084210880 if (displayContent == null ) {
10843- displayContent = new DisplayContent (mDisplayManager .getDisplay (displayId ));
10844- mDisplayContents .put (displayId , displayContent );
10881+ final Display display = mDisplayManager .getDisplay (displayId );
10882+ if (display != null ) {
10883+ displayContent = new DisplayContent (display );
10884+ mDisplayContents .put (displayId , displayContent );
10885+ }
1084510886 }
1084610887 return displayContent ;
1084710888 }
@@ -10927,6 +10968,7 @@ public void remove() {
1092710968 }
1092810969 }
1092910970
10971+ // There is an inherent assumption that this will never return null.
1093010972 public DisplayContent getDefaultDisplayContentLocked () {
1093110973 return getDisplayContentLocked (Display .DEFAULT_DISPLAY );
1093210974 }
@@ -10939,8 +10981,14 @@ public DisplayInfo getDefaultDisplayInfoLocked() {
1093910981 return getDefaultDisplayContentLocked ().getDisplayInfo ();
1094010982 }
1094110983
10984+ /**
10985+ * Return the list of WindowStates associated on the passed display.
10986+ * @param display The screen to return windows from.
10987+ * @return The list of WindowStates on the screen, or null if the there is no screen.
10988+ */
1094210989 public WindowList getWindowListLocked (final Display display ) {
10943- return getDisplayContentLocked (display .getDisplayId ()).getWindowList ();
10990+ final DisplayContent displayContent = getDisplayContentLocked (display .getDisplayId ());
10991+ return displayContent != null ? displayContent .getWindowList () : null ;
1094410992 }
1094510993
1094610994 @ Override
@@ -10949,8 +10997,11 @@ public void onDisplayAdded(int displayId) {
1094910997 }
1095010998
1095110999 private void handleDisplayAddedLocked (int displayId ) {
10952- createDisplayContentLocked (mDisplayManager .getDisplay (displayId ));
10953- displayReady (displayId );
11000+ final Display display = mDisplayManager .getDisplay (displayId );
11001+ if (display != null ) {
11002+ createDisplayContentLocked (display );
11003+ displayReady (displayId );
11004+ }
1095411005 }
1095511006
1095611007 @ Override
@@ -10960,11 +11011,13 @@ public void onDisplayRemoved(int displayId) {
1096011011
1096111012 private void handleDisplayRemovedLocked (int displayId ) {
1096211013 final DisplayContent displayContent = getDisplayContentLocked (displayId );
10963- mDisplayContents .delete (displayId );
10964- WindowList windows = displayContent .getWindowList ();
10965- while (!windows .isEmpty ()) {
10966- final WindowState win = windows .get (windows .size () - 1 );
10967- removeWindowLocked (win .mSession , win );
11014+ if (displayContent != null ) {
11015+ mDisplayContents .delete (displayId );
11016+ WindowList windows = displayContent .getWindowList ();
11017+ while (!windows .isEmpty ()) {
11018+ final WindowState win = windows .get (windows .size () - 1 );
11019+ removeWindowLocked (win .mSession , win );
11020+ }
1096811021 }
1096911022 mAnimator .removeDisplayLocked (displayId );
1097011023 }
0 commit comments