diff --git a/core/java/android/view/SurfaceSession.java b/core/java/android/view/SurfaceSession.java index b5912bc1e1c89..ee08bf7595118 100644 --- a/core/java/android/view/SurfaceSession.java +++ b/core/java/android/view/SurfaceSession.java @@ -37,7 +37,12 @@ public final class SurfaceSession { } public SurfaceSession(Surface root) { - mNativeClient = nativeCreateScoped(root.mNativeObject); + synchronized (root.mLock) { + if (root.mNativeObject == 0) { + throw new IllegalStateException("Surface is not initialized or has been released"); + } + mNativeClient = nativeCreateScoped(root.mNativeObject); + } } /* no user serviceable parts here ... */ diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 964ee5eee06d5..0e5527dfe39e5 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -23993,6 +23993,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Log.w(VIEW_LOG_TAG, "startDragAndDrop called on a detached view."); return false; } + if (!mAttachInfo.mViewRootImpl.mSurface.isValid()) { + Log.w(VIEW_LOG_TAG, "startDragAndDrop called with an invalid surface."); + return false; + } if (data != null) { data.prepareToLeaveProcess((flags & View.DRAG_FLAG_GLOBAL) != 0);