OSDN Git Service

Check for valid surface when starting to drag
authorRiddle Hsu <riddlehsu@google.com>
Thu, 28 Jun 2018 13:44:50 +0000 (21:44 +0800)
committerRiddle Hsu <riddlehsu@google.com>
Thu, 28 Jun 2018 20:59:37 +0000 (20:59 +0000)
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
core/java/android/view/View.java

index b5912bc..ee08bf7 100644 (file)
@@ -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 ... */
index 964ee5e..0e5527d 100644 (file)
@@ -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);