Merge "Don't create a delegate for null callbacks." into lmp-dev
diff --git a/core/java/android/hardware/display/DisplayManagerGlobal.java b/core/java/android/hardware/display/DisplayManagerGlobal.java
index f2426e5..1b9a0c5 100644
--- a/core/java/android/hardware/display/DisplayManagerGlobal.java
+++ b/core/java/android/hardware/display/DisplayManagerGlobal.java
@@ -471,22 +471,30 @@
         private VirtualDisplayCallbacksDelegate mDelegate;
 
         public VirtualDisplayCallbacks(VirtualDisplay.Callbacks callbacks, Handler handler) {
-            mDelegate = new VirtualDisplayCallbacksDelegate(callbacks, handler);
+            if (callbacks != null) {
+                mDelegate = new VirtualDisplayCallbacksDelegate(callbacks, handler);
+            }
         }
 
         @Override // Binder call
         public void onDisplayPaused() {
-            mDelegate.sendEmptyMessage(VirtualDisplayCallbacksDelegate.MSG_DISPLAY_PAUSED);
+            if (mDelegate != null) {
+                mDelegate.sendEmptyMessage(VirtualDisplayCallbacksDelegate.MSG_DISPLAY_PAUSED);
+            }
         }
 
         @Override // Binder call
         public void onDisplayResumed() {
-            mDelegate.sendEmptyMessage(VirtualDisplayCallbacksDelegate.MSG_DISPLAY_RESUMED);
+            if (mDelegate != null) {
+                mDelegate.sendEmptyMessage(VirtualDisplayCallbacksDelegate.MSG_DISPLAY_RESUMED);
+            }
         }
 
         @Override // Binder call
         public void onDisplayStopped() {
-            mDelegate.sendEmptyMessage(VirtualDisplayCallbacksDelegate.MSG_DISPLAY_STOPPED);
+            if (mDelegate != null) {
+                mDelegate.sendEmptyMessage(VirtualDisplayCallbacksDelegate.MSG_DISPLAY_STOPPED);
+            }
         }
     }
 
@@ -505,9 +513,6 @@
 
         @Override
         public void handleMessage(Message msg) {
-            if (mCallbacks == null) {
-                return;
-            }
             switch (msg.what) {
                 case MSG_DISPLAY_PAUSED:
                     mCallbacks.onDisplayPaused();