Fix free after use with createFromBitmapResource

Bug 9227350

Change-Id: Iee7610a9bf3d9d1baf14b968aed2a7d0876d2af7
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 773328c..8ba09e0 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -1650,6 +1650,9 @@
                                                       int usage) {
 
         rs.validate();
+        if ((usage & (USAGE_SHARED | USAGE_IO_INPUT | USAGE_IO_OUTPUT)) != 0) {
+            throw new RSIllegalArgumentException("Unsupported usage specified.");
+        }
         Bitmap b = BitmapFactory.decodeResource(res, id);
         Allocation alloc = createFromBitmap(rs, b, mips, usage);
         b.recycle();
@@ -1677,7 +1680,7 @@
         if (rs.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) {
             return createFromBitmapResource(rs, res, id,
                                             MipmapControl.MIPMAP_NONE,
-                                            USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE);
+                                            USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE);
         }
         return createFromBitmapResource(rs, res, id,
                                         MipmapControl.MIPMAP_NONE,