From 0328b9c0255d7156a070eaed64682fddffe06a0e Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 28 Jun 2018 21:44:50 +0800 Subject: [PATCH] Check for valid surface when starting to drag Also protect creating SurfaceSession with root surface. Change-Id: I3649f160e85367169710b36faf26c96bef0f71fe Fix: 110922266 Test: atest CtsViewTestCases:android.view.cts.DragDropTest --- core/java/android/view/SurfaceSession.java | 7 ++++++- core/java/android/view/View.java | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/SurfaceSession.java b/core/java/android/view/SurfaceSession.java index b5912bc1e1c8..ee08bf759511 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 964ee5eee06d..0e5527dfe39e 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); -- 2.11.0