Merge "Increase activity timeouts when using a wrapper process."
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java
index 61deea4..9c12a44 100644
--- a/core/java/android/provider/ContactsContract.java
+++ b/core/java/android/provider/ContactsContract.java
@@ -135,14 +135,6 @@
     public static final String ALLOW_PROFILE = "allow_profile";
 
     /**
-     * A query parameter key used to specify the package that is requesting a query.
-     * This is used for restricting data based on package name.
-     *
-     * @hide
-     */
-    public static final String REQUESTING_PACKAGE_PARAM_KEY = "requesting_package";
-
-    /**
      * Query parameter that should be used by the client to access a specific
      * {@link Directory}. The parameter value should be the _ID of the corresponding
      * directory, e.g.
@@ -271,8 +263,6 @@
      * <li>The URI authority is replaced with the corresponding {@link #DIRECTORY_AUTHORITY}.</li>
      * <li>The {@code accountName=} and {@code accountType=} parameters are added or
      * replaced using the corresponding {@link #ACCOUNT_TYPE} and {@link #ACCOUNT_NAME} values.</li>
-     * <li>If the URI is missing a ContactsContract.REQUESTING_PACKAGE_PARAM_KEY
-     * parameter, this parameter is added.</li>
      * </ul>
      * </p>
      * <p>
@@ -1881,15 +1871,6 @@
         public static final String CONTACT_ID = "contact_id";
 
         /**
-         * Flag indicating that this {@link RawContacts} entry and its children have
-         * been restricted to specific platform apps.
-         * <P>Type: INTEGER (boolean)</P>
-         *
-         * @hide until finalized in future platform release
-         */
-        public static final String IS_RESTRICTED = "is_restricted";
-
-        /**
          * The aggregation mode for this contact.
          * <P>Type: INTEGER</P>
          */
@@ -2537,7 +2518,6 @@
                 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DELETED);
                 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, CONTACT_ID);
                 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, STARRED);
-                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, IS_RESTRICTED);
                 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, NAME_VERIFIED);
                 android.content.Entity contact = new android.content.Entity(cv);
 
@@ -3814,27 +3794,6 @@
 
         /**
          * <p>
-         * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward
-         * Data.CONTENT_URI contains only exportable data.
-         * </p>
-         * <p>
-         * This flag is useful (currently) only for vCard exporter in Contacts app, which
-         * needs to exclude "un-exportable" data from available data to export, while
-         * Contacts app itself has priviledge to access all data including "un-exportable"
-         * ones and providers return all of them regardless of the callers' intention.
-         * </p>
-         * <p>
-         * Type: INTEGER
-         * </p>
-         *
-         * @hide Maybe available only in Eclair and not really ready for public use.
-         * TODO: remove, or implement this feature completely. As of now (Eclair),
-         * we only use this flag in queryEntities(), not query().
-         */
-        public static final String FOR_EXPORT_ONLY = "for_export_only";
-
-        /**
-         * <p>
          * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}
          * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts}
          * entry of the given {@link ContactsContract.Data} entry.
diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java
index 1638c74..011e44c 100644
--- a/core/java/android/view/HardwareRenderer.java
+++ b/core/java/android/view/HardwareRenderer.java
@@ -128,10 +128,19 @@
     abstract void updateSurface(SurfaceHolder holder) throws Surface.OutOfResourcesException;
 
     /**
-     * Invoked whenever the size of the target surface changes. This will
-     * not be invoked when the surface is first created.
+     * This method should be invoked whenever the current hardware renderer
+     * context should be reset. 
      */
-    abstract void preapareSurfaceForResize();
+    abstract void invalidate();
+
+    /**
+     * This method should be invoked to ensure the hardware renderer is in
+     * valid state (for instance, to ensure the correct EGL context is bound
+     * to the current thread.)
+     * 
+     * @return true if the renderer is now valid, false otherwise
+     */
+    abstract boolean validate();
 
     /**
      * Setup the hardware renderer for drawing. This is called whenever the
@@ -629,11 +638,16 @@
         }
 
         @Override
-        void preapareSurfaceForResize() {
+        void invalidate() {
             // Cancels any existing buffer to ensure we'll get a buffer
             // of the right size before we call eglSwapBuffers
             sEgl.eglMakeCurrent(sEglDisplay, EGL10.EGL_NO_SURFACE,
-                    EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);              
+                    EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
+        }
+        
+        @Override
+        boolean validate() {
+            return checkCurrent() != SURFACE_STATE_ERROR;
         }
 
         @Override
@@ -662,7 +676,7 @@
                 attachInfo.mDrawingTime = SystemClock.uptimeMillis();
 
                 view.mPrivateFlags |= View.DRAWN;
-                
+
                 final int surfaceState = checkCurrent();
                 if (surfaceState != SURFACE_STATE_ERROR) {
                     // We had to change the current surface and/or context, redraw everything
@@ -723,10 +737,21 @@
                 }
             }
         }
-        
+
+        /**
+         * Ensures the currnet EGL context is the one we expect.
+         * 
+         * @return {@link #SURFACE_STATE_ERROR} if the correct EGL context cannot be made current,
+         *         {@link #SURFACE_STATE_UPDATED} if the EGL context was changed or
+         *         {@link #SURFACE_STATE_SUCCESS} if the EGL context was the correct one
+         */
         private int checkCurrent() {
-            // TODO: Don't check the current context when we have one per UI thread
-            // TODO: Use a threadlocal flag to know whether the surface has changed
+            if (sEglThread != Thread.currentThread()) {
+                throw new IllegalStateException("Hardware acceleration can only be used with a " +
+                        "single UI thread.\nOriginal thread: " + sEglThread + "\n" +
+                        "Current thread: " + Thread.currentThread());
+            }
+
             if (!sEglContext.equals(sEgl.eglGetCurrentContext()) ||
                     !mEglSurface.equals(sEgl.eglGetCurrentSurface(EGL10.EGL_DRAW))) {
                 if (!sEgl.eglMakeCurrent(sEglDisplay, mEglSurface, mEglSurface, sEglContext)) {
diff --git a/core/java/android/view/ViewAncestor.java b/core/java/android/view/ViewAncestor.java
index b4f323c..1dcbc26 100644
--- a/core/java/android/view/ViewAncestor.java
+++ b/core/java/android/view/ViewAncestor.java
@@ -901,6 +901,7 @@
                             !mAttachInfo.mTurnOffWindowResizeAnim &&
                             mAttachInfo.mHardwareRenderer != null &&
                             mAttachInfo.mHardwareRenderer.isEnabled() &&
+                            mAttachInfo.mHardwareRenderer.validate() &&
                             lp != null && !PixelFormat.formatHasAlpha(lp.format)) {
 
                         disposeResizeBuffer();
@@ -1314,10 +1315,10 @@
             if (hwInitialized || ((windowShouldResize || params != null) &&
                     mAttachInfo.mHardwareRenderer != null &&
                     mAttachInfo.mHardwareRenderer.isEnabled())) {
-                if (!hwInitialized) {
-                    mAttachInfo.mHardwareRenderer.preapareSurfaceForResize();
-                }
                 mAttachInfo.mHardwareRenderer.setup(mWidth, mHeight);
+                if (!hwInitialized) {
+                    mAttachInfo.mHardwareRenderer.invalidate();
+                }
             }
 
             if (!mStopped) {
diff --git a/core/java/android/webkit/ZoomManager.java b/core/java/android/webkit/ZoomManager.java
index 7d3f313..49ea944 100644
--- a/core/java/android/webkit/ZoomManager.java
+++ b/core/java/android/webkit/ZoomManager.java
@@ -344,6 +344,8 @@
 
     public final void setInitialScaleInPercent(int scaleInPercent) {
         mInitialScale = scaleInPercent * 0.01f;
+        mActualScale = mInitialScale > 0 ? mInitialScale : mDefaultScale;
+        mInvActualScale = 1 / mActualScale;
     }
 
     public final float computeScaleWithLimits(float scale) {
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 6254192..12e5ada 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -155,6 +155,14 @@
         }
     }
 
+
+    private int getIDSafe() {
+        if (mAdaptedAllocation != null) {
+            return mAdaptedAllocation.getID();
+        }
+        return getID();
+    }
+
     private void updateCacheInfo(Type t) {
         mCurrentDimX = t.getX();
         mCurrentDimY = t.getY();
@@ -262,7 +270,7 @@
             throw new RSIllegalArgumentException("Source must be exactly one usage type.");
         }
         mRS.validate();
-        mRS.nAllocationSyncAll(getID(), srcLocation);
+        mRS.nAllocationSyncAll(getIDSafe(), srcLocation);
     }
 
     public void copyFrom(BaseObj[] d) {
@@ -480,7 +488,7 @@
                                                " does not match component size " + eSize + ".");
         }
 
-        mRS.nAllocationElementData1D(getID(), xoff, mSelectedLOD,
+        mRS.nAllocationElementData1D(getIDSafe(), xoff, mSelectedLOD,
                                      component_number, data, data.length);
     }
 
@@ -527,7 +535,7 @@
     public void copy1DRangeFromUnchecked(int off, int count, int[] d) {
         int dataSize = mType.mElement.getSizeBytes() * count;
         data1DChecks(off, count, d.length * 4, dataSize);
-        mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+        mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
     }
     /**
      * Copy part of an allocation from an array.  This variant is
@@ -541,7 +549,7 @@
     public void copy1DRangeFromUnchecked(int off, int count, short[] d) {
         int dataSize = mType.mElement.getSizeBytes() * count;
         data1DChecks(off, count, d.length * 2, dataSize);
-        mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+        mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
     }
     /**
      * Copy part of an allocation from an array.  This variant is
@@ -555,7 +563,7 @@
     public void copy1DRangeFromUnchecked(int off, int count, byte[] d) {
         int dataSize = mType.mElement.getSizeBytes() * count;
         data1DChecks(off, count, d.length, dataSize);
-        mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+        mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
     }
     /**
      * Copy part of an allocation from an array.  This variant is
@@ -569,7 +577,7 @@
     public void copy1DRangeFromUnchecked(int off, int count, float[] d) {
         int dataSize = mType.mElement.getSizeBytes() * count;
         data1DChecks(off, count, d.length * 4, dataSize);
-        mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+        mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
     }
 
     /**
@@ -638,7 +646,7 @@
      *          be copied.
      */
     public void copy1DRangeFrom(int off, int count, Allocation data, int dataOff) {
-        mRS.nAllocationData2D(getID(), off, 0,
+        mRS.nAllocationData2D(getIDSafe(), off, 0,
                               mSelectedLOD, mSelectedFace.mID,
                               count, 1, data.getID(), dataOff, 0,
                               data.mSelectedLOD, data.mSelectedFace.mID);
@@ -674,28 +682,28 @@
     public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) {
         mRS.validate();
         validate2DRange(xoff, yoff, w, h);
-        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+        mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
                               w, h, data, data.length);
     }
 
     public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) {
         mRS.validate();
         validate2DRange(xoff, yoff, w, h);
-        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+        mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
                               w, h, data, data.length * 2);
     }
 
     public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) {
         mRS.validate();
         validate2DRange(xoff, yoff, w, h);
-        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+        mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
                               w, h, data, data.length * 4);
     }
 
     public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) {
         mRS.validate();
         validate2DRange(xoff, yoff, w, h);
-        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+        mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
                               w, h, data, data.length * 4);
     }
 
@@ -715,7 +723,7 @@
                                 Allocation data, int dataXoff, int dataYoff) {
         mRS.validate();
         validate2DRange(xoff, yoff, w, h);
-        mRS.nAllocationData2D(getID(), xoff, yoff,
+        mRS.nAllocationData2D(getIDSafe(), xoff, yoff,
                               mSelectedLOD, mSelectedFace.mID,
                               w, h, data.getID(), dataXoff, dataYoff,
                               data.mSelectedLOD, data.mSelectedFace.mID);
@@ -734,10 +742,16 @@
         mRS.validate();
         validateBitmapFormat(data);
         validate2DRange(xoff, yoff, data.getWidth(), data.getHeight());
-        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data);
+        mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data);
     }
 
 
+    /**
+     * Copy from the Allocation into a Bitmap.  The bitmap must
+     * match the dimensions of the Allocation.
+     *
+     * @param b The bitmap to be set from the Allocation.
+     */
     public void copyTo(Bitmap b) {
         mRS.validate();
         validateBitmapFormat(b);
@@ -745,24 +759,52 @@
         mRS.nAllocationCopyToBitmap(getID(), b);
     }
 
+    /**
+     * Copy from the Allocation into a byte array.  The array must
+     * be at least as large as the Allocation.  The allocation must
+     * be of an 8 bit elemental type.
+     *
+     * @param d The array to be set from the Allocation.
+     */
     public void copyTo(byte[] d) {
         validateIsInt8();
         mRS.validate();
         mRS.nAllocationRead(getID(), d);
     }
 
+    /**
+     * Copy from the Allocation into a short array.  The array must
+     * be at least as large as the Allocation.  The allocation must
+     * be of an 16 bit elemental type.
+     *
+     * @param d The array to be set from the Allocation.
+     */
     public void copyTo(short[] d) {
         validateIsInt16();
         mRS.validate();
         mRS.nAllocationRead(getID(), d);
     }
 
+    /**
+     * Copy from the Allocation into a int array.  The array must be
+     * at least as large as the Allocation.  The allocation must be
+     * of an 32 bit elemental type.
+     *
+     * @param d The array to be set from the Allocation.
+     */
     public void copyTo(int[] d) {
         validateIsInt32();
         mRS.validate();
         mRS.nAllocationRead(getID(), d);
     }
 
+    /**
+     * Copy from the Allocation into a float array.  The array must
+     * be at least as large as the Allocation.  The allocation must
+     * be of an 32 bit float elemental type.
+     *
+     * @param d The array to be set from the Allocation.
+     */
     public void copyTo(float[] d) {
         validateIsFloat32();
         mRS.validate();
diff --git a/graphics/java/android/renderscript/AllocationAdapter.java b/graphics/java/android/renderscript/AllocationAdapter.java
index ca5246a..d38f2df 100644
--- a/graphics/java/android/renderscript/AllocationAdapter.java
+++ b/graphics/java/android/renderscript/AllocationAdapter.java
@@ -31,7 +31,8 @@
     }
 
     int getID() {
-        return mAdaptedAllocation.getID();
+        throw new RSInvalidStateException(
+            "This operation is not supported with adapters at this time.");
     }
 
     /**
diff --git a/include/gui/SurfaceTextureClient.h b/include/gui/SurfaceTextureClient.h
index 6ce44fc..9db7364 100644
--- a/include/gui/SurfaceTextureClient.h
+++ b/include/gui/SurfaceTextureClient.h
@@ -65,6 +65,8 @@
     int dispatchDisconnect(va_list args);
     int dispatchSetBufferCount(va_list args);
     int dispatchSetBuffersGeometry(va_list args);
+    int dispatchSetBuffersDimensions(va_list args);
+    int dispatchSetBuffersFormat(va_list args);
     int dispatchSetBuffersTransform(va_list args);
     int dispatchSetBuffersTimestamp(va_list args);
     int dispatchSetCrop(va_list args);
@@ -73,7 +75,8 @@
     int connect(int api);
     int disconnect(int api);
     int setBufferCount(int bufferCount);
-    int setBuffersGeometry(int w, int h, int format);
+    int setBuffersDimensions(int w, int h);
+    int setBuffersFormat(int format);
     int setBuffersTransform(int transform);
     int setBuffersTimestamp(int64_t timestamp);
     int setCrop(Rect const* rect);
diff --git a/libs/gui/SurfaceTextureClient.cpp b/libs/gui/SurfaceTextureClient.cpp
index b9b2310..e203035 100644
--- a/libs/gui/SurfaceTextureClient.cpp
+++ b/libs/gui/SurfaceTextureClient.cpp
@@ -254,6 +254,12 @@
     case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP:
         res = dispatchSetBuffersTimestamp(args);
         break;
+    case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS:
+        res = dispatchSetBuffersDimensions(args);
+        break;
+    case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
+        res = dispatchSetBuffersFormat(args);
+        break;
     default:
         res = NAME_NOT_FOUND;
         break;
@@ -290,7 +296,22 @@
     int w = va_arg(args, int);
     int h = va_arg(args, int);
     int f = va_arg(args, int);
-    return setBuffersGeometry(w, h, f);
+    int err = setBuffersDimensions(w, h);
+    if (err != 0) {
+        return err;
+    }
+    return setBuffersFormat(f);
+}
+
+int SurfaceTextureClient::dispatchSetBuffersDimensions(va_list args) {
+    int w = va_arg(args, int);
+    int h = va_arg(args, int);
+    return setBuffersDimensions(w, h);
+}
+
+int SurfaceTextureClient::dispatchSetBuffersFormat(va_list args) {
+    int f = va_arg(args, int);
+    return setBuffersFormat(f);
 }
 
 int SurfaceTextureClient::dispatchSetBuffersTransform(va_list args) {
@@ -390,12 +411,12 @@
     return err;
 }
 
-int SurfaceTextureClient::setBuffersGeometry(int w, int h, int format)
+int SurfaceTextureClient::setBuffersDimensions(int w, int h)
 {
-    LOGV("SurfaceTextureClient::setBuffersGeometry");
+    LOGV("SurfaceTextureClient::setBuffersDimensions");
     Mutex::Autolock lock(mMutex);
 
-    if (w<0 || h<0 || format<0)
+    if (w<0 || h<0)
         return BAD_VALUE;
 
     if ((w && !h) || (!w && h))
@@ -403,7 +424,6 @@
 
     mReqWidth = w;
     mReqHeight = h;
-    mReqFormat = format;
 
     status_t err = mSurfaceTexture->setCrop(Rect(0, 0));
     LOGE_IF(err, "ISurfaceTexture::setCrop(...) returned %s", strerror(-err));
@@ -411,6 +431,19 @@
     return err;
 }
 
+int SurfaceTextureClient::setBuffersFormat(int format)
+{
+    LOGV("SurfaceTextureClient::setBuffersFormat");
+    Mutex::Autolock lock(mMutex);
+
+    if (format<0)
+        return BAD_VALUE;
+
+    mReqFormat = format;
+
+    return NO_ERROR;
+}
+
 int SurfaceTextureClient::setBuffersTransform(int transform)
 {
     LOGV("SurfaceTextureClient::setBuffersTransform");
diff --git a/libs/ui/FramebufferNativeWindow.cpp b/libs/ui/FramebufferNativeWindow.cpp
index 4393504..9c10c75 100644
--- a/libs/ui/FramebufferNativeWindow.cpp
+++ b/libs/ui/FramebufferNativeWindow.cpp
@@ -299,6 +299,7 @@
 {
     switch (operation) {
         case NATIVE_WINDOW_SET_USAGE:
+        case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
         case NATIVE_WINDOW_CONNECT:
         case NATIVE_WINDOW_DISCONNECT:
             break;
diff --git a/media/libeffects/factory/EffectsFactory.c b/media/libeffects/factory/EffectsFactory.c
index a3e76d9..a9689bc 100644
--- a/media/libeffects/factory/EffectsFactory.c
+++ b/media/libeffects/factory/EffectsFactory.c
@@ -130,10 +130,43 @@
     return ret;
 }
 
+int Effect_ProcessReverse(effect_handle_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer)
+{
+    int ret = init();
+    if (ret < 0) {
+        return ret;
+    }
+    effect_entry_t *fx = (effect_entry_t *)self;
+    pthread_mutex_lock(&gLibLock);
+    if (fx->lib == NULL) {
+        pthread_mutex_unlock(&gLibLock);
+        return -EPIPE;
+    }
+    pthread_mutex_lock(&fx->lib->lock);
+    pthread_mutex_unlock(&gLibLock);
+
+    if ((*fx->subItfe)->process_reverse != NULL) {
+        ret = (*fx->subItfe)->process_reverse(fx->subItfe, inBuffer, outBuffer);
+    } else {
+        ret = -ENOSYS;
+    }
+    pthread_mutex_unlock(&fx->lib->lock);
+    return ret;
+}
+
+
 const struct effect_interface_s gInterface = {
         Effect_Process,
         Effect_Command,
-        Effect_GetDescriptor
+        Effect_GetDescriptor,
+        NULL
+};
+
+const struct effect_interface_s gInterfaceWithReverse = {
+        Effect_Process,
+        Effect_Command,
+        Effect_GetDescriptor,
+        Effect_ProcessReverse
 };
 
 /////////////////////////////////////////////////
@@ -266,7 +299,13 @@
     // add entry to effect list
     fx = (effect_entry_t *)malloc(sizeof(effect_entry_t));
     fx->subItfe = itfe;
-    fx->itfe = (struct effect_interface_s *)&gInterface;
+    if ((*itfe)->process_reverse != NULL) {
+        fx->itfe = (struct effect_interface_s *)&gInterfaceWithReverse;
+        LOGV("EffectCreate() gInterfaceWithReverse");
+    }   else {
+        fx->itfe = (struct effect_interface_s *)&gInterface;
+        LOGV("EffectCreate() gInterface");
+    }
     fx->lib = l;
 
     e = (list_elem_t *)malloc(sizeof(list_elem_t));
diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
index 21c451f..efa1c45 100644
--- a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
+++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
@@ -3231,7 +3231,8 @@
 const struct effect_interface_s gLvmEffectInterface = {
     Effect_process,
     Effect_command,
-    Effect_getDescriptor
+    Effect_getDescriptor,
+    NULL,
 };    /* end gLvmEffectInterface */
 
 audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
diff --git a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
index 2727375..663f8ff 100755
--- a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
+++ b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
@@ -2134,7 +2134,8 @@
 const struct effect_interface_s gReverbInterface = {
     Reverb_process,
     Reverb_command,
-    Reverb_getDescriptor
+    Reverb_getDescriptor,
+    NULL,
 };    /* end gReverbInterface */
 
 audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
diff --git a/media/libeffects/testlibs/EffectEqualizer.cpp b/media/libeffects/testlibs/EffectEqualizer.cpp
index c2ffce5..b22ebec 100644
--- a/media/libeffects/testlibs/EffectEqualizer.cpp
+++ b/media/libeffects/testlibs/EffectEqualizer.cpp
@@ -736,7 +736,8 @@
 const struct effect_interface_s gEqualizerInterface = {
         Equalizer_process,
         Equalizer_command,
-        Equalizer_getDescriptor
+        Equalizer_getDescriptor,
+        NULL
 };
 
 
diff --git a/media/libeffects/testlibs/EffectReverb.c b/media/libeffects/testlibs/EffectReverb.c
index 02762c9..405f908 100644
--- a/media/libeffects/testlibs/EffectReverb.c
+++ b/media/libeffects/testlibs/EffectReverb.c
@@ -27,7 +27,8 @@
 const struct effect_interface_s gReverbInterface = {
         Reverb_Process,
         Reverb_Command,
-        Reverb_GetDescriptor
+        Reverb_GetDescriptor,
+        NULL
 };
 
 // Google auxiliary environmental reverb UUID: 1f0ae2e0-4ef7-11df-bc09-0002a5d5c51b
diff --git a/media/libeffects/visualizer/EffectVisualizer.cpp b/media/libeffects/visualizer/EffectVisualizer.cpp
index aeebd4d..3c3af8f 100644
--- a/media/libeffects/visualizer/EffectVisualizer.cpp
+++ b/media/libeffects/visualizer/EffectVisualizer.cpp
@@ -450,7 +450,8 @@
 const struct effect_interface_s gVisualizerInterface = {
         Visualizer_process,
         Visualizer_command,
-        Visualizer_getDescriptor
+        Visualizer_getDescriptor,
+        NULL,
 };
 
 
diff --git a/opengl/libs/EGL/egl.cpp b/opengl/libs/EGL/egl.cpp
index b11db32..ddad2d3 100644
--- a/opengl/libs/EGL/egl.cpp
+++ b/opengl/libs/EGL/egl.cpp
@@ -31,6 +31,7 @@
 #include <cutils/properties.h>
 #include <cutils/memory.h>
 
+#include <utils/CallStack.h>
 #include <utils/String8.h>
 
 #include "egldefs.h"
@@ -147,6 +148,10 @@
     if (egl_tls_t::logNoContextCall()) {
         LOGE("call to OpenGL ES API with no current context "
              "(logged once per thread)");
+        LOGE("call stack before error:");
+        CallStack stack;
+        stack.update();
+        stack.dump();
     }
     return 0;
 }
diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp
index 7d5d010..ba5d29a 100644
--- a/opengl/libs/EGL/eglApi.cpp
+++ b/opengl/libs/EGL/eglApi.cpp
@@ -367,7 +367,12 @@
         if (cnx->egl.eglGetConfigAttrib(iDpy,
                 iConfig, EGL_NATIVE_VISUAL_ID, &format)) {
             if (format != 0) {
-                native_window_set_buffers_geometry(window, 0, 0, format);
+                int err = native_window_set_buffers_format(window, format);
+                if (err != 0) {
+                    LOGE("error setting native window pixel format: %s (%d)",
+                            strerror(-err), err);
+                    return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
+                }
             }
         }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
index 826ac92..dedbe5d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
@@ -785,7 +785,7 @@
             int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
             mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
         } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
-            int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
+            int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
                 BluetoothAdapter.STATE_DISCONNECTED);
             if (state == BluetoothAdapter.STATE_CONNECTED) {
                 iconId = R.drawable.stat_sys_data_bluetooth_connected;
diff --git a/services/java/com/android/server/usb/UsbDeviceManager.java b/services/java/com/android/server/usb/UsbDeviceManager.java
index 1ab570a..86b3d36 100644
--- a/services/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/java/com/android/server/usb/UsbDeviceManager.java
@@ -251,19 +251,18 @@
 
         public UsbHandler() {
             try {
+                // persist.sys.usb.config should never be unset.  But if it is, set it to "adb"
+                // so we have a chance of debugging what happened.
+                mDefaultFunctions = SystemProperties.get("persist.sys.usb.config", "adb");
                 // sanity check the sys.usb.config system property
                 // this may be necessary if we crashed while switching USB configurations
                 String config = SystemProperties.get("sys.usb.config", "none");
-                if (config.equals("none")) {
-                    String persistConfig = SystemProperties.get("persist.sys.usb.config", "none");
-                    Slog.w(TAG, "resetting config to persistent property: " + persistConfig);
-                    SystemProperties.set("sys.usb.config", persistConfig);
+                if (!config.equals(mDefaultFunctions)) {
+                    Slog.w(TAG, "resetting config to persistent property: " + mDefaultFunctions);
+                    SystemProperties.set("sys.usb.config", mDefaultFunctions);
                 }
 
-                // Read initial USB state
-                mCurrentFunctions = FileUtils.readTextFile(
-                        new File(FUNCTIONS_PATH), 0, null).trim();
-                mDefaultFunctions = mCurrentFunctions;
+                mCurrentFunctions = mDefaultFunctions;
                 String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim();
                 updateState(state);
                 mAdbEnabled = containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB);
@@ -621,6 +620,16 @@
             pw.println("    mConnected: " + mConnected);
             pw.println("    mConfigured: " + mConfigured);
             pw.println("    mCurrentAccessory: " + mCurrentAccessory);
+            try {
+                pw.println("    Kernel state: "
+                        + FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim());
+                pw.println("    Kernel function list: "
+                        + FileUtils.readTextFile(new File(FUNCTIONS_PATH), 0, null).trim());
+                pw.println("    Mass storage backing file: "
+                        + FileUtils.readTextFile(new File(MASS_STORAGE_FILE_PATH), 0, null).trim());
+            } catch (IOException e) {
+                pw.println("IOException: " + e);
+            }
         }
     }