@@ -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 ) {
@@ -5712,6 +5716,7 @@ public void setStrictModeVisualIndicatorPreference(String value) {
57125716 * @param width the width of the target bitmap
57135717 * @param height the height of the target bitmap
57145718 */
5719+ @ Override
57155720 public Bitmap screenshotApplications (IBinder appToken , int displayId , int width , int height ) {
57165721 if (!checkCallingPermission (android .Manifest .permission .READ_FRAME_BUFFER ,
57175722 "screenshotApplications()" )) {
@@ -5731,6 +5736,9 @@ public Bitmap screenshotApplications(IBinder appToken, int displayId, int width,
57315736 long ident = Binder .clearCallingIdentity ();
57325737
57335738 final DisplayContent displayContent = getDisplayContentLocked (displayId );
5739+ if (displayContent == null ) {
5740+ return null ;
5741+ }
57345742 final DisplayInfo displayInfo = displayContent .getDisplayInfo ();
57355743 dw = displayInfo .logicalWidth ;
57365744 dh = displayInfo .logicalHeight ;
@@ -6473,6 +6481,7 @@ boolean viewServerWindowCommand(Socket client, String command, String parameters
64736481 return success ;
64746482 }
64756483
6484+ @ Override
64766485 public void addDisplayContentChangeListener (int displayId ,
64776486 IDisplayContentChangeListener listener ) {
64786487 if (!checkCallingPermission (android .Manifest .permission .RETRIEVE_WINDOW_INFO ,
@@ -6481,14 +6490,17 @@ public void addDisplayContentChangeListener(int displayId,
64816490 }
64826491 synchronized (mWindowMap ) {
64836492 DisplayContent displayContent = getDisplayContentLocked (displayId );
6484- if (displayContent .mDisplayContentChangeListeners == null ) {
6485- displayContent .mDisplayContentChangeListeners =
6486- new RemoteCallbackList <IDisplayContentChangeListener >();
6487- displayContent .mDisplayContentChangeListeners .register (listener );
6493+ if (displayContent != null ) {
6494+ if (displayContent .mDisplayContentChangeListeners == null ) {
6495+ displayContent .mDisplayContentChangeListeners =
6496+ new RemoteCallbackList <IDisplayContentChangeListener >();
6497+ displayContent .mDisplayContentChangeListeners .register (listener );
6498+ }
64886499 }
64896500 }
64906501 }
64916502
6503+ @ Override
64926504 public void removeDisplayContentChangeListener (int displayId ,
64936505 IDisplayContentChangeListener listener ) {
64946506 if (!checkCallingPermission (android .Manifest .permission .RETRIEVE_WINDOW_INFO ,
@@ -6497,11 +6509,13 @@ public void removeDisplayContentChangeListener(int displayId,
64976509 }
64986510 synchronized (mWindowMap ) {
64996511 DisplayContent displayContent = getDisplayContentLocked (displayId );
6500- if (displayContent .mDisplayContentChangeListeners != null ) {
6501- displayContent .mDisplayContentChangeListeners .unregister (listener );
6502- if (displayContent .mDisplayContentChangeListeners
6503- .getRegisteredCallbackCount () == 0 ) {
6504- displayContent .mDisplayContentChangeListeners = null ;
6512+ if (displayContent != null ) {
6513+ if (displayContent .mDisplayContentChangeListeners != null ) {
6514+ displayContent .mDisplayContentChangeListeners .unregister (listener );
6515+ if (displayContent .mDisplayContentChangeListeners
6516+ .getRegisteredCallbackCount () == 0 ) {
6517+ displayContent .mDisplayContentChangeListeners = null ;
6518+ }
65056519 }
65066520 }
65076521 }
@@ -7157,7 +7171,6 @@ public void displayReady() {
71577171
71587172 synchronized (mWindowMap ) {
71597173 final DisplayContent displayContent = getDefaultDisplayContentLocked ();
7160- final Display display = displayContent .getDisplay ();
71617174 readForcedDisplaySizeAndDensityLocked (displayContent );
71627175
71637176 mDisplayReady = true ;
@@ -7181,24 +7194,25 @@ public void displayReady() {
71817194 }
71827195 }
71837196
7184- public void displayReady (int displayId ) {
7197+ private void displayReady (int displayId ) {
71857198 synchronized (mWindowMap ) {
71867199 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7187- final DisplayInfo displayInfo ;
7188- mAnimator .addDisplayLocked (displayId );
7189- synchronized (displayContent .mDisplaySizeLock ) {
7190- // Bootstrap the default logical display from the display manager.
7191- displayInfo = displayContent .getDisplayInfo ();
7192- DisplayInfo newDisplayInfo = mDisplayManagerService .getDisplayInfo (displayId );
7193- if (newDisplayInfo != null ) {
7194- displayInfo .copyFrom (newDisplayInfo );
7200+ if (displayContent != null ) {
7201+ mAnimator .addDisplayLocked (displayId );
7202+ synchronized (displayContent .mDisplaySizeLock ) {
7203+ // Bootstrap the default logical display from the display manager.
7204+ final DisplayInfo displayInfo = displayContent .getDisplayInfo ();
7205+ DisplayInfo newDisplayInfo = mDisplayManagerService .getDisplayInfo (displayId );
7206+ if (newDisplayInfo != null ) {
7207+ displayInfo .copyFrom (newDisplayInfo );
7208+ }
7209+ displayContent .mInitialDisplayWidth = displayInfo .logicalWidth ;
7210+ displayContent .mInitialDisplayHeight = displayInfo .logicalHeight ;
7211+ displayContent .mInitialDisplayDensity = displayInfo .logicalDensityDpi ;
7212+ displayContent .mBaseDisplayWidth = displayContent .mInitialDisplayWidth ;
7213+ displayContent .mBaseDisplayHeight = displayContent .mInitialDisplayHeight ;
7214+ displayContent .mBaseDisplayDensity = displayContent .mInitialDisplayDensity ;
71957215 }
7196- displayContent .mInitialDisplayWidth = displayInfo .logicalWidth ;
7197- displayContent .mInitialDisplayHeight = displayInfo .logicalHeight ;
7198- displayContent .mInitialDisplayDensity = displayInfo .logicalDensityDpi ;
7199- displayContent .mBaseDisplayWidth = displayContent .mInitialDisplayWidth ;
7200- displayContent .mBaseDisplayHeight = displayContent .mInitialDisplayHeight ;
7201- displayContent .mBaseDisplayDensity = displayContent .mInitialDisplayDensity ;
72027216 }
72037217 }
72047218 }
@@ -7839,12 +7853,15 @@ public void getInitialDisplaySize(int displayId, Point size) {
78397853 // TODO(cmautner): Access to DisplayContent should be locked on mWindowMap. Doing that
78407854 // could lead to deadlock since this is called from ActivityManager.
78417855 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7842- synchronized (displayContent .mDisplaySizeLock ) {
7843- size .x = displayContent .mInitialDisplayWidth ;
7844- size .y = displayContent .mInitialDisplayHeight ;
7856+ if (displayContent != null ) {
7857+ synchronized (displayContent .mDisplaySizeLock ) {
7858+ size .x = displayContent .mInitialDisplayWidth ;
7859+ size .y = displayContent .mInitialDisplayHeight ;
7860+ }
78457861 }
78467862 }
78477863
7864+ @ Override
78487865 public void setForcedDisplaySize (int displayId , int width , int height ) {
78497866 synchronized (mWindowMap ) {
78507867 // Set some sort of reasonable bounds on the size of the display that we
@@ -7853,14 +7870,15 @@ public void setForcedDisplaySize(int displayId, int width, int height) {
78537870 final int MIN_HEIGHT = 200 ;
78547871 final int MAX_SCALE = 2 ;
78557872 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7856-
7857- width = Math .min (Math .max (width , MIN_WIDTH ),
7858- displayContent .mInitialDisplayWidth * MAX_SCALE );
7859- height = Math .min (Math .max (height , MIN_HEIGHT ),
7860- displayContent .mInitialDisplayHeight * MAX_SCALE );
7861- setForcedDisplaySizeLocked (displayContent , width , height );
7862- Settings .Global .putString (mContext .getContentResolver (),
7863- Settings .Global .DISPLAY_SIZE_FORCED , width + "," + height );
7873+ if (displayContent != null ) {
7874+ width = Math .min (Math .max (width , MIN_WIDTH ),
7875+ displayContent .mInitialDisplayWidth * MAX_SCALE );
7876+ height = Math .min (Math .max (height , MIN_HEIGHT ),
7877+ displayContent .mInitialDisplayHeight * MAX_SCALE );
7878+ setForcedDisplaySizeLocked (displayContent , width , height );
7879+ Settings .Global .putString (mContext .getContentResolver (),
7880+ Settings .Global .DISPLAY_SIZE_FORCED , width + "," + height );
7881+ }
78647882 }
78657883 }
78667884
@@ -7903,6 +7921,7 @@ private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayC
79037921 }
79047922 }
79057923
7924+ // displayContent must not be null
79067925 private void setForcedDisplaySizeLocked (DisplayContent displayContent , int width , int height ) {
79077926 Slog .i (TAG , "Using new display size: " + width + "x" + height );
79087927
@@ -7913,25 +7932,32 @@ private void setForcedDisplaySizeLocked(DisplayContent displayContent, int width
79137932 reconfigureDisplayLocked (displayContent );
79147933 }
79157934
7935+ @ Override
79167936 public void clearForcedDisplaySize (int displayId ) {
79177937 synchronized (mWindowMap ) {
79187938 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7919- setForcedDisplaySizeLocked (displayContent , displayContent .mInitialDisplayWidth ,
7920- displayContent .mInitialDisplayHeight );
7921- Settings .Global .putString (mContext .getContentResolver (),
7922- Settings .Global .DISPLAY_SIZE_FORCED , "" );
7939+ if (displayContent != null ) {
7940+ setForcedDisplaySizeLocked (displayContent , displayContent .mInitialDisplayWidth ,
7941+ displayContent .mInitialDisplayHeight );
7942+ Settings .Global .putString (mContext .getContentResolver (),
7943+ Settings .Global .DISPLAY_SIZE_FORCED , "" );
7944+ }
79237945 }
79247946 }
79257947
7948+ @ Override
79267949 public void setForcedDisplayDensity (int displayId , int density ) {
79277950 synchronized (mWindowMap ) {
79287951 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7929- setForcedDisplayDensityLocked (displayContent , density );
7930- Settings .Global .putString (mContext .getContentResolver (),
7931- Settings .Global .DISPLAY_DENSITY_FORCED , Integer .toString (density ));
7952+ if (displayContent != null ) {
7953+ setForcedDisplayDensityLocked (displayContent , density );
7954+ Settings .Global .putString (mContext .getContentResolver (),
7955+ Settings .Global .DISPLAY_DENSITY_FORCED , Integer .toString (density ));
7956+ }
79327957 }
79337958 }
79347959
7960+ // displayContent must not be null
79357961 private void setForcedDisplayDensityLocked (DisplayContent displayContent , int density ) {
79367962 Slog .i (TAG , "Using new display density: " + density );
79377963
@@ -7941,15 +7967,19 @@ private void setForcedDisplayDensityLocked(DisplayContent displayContent, int de
79417967 reconfigureDisplayLocked (displayContent );
79427968 }
79437969
7970+ @ Override
79447971 public void clearForcedDisplayDensity (int displayId ) {
79457972 synchronized (mWindowMap ) {
79467973 final DisplayContent displayContent = getDisplayContentLocked (displayId );
7947- setForcedDisplayDensityLocked (displayContent , displayContent .mInitialDisplayDensity );
7948- Settings .Global .putString (mContext .getContentResolver (),
7949- Settings .Global .DISPLAY_DENSITY_FORCED , "" );
7974+ if (displayContent != null ) {
7975+ setForcedDisplayDensityLocked (displayContent , displayContent .mInitialDisplayDensity );
7976+ Settings .Global .putString (mContext .getContentResolver (),
7977+ Settings .Global .DISPLAY_DENSITY_FORCED , "" );
7978+ }
79507979 }
79517980 }
79527981
7982+ // displayContent must not be null
79537983 private void reconfigureDisplayLocked (DisplayContent displayContent ) {
79547984 // TODO: Multidisplay: for now only use with default display.
79557985 mPolicy .setInitialDisplaySize (displayContent .getDisplay (),
@@ -9719,7 +9749,9 @@ private boolean copyAnimToLayoutParamsLocked() {
97199749 for (int i = 0 ; i < count ; ++i ) {
97209750 final DisplayContent displayContent =
97219751 getDisplayContentLocked (pendingLayouts .keyAt (i ));
9722- displayContent .pendingLayoutChanges |= pendingLayouts .valueAt (i );
9752+ if (displayContent != null ) {
9753+ displayContent .pendingLayoutChanges |= pendingLayouts .valueAt (i );
9754+ }
97239755 }
97249756
97259757 mWindowDetachedWallpaper = animToLayout .mWindowDetachedWallpaper ;
@@ -10845,11 +10877,20 @@ public void createDisplayContentLocked(final Display display) {
1084510877 mDisplayContents .put (display .getDisplayId (), displayContent );
1084610878 }
1084710879
10880+ /**
10881+ * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
10882+ * there is a Display for the displayId.
10883+ * @param displayId The display the caller is interested in.
10884+ * @return The DisplayContent associated with displayId or null if there is no Display for it.
10885+ */
1084810886 public DisplayContent getDisplayContentLocked (final int displayId ) {
1084910887 DisplayContent displayContent = mDisplayContents .get (displayId );
1085010888 if (displayContent == null ) {
10851- displayContent = new DisplayContent (mDisplayManager .getDisplay (displayId ));
10852- mDisplayContents .put (displayId , displayContent );
10889+ final Display display = mDisplayManager .getDisplay (displayId );
10890+ if (display != null ) {
10891+ displayContent = new DisplayContent (display );
10892+ mDisplayContents .put (displayId , displayContent );
10893+ }
1085310894 }
1085410895 return displayContent ;
1085510896 }
@@ -10935,6 +10976,7 @@ public void remove() {
1093510976 }
1093610977 }
1093710978
10979+ // There is an inherent assumption that this will never return null.
1093810980 public DisplayContent getDefaultDisplayContentLocked () {
1093910981 return getDisplayContentLocked (Display .DEFAULT_DISPLAY );
1094010982 }
@@ -10947,8 +10989,14 @@ public DisplayInfo getDefaultDisplayInfoLocked() {
1094710989 return getDefaultDisplayContentLocked ().getDisplayInfo ();
1094810990 }
1094910991
10992+ /**
10993+ * Return the list of WindowStates associated on the passed display.
10994+ * @param display The screen to return windows from.
10995+ * @return The list of WindowStates on the screen, or null if the there is no screen.
10996+ */
1095010997 public WindowList getWindowListLocked (final Display display ) {
10951- return getDisplayContentLocked (display .getDisplayId ()).getWindowList ();
10998+ final DisplayContent displayContent = getDisplayContentLocked (display .getDisplayId ());
10999+ return displayContent != null ? displayContent .getWindowList () : null ;
1095211000 }
1095311001
1095411002 @ Override
@@ -10957,8 +11005,11 @@ public void onDisplayAdded(int displayId) {
1095711005 }
1095811006
1095911007 private void handleDisplayAddedLocked (int displayId ) {
10960- createDisplayContentLocked (mDisplayManager .getDisplay (displayId ));
10961- displayReady (displayId );
11008+ final Display display = mDisplayManager .getDisplay (displayId );
11009+ if (display != null ) {
11010+ createDisplayContentLocked (display );
11011+ displayReady (displayId );
11012+ }
1096211013 }
1096311014
1096411015 @ Override
@@ -10968,11 +11019,13 @@ public void onDisplayRemoved(int displayId) {
1096811019
1096911020 private void handleDisplayRemovedLocked (int displayId ) {
1097011021 final DisplayContent displayContent = getDisplayContentLocked (displayId );
10971- mDisplayContents .delete (displayId );
10972- WindowList windows = displayContent .getWindowList ();
10973- while (!windows .isEmpty ()) {
10974- final WindowState win = windows .get (windows .size () - 1 );
10975- removeWindowLocked (win .mSession , win );
11022+ if (displayContent != null ) {
11023+ mDisplayContents .delete (displayId );
11024+ WindowList windows = displayContent .getWindowList ();
11025+ while (!windows .isEmpty ()) {
11026+ final WindowState win = windows .get (windows .size () - 1 );
11027+ removeWindowLocked (win .mSession , win );
11028+ }
1097611029 }
1097711030 mAnimator .removeDisplayLocked (displayId );
1097811031 }
0 commit comments