Prevent NPE when a View is detached without having been attached.
Bug #3355252

Change-Id: I58e03983ccf6a27a24619ec0f49659d6d7cc0a64
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 63a3ff0..f05ef8c 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -7580,8 +7580,12 @@
             mHardwareLayer.destroy();
             mHardwareLayer = null;
         }
-        mAttachInfo.mHandler.removeMessages(AttachInfo.INVALIDATE_MSG, this);
-        mAttachInfo.mHandler.removeMessages(AttachInfo.INVALIDATE_RECT_MSG, this);
+
+        if (mAttachInfo != null) {
+            mAttachInfo.mHandler.removeMessages(AttachInfo.INVALIDATE_MSG, this);
+            mAttachInfo.mHandler.removeMessages(AttachInfo.INVALIDATE_RECT_MSG, this);
+        }
+
         mCurrentAnimation = null;
     }