Gracefully handle drawing caches allocation failure.
Bug #3431451

This bug was causing ListView to not render properly when showing an item
larger than the maximum drawing cache size. ListView relies on the drawing
cache to correctly mask all the background pixels. However, if the cache
is not properly created, the background will show through even though
ListView.isOpaque() == true. This change detects this case and falls
back to the default non opaque behavior.

Change-Id: I30a45e7a03fb7ebb2b12f0e85c075c2901954c44
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 378eb21..0df464f 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -2138,6 +2138,13 @@
 
     private int[] mDrawableState = null;
 
+    /**
+     * Set to true when drawing cache is enabled and cannot be created.
+     * 
+     * @hide
+     */
+    public boolean mCachingFailed;
+
     private Bitmap mDrawingCache;
     private Bitmap mUnscaledDrawingCache;
     private DisplayList mDisplayList;
@@ -8355,6 +8362,7 @@
      * @see #setLayerType(int, android.graphics.Paint)
      */
     public void setDrawingCacheEnabled(boolean enabled) {
+        mCachingFailed = false;
         setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED);
     }
 
@@ -8597,7 +8605,7 @@
     public void buildDrawingCache() {
         buildDrawingCache(false);
     }
-
+    
     /**
      * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p>
      *
@@ -8624,6 +8632,7 @@
     public void buildDrawingCache(boolean autoScale) {
         if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || (autoScale ?
                 mDrawingCache == null : mUnscaledDrawingCache == null)) {
+            mCachingFailed = false;
 
             if (ViewDebug.TRACE_HIERARCHY) {
                 ViewDebug.trace(this, ViewDebug.HierarchyTraceType.BUILD_CACHE);
@@ -8649,6 +8658,7 @@
                     (width * height * (opaque && !use32BitCache ? 2 : 4) >
                             ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) {
                 destroyDrawingCache();
+                mCachingFailed = true;
                 return;
             }
 
@@ -8701,6 +8711,7 @@
                     } else {
                         mUnscaledDrawingCache = null;
                     }
+                    mCachingFailed = true;
                     return;
                 }