Implement more type checks on Allocations.
Add tracking for allocations created using the "sized" helper.
Add more param validation for data upload calls.
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index b6b7adf..df60990 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -23,13 +23,74 @@
  *
  **/
 public class Type extends BaseObj {
-    Dimension[] mDimensions;
-    int[] mValues;
+    int mDimX;
+    int mDimY;
+    int mDimZ;
+    boolean mDimLOD;
+    boolean mDimFaces;
+    int mElementCount;
     Element mElement;
+
     private int mNativeCache;
     Class mJavaClass;
 
 
+    public int getX() {
+        return mDimX;
+    }
+    public int getY() {
+        return mDimY;
+    }
+    public int getZ() {
+        return mDimZ;
+    }
+    public boolean getLOD() {
+        return mDimLOD;
+    }
+    public boolean getFaces() {
+        return mDimFaces;
+    }
+    public int getElementCount() {
+        return mElementCount;
+    }
+
+    void calcElementCount() {
+        boolean hasLod = getLOD();
+        int x = getX();
+        int y = getY();
+        int z = getZ();
+        int faces = 1;
+        if(getFaces()) {
+            faces = 6;
+        }
+        if(x == 0) {
+            x = 1;
+        }
+        if(y == 0) {
+            y = 1;
+        }
+        if(z == 0) {
+            z = 1;
+        }
+
+        int count = x * y * z * faces;
+        if(hasLod && (x > 1) && (y > 1) && (z > 1)) {
+            if(x > 1) {
+                x >>= 1;
+            }
+            if(y > 1) {
+                y >>= 1;
+            }
+            if(z > 1) {
+                z >>= 1;
+            }
+
+            count += x * y * z * faces;
+        }
+        mElementCount = count;
+    }
+
+
     Type(int id, RenderScript rs) {
         super(rs);
         mID = id;
@@ -131,12 +192,25 @@
         public Type create() {
             Type t = internalCreate(mRS, this);
             t.mElement = mElement;
-            t.mDimensions = new Dimension[mEntryCount];
-            t.mValues = new int[mEntryCount];
+
             for(int ct=0; ct < mEntryCount; ct++) {
-                t.mDimensions[ct] = mEntries[ct].mDim;
-                t.mValues[ct] = mEntries[ct].mValue;
+                if(mEntries[ct].mDim == Dimension.X) {
+                    t.mDimX = mEntries[ct].mValue;
+                }
+                if(mEntries[ct].mDim == Dimension.Y) {
+                    t.mDimY = mEntries[ct].mValue;
+                }
+                if(mEntries[ct].mDim == Dimension.Z) {
+                    t.mDimZ = mEntries[ct].mValue;
+                }
+                if(mEntries[ct].mDim == Dimension.LOD) {
+                    t.mDimLOD = mEntries[ct].mValue != 0;
+                }
+                if(mEntries[ct].mDim == Dimension.FACE) {
+                    t.mDimFaces = mEntries[ct].mValue != 0;
+                }
             }
+            t.calcElementCount();
             return t;
         }
     }