Merge "Add NetworkFactory names and unregistration."
diff --git a/api/current.txt b/api/current.txt
index 5f8b90c..86d1457 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -864,6 +864,7 @@
     field public static final int paddingBottom = 16842969; // 0x10100d9
     field public static final int paddingEnd = 16843700; // 0x10103b4
     field public static final int paddingLeft = 16842966; // 0x10100d6
+    field public static final int paddingMode = 16843866; // 0x101045a
     field public static final int paddingRight = 16842968; // 0x10100d8
     field public static final int paddingStart = 16843699; // 0x10103b3
     field public static final int paddingTop = 16842967; // 0x10100d7
@@ -8270,6 +8271,7 @@
     field public static final java.lang.String FEATURE_USB_ACCESSORY = "android.hardware.usb.accessory";
     field public static final java.lang.String FEATURE_USB_HOST = "android.hardware.usb.host";
     field public static final java.lang.String FEATURE_WATCH = "android.hardware.type.watch";
+    field public static final java.lang.String FEATURE_WEBVIEW = "android.software.webview";
     field public static final java.lang.String FEATURE_WIFI = "android.hardware.wifi";
     field public static final java.lang.String FEATURE_WIFI_DIRECT = "android.hardware.wifi.direct";
     field public static final int GET_ACTIVITIES = 1; // 0x1
@@ -12826,15 +12828,14 @@
 
   public class UsbConfiguration implements android.os.Parcelable {
     method public int describeContents();
-    method public int getAttributes();
     method public int getId();
     method public android.hardware.usb.UsbInterface getInterface(int);
     method public int getInterfaceCount();
     method public int getMaxPower();
     method public java.lang.String getName();
+    method public boolean isRemoteWakeup();
+    method public boolean isSelfPowered();
     method public void writeToParcel(android.os.Parcel, int);
-    field public static final int ATTR_REMOTE_WAKEUP_MASK = 32; // 0x20
-    field public static final int ATTR_SELF_POWERED_MASK = 64; // 0x40
     field public static final android.os.Parcelable.Creator CREATOR;
   }
 
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 58d707c..48ff5b6 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -911,6 +911,35 @@
      */
     public void suggestDesiredDimensions(int minimumWidth, int minimumHeight) {
         try {
+            /**
+             * The framework makes no attempt to limit the window size
+             * to the maximum texture size. Any window larger than this
+             * cannot be composited.
+             *
+             * Read maximum texture size from system property and scale down
+             * minimumWidth and minimumHeight accordingly.
+             */
+            int maximumTextureSize;
+            try {
+                maximumTextureSize = SystemProperties.getInt("sys.max_texture_size", 0);
+            } catch (Exception e) {
+                maximumTextureSize = 0;
+            }
+
+            if (maximumTextureSize > 0) {
+                if ((minimumWidth > maximumTextureSize) ||
+                    (minimumHeight > maximumTextureSize)) {
+                    float aspect = (float)minimumHeight / (float)minimumWidth;
+                    if (minimumWidth > minimumHeight) {
+                        minimumWidth = maximumTextureSize;
+                        minimumHeight = (int)((minimumWidth * aspect) + 0.5);
+                    } else {
+                        minimumHeight = maximumTextureSize;
+                        minimumWidth = (int)((minimumHeight / aspect) + 0.5);
+                    }
+                }
+            }
+
             if (sGlobals.mService == null) {
                 Log.w(TAG, "WallpaperService not running");
             } else {
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 0e2eab7..35bcc02 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -1405,6 +1405,14 @@
     public static final String FEATURE_MANAGEDPROFILES = "android.software.managedprofiles";
 
     /**
+     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
+     * The device has a full implementation of the android.webkit.* APIs. Devices
+     * lacking this feature will not have a functioning WebView implementation.
+     */
+    @SdkConstant(SdkConstantType.FEATURE)
+    public static final String FEATURE_WEBVIEW = "android.software.webview";
+
+    /**
      * Action to external storage service to clean out removed apps.
      * @hide
      */
diff --git a/core/java/android/hardware/usb/UsbConfiguration.java b/core/java/android/hardware/usb/UsbConfiguration.java
index 92d6f75..da5c128 100644
--- a/core/java/android/hardware/usb/UsbConfiguration.java
+++ b/core/java/android/hardware/usb/UsbConfiguration.java
@@ -44,13 +44,13 @@
      * Mask for "self-powered" bit in the configuration's attributes.
      * @see #getAttributes
      */
-    public static final int ATTR_SELF_POWERED_MASK = 1 << 6;
+    private static final int ATTR_SELF_POWERED = 1 << 6;
 
     /**
      * Mask for "remote wakeup" bit in the configuration's attributes.
      * @see #getAttributes
      */
-    public static final int ATTR_REMOTE_WAKEUP_MASK = 1 << 5;
+    private static final int ATTR_REMOTE_WAKEUP = 1 << 5;
 
     /**
      * UsbConfiguration should only be instantiated by UsbService implementation
@@ -83,19 +83,23 @@
     }
 
     /**
-     * Returns the configuration's attributes field.
-     * This field contains a bit field with the following flags:
+     * Returns the self-powered attribute value configuration's attributes field.
+     * This attribute indicates that the device has a power source other than the USB connection.
      *
-     * Bit 7: always set to 1
-     * Bit 6: self-powered
-     * Bit 5: remote wakeup enabled
-     * Bit 0-4: reserved
-     * @see #ATTR_SELF_POWERED_MASK
-     * @see #ATTR_REMOTE_WAKEUP_MASK
-     * @return the configuration's attributes
+     * @return the configuration's self-powered attribute
      */
-    public int getAttributes() {
-        return mAttributes;
+    public boolean isSelfPowered() {
+        return (mAttributes & ATTR_SELF_POWERED) != 0;
+    }
+
+    /**
+     * Returns the remote-wakeup attribute value configuration's attributes field.
+     * This attributes that the device may signal the host to wake from suspend.
+     *
+     * @return the configuration's remote-wakeup attribute
+     */
+    public boolean isRemoteWakeup() {
+        return (mAttributes & ATTR_REMOTE_WAKEUP) != 0;
     }
 
     /**
diff --git a/core/java/android/hardware/usb/UsbDeviceConnection.java b/core/java/android/hardware/usb/UsbDeviceConnection.java
index 6283951..c062b3a 100644
--- a/core/java/android/hardware/usb/UsbDeviceConnection.java
+++ b/core/java/android/hardware/usb/UsbDeviceConnection.java
@@ -104,7 +104,7 @@
      * Sets the current {@link android.hardware.usb.UsbInterface}.
      * Used to select between two interfaces with the same ID but different alternate setting.
      *
-     * @return true if the interface was successfully released
+     * @return true if the interface was successfully selected
      */
     public boolean setInterface(UsbInterface intf) {
         return native_set_interface(intf.getId(), intf.getAlternateSetting());
diff --git a/core/jni/android_hardware_UsbRequest.cpp b/core/jni/android_hardware_UsbRequest.cpp
index 01eaec4..a3c7b0a 100644
--- a/core/jni/android_hardware_UsbRequest.cpp
+++ b/core/jni/android_hardware_UsbRequest.cpp
@@ -100,18 +100,19 @@
     }
     request->buffer_length = length;
 
+    // save a reference to ourselves so UsbDeviceConnection.waitRequest() can find us
+    request->client_data = (void *)env->NewGlobalRef(thiz);
+
     if (usb_request_queue(request)) {
         if (request->buffer) {
             // free our buffer if usb_request_queue fails
             free(request->buffer);
             request->buffer = NULL;
         }
+        env->DeleteGlobalRef((jobject)request->client_data);
         return false;
-    } else {
-        // save a reference to ourselves so UsbDeviceConnection.waitRequest() can find us
-        request->client_data = (void *)env->NewGlobalRef(thiz);
-        return true;
     }
+    return true;
 }
 
 static jint
@@ -152,16 +153,17 @@
     }
     request->buffer_length = length;
 
+    // save a reference to ourselves so UsbDeviceConnection.waitRequest() can find us
+    // we also need this to make sure our native buffer is not deallocated
+    // while IO is active
+    request->client_data = (void *)env->NewGlobalRef(thiz);
+
     if (usb_request_queue(request)) {
         request->buffer = NULL;
+        env->DeleteGlobalRef((jobject)request->client_data);
         return false;
-    } else {
-        // save a reference to ourselves so UsbDeviceConnection.waitRequest() can find us
-        // we also need this to make sure our native buffer is not deallocated
-        // while IO is active
-        request->client_data = (void *)env->NewGlobalRef(thiz);
-        return true;
     }
+    return true;
 }
 
 static jint
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 55e2983..4b03f31 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -4497,7 +4497,7 @@
              RTL (right-to-left). -->
         <attr name="autoMirrored" />
         <!-- Indicates how layer padding should affect the bounds of subsequent layers.
-            The default value is nest. -->
+             The default padding mode value is nest. -->
         <attr name="paddingMode">
             <!-- Nest each layer inside the padding of the previous layer. -->
             <enum name="nest" value="0" />
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 1bb0d42..32ce568 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2177,6 +2177,7 @@
   <public type="attr" name="contentInsetEnd" />
   <public type="attr" name="contentInsetLeft" />
   <public type="attr" name="contentInsetRight" />
+  <public type="attr" name="paddingMode" />
 
   <public-padding type="dimen" name="l_resource_pad" end="0x01050010" />
 
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java
index c78096a..3eabc3a 100644
--- a/graphics/java/android/graphics/drawable/Drawable.java
+++ b/graphics/java/android/graphics/drawable/Drawable.java
@@ -1005,6 +1005,11 @@
         return createFromXmlInnerThemed(r, parser, attrs, null);
     }
 
+    /**
+     * Create a themed drawable from inside an XML document. Called on a parser
+     * positioned at a tag in an XML document, tries to create a Drawable from
+     * that tag. Returns null if the tag is not a valid drawable.
+     */
     public static Drawable createFromXmlInnerThemed(Resources r, XmlPullParser parser,
             AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException {
         final Drawable drawable;
diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java
index 373d894..f446000 100644
--- a/graphics/java/android/graphics/drawable/LayerDrawable.java
+++ b/graphics/java/android/graphics/drawable/LayerDrawable.java
@@ -38,10 +38,12 @@
  * order, so the element with the largest index will be drawn on top.
  * <p>
  * It can be defined in an XML file with the <code>&lt;layer-list></code> element.
- * Each Drawable in the layer is defined in a nested <code>&lt;item></code>. For more
- * information, see the guide to <a
- * href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.</p>
+ * Each Drawable in the layer is defined in a nested <code>&lt;item></code>.
+ * <p>
+ * For more information, see the guide to
+ * <a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.
  *
+ * @attr ref android.R.styleable#LayerDrawable_paddingMode
  * @attr ref android.R.styleable#LayerDrawableItem_left
  * @attr ref android.R.styleable#LayerDrawableItem_top
  * @attr ref android.R.styleable#LayerDrawableItem_right
@@ -53,10 +55,16 @@
     /**
      * Padding mode used to nest each layer inside the padding of the previous
      * layer.
+     *
+     * @see #setPaddingMode(int)
      */
     public static final int PADDING_MODE_NEST = 0;
 
-    /** Padding mode used to stack each layer directly atop the previous layer. */
+    /**
+     * Padding mode used to stack each layer directly atop the previous layer.
+     *
+     * @see #setPaddingMode(int)
+     */
     public static final int PADDING_MODE_STACK = 1;
 
     LayerState mLayerState;
@@ -127,9 +135,8 @@
             throws XmlPullParserException, IOException {
         super.inflate(r, parser, attrs, theme);
 
-        final TypedArray a = obtainAttributes(
-                r, theme, attrs, R.styleable.LayerDrawable);
-        inflateStateFromTypedArray(a);
+        final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawable);
+        updateStateFromTypedArray(a);
         a.recycle();
 
         inflateLayers(r, parser, attrs, theme);
@@ -141,25 +148,19 @@
     /**
      * Initializes the constant state from the values in the typed array.
      */
-    private void inflateStateFromTypedArray(TypedArray a) {
+    private void updateStateFromTypedArray(TypedArray a) {
         final LayerState state = mLayerState;
 
         // Extract the theme attributes, if any.
         final int[] themeAttrs = a.extractThemeAttrs();
         state.mThemeAttrs = themeAttrs;
 
-        if (themeAttrs == null || themeAttrs[R.styleable.LayerDrawable_opacity] == 0) {
-            mOpacityOverride = a.getInt(R.styleable.LayerDrawable_opacity, PixelFormat.UNKNOWN);
-        }
+        mOpacityOverride = a.getInt(R.styleable.LayerDrawable_opacity, mOpacityOverride);
 
-        if (themeAttrs == null || themeAttrs[R.styleable.LayerDrawable_autoMirrored] == 0) {
-            state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_autoMirrored, false);
-        }
-
-        if (themeAttrs == null || themeAttrs[R.styleable.LayerDrawableItem_drawable] == 0) {
-            state.mPaddingMode = a.getInteger(
-                    R.styleable.LayerDrawableItem_drawable, PADDING_MODE_NEST);
-        }
+        state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_autoMirrored,
+                state.mAutoMirrored);
+        state.mPaddingMode = a.getInteger(R.styleable.LayerDrawable_paddingMode,
+                state.mPaddingMode);
     }
 
     /**
@@ -181,9 +182,9 @@
                 continue;
             }
 
-            a = obtainAttributes(
-                    r, theme, attrs, R.styleable.LayerDrawableItem);
+            a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawableItem);
 
+            final int[] themeAttrs = a.extractThemeAttrs();
             final int left = a.getDimensionPixelOffset(
                     R.styleable.LayerDrawableItem_left, 0);
             final int top = a.getDimensionPixelOffset(
@@ -197,7 +198,6 @@
             final int id = a.getResourceId(
                     R.styleable.LayerDrawableItem_id, View.NO_ID);
 
-            // TODO: Cache typed array, if necessary.
             a.recycle();
 
             final Drawable dr;
@@ -214,7 +214,7 @@
                 dr = Drawable.createFromXmlInnerThemed(r, parser, attrs, theme);
             }
 
-            addLayer(dr, id, left, top, right, bottom);
+            addLayer(dr, themeAttrs, id, left, top, right, bottom);
         }
     }
 
@@ -224,7 +224,7 @@
 
         final LayerState state = mLayerState;
         if (state == null) {
-            throw new RuntimeException("Can't apply theme to <layer-list> with no constant state");
+            return;
         }
 
         final int[] themeAttrs = state.mThemeAttrs;
@@ -239,9 +239,10 @@
         final ChildDrawable[] array = mLayerState.mChildren;
         final int N = mLayerState.mNum;
         for (int i = 0; i < N; i++) {
-            final Drawable layer = array[i].mDrawable;
-            if (layer.canApplyTheme()) {
-                layer.applyTheme(t);
+            final ChildDrawable layer = array[i];
+            final Drawable d = layer.mDrawable;
+            if (d.canApplyTheme()) {
+                d.applyTheme(t);
             }
         }
 
@@ -249,26 +250,6 @@
         onStateChange(getState());
     }
 
-    /**
-     * Updates the constant state from the values in the typed array.
-     */
-    private void updateStateFromTypedArray(TypedArray a) {
-        final LayerState state = mLayerState;
-
-        if (a.hasValue(R.styleable.LayerDrawable_opacity)) {
-            mOpacityOverride = a.getInt(R.styleable.LayerDrawable_opacity, PixelFormat.UNKNOWN);
-        }
-
-        if (a.hasValue(R.styleable.LayerDrawable_autoMirrored)) {
-            state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_autoMirrored, false);
-        }
-
-        if (a.hasValue(R.styleable.LayerDrawableItem_drawable)) {
-            state.mPaddingMode = a.getInteger(
-                    R.styleable.LayerDrawableItem_drawable, PADDING_MODE_NEST);
-        }
-    }
-
     @Override
     public boolean canApplyTheme() {
         final LayerState state = mLayerState;
@@ -283,14 +264,15 @@
         final ChildDrawable[] array = state.mChildren;
         final int N = state.mNum;
         for (int i = 0; i < N; i++) {
-            if (array[i].mDrawable.canApplyTheme()) {
+            final ChildDrawable layer = array[i];
+            if (layer.mThemeAttrs != null || layer.mDrawable.canApplyTheme()) {
                 return true;
             }
         }
 
         return false;
     }
-    
+
     /**
      * @hide
      */
@@ -315,13 +297,15 @@
      * Add a new layer to this drawable. The new layer is identified by an id.
      *
      * @param layer The drawable to add as a layer.
+     * @param themeAttrs Theme attributes extracted from the layer.
      * @param id The id of the new layer.
      * @param left The left padding of the new layer.
      * @param top The top padding of the new layer.
      * @param right The right padding of the new layer.
      * @param bottom The bottom padding of the new layer.
      */
-    private void addLayer(Drawable layer, int id, int left, int top, int right, int bottom) {
+    private void addLayer(Drawable layer, int[] themeAttrs, int id, int left, int top, int right,
+            int bottom) {
         final LayerState st = mLayerState;
         final int N = st.mChildren != null ? st.mChildren.length : 0;
         final int i = st.mNum;
@@ -339,6 +323,7 @@
         final ChildDrawable childDrawable = new ChildDrawable();
         st.mChildren[i] = childDrawable;
         childDrawable.mId = id;
+        childDrawable.mThemeAttrs = themeAttrs;
         childDrawable.mDrawable = layer;
         childDrawable.mDrawable.setAutoMirrored(isAutoMirrored());
         childDrawable.mInsetL = left;
@@ -471,8 +456,14 @@
      *
      * @param mode padding mode, one of:
      *            <ul>
-     *            <li>{@link #PADDING_MODE_NEST} <li>{@link #PADDING_MODE_STACK}
+     *            <li>{@link #PADDING_MODE_NEST} to nest each layer inside the
+     *            padding of the previous layer
+     *            <li>{@link #PADDING_MODE_STACK} to stack each layer directly
+     *            atop the previous layer
      *            </ul>
+     *
+     * @see #getPaddingMode()
+     * @attr ref android.R.styleable#LayerDrawable_paddingMode
      */
     public void setPaddingMode(int mode) {
         if (mLayerState.mPaddingMode != mode) {
@@ -482,7 +473,9 @@
 
     /**
      * @return the current padding mode
+     *
      * @see #setPaddingMode(int)
+     * @attr ref android.R.styleable#LayerDrawable_paddingMode
      */
     public int getPaddingMode() {
       return mLayerState.mPaddingMode;
@@ -905,7 +898,7 @@
         private boolean mHaveIsStateful;
         private boolean mIsStateful;
 
-        private boolean mAutoMirrored;
+        private boolean mAutoMirrored = false;
 
         private int mPaddingMode = PADDING_MODE_NEST;
 
diff --git a/graphics/java/android/graphics/drawable/RotateDrawable.java b/graphics/java/android/graphics/drawable/RotateDrawable.java
index edf1091..5f9d1cd 100644
--- a/graphics/java/android/graphics/drawable/RotateDrawable.java
+++ b/graphics/java/android/graphics/drawable/RotateDrawable.java
@@ -145,6 +145,9 @@
      * Sets the start angle for rotation.
      *
      * @param fromDegrees Starting angle in degrees
+     *
+     * @see #getFromDegrees()
+     * @attr ref android.R.styleable#RotateDrawable_fromDegrees
      */
     public void setFromDegrees(float fromDegrees) {
         if (mState.mFromDegrees != fromDegrees) {
@@ -155,6 +158,9 @@
 
     /**
      * @return The starting angle for rotation in degrees
+     *
+     * @see #setFromDegrees(float)
+     * @attr ref android.R.styleable#RotateDrawable_fromDegrees
      */
     public float getFromDegrees() {
         return mState.mFromDegrees;
@@ -164,6 +170,9 @@
      * Sets the end angle for rotation.
      *
      * @param toDegrees Ending angle in degrees
+     *
+     * @see #getToDegrees()
+     * @attr ref android.R.styleable#RotateDrawable_toDegrees
      */
     public void setToDegrees(float toDegrees) {
         if (mState.mToDegrees != toDegrees) {
@@ -174,6 +183,9 @@
 
     /**
      * @return The ending angle for rotation in degrees
+     *
+     * @see #setToDegrees(float)
+     * @attr ref android.R.styleable#RotateDrawable_toDegrees
      */
     public float getToDegrees() {
         return mState.mToDegrees;
@@ -186,7 +198,9 @@
      *            relative, the position represents a fraction of the drawable
      *            width. Otherwise, the position represents an absolute value in
      *            pixels.
+     *
      * @see #setPivotXRelative(boolean)
+     * @attr ref android.R.styleable#RotateDrawable_pivotX
      */
     public void setPivotX(float pivotX) {
         if (mState.mPivotX == pivotX) {
@@ -197,7 +211,9 @@
 
     /**
      * @return X position around which to rotate
+     *
      * @see #setPivotX(float)
+     * @attr ref android.R.styleable#RotateDrawable_pivotX
      */
     public float getPivotX() {
         return mState.mPivotX;
@@ -209,6 +225,8 @@
      *
      * @param relative True if the X pivot represents a fraction of the drawable
      *            width, or false if it represents an absolute value in pixels
+     *
+     * @see #isPivotXRelative()
      */
     public void setPivotXRelative(boolean relative) {
         if (mState.mPivotXRel == relative) {
@@ -220,6 +238,7 @@
     /**
      * @return True if the X pivot represents a fraction of the drawable width,
      *         or false if it represents an absolute value in pixels
+     *
      * @see #setPivotXRelative(boolean)
      */
     public boolean isPivotXRelative() {
@@ -233,7 +252,9 @@
      *            relative, the position represents a fraction of the drawable
      *            height. Otherwise, the position represents an absolute value
      *            in pixels.
-     * @see #setPivotYRelative(boolean)
+     *
+     * @see #getPivotY()
+     * @attr ref android.R.styleable#RotateDrawable_pivotY
      */
     public void setPivotY(float pivotY) {
         if (mState.mPivotY == pivotY) {
@@ -244,7 +265,9 @@
 
     /**
      * @return Y position around which to rotate
+     *
      * @see #setPivotY(float)
+     * @attr ref android.R.styleable#RotateDrawable_pivotY
      */
     public float getPivotY() {
         return mState.mPivotY;
@@ -256,6 +279,8 @@
      *
      * @param relative True if the Y pivot represents a fraction of the drawable
      *            height, or false if it represents an absolute value in pixels
+     *
+     * @see #isPivotYRelative()
      */
     public void setPivotYRelative(boolean relative) {
         if (mState.mPivotYRel == relative) {
@@ -267,6 +292,7 @@
     /**
      * @return True if the Y pivot represents a fraction of the drawable height,
      *         or false if it represents an absolute value in pixels
+     *
      * @see #setPivotYRelative(boolean)
      */
     public boolean isPivotYRelative() {
diff --git a/media/jni/android_media_MediaScanner.cpp b/media/jni/android_media_MediaScanner.cpp
index 84028b7..d21b442 100644
--- a/media/jni/android_media_MediaScanner.cpp
+++ b/media/jni/android_media_MediaScanner.cpp
@@ -351,7 +351,7 @@
     if (!data) {
         return NULL;
     }
-    long len = *((long*)data);
+    jsize len = *((uint32_t*)data);
 
     jbyteArray array = env->NewByteArray(len);
     if (array != NULL) {