From 3d0c57a1d3b8eb6bb54045c02c2e93a9313d3cf7 Mon Sep 17 00:00:00 2001 From: Craig Mautner Date: Mon, 21 Jul 2014 14:18:29 -0700 Subject: [PATCH] Don't create a delegate for null callbacks. ActivityView does not create callbacks for the VirtualDisplay. This leads to setting Looper.myLooper() from a Binder thread which leads to NPE when trying to dereference its message queue. Fixes bug 16386002. Change-Id: I12760a22075ed4770f3fe960763e0135fe095cfe --- .../hardware/display/DisplayManagerGlobal.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/core/java/android/hardware/display/DisplayManagerGlobal.java b/core/java/android/hardware/display/DisplayManagerGlobal.java index f2426e51fb83..1b9a0c5d1661 100644 --- a/core/java/android/hardware/display/DisplayManagerGlobal.java +++ b/core/java/android/hardware/display/DisplayManagerGlobal.java @@ -471,22 +471,30 @@ public final class DisplayManagerGlobal { 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 @@ public final class DisplayManagerGlobal { @Override public void handleMessage(Message msg) { - if (mCallbacks == null) { - return; - } switch (msg.what) { case MSG_DISPLAY_PAUSED: mCallbacks.onDisplayPaused(); -- 2.11.0