Merge "Sharpening text edit assets"
diff --git a/api/current.txt b/api/current.txt
index ffa46ec..b30f7a6 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -26782,6 +26782,7 @@
     method public void setChar(int, java.lang.String, char);
     method public void setCharSequence(int, java.lang.String, java.lang.CharSequence);
     method public void setChronometer(int, long, java.lang.String, boolean);
+    method public void setContentDescription(int, java.lang.CharSequence);
     method public void setDisplayedChild(int, int);
     method public void setDouble(int, java.lang.String, double);
     method public void setEmptyView(int, int);
diff --git a/core/java/android/app/StatusBarManager.java b/core/java/android/app/StatusBarManager.java
index 7863102..5b8addf 100644
--- a/core/java/android/app/StatusBarManager.java
+++ b/core/java/android/app/StatusBarManager.java
@@ -22,6 +22,7 @@
 import android.os.RemoteException;
 import android.os.IBinder;
 import android.os.ServiceManager;
+import android.util.Slog;
 import android.view.View;
 
 import com.android.internal.statusbar.IStatusBarService;
@@ -61,8 +62,17 @@
 
     StatusBarManager(Context context) {
         mContext = context;
-        mService = IStatusBarService.Stub.asInterface(
-                ServiceManager.getService(Context.STATUS_BAR_SERVICE));
+    }
+
+    private synchronized IStatusBarService getService() {
+        if (mService == null) {
+            mService = IStatusBarService.Stub.asInterface(
+                    ServiceManager.getService(Context.STATUS_BAR_SERVICE));
+            if (mService == null) {
+                Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
+            }
+        }
+        return mService;
     }
 
     /**
@@ -71,8 +81,9 @@
      */
     public void disable(int what) {
         try {
-            if (mService != null) {
-                mService.disable(what, mToken, mContext.getPackageName());
+            final IStatusBarService svc = getService();
+            if (svc != null) {
+                svc.disable(what, mToken, mContext.getPackageName());
             }
         } catch (RemoteException ex) {
             // system process is dead anyway.
@@ -85,7 +96,10 @@
      */
     public void expand() {
         try {
-            mService.expand();
+            final IStatusBarService svc = getService();
+            if (svc != null) {
+                svc.expand();
+            }
         } catch (RemoteException ex) {
             // system process is dead anyway.
             throw new RuntimeException(ex);
@@ -97,7 +111,10 @@
      */
     public void collapse() {
         try {
-            mService.collapse();
+            final IStatusBarService svc = getService();
+            if (svc != null) {
+                svc.collapse();
+            }
         } catch (RemoteException ex) {
             // system process is dead anyway.
             throw new RuntimeException(ex);
@@ -106,8 +123,11 @@
 
     public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
         try {
-            mService.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
+            final IStatusBarService svc = getService();
+            if (svc != null) {
+                svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
                     contentDescription);
+            }
         } catch (RemoteException ex) {
             // system process is dead anyway.
             throw new RuntimeException(ex);
@@ -116,7 +136,10 @@
 
     public void removeIcon(String slot) {
         try {
-            mService.removeIcon(slot);
+            final IStatusBarService svc = getService();
+            if (svc != null) {
+                svc.removeIcon(slot);
+            }
         } catch (RemoteException ex) {
             // system process is dead anyway.
             throw new RuntimeException(ex);
@@ -125,7 +148,10 @@
 
     public void setIconVisibility(String slot, boolean visible) {
         try {
-            mService.setIconVisibility(slot, visible);
+            final IStatusBarService svc = getService();
+            if (svc != null) {
+                svc.setIconVisibility(slot, visible);
+            }
         } catch (RemoteException ex) {
             // system process is dead anyway.
             throw new RuntimeException(ex);
diff --git a/core/java/android/database/sqlite/package.html b/core/java/android/database/sqlite/package.html
index ff0f9f5..ceed171 100644
--- a/core/java/android/database/sqlite/package.html
+++ b/core/java/android/database/sqlite/package.html
@@ -3,7 +3,7 @@
 Contains the SQLite database management
 classes that an application would use to manage its own private database.
 <p>
-Applications use these classes to maange private databases. If creating a
+Applications use these classes to manage private databases. If creating a
 content provider, you will probably have to use these classes to create and
 manage your own database to store content. See <a
 href="{@docRoot}guide/topics/providers/content-providers.html">Content Providers</a> to learn
diff --git a/core/java/android/os/CountDownTimer.java b/core/java/android/os/CountDownTimer.java
index 0c5c615..15e6405 100644
--- a/core/java/android/os/CountDownTimer.java
+++ b/core/java/android/os/CountDownTimer.java
@@ -25,7 +25,7 @@
  * Example of showing a 30 second countdown in a text field:
  *
  * <pre class="prettyprint">
- * new CountdownTimer(30000, 1000) {
+ * new CountDownTimer(30000, 1000) {
  *
  *     public void onTick(long millisUntilFinished) {
  *         mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
diff --git a/core/java/android/provider/CalendarContract.java b/core/java/android/provider/CalendarContract.java
index ded496c..b14ca2b0 100644
--- a/core/java/android/provider/CalendarContract.java
+++ b/core/java/android/provider/CalendarContract.java
@@ -304,7 +304,8 @@
          * or an empty string are reserved for indicating that the calendar does
          * not use an index for looking up the color. The provider will update
          * {@link #CALENDAR_COLOR} automatically when a valid index is written
-         * to this column. @see Colors
+         * to this column. The index must reference an existing row of the
+         * {@link Colors} table. @see Colors
          * <P>
          * Type: TEXT
          * </P>
@@ -852,8 +853,11 @@
          * string are reserved for indicating that the event does not use an
          * index for looking up the color. The provider will update
          * {@link #EVENT_COLOR} automatically when a valid index is written to
-         * this column. @see Colors
-         * <P>Type: TEXT</P>
+         * this column. The index must reference an existing row of the
+         * {@link Colors} table. @see Colors
+         * <P>
+         * Type: TEXT
+         * </P>
          * TODO UNHIDE
          *
          * @hide
@@ -2329,7 +2333,7 @@
         /**
          * The index used to reference this color. This can be any non-empty
          * string, but must be unique for a given {@link #ACCOUNT_TYPE} and
-         * {@link #ACCOUNT_NAME} . Column name.
+         * {@link #ACCOUNT_NAME}. Column name.
          * <P>
          * Type: TEXT
          * </P>
@@ -2353,8 +2357,10 @@
     /**
      * Fields for accessing colors available for a given account. Colors are
      * referenced by {@link #COLOR_INDEX} which must be unique for a given
-     * account name/type. These values should only be updated by the sync
-     * adapter.
+     * account name/type. These values can only be updated by the sync
+     * adapter. Only {@link #COLOR} may be updated after the initial insert. In
+     * addition, a row can only be deleted once all references to that color
+     * have been removed from the {@link Calendars} or {@link Events} tables.
      * TODO UNHIDE
      *
      * @hide
diff --git a/core/java/android/text/DynamicLayout.java b/core/java/android/text/DynamicLayout.java
index f82c9c4..026af34 100644
--- a/core/java/android/text/DynamicLayout.java
+++ b/core/java/android/text/DynamicLayout.java
@@ -281,9 +281,9 @@
         }
 
         reflowed.generate(text, where, where + after,
-                getPaint(), getWidth(), getAlignment(), getTextDirectionHeuristic(),
-                getSpacingMultiplier(), getSpacingAdd(),
-                false, true, mEllipsizedWidth, mEllipsizeAt);
+                getPaint(), getWidth(), getTextDirectionHeuristic(), getSpacingMultiplier(),
+                getSpacingAdd(), false,
+                true, mEllipsizedWidth, mEllipsizeAt);
         int n = reflowed.getLineCount();
 
         // If the new layout has a blank line at the end, but it is not
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index 583cbe6..1dd4c8a 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -137,9 +137,9 @@
 
         mMeasured = MeasuredText.obtain();
 
-        generate(source, bufstart, bufend, paint, outerwidth, align, textDir,
-                 spacingmult, spacingadd, includepad, includepad,
-                 ellipsizedWidth, ellipsize);
+        generate(source, bufstart, bufend, paint, outerwidth, textDir, spacingmult,
+                 spacingadd, includepad, includepad, ellipsizedWidth,
+                 ellipsize);
 
         mMeasured = MeasuredText.recycle(mMeasured);
         mFontMetricsInt = null;
@@ -157,10 +157,10 @@
 
     /* package */ void generate(CharSequence source, int bufStart, int bufEnd,
                         TextPaint paint, int outerWidth,
-                        Alignment align, TextDirectionHeuristic textDir,
-                        float spacingmult, float spacingadd,
-                        boolean includepad, boolean trackpad,
-                        float ellipsizedWidth, TextUtils.TruncateAt ellipsize) {
+                        TextDirectionHeuristic textDir, float spacingmult,
+                        float spacingadd, boolean includepad,
+                        boolean trackpad, float ellipsizedWidth,
+                        TextUtils.TruncateAt ellipsize) {
         mLineCount = 0;
 
         int v = 0;
@@ -328,9 +328,7 @@
                                     whichPaint = mWorkPaint;
                                 }
 
-                                float wid = bm.getWidth() *
-                                            -whichPaint.ascent() /
-                                            bm.getHeight();
+                                float wid = bm.getWidth() * -whichPaint.ascent() / bm.getHeight();
 
                                 w += wid;
                                 hasTabOrEmoji = true;
@@ -398,67 +396,49 @@
                                 okBottom = fitBottom;
                         }
                     } else {
-                            final boolean moreChars = (j + 1 < spanEnd);
-                            if (ok != here) {
-                                // Log.e("text", "output ok " + here + " to " +ok);
+                        final boolean moreChars = (j + 1 < spanEnd);
+                        int endPos;
+                        int above, below, top, bottom;
+                        float currentTextWidth;
 
-                                while (ok < spanEnd && chs[ok - paraStart] == CHAR_SPACE) {
-                                    ok++;
-                                }
+                        if (ok != here) {
+                            // If it is a space that makes the length exceed width, cut here
+                            if (c == CHAR_SPACE) ok = j + 1;
 
-                                v = out(source,
-                                        here, ok,
-                                        okAscent, okDescent, okTop, okBottom,
-                                        v,
-                                        spacingmult, spacingadd, chooseHt,
-                                        chooseHtv, fm, hasTabOrEmoji,
-                                        needMultiply, paraStart, chdirs, dir, easy,
-                                        ok == bufEnd, includepad, trackpad,
-                                        chs, widths, paraStart,
-                                        ellipsize, ellipsizedWidth, okWidth,
-                                        paint, moreChars);
-
-                                here = ok;
-                            } else if (fit != here) {
-                                // Log.e("text", "output fit " + here + " to " +fit);
-                                v = out(source,
-                                        here, fit,
-                                        fitAscent, fitDescent,
-                                        fitTop, fitBottom,
-                                        v,
-                                        spacingmult, spacingadd, chooseHt,
-                                        chooseHtv, fm, hasTabOrEmoji,
-                                        needMultiply, paraStart, chdirs, dir, easy,
-                                        fit == bufEnd, includepad, trackpad,
-                                        chs, widths, paraStart,
-                                        ellipsize, ellipsizedWidth, fitWidth,
-                                        paint, moreChars);
-
-                                here = fit;
-                            } else {
-                                // Log.e("text", "output one " + here + " to " +(here + 1));
-                                // XXX not sure why the existing fm wasn't ok.
-                                // measureText(paint, mWorkPaint,
-                                //             source, here, here + 1, fm, tab,
-                                //             null);
-
-                                v = out(source,
-                                        here, here+1,
-                                        fm.ascent, fm.descent,
-                                        fm.top, fm.bottom,
-                                        v,
-                                        spacingmult, spacingadd, chooseHt,
-                                        chooseHtv, fm, hasTabOrEmoji,
-                                        needMultiply, paraStart, chdirs, dir, easy,
-                                        here + 1 == bufEnd, includepad,
-                                        trackpad,
-                                        chs, widths, paraStart,
-                                        ellipsize, ellipsizedWidth,
-                                        widths[here - paraStart], paint, moreChars);
-
-                                here = here + 1;
+                            while (ok < spanEnd && chs[ok - paraStart] == CHAR_SPACE) {
+                                ok++;
                             }
 
+                            endPos = ok;
+                            above = okAscent;
+                            below = okDescent;
+                            top = okTop;
+                            bottom = okBottom;
+                            currentTextWidth = okWidth;
+                        } else if (fit != here) {
+                            endPos = fit;
+                            above = fitAscent;
+                            below = fitDescent;
+                            top = fitTop;
+                            bottom = fitBottom;
+                            currentTextWidth = fitWidth;
+                        } else {
+                            endPos = here + 1;
+                            above = fm.ascent;
+                            below = fm.descent;
+                            top = fm.top;
+                            bottom = fm.bottom;
+                            currentTextWidth = widths[here - paraStart];
+                        }
+
+                        v = out(source, here, endPos,
+                                above, below, top, bottom,
+                                v, spacingmult, spacingadd, chooseHt,chooseHtv, fm, hasTabOrEmoji,
+                                needMultiply, chdirs, dir, easy, bufEnd, includepad, trackpad,
+                                chs, widths, paraStart, ellipsize, ellipsizedWidth,
+                                currentTextWidth, paint, moreChars);
+                        here = endPos;
+
                         if (here < spanStart) {
                             // didn't output all the text for this span
                             // we've measured the raw widths, though, so
@@ -501,10 +481,10 @@
                         v,
                         spacingmult, spacingadd, chooseHt,
                         chooseHtv, fm, hasTabOrEmoji,
-                        needMultiply, paraStart, chdirs, dir, easy,
-                        paraEnd == bufEnd, includepad, trackpad,
-                        chs, widths, paraStart,
-                        ellipsize, ellipsizedWidth, w, paint, paraEnd != bufEnd);
+                        needMultiply, chdirs, dir, easy, bufEnd,
+                        includepad, trackpad, chs,
+                        widths, paraStart, ellipsize,
+                        ellipsizedWidth, w, paint, paraEnd != bufEnd);
             }
 
             paraStart = paraEnd;
@@ -525,10 +505,10 @@
                     v,
                     spacingmult, spacingadd, null,
                     null, fm, false,
-                    needMultiply, bufEnd, null, DEFAULT_DIR, true,
-                    true, includepad, trackpad,
-                    null, null, bufStart,
-                    ellipsize, ellipsizedWidth, 0, paint, false);
+                    needMultiply, null, DEFAULT_DIR, true, bufEnd,
+                    includepad, trackpad, null,
+                    null, bufStart, ellipsize,
+                    ellipsizedWidth, 0, paint, false);
         }
     }
 
@@ -628,12 +608,12 @@
                       float spacingmult, float spacingadd,
                       LineHeightSpan[] chooseHt, int[] chooseHtv,
                       Paint.FontMetricsInt fm, boolean hasTabOrEmoji,
-                      boolean needMultiply, int pstart, byte[] chdirs,
-                      int dir, boolean easy, boolean last,
-                      boolean includePad, boolean trackPad,
-                      char[] chs, float[] widths, int widthStart,
-                      TextUtils.TruncateAt ellipsize, float ellipsisWidth,
-                      float textWidth, TextPaint paint, boolean moreChars) {
+                      boolean needMultiply, byte[] chdirs, int dir,
+                      boolean easy, int bufEnd, boolean includePad,
+                      boolean trackPad, char[] chs,
+                      float[] widths, int widthStart, TextUtils.TruncateAt ellipsize,
+                      float ellipsisWidth, float textWidth,
+                      TextPaint paint, boolean moreChars) {
         int j = mLineCount;
         int off = j * mColumns;
         int want = off + mColumns + TOP;
@@ -683,7 +663,7 @@
                 above = top;
             }
         }
-        if (last) {
+        if (end == bufEnd) {
             if (trackPad) {
                 mBottomPadding = bottom - below;
             }
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index a2f9b36..fea79d5 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -4219,6 +4219,7 @@
      *
      * @attr ref android.R.styleable#View_contentDescription
      */
+    @RemotableViewMethod
     public void setContentDescription(CharSequence contentDescription) {
         mContentDescription = contentDescription;
     }
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index abb5bc8..a36aecb 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -287,7 +287,7 @@
 
     final AccessibilityManager mAccessibilityManager;
 
-    AccessibilityInteractionController mAccessibilityInteractionContrtoller;
+    AccessibilityInteractionController mAccessibilityInteractionController;
 
     AccessibilityInteractionConnectionManager mAccessibilityInteractionConnectionManager;
 
@@ -3526,10 +3526,10 @@
             throw new IllegalStateException("getAccessibilityInteractionController"
                     + " called when there is no mView");
         }
-        if (mAccessibilityInteractionContrtoller == null) {
-            mAccessibilityInteractionContrtoller = new AccessibilityInteractionController();
+        if (mAccessibilityInteractionController == null) {
+            mAccessibilityInteractionController = new AccessibilityInteractionController();
         }
-        return mAccessibilityInteractionContrtoller;
+        return mAccessibilityInteractionController;
     }
 
     private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility,
diff --git a/core/java/android/webkit/JniUtil.java b/core/java/android/webkit/JniUtil.java
index 7759ff3..4662040 100644
--- a/core/java/android/webkit/JniUtil.java
+++ b/core/java/android/webkit/JniUtil.java
@@ -22,6 +22,7 @@
 import android.provider.Settings;
 import android.util.Log;
 
+import java.io.File;
 import java.io.InputStream;
 
 class JniUtil {
@@ -79,7 +80,12 @@
         checkInitialized();
 
         if (sCacheDirectory == null) {
-            sCacheDirectory = sContext.getCacheDir().getAbsolutePath();
+            File cacheDir = sContext.getCacheDir();
+            if (cacheDir == null) {
+                sCacheDirectory = "";
+            } else {
+                sCacheDirectory = cacheDir.getAbsolutePath();
+            }
         }
 
         return sCacheDirectory;
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java
index f1c2bde..f240a2e 100644
--- a/core/java/android/webkit/WebSettings.java
+++ b/core/java/android/webkit/WebSettings.java
@@ -777,7 +777,7 @@
     public void setDoubleTapZoom(int doubleTapZoom) {
         if (mDoubleTapZoom != doubleTapZoom) {
             mDoubleTapZoom = doubleTapZoom;
-            mWebView.updateDoubleTapZoom();
+            mWebView.updateDoubleTapZoom(doubleTapZoom);
         }
     }
 
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index b0ecf09..ccacd09 100644
--- a/core/java/android/webkit/WebTextView.java
+++ b/core/java/android/webkit/WebTextView.java
@@ -607,23 +607,31 @@
         // character or the existing selection, so it will not get cleared
         // above.
         mGotDelete = false;
+        // Prefer sending javascript events, so when adding one character,
+        // don't replace the unchanged text.
+        if (count > 1 && before == count - 1) {
+            String replaceButOne =  s.subSequence(start,
+                    start + before).toString();
+            String replacedString = getText().subSequence(start,
+                    start + before).toString();
+            if (replaceButOne.equals(replacedString)) {
+                // we're just adding one character
+                start += before;
+                before = 0;
+                count = 1;
+            }
+        }
         // Find the last character being replaced.  If it can be represented by
-        // events, we will pass them to native (after replacing the beginning
-        // of the changed text), so we can see javascript events.
-        // Otherwise, replace the text being changed (including the last
-        // character) in the textfield.
-        TextUtils.getChars(s, start + count - 1, start + count, mCharacter, 0);
-        KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
-        KeyEvent[] events = kmap.getEvents(mCharacter);
-        boolean cannotUseKeyEvents = null == events;
-        int charactersFromKeyEvents = cannotUseKeyEvents ? 0 : 1;
-        if (count > 1 || cannotUseKeyEvents) {
-            String replace = s.subSequence(start,
-                    start + count - charactersFromKeyEvents).toString();
-            mWebView.replaceTextfieldText(start, start + before, replace,
-                    start + count - charactersFromKeyEvents,
-                    start + count - charactersFromKeyEvents);
-        } else {
+        // events, we will pass them to native so we can see javascript events.
+        // Otherwise, replace the text being changed in the textfield.
+        KeyEvent[] events = null;
+        if (count == 1) {
+            TextUtils.getChars(s, start + count - 1, start + count, mCharacter, 0);
+            KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
+            events = kmap.getEvents(mCharacter);
+        }
+        boolean useKeyEvents = (events != null);
+        if (useKeyEvents) {
             // This corrects the selection which may have been affected by the
             // trackball or auto-correct.
             if (DebugFlags.WEB_TEXT_VIEW) {
@@ -633,8 +641,6 @@
             if (!mInSetTextAndKeepSelection) {
                 mWebView.setSelection(start, start + before);
             }
-        }
-        if (!cannotUseKeyEvents) {
             int length = events.length;
             for (int i = 0; i < length; i++) {
                 // We never send modifier keys to native code so don't send them
@@ -643,6 +649,12 @@
                     sendDomEvent(events[i]);
                 }
             }
+        } else {
+            String replace = s.subSequence(start,
+                    start + count).toString();
+            mWebView.replaceTextfieldText(start, start + before, replace,
+                    start + count,
+                    start + count);
         }
         updateCachedTextfield();
     }
@@ -966,8 +978,11 @@
      * @param   text    The new text to place in the textfield.
      */
     /* package */ void setTextAndKeepSelection(String text) {
-        mPreChange = text.toString();
         Editable edit = getText();
+        mPreChange = text;
+        if (edit.toString().equals(text)) {
+            return;
+        }
         int selStart = Selection.getSelectionStart(edit);
         int selEnd = Selection.getSelectionEnd(edit);
         mInSetTextAndKeepSelection = true;
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 71ba7eb..a814b12 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -2995,8 +2995,8 @@
     /**
      * Update the double-tap zoom.
      */
-    /* package */ void updateDoubleTapZoom() {
-        mZoomManager.updateDoubleTapZoom();
+    /* package */ void updateDoubleTapZoom(int doubleTapZoom) {
+        mZoomManager.updateDoubleTapZoom(doubleTapZoom);
     }
 
     private int computeRealHorizontalScrollRange() {
diff --git a/core/java/android/webkit/ZoomManager.java b/core/java/android/webkit/ZoomManager.java
index 9151fdd..7d3cf8e 100644
--- a/core/java/android/webkit/ZoomManager.java
+++ b/core/java/android/webkit/ZoomManager.java
@@ -152,6 +152,12 @@
     private float mDisplayDensity;
 
     /*
+     * The factor that is used to tweak the zoom scale on a double-tap,
+     * and can be changed via WebSettings. Range is from 0.75f to 1.25f.
+     */
+    private float mDoubleTapZoomFactor = 1.0f;
+
+    /*
      * The scale factor that is used as the minimum increment when going from
      * overview to reading level on a double tap.
      */
@@ -314,10 +320,7 @@
      * Returns the zoom scale used for reading text on a double-tap.
      */
     public final float getReadingLevelScale() {
-        WebSettings settings = mWebView.getSettings();
-        final float doubleTapZoomFactor = settings != null
-            ? settings.getDoubleTapZoom() / 100.f : 1.0f;
-        return mDisplayDensity * doubleTapZoomFactor;
+        return mDisplayDensity * mDoubleTapZoomFactor;
     }
 
     public final float getInvDefaultScale() {
@@ -516,8 +519,9 @@
         return mZoomScale != 0 || mInHWAcceleratedZoom;
     }
 
-    public void updateDoubleTapZoom() {
+    public void updateDoubleTapZoom(int doubleTapZoom) {
         if (mInZoomOverview) {
+            mDoubleTapZoomFactor = doubleTapZoom / 100.0f;
             mTextWrapScale = getReadingLevelScale();
             refreshZoomScale(true);
         }
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index 9cf2718..1592061 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -1546,6 +1546,16 @@
     }
 
     /**
+     * Equivalent to calling View.setContentDescription
+     *
+     * @param viewId The id of the view whose content description should change
+     * @param contentDescription The new content description for the view
+     */
+    public void setContentDescription(int viewId, CharSequence contentDescription) {
+        setCharSequence(viewId, "setContentDescription", contentDescription);
+    }
+
+    /**
      * Inflates the view hierarchy represented by this object and applies
      * all of the actions.
      * 
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 55e49ea..5a300e8 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -359,7 +359,7 @@
 
     private SpellChecker mSpellChecker;
 
-    private boolean mShowSoftInputOnFocus = true;
+    private boolean mSoftInputShownOnFocus = true;
 
     // The alignment to pass to Layout, or null if not resolved.
     private Layout.Alignment mLayoutAlignment;
@@ -2381,23 +2381,23 @@
      * Sets whether the soft input method will be made visible when this
      * TextView gets focused. The default is true.
      *
-     * @attr ref android.R.styleable#TextView_showSoftInputOnFocus
+     * @attr ref android.R.styleable#TextView_softInputShownOnFocus
      * @hide
      */
     @android.view.RemotableViewMethod
-    public final void setShowSoftInputOnFocus(boolean show) {
-        mShowSoftInputOnFocus = show;
+    public final void setSoftInputShownOnFocus(boolean show) {
+        mSoftInputShownOnFocus = show;
     }
 
     /**
      * Returns whether the soft input method will be made visible when this
      * TextView gets focused. The default is true.
      *
-     * @attr ref android.R.styleable#TextView_showSoftInputOnFocus
+     * @attr ref android.R.styleable#TextView_softInputShownOnFocus
      * @hide
      */
-    public final boolean getShowSoftInputOnFocus() {
-        return mShowSoftInputOnFocus;
+    public final boolean getSoftInputShownOnFocus() {
+        return mSoftInputShownOnFocus;
     }
 
     /**
@@ -5502,7 +5502,7 @@
                                 && mLayout != null && onCheckIsTextEditor()) {
                             InputMethodManager imm = InputMethodManager.peekInstance();
                             viewClicked(imm);
-                            if (imm != null && mShowSoftInputOnFocus) {
+                            if (imm != null && mSoftInputShownOnFocus) {
                                 imm.showSoftInput(this, 0);
                             }
                         }
@@ -8344,7 +8344,7 @@
                 // Show the IME, except when selecting in read-only text.
                 final InputMethodManager imm = InputMethodManager.peekInstance();
                 viewClicked(imm);
-                if (!mTextIsSelectable && mShowSoftInputOnFocus) {
+                if (!mTextIsSelectable && mSoftInputShownOnFocus) {
                     handled |= imm != null && imm.showSoftInput(this, 0);
                 }
 
@@ -10202,7 +10202,7 @@
         final boolean selectionStarted = mSelectionActionMode != null ||
                 extractedTextModeWillBeStartedFullScreen;
 
-        if (selectionStarted && !mTextIsSelectable && imm != null && mShowSoftInputOnFocus) {
+        if (selectionStarted && !mTextIsSelectable && imm != null && mSoftInputShownOnFocus) {
             // Show the IME to be able to replace text, except when selecting non editable text.
             imm.showSoftInput(this, 0, null);
         }
diff --git a/core/java/com/android/internal/widget/ActionBarContextView.java b/core/java/com/android/internal/widget/ActionBarContextView.java
index 446dab1..18d45f7 100644
--- a/core/java/com/android/internal/widget/ActionBarContextView.java
+++ b/core/java/com/android/internal/widget/ActionBarContextView.java
@@ -94,6 +94,15 @@
     }
 
     @Override
+    public void onDetachedFromWindow() {
+        super.onDetachedFromWindow();
+        if (mActionMenuPresenter != null) {
+            mActionMenuPresenter.hideOverflowMenu();
+            mActionMenuPresenter.hideSubMenus();
+        }
+    }
+
+    @Override
     public void setSplitActionBar(boolean split) {
         if (mSplitActionBar != split) {
             if (mActionMenuPresenter != null) {
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index 61bce60..e131242 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -285,6 +285,10 @@
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
         removeCallbacks(mTabSelector);
+        if (mActionMenuPresenter != null) {
+            mActionMenuPresenter.hideOverflowMenu();
+            mActionMenuPresenter.hideSubMenus();
+        }
     }
 
     @Override
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp
index 0b53850..c207150 100644
--- a/core/jni/android/graphics/TextLayoutCache.cpp
+++ b/core/jni/android/graphics/TextLayoutCache.cpp
@@ -534,7 +534,7 @@
 #if DEBUG_GLYPHS
     LOGD("HARFBUZZ -- num_glypth=%d - kerning_applied=%d", shaperItem.num_glyphs,
             shaperItem.kerning_applied);
-    LOGD("         -- string= '%s'", String8(chars + start, count).string());
+    LOGD("         -- string= '%s'", String8(shaperItem.string + start, count).string());
     LOGD("         -- isDevKernText=%d", paint->isDevKernText());
 
     logGlyphs(shaperItem);
diff --git a/docs/html/guide/topics/resources/drawable-resource.jd b/docs/html/guide/topics/resources/drawable-resource.jd
index ed9f990..fdf6c5a 100644
--- a/docs/html/guide/topics/resources/drawable-resource.jd
+++ b/docs/html/guide/topics/resources/drawable-resource.jd
@@ -1458,7 +1458,7 @@
         android:gradientRadius="<em>integer</em>"
         android:startColor="<em>color</em>"
         android:type=["linear" | "radial" | "sweep"]
-        android:usesLevel=["true" | "false"] /&gt;
+        android:useLevel=["true" | "false"] /&gt;
     &lt;<a href="#padding-element">padding</a>
         android:left="<em>integer</em>"
         android:top="<em>integer</em>"
diff --git a/docs/html/sdk/android-4.0-highlights.jd b/docs/html/sdk/android-4.0-highlights.jd
index 467159b..d6a2dcd 100644
--- a/docs/html/sdk/android-4.0-highlights.jd
+++ b/docs/html/sdk/android-4.0-highlights.jd
@@ -14,7 +14,8 @@
 }
 #jd-content div.video {
   float:right;
-  margin-top:-15px;
+  padding:0 0 40px 60px;
+  margin-top:-30px;
 }
 #jd-content table.columns {
   margin:0 0 1em 0;
@@ -37,16 +38,20 @@
 }
 </style>
 
-<div class="video" style="margin:1.5em 0 1.5em 1.5em">
+<div class="video">
 <iframe width="380" height="223" src="http://www.youtube.com/embed/-F_ke3rxopc?hd=1" frameborder="0"
 allowfullscreen></iframe>
 </div>
 
 <p>Welcome to Android 4.0!</p>
 
-<p>Android 4.0 delivers a refined, unified UI for phones and tablets and introduces innovative features for users and developers. This document provides a glimpse of the many new features and technologies that make Android 4.0 simple, beautiful, and beyond smart. <!--For technical details about
+<p>Android 4.0 delivers a refined, unified UI for phones and tablets and
+introduces innovative features for users and developers. This document provides
+a glimpse of the many new features and technologies that make Android 4.0
+simple, beautiful, and beyond smart. <!--For technical details about
 new developer APIs described below, see the <a
-href="{@docRoot}sdk/android-4.0.html">Android 4.0 API Overview</a> document.--></p>
+href="{@docRoot}sdk/android-4.0.html">Android 4.0 API Overview</a>
+document.--></p>
 
 <ul>
   <li><a href="#UserFeatures">Android 4.0 for Users</a></li>
@@ -126,10 +131,10 @@
 <p style="margin-top:1em;margin-bottom:.75em;"><strong>Home screen folders and
 favorites tray</strong></p>
 
-<p>New <strong>home screen folders</strong> offer a new way for users to group
-their apps and shortcuts logically, just by dragging one onto another. From the
-All Apps launcher, users can now simply drag an app to get information about it
-or immediately uninstall it, or disable a pre-installed app.</p>
+<p>New home screen <strong>folders</strong> offer a new way for users to group
+their apps and shortcuts logically, just by dragging one onto another. Also, 
+in All Apps launcher, users can now simply <strong>drag an app</strong> to get
+information about it or immediately uninstall it, or disable a pre-installed app.</p>
 
 <p>On smaller-screen devices, the home screen now includes a customizable
 <strong>favorites tray</strong> visible from all home screens. Users can drag
@@ -192,17 +197,17 @@
 <p>The soft keyboard in Android 4.0 makes text input even faster and more
 accurate. Error correction and word suggestion are improved through a new set of
 default dictionaries and more accurate heuristics for handling cases such as
-double-typed characters, skipped letters, and omitted spaces. Word suggestion is
-also improved and the suggestion strip is simplified to show only three words at
-a time.</p>
+double-typed characters, skipped letters, and omitted spaces. Word suggestion
+is also improved and the suggestion strip is simplified to show only three
+words at a time.</p>
 
-<p>To fix misspelled words more easily, Android 4.0 adds a spell-checker that
-locates and underlines errors and suggests replacement words. With one tap,
-users can choose from multiple spelling suggestions, delete a word, or add it to
-the dictionary. Users can even tap to see replacement suggestions for words that
-are spelled correctly. For specialized features or additional languages, users
-can now download and install third-party dictionaries, spell-checkers, and other
-text services.</p>
+<p>To fix misspelled words more easily, Android 4.0 adds a
+<strong>spell-checker</strong> that locates and underlines errors and suggests
+replacement words. With one tap, users can choose from multiple spelling
+suggestions, delete a word, or add it to the dictionary. Users can even tap to
+see replacement suggestions for words that are spelled correctly. For
+specialized features or additional languages, users can now download and install
+third-party dictionaries, spell-checkers, and other text services.</p>
 
 
 <p style="margin-top:1em;margin-bottom:.75em;"><strong>Powerful voice input
@@ -211,7 +216,7 @@
 <p>Android 4.0 introduces a powerful new voice input engine that offers a
 continuous "open microphone" experience and streaming voice recognition. The new
 voice input engine lets users dictate the text they want, for as long as they
-want, using the language they want. Users can speak continously for a prolonged
+want, using the language they want. Users can <strong>speak continously</strong> for a prolonged
 time, even pausing for intervals if needed, and dictate punctuation to create
 correct sentences. As the voice input engine enters text, it underlines possible
 dictation errors in gray. After dictating, users can tap the underlined words to
@@ -399,14 +404,14 @@
 <p style="margin-top:1em;margin-bottom:.75em;"><strong>Live Effects for transforming video</strong></p>
 
 <p>Live Effects is a collection of graphical transformations that add interest
-and fun to videos captured in the Camera app. For example, users can change the
-background behind them to any stock or custom image, for just the right setting
-when shooting video or using Google Talk video chat. Also available is Silly
-Faces, a set of morphing effects that use state-of-the-art face recognition and
-GPU filters to add great effects to facial features during video capture. For
-example, you can use effects such as small eyes, big mouth, big nose, face
-squeeze, and more. Outside of the Camera app, Live Effects is available during
-video chat in the Google Talk app.</p>
+and fun to videos captured in the Camera app. For example, users can
+<strong>change the background</strong> behind them to any stock or custom image,
+for just the right setting when shooting videeo. Also available for video is
+Silly Faces, a set of morphing effects that use state-of-the-art face
+recognition and GPU filters to transform facial features. For example, you can
+use effects such as small eyes, big mouth, big nose, face squeeze, and more.
+Outside of the Camera app, Live Effects is available during video chat in the
+Google Talk app.</p>
 
 <div  style="padding-top:0em;">
 <div style="margsin-right:.8em;float:left;width:186px;padding-top:1em;">
@@ -540,11 +545,12 @@
 <p style="margin-top:1em;margin-bottom:.75em;"><strong>Face Unlock</strong></p>
 
 <p>Android 4.0 introduces a completely new approach to securing a device, making
-it even more personal &mdash; Face Unlock is a new screen-lock option that lets
-users unlock their devices with their faces. It takes advantage of
-state-of-the-art facial recognition technology to register a face and to
-recognize it later when unlocking the device. Users just hold their devices in
-front of their faces to unlock, or use a backup PIN or pattern. </p>
+each person's device even more personal &mdash; Face Unlock is a new screen-lock
+option that lets users unlock their devices with their faces. It takes advantage
+of the device front-facing camera and state-of-the-art facial recognition
+technology to register a face during setup and then to recognize it again when
+unlocking the device. Users just hold their devices in front of their faces to
+unlock, or use a backup PIN or pattern. </p>
 
 
 <p style="margin-top:1em;margin-bottom:.75em;"><strong>Wi-Fi Direct and Bluetooth HDP</strong></p>
diff --git a/docs/html/sdk/eclipse-adt.jd b/docs/html/sdk/eclipse-adt.jd
index 59675a8..6a99d35 100644
--- a/docs/html/sdk/eclipse-adt.jd
+++ b/docs/html/sdk/eclipse-adt.jd
@@ -67,7 +67,7 @@
 the ADT Plugin, as denoted by revision number. </p>
 
 <p>For a summary of all known issues in ADT, see <a
-href="http://tools.android.com/release/knownissues">http://tools.android.com/release/knownissues</a>.</p>
+href="http://tools.android.com/knownissues">http://tools.android.com/knownissues</a>.</p>
 
 <script type="text/javascript">
 function toggleDiv(link) {
diff --git a/docs/html/sdk/tools-notes.jd b/docs/html/sdk/tools-notes.jd
index f5b61ee..272efcb 100644
--- a/docs/html/sdk/tools-notes.jd
+++ b/docs/html/sdk/tools-notes.jd
@@ -24,7 +24,7 @@
 and AVD Manager. </p>
 
 <p>For a summary of all known issues in SDK Tools, see <a
-href="http://tools.android.com/release/knownissues">http://tools.android.com/release/knownissues</a>.</p>
+href="http://tools.android.com/knownissues">http://tools.android.com/knownissues</a>.</p>
 
 <script type="text/javascript">
 function toggleDiv(link) {
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index f844331..8a9ca85 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -46,13 +46,18 @@
     Element[] mElements;
     String[] mElementNames;
     int[] mArraySizes;
+    int[] mOffsetInBytes;
 
     DataType mType;
     DataKind mKind;
     boolean mNormalized;
     int mVectorSize;
 
-    int getSizeBytes() {return mSize;}
+    /**
+    * @hide
+    * @return element size in bytes
+    */
+    public int getSizeBytes() {return mSize;}
 
 
     /**
@@ -152,6 +157,77 @@
     }
 
     /**
+    * @hide
+    * @return number of sub-elements in this element
+    */
+    public int getSubElementCount() {
+        if (mElements == null) {
+            return 0;
+        }
+        return mElements.length;
+    }
+
+    /**
+    * @hide
+    * @param index index of the sub-element to return
+    * @return sub-element in this element at given index
+    */
+    public Element getSubElement(int index) {
+        if (mElements == null) {
+            throw new RSIllegalArgumentException("Element contains no sub-elements");
+        }
+        if (index < 0 || index >= mElements.length) {
+            throw new RSIllegalArgumentException("Illegal sub-element index");
+        }
+        return mElements[index];
+    }
+
+    /**
+    * @hide
+    * @param index index of the sub-element
+    * @return sub-element in this element at given index
+    */
+    public String getSubElementName(int index) {
+        if (mElements == null) {
+            throw new RSIllegalArgumentException("Element contains no sub-elements");
+        }
+        if (index < 0 || index >= mElements.length) {
+            throw new RSIllegalArgumentException("Illegal sub-element index");
+        }
+        return mElementNames[index];
+    }
+
+    /**
+    * @hide
+    * @param index index of the sub-element
+    * @return array size of sub-element in this element at given index
+    */
+    public int getSubElementArraySize(int index) {
+        if (mElements == null) {
+            throw new RSIllegalArgumentException("Element contains no sub-elements");
+        }
+        if (index < 0 || index >= mElements.length) {
+            throw new RSIllegalArgumentException("Illegal sub-element index");
+        }
+        return mArraySizes[index];
+    }
+
+    /**
+    * @hide
+    * @param index index of the sub-element
+    * @return offset in bytes of sub-element in this element at given index
+    */
+    public int getSubElementOffsetBytes(int index) {
+        if (mElements == null) {
+            throw new RSIllegalArgumentException("Element contains no sub-elements");
+        }
+        if (index < 0 || index >= mElements.length) {
+            throw new RSIllegalArgumentException("Illegal sub-element index");
+        }
+        return mOffsetInBytes[index];
+    }
+
+    /**
      * Utility function for returning an Element containing a single Boolean.
      *
      * @param rs Context to which the element will belong.
@@ -602,7 +678,9 @@
         mElements = e;
         mElementNames = n;
         mArraySizes = as;
+        mOffsetInBytes = new int[mElements.length];
         for (int ct = 0; ct < mElements.length; ct++ ) {
+            mOffsetInBytes[ct] = mSize;
             mSize += mElements[ct].mSize * mArraySizes[ct];
         }
     }
@@ -653,13 +731,16 @@
         if(numSubElements > 0) {
             mElements = new Element[numSubElements];
             mElementNames = new String[numSubElements];
+            mArraySizes = new int[numSubElements];
+            mOffsetInBytes = new int[numSubElements];
 
             int[] subElementIds = new int[numSubElements];
-            mRS.nElementGetSubElements(getID(), subElementIds, mElementNames);
+            mRS.nElementGetSubElements(getID(), subElementIds, mElementNames, mArraySizes);
             for(int i = 0; i < numSubElements; i ++) {
                 mElements[i] = new Element(subElementIds[i], mRS);
                 mElements[i].updateFromNative();
-                mSize += mElements[i].mSize;
+                mOffsetInBytes[i] = mSize;
+                mSize += mElements[i].mSize * mArraySizes[i];
             }
         }
 
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java
index 60d9698..93ee0ce 100644
--- a/graphics/java/android/renderscript/ProgramRaster.java
+++ b/graphics/java/android/renderscript/ProgramRaster.java
@@ -37,23 +37,32 @@
         }
     }
 
-    boolean mPointSmooth;
-    boolean mLineSmooth;
     boolean mPointSprite;
-    float mLineWidth;
     CullMode mCullMode;
 
     ProgramRaster(int id, RenderScript rs) {
         super(id, rs);
 
-        mLineWidth = 1.0f;
-        mPointSmooth = false;
-        mLineSmooth = false;
         mPointSprite = false;
-
         mCullMode = CullMode.BACK;
     }
 
+    /**
+     * @hide
+     * @return whether point sprites are enabled
+     */
+    public boolean getPointSpriteEnabled() {
+        return mPointSprite;
+    }
+
+    /**
+     * @hide
+     * @return cull mode
+     */
+    public CullMode getCullMode() {
+        return mCullMode;
+    }
+
     public static ProgramRaster CULL_BACK(RenderScript rs) {
         if(rs.mProgramRaster_CULL_BACK == null) {
             ProgramRaster.Builder builder = new ProgramRaster.Builder(rs);
@@ -105,7 +114,10 @@
         public ProgramRaster create() {
             mRS.validate();
             int id = mRS.nProgramRasterCreate(mPointSprite, mCullMode.mID);
-            return new ProgramRaster(id, mRS);
+            ProgramRaster programRaster = new ProgramRaster(id, mRS);
+            programRaster.mPointSprite = mPointSprite;
+            programRaster.mCullMode = mCullMode;
+            return programRaster;
         }
     }
 
diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java
index fb7c8ca..677dadd 100644
--- a/graphics/java/android/renderscript/ProgramStore.java
+++ b/graphics/java/android/renderscript/ProgramStore.java
@@ -135,12 +135,93 @@
         }
     }
 
+    DepthFunc mDepthFunc;
+    boolean mDepthMask;
+    boolean mColorMaskR;
+    boolean mColorMaskG;
+    boolean mColorMaskB;
+    boolean mColorMaskA;
+    BlendSrcFunc mBlendSrc;
+    BlendDstFunc mBlendDst;
+    boolean mDither;
 
     ProgramStore(int id, RenderScript rs) {
         super(id, rs);
     }
 
     /**
+    * @hide
+    * @return depth function
+    */
+    public DepthFunc getDepthFunc() {
+        return mDepthFunc;
+    }
+
+    /**
+    * @hide
+    * @return whether depth writes are enabled
+    */
+    public boolean getDepthMaskEnabled() {
+        return mDepthMask;
+    }
+
+    /**
+    * @hide
+    * @return red color channel mask
+    */
+    public boolean getColorMaskREnabled() {
+        return mColorMaskR;
+    }
+
+    /**
+    * @hide
+    * @return green color channel mask
+    */
+    public boolean getColorMaskGEnabled() {
+        return mColorMaskG;
+    }
+
+    /**
+    * @hide
+    * @return blue color channel mask
+    */
+    public boolean getColorMaskBEnabled() {
+        return mColorMaskB;
+    }
+
+    /**
+    * @hide
+    * @return alpha channel mask
+    */
+    public boolean getColorMaskAEnabled() {
+        return mColorMaskA;
+    }
+
+    /**
+    * @hide
+    * @return source blend function
+    */
+    public BlendSrcFunc getBlendSrcFunc() {
+        return mBlendSrc;
+    }
+
+    /**
+    * @hide
+    * @return destination blend function
+    */
+    public BlendDstFunc getBlendDstFunc() {
+        return mBlendDst;
+    }
+
+    /**
+    * @hide
+    * @return whether dither is enabled
+    */
+    public boolean getDitherEnabled() {
+        return mDither;
+    }
+
+    /**
     * Returns a pre-defined program store object with the following
     * characteristics:
     *  - incoming pixels are drawn if their depth value is less than
@@ -340,7 +421,17 @@
             int id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA,
                                              mDepthMask, mDither,
                                              mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID);
-            return new ProgramStore(id, mRS);
+            ProgramStore programStore = new ProgramStore(id, mRS);
+            programStore.mDepthFunc = mDepthFunc;
+            programStore.mDepthMask = mDepthMask;
+            programStore.mColorMaskR = mColorMaskR;
+            programStore.mColorMaskG = mColorMaskG;
+            programStore.mColorMaskB = mColorMaskB;
+            programStore.mColorMaskA = mColorMaskA;
+            programStore.mBlendSrc = mBlendSrc;
+            programStore.mBlendDst = mBlendDst;
+            programStore.mDither = mDither;
+            return programStore;
         }
     }
 
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index d3d65a3..1305633 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -210,10 +210,11 @@
         validate();
         rsnElementGetNativeData(mContext, id, elementData);
     }
-    native void rsnElementGetSubElements(int con, int id, int[] IDs, String[] names);
-    synchronized void nElementGetSubElements(int id, int[] IDs, String[] names) {
+    native void rsnElementGetSubElements(int con, int id,
+                                         int[] IDs, String[] names, int[] arraySizes);
+    synchronized void nElementGetSubElements(int id, int[] IDs, String[] names, int[] arraySizes) {
         validate();
-        rsnElementGetSubElements(mContext, id, IDs, names);
+        rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
     }
 
     native int rsnTypeCreate(int con, int eid, int x, int y, int z, boolean mips, boolean faces);
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index 98943a1..0a3c91d 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -47,11 +47,58 @@
         }
     }
 
+    Value mMin;
+    Value mMag;
+    Value mWrapS;
+    Value mWrapT;
+    Value mWrapR;
+    float mAniso;
+
     Sampler(int id, RenderScript rs) {
         super(id, rs);
     }
 
     /**
+     * @hide
+     * @return minification setting for the sampler
+     */
+    public Value getMinification() {
+        return mMin;
+    }
+
+    /**
+     * @hide
+     * @return magnification setting for the sampler
+     */
+    public Value getMagnification() {
+        return mMag;
+    }
+
+    /**
+     * @hide
+     * @return S wrapping mode for the sampler
+     */
+    public Value getWrapS() {
+        return mWrapS;
+    }
+
+    /**
+     * @hide
+     * @return T wrapping mode for the sampler
+     */
+    public Value getWrapT() {
+        return mWrapT;
+    }
+
+    /**
+     * @hide
+     * @return anisotropy setting for the sampler
+     */
+    public float getAnisotropy() {
+        return mAniso;
+    }
+
+    /**
      * Retrieve a sampler with min and mag set to nearest and wrap modes set to
      * clamp.
      *
@@ -241,8 +288,16 @@
 
         public Sampler create() {
             mRS.validate();
-            int id = mRS.nSamplerCreate(mMag.mID, mMin.mID, mWrapS.mID, mWrapT.mID, mWrapR.mID, mAniso);
-            return new Sampler(id, mRS);
+            int id = mRS.nSamplerCreate(mMag.mID, mMin.mID, 
+                                        mWrapS.mID, mWrapT.mID, mWrapR.mID, mAniso);
+            Sampler sampler = new Sampler(id, mRS);
+            sampler.mMin = mMin;
+            sampler.mMag = mMag;
+            sampler.mWrapS = mWrapS;
+            sampler.mWrapT = mWrapT;
+            sampler.mWrapR = mWrapR;
+            sampler.mAniso = mAniso;
+            return sampler;
         }
     }
 
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index ec1f8de..af03ee2 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -371,23 +371,29 @@
 
 
 static void
-nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _IDs, jobjectArray _names)
+nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
+                       jintArray _IDs,
+                       jobjectArray _names,
+                       jintArray _arraySizes)
 {
     int dataSize = _env->GetArrayLength(_IDs);
     LOG_API("nElementGetSubElements, con(%p)", con);
 
     uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
     const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
+    uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
 
-    rsaElementGetSubElements(con, (RsElement)id, ids, names, (uint32_t)dataSize);
+    rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
 
     for(jint i = 0; i < dataSize; i++) {
         _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
         _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
+        _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
     }
 
     free(ids);
     free(names);
+    free(arraySizes);
 }
 
 // -----------------------------------
@@ -1239,7 +1245,7 @@
 {"rsnElementCreate",                 "(IIIZI)I",                              (void*)nElementCreate },
 {"rsnElementCreate2",                "(I[I[Ljava/lang/String;[I)I",           (void*)nElementCreate2 },
 {"rsnElementGetNativeData",          "(II[I)V",                               (void*)nElementGetNativeData },
-{"rsnElementGetSubElements",         "(II[I[Ljava/lang/String;)V",            (void*)nElementGetSubElements },
+{"rsnElementGetSubElements",         "(II[I[Ljava/lang/String;[I)V",          (void*)nElementGetSubElements },
 
 {"rsnTypeCreate",                    "(IIIIIZZ)I",                            (void*)nTypeCreate },
 {"rsnTypeGetNativeData",             "(II[I)V",                               (void*)nTypeGetNativeData },
diff --git a/libs/hwui/Patch.cpp b/libs/hwui/Patch.cpp
index f7dacae..47a2c99 100644
--- a/libs/hwui/Patch.cpp
+++ b/libs/hwui/Patch.cpp
@@ -157,14 +157,17 @@
 
     for (uint32_t i = 0; i < mYCount; i++) {
         float stepY = mYDivs[i];
+        const float segment = stepY - previousStepY;
 
         if (i & 1) {
-            const float segment = stepY - previousStepY;
             y2 = y1 + floorf(segment * stretchY + 0.5f);
         } else {
-            y2 = y1 + stepY - previousStepY;
+            y2 = y1 + segment;
         }
-        float v2 = fmax(0.0f, stepY - 0.5f) / bitmapHeight;
+
+        float vOffset = y1 == y2 ? 0.0f : 0.5 - (0.5 * segment / (y2 - y1));
+        float v2 = fmax(0.0f, stepY - vOffset) / bitmapHeight;
+        v1 += vOffset / bitmapHeight;
 
         if (stepY > 0.0f) {
 #if DEBUG_EXPLODE_PATCHES
@@ -179,7 +182,7 @@
         }
 
         y1 = y2;
-        v1 = (stepY + 0.5f) / bitmapHeight;
+        v1 = stepY / bitmapHeight;
 
         previousStepY = stepY;
     }
@@ -190,8 +193,7 @@
         y1 += mYCount * EXPLODE_GAP;
         y2 += mYCount * EXPLODE_GAP;
 #endif
-        generateRow(vertex, y1, y2, v1, 1.0f, stretchX, right - left,
-                bitmapWidth, quadCount);
+        generateRow(vertex, y1, y2, v1, 1.0f, stretchX, right - left, bitmapWidth, quadCount);
     }
 
     if (verticesCount > 0) {
@@ -220,14 +222,17 @@
     // Generate the row quad by quad
     for (uint32_t i = 0; i < mXCount; i++) {
         float stepX = mXDivs[i];
+        const float segment = stepX - previousStepX;
 
         if (i & 1) {
-            const float segment = stepX - previousStepX;
             x2 = x1 + floorf(segment * stretchX + 0.5f);
         } else {
-            x2 = x1 + stepX - previousStepX;
+            x2 = x1 + segment;
         }
-        float u2 = fmax(0.0f, stepX - 0.5f) / bitmapWidth;
+
+        float uOffset = x1 == x2 ? 0.0f : 0.5 - (0.5 * segment / (x2 - x1));
+        float u2 = fmax(0.0f, stepX - uOffset) / bitmapWidth;
+        u1 += uOffset / bitmapWidth;
 
         if (stepX > 0.0f) {
 #if DEBUG_EXPLODE_PATCHES
@@ -241,7 +246,7 @@
         }
 
         x1 = x2;
-        u1 = (stepX + 0.5f) / bitmapWidth;
+        u1 = stepX / bitmapWidth;
 
         previousStepX = stepX;
     }
@@ -265,8 +270,8 @@
     if ((mColorKey >> oldQuadCount) & 0x1) {
 #if DEBUG_PATCHES_EMPTY_VERTICES
         PATCH_LOGD("    quad %d (empty)", oldQuadCount);
-        PATCH_LOGD("        left,  top    = %.2f, %.2f\t\tu1, v1 = %.2f, %.2f", x1, y1, u1, v1);
-        PATCH_LOGD("        right, bottom = %.2f, %.2f\t\tu2, v2 = %.2f, %.2f", x2, y2, u2, v2);
+        PATCH_LOGD("        left,  top    = %.2f, %.2f\t\tu1, v1 = %.4f, %.4f", x1, y1, u1, v1);
+        PATCH_LOGD("        right, bottom = %.2f, %.2f\t\tu2, v2 = %.4f, %.4f", x2, y2, u2, v2);
 #endif
         return;
     }
@@ -294,8 +299,8 @@
 
 #if DEBUG_PATCHES_VERTICES
     PATCH_LOGD("    quad %d", oldQuadCount);
-    PATCH_LOGD("        left,  top    = %.2f, %.2f\t\tu1, v1 = %.2f, %.2f", x1, y1, u1, v1);
-    PATCH_LOGD("        right, bottom = %.2f, %.2f\t\tu2, v2 = %.2f, %.2f", x2, y2, u2, v2);
+    PATCH_LOGD("        left,  top    = %.2f, %.2f\t\tu1, v1 = %.4f, %.4f", x1, y1, u1, v1);
+    PATCH_LOGD("        right, bottom = %.2f, %.2f\t\tu2, v2 = %.4f, %.4f", x2, y2, u2, v2);
 #endif
 }
 
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index 3ba0123..6d54268 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -34,26 +34,30 @@
 RsFile rsaFileA3DCreateFromAsset(RsContext, void *asset);
 RsFile rsaFileA3DCreateFromFile(RsContext, const char *path);
 void rsaFileA3DGetNumIndexEntries(RsContext, int32_t *numEntries, RsFile);
-void rsaFileA3DGetIndexEntries(RsContext, RsFileIndexEntry *fileEntries,uint32_t numEntries, RsFile);
+void rsaFileA3DGetIndexEntries(RsContext, RsFileIndexEntry *fileEntries,
+                               uint32_t numEntries, RsFile);
 void rsaGetName(RsContext, void * obj, const char **name);
 // Mesh update functions
 void rsaMeshGetVertexBufferCount(RsContext, RsMesh, int32_t *vtxCount);
 void rsaMeshGetIndexCount(RsContext, RsMesh, int32_t *idxCount);
 void rsaMeshGetVertices(RsContext, RsMesh, RsAllocation *vtxData, uint32_t vtxDataCount);
-void rsaMeshGetIndices(RsContext, RsMesh, RsAllocation *va, uint32_t *primType, uint32_t idxDataCount);
+void rsaMeshGetIndices(RsContext, RsMesh, RsAllocation *va,
+                       uint32_t *primType, uint32_t idxDataCount);
 // Allocation update
 const void* rsaAllocationGetType(RsContext con, RsAllocation va);
 // Type update
 void rsaTypeGetNativeData(RsContext, RsType, uint32_t *typeData, uint32_t typeDataSize);
 // Element update
 void rsaElementGetNativeData(RsContext, RsElement, uint32_t *elemData, uint32_t elemDataSize);
-void rsaElementGetSubElements(RsContext, RsElement, uint32_t *ids, const char **names, uint32_t dataSize);
+void rsaElementGetSubElements(RsContext, RsElement, uint32_t *ids, const char **names,
+                              uint32_t *arraySizes, uint32_t dataSize);
 
 RsDevice rsDeviceCreate();
 void rsDeviceDestroy(RsDevice dev);
 void rsDeviceSetConfig(RsDevice dev, RsDeviceParam p, int32_t value);
 RsContext rsContextCreate(RsDevice dev, uint32_t version, uint32_t sdkVersion);
-RsContext rsContextCreateGL(RsDevice dev, uint32_t version, uint32_t sdkVersion, RsSurfaceConfig sc, uint32_t dpi);
+RsContext rsContextCreateGL(RsDevice dev, uint32_t version, uint32_t sdkVersion,
+                            RsSurfaceConfig sc, uint32_t dpi);
 
 #include "rsgApiFuncDecl.h"
 
diff --git a/libs/rs/driver/rsdFrameBuffer.cpp b/libs/rs/driver/rsdFrameBuffer.cpp
index 8c1b12d..bb07d29 100644
--- a/libs/rs/driver/rsdFrameBuffer.cpp
+++ b/libs/rs/driver/rsdFrameBuffer.cpp
@@ -33,11 +33,11 @@
     RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv;
 
     DrvAllocation *depth = NULL;
-    if (fb->mHal.state.depthTarget.get() != NULL) {
+    if (fb->mHal.state.depthTarget != NULL) {
         depth = (DrvAllocation *)fb->mHal.state.depthTarget->mHal.drv;
 
         if (depth->uploadDeferred) {
-            rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget.get(),
+            rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget,
                                  RS_ALLOCATION_USAGE_SCRIPT);
         }
     }
@@ -49,11 +49,11 @@
     // Now attach color targets
     for (uint32_t i = 0; i < fb->mHal.state.colorTargetsCount; i ++) {
         DrvAllocation *color = NULL;
-        if (fb->mHal.state.colorTargets[i].get() != NULL) {
+        if (fb->mHal.state.colorTargets[i] != NULL) {
             color = (DrvAllocation *)fb->mHal.state.colorTargets[i]->mHal.drv;
 
             if (color->uploadDeferred) {
-                rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i].get(),
+                rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i],
                                      RS_ALLOCATION_USAGE_SCRIPT);
             }
         }
@@ -79,10 +79,10 @@
     setColorAttachment(rsc, fb);
 
     RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv;
-    if (fb->mHal.state.colorTargets[0].get()) {
+    if (fb->mHal.state.colorTargets[0]) {
         fbo->setDimensions(fb->mHal.state.colorTargets[0]->getType()->getDimX(),
                            fb->mHal.state.colorTargets[0]->getType()->getDimY());
-    } else if (fb->mHal.state.depthTarget.get()) {
+    } else if (fb->mHal.state.depthTarget) {
         fbo->setDimensions(fb->mHal.state.depthTarget->getType()->getDimX(),
                            fb->mHal.state.depthTarget->getType()->getDimY());
     }
diff --git a/libs/rs/driver/rsdMeshObj.cpp b/libs/rs/driver/rsdMeshObj.cpp
index 019167b..24a7183 100644
--- a/libs/rs/driver/rsdMeshObj.cpp
+++ b/libs/rs/driver/rsdMeshObj.cpp
@@ -138,7 +138,7 @@
     }
 
     for (uint32_t ct=0; ct < mRSMesh->mHal.state.vertexBuffersCount; ct++) {
-        const Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[ct].get();
+        const Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[ct];
         DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
         if (drv->uploadDeferred) {
             rsdAllocationSyncAll(rsc, alloc, RS_ALLOCATION_USAGE_SCRIPT);
@@ -148,7 +148,7 @@
     // update attributes with either buffer information or data ptr based on their current state
     for (uint32_t ct=0; ct < mAttribCount; ct++) {
         uint32_t allocIndex = mAttribAllocationIndex[ct];
-        Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[allocIndex].get();
+        Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[allocIndex];
         DrvAllocation *drvAlloc = (DrvAllocation *)alloc->mHal.drv;
 
         if (drvAlloc->bufferID) {
@@ -163,8 +163,7 @@
     RsdVertexArray va(mAttribs, mAttribCount);
     va.setup(rsc);
 
-    Mesh::Primitive_t *prim = mRSMesh->mHal.state.primitives[primIndex];
-    const Allocation *idxAlloc = prim->mIndexBuffer.get();
+    const Allocation *idxAlloc = mRSMesh->mHal.state.indexBuffers[primIndex];
     if (idxAlloc) {
         DrvAllocation *drvAlloc = (DrvAllocation *)idxAlloc->mHal.drv;
         if (drvAlloc->uploadDeferred) {
@@ -190,7 +189,7 @@
 void RsdMeshObj::updateGLPrimitives() {
     mGLPrimitives = new uint32_t[mRSMesh->mHal.state.primitivesCount];
     for (uint32_t i = 0; i < mRSMesh->mHal.state.primitivesCount; i ++) {
-        switch (mRSMesh->mHal.state.primitives[i]->mPrimitive) {
+        switch (mRSMesh->mHal.state.primitives[i]) {
             case RS_PRIMITIVE_POINT:          mGLPrimitives[i] = GL_POINTS; break;
             case RS_PRIMITIVE_LINE:           mGLPrimitives[i] = GL_LINES; break;
             case RS_PRIMITIVE_LINE_STRIP:     mGLPrimitives[i] = GL_LINE_STRIP; break;
diff --git a/libs/rs/driver/rsdProgram.cpp b/libs/rs/driver/rsdProgram.cpp
index 27a6663..7556e50 100644
--- a/libs/rs/driver/rsdProgram.cpp
+++ b/libs/rs/driver/rsdProgram.cpp
@@ -43,7 +43,7 @@
 
 static void SyncProgramConstants(const Context *rsc, const Program *p) {
     for (uint32_t ct=0; ct < p->mHal.state.texturesCount; ct++) {
-        const Allocation *a = p->mHal.state.textures[ct].get();
+        const Allocation *a = p->mHal.state.textures[ct];
         if (!a) {
             continue;
         }
diff --git a/libs/rs/driver/rsdShader.cpp b/libs/rs/driver/rsdShader.cpp
index 16ff063..bdb60c2 100644
--- a/libs/rs/driver/rsdShader.cpp
+++ b/libs/rs/driver/rsdShader.cpp
@@ -69,7 +69,7 @@
     uint32_t attribCount = 0;
     uint32_t uniformCount = 0;
     for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
-        initAddUserElement(mRSProgram->mHal.state.inputElements[ct].get(), mAttribNames, NULL, &attribCount, RS_SHADER_ATTR);
+        initAddUserElement(mRSProgram->mHal.state.inputElements[ct], mAttribNames, NULL, &attribCount, RS_SHADER_ATTR);
     }
     for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) {
         initAddUserElement(mRSProgram->mHal.state.constantTypes[ct]->getElement(), mUniformNames, mUniformArraySizes, &uniformCount, RS_SHADER_UNI);
@@ -89,7 +89,7 @@
 String8 RsdShader::getGLSLInputString() const {
     String8 s;
     for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
-        const Element *e = mRSProgram->mHal.state.inputElements[ct].get();
+        const Element *e = mRSProgram->mHal.state.inputElements[ct];
         for (uint32_t field=0; field < e->getFieldCount(); field++) {
             const Element *f = e->getField(field);
 
@@ -113,7 +113,7 @@
 
 void RsdShader::appendAttributes() {
     for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
-        const Element *e = mRSProgram->mHal.state.inputElements[ct].get();
+        const Element *e = mRSProgram->mHal.state.inputElements[ct];
         for (uint32_t field=0; field < e->getFieldCount(); field++) {
             const Element *f = e->getField(field);
             const char *fn = e->getFieldName(field);
@@ -414,7 +414,7 @@
         RSD_CALL_GL(glActiveTexture, GL_TEXTURE0 + ct);
         RSD_CALL_GL(glUniform1i, sc->fragUniformSlot(mTextureUniformIndexStart + ct), ct);
 
-        if (!mRSProgram->mHal.state.textures[ct].get()) {
+        if (!mRSProgram->mHal.state.textures[ct]) {
             // if nothing is bound, reset to default GL texture
             RSD_CALL_GL(glBindTexture, mTextureTargets[ct], 0);
             continue;
@@ -427,9 +427,9 @@
         }
         RSD_CALL_GL(glBindTexture, drvTex->glTarget, drvTex->textureID);
         rsdGLCheckError(rsc, "ProgramFragment::setup tex bind");
-        if (mRSProgram->mHal.state.samplers[ct].get()) {
-            setupSampler(rsc, mRSProgram->mHal.state.samplers[ct].get(),
-                         mRSProgram->mHal.state.textures[ct].get());
+        if (mRSProgram->mHal.state.samplers[ct]) {
+            setupSampler(rsc, mRSProgram->mHal.state.samplers[ct],
+                         mRSProgram->mHal.state.textures[ct]);
         } else {
             RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
             RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -448,7 +448,7 @@
 void RsdShader::setupUserConstants(const Context *rsc, RsdShaderCache *sc, bool isFragment) {
     uint32_t uidx = 0;
     for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) {
-        Allocation *alloc = mRSProgram->mHal.state.constants[ct].get();
+        Allocation *alloc = mRSProgram->mHal.state.constants[ct];
         if (!alloc) {
             LOGE("Attempting to set constants on shader id %u, but alloc at slot %u is not set",
                  (uint32_t)this, ct);
@@ -504,7 +504,7 @@
 void RsdShader::initAttribAndUniformArray() {
     mAttribCount = 0;
     for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
-        const Element *elem = mRSProgram->mHal.state.inputElements[ct].get();
+        const Element *elem = mRSProgram->mHal.state.inputElements[ct];
         for (uint32_t field=0; field < elem->getFieldCount(); field++) {
             if (elem->getFieldName(field)[0] != '#') {
                 mAttribCount ++;
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 4359d95..e732630 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -30,7 +30,7 @@
     mHal.state.usageFlags = usages;
     mHal.state.mipmapControl = mc;
 
-    mHal.state.type.set(type);
+    setType(type);
     updateCache();
 }
 
@@ -47,7 +47,7 @@
 }
 
 void Allocation::updateCache() {
-    const Type *type = mHal.state.type.get();
+    const Type *type = mHal.state.type;
     mHal.state.dimensionX = type->getDimX();
     mHal.state.dimensionY = type->getDimY();
     mHal.state.dimensionZ = type->getDimZ();
@@ -187,7 +187,7 @@
 
     String8 s(prefix);
     s.append(" type ");
-    if (mHal.state.type.get()) {
+    if (mHal.state.type) {
         mHal.state.type->dumpLOGV(s.string());
     }
 
@@ -314,7 +314,7 @@
         decRefs(getPtr(), oldDimX - dimX, dimX);
     }
     rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences);
-    mHal.state.type.set(t.get());
+    setType(t.get());
     updateCache();
 }
 
diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h
index 67fc3b5..714798a 100644
--- a/libs/rs/rsAllocation.h
+++ b/libs/rs/rsAllocation.h
@@ -41,7 +41,7 @@
         void * drv;
 
         struct State {
-            ObjectBaseRef<const Type> type;
+            const Type * type;
 
             uint32_t usageFlags;
             RsAllocationMipmapControl mipmapControl;
@@ -71,7 +71,7 @@
     void updateCache();
 
     void * getPtr() const {return mHal.drvState.mallocPtr;}
-    const Type * getType() const {return mHal.state.type.get();}
+    const Type * getType() const {return mHal.state.type;}
 
     void syncAll(Context *rsc, RsAllocationUsageType src);
 
@@ -126,6 +126,11 @@
 
 protected:
     Vector<const Program *> mToDirtyList;
+    ObjectBaseRef<const Type> mType;
+    void setType(const Type *t) {
+        mType.set(t);
+        mHal.state.type = t;
+    }
 
 private:
     void freeChildrenUnlocked();
diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp
index d6ab0da..71e1b91 100644
--- a/libs/rs/rsElement.cpp
+++ b/libs/rs/rsElement.cpp
@@ -364,7 +364,7 @@
 }
 
 void rsaElementGetSubElements(RsContext con, RsElement elem, uint32_t *ids,
-                              const char **names, uint32_t dataSize) {
+                              const char **names, uint32_t *arraySizes, uint32_t dataSize) {
     Element *e = static_cast<Element *>(elem);
     rsAssert(e->getFieldCount() == dataSize);
 
@@ -372,5 +372,6 @@
         e->getField(i)->incUserRef();
         ids[i] = (uint32_t)e->getField(i);
         names[i] = e->getFieldName(i);
+        arraySizes[i] = e->getFieldArraySize(i);
     }
 }
diff --git a/libs/rs/rsFBOCache.cpp b/libs/rs/rsFBOCache.cpp
index c5c64c2..f4a8bc6 100644
--- a/libs/rs/rsFBOCache.cpp
+++ b/libs/rs/rsFBOCache.cpp
@@ -26,11 +26,14 @@
 FBOCache::FBOCache() {
     mDirty = true;
     mHal.state.colorTargetsCount = 1;
-    mHal.state.colorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount];
+    mHal.state.colorTargets = new Allocation*[mHal.state.colorTargetsCount];
+    mColorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount];
+    resetAll(NULL);
 }
 
 FBOCache::~FBOCache() {
     delete[] mHal.state.colorTargets;
+    delete[] mColorTargets;
 }
 
 void FBOCache::init(Context *rsc) {
@@ -52,7 +55,8 @@
             return;
         }
     }
-    mHal.state.colorTargets[slot].set(a);
+    mColorTargets[slot].set(a);
+    mHal.state.colorTargets[slot] = a;
     mDirty = true;
 }
 
@@ -63,15 +67,18 @@
             return;
         }
     }
-    mHal.state.depthTarget.set(a);
+    mDepthTarget.set(a);
+    mHal.state.depthTarget = a;
     mDirty = true;
 }
 
 void FBOCache::resetAll(Context *) {
     for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) {
-        mHal.state.colorTargets[i].set(NULL);
+        mColorTargets[i].set(NULL);
+        mHal.state.colorTargets[i] = NULL;
     }
-    mHal.state.depthTarget.set(NULL);
+    mDepthTarget.set(NULL);
+    mHal.state.depthTarget = NULL;
     mDirty = true;
 }
 
diff --git a/libs/rs/rsFBOCache.h b/libs/rs/rsFBOCache.h
index 5d58ba4..abb84de 100644
--- a/libs/rs/rsFBOCache.h
+++ b/libs/rs/rsFBOCache.h
@@ -44,15 +44,17 @@
         mutable void *drv;
 
         struct State {
-            ObjectBaseRef<Allocation> *colorTargets;
+            Allocation **colorTargets;
             uint32_t colorTargetsCount;
-            ObjectBaseRef<Allocation> depthTarget;
+            Allocation *depthTarget;
         };
         State state;
     };
     Hal mHal;
 
 protected:
+    ObjectBaseRef<Allocation> *mColorTargets;
+    ObjectBaseRef<Allocation> mDepthTarget;
     bool mDirty;
     void checkError(Context *);
     void setColorAttachment(Context *rsc);
diff --git a/libs/rs/rsMesh.cpp b/libs/rs/rsMesh.cpp
index 359d09f..bf9284f 100644
--- a/libs/rs/rsMesh.cpp
+++ b/libs/rs/rsMesh.cpp
@@ -23,9 +23,14 @@
     mHal.drv = NULL;
     mHal.state.primitives = NULL;
     mHal.state.primitivesCount = 0;
+    mHal.state.indexBuffers = NULL;
+    mHal.state.indexBuffersCount = 0;
     mHal.state.vertexBuffers = NULL;
     mHal.state.vertexBuffersCount = 0;
     mInitialized = false;
+
+    mVertexBuffers = NULL;
+    mIndexBuffers = NULL;
 }
 
 Mesh::Mesh(Context *rsc,
@@ -33,12 +38,23 @@
            uint32_t primitivesCount) : ObjectBase(rsc) {
     mHal.drv = NULL;
     mHal.state.primitivesCount = primitivesCount;
-    mHal.state.primitives = new Primitive_t *[mHal.state.primitivesCount];
+    mHal.state.indexBuffersCount = primitivesCount;
+    mHal.state.primitives = new RsPrimitive[mHal.state.primitivesCount];
+    mHal.state.indexBuffers = new Allocation *[mHal.state.indexBuffersCount];
     for (uint32_t i = 0; i < mHal.state.primitivesCount; i ++) {
-        mHal.state.primitives[i] = new Primitive_t;
+        mHal.state.primitives[i] = RS_PRIMITIVE_POINT;
+    }
+    for (uint32_t i = 0; i < mHal.state.indexBuffersCount; i ++) {
+        mHal.state.indexBuffers[i] = NULL;
     }
     mHal.state.vertexBuffersCount = vertexBuffersCount;
-    mHal.state.vertexBuffers = new ObjectBaseRef<Allocation>[mHal.state.vertexBuffersCount];
+    mHal.state.vertexBuffers = new Allocation *[mHal.state.vertexBuffersCount];
+    for (uint32_t i = 0; i < mHal.state.vertexBuffersCount; i ++) {
+        mHal.state.vertexBuffers[i] = NULL;
+    }
+
+    mVertexBuffers = new ObjectBaseRef<Allocation>[mHal.state.vertexBuffersCount];
+    mIndexBuffers = new ObjectBaseRef<Allocation>[mHal.state.primitivesCount];
 }
 
 Mesh::~Mesh() {
@@ -46,17 +62,12 @@
     mRSC->mHal.funcs.mesh.destroy(mRSC, this);
 #endif
 
-    if (mHal.state.vertexBuffers) {
-        delete[] mHal.state.vertexBuffers;
-    }
+    delete[] mHal.state.vertexBuffers;
+    delete[] mHal.state.primitives;
+    delete[] mHal.state.indexBuffers;
 
-    if (mHal.state.primitives) {
-        for (uint32_t i = 0; i < mHal.state.primitivesCount; i ++) {
-            mHal.state.primitives[i]->mIndexBuffer.clear();
-            delete mHal.state.primitives[i];
-        }
-        delete[] mHal.state.primitives;
-    }
+    delete[] mVertexBuffers;
+    delete[] mIndexBuffers;
 }
 
 void Mesh::init() {
@@ -81,13 +92,11 @@
     stream->addU32(mHal.state.primitivesCount);
     // Store the primitives
     for (uint32_t pCount = 0; pCount < mHal.state.primitivesCount; pCount ++) {
-        Primitive_t * prim = mHal.state.primitives[pCount];
+        stream->addU8((uint8_t)mHal.state.primitives[pCount]);
 
-        stream->addU8((uint8_t)prim->mPrimitive);
-
-        if (prim->mIndexBuffer.get()) {
+        if (mHal.state.indexBuffers[pCount]) {
             stream->addU32(1);
-            prim->mIndexBuffer->serialize(stream);
+            mHal.state.indexBuffers[pCount]->serialize(stream);
         } else {
             stream->addU32(0);
         }
@@ -173,10 +182,8 @@
         return;
     }
 
-    Primitive_t *prim = mHal.state.primitives[primIndex];
-
-    if (prim->mIndexBuffer.get()) {
-        renderPrimitiveRange(rsc, primIndex, 0, prim->mIndexBuffer->getType()->getDimX());
+    if (mHal.state.indexBuffers[primIndex]) {
+        renderPrimitiveRange(rsc, primIndex, 0, mHal.state.indexBuffers[primIndex]->getType()->getDimX());
         return;
     }
 
@@ -194,14 +201,14 @@
 
 void Mesh::uploadAll(Context *rsc) {
     for (uint32_t ct = 0; ct < mHal.state.vertexBuffersCount; ct ++) {
-        if (mHal.state.vertexBuffers[ct].get()) {
-            rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.vertexBuffers[ct].get());
+        if (mHal.state.vertexBuffers[ct]) {
+            rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.vertexBuffers[ct]);
         }
     }
 
     for (uint32_t ct = 0; ct < mHal.state.primitivesCount; ct ++) {
-        if (mHal.state.primitives[ct]->mIndexBuffer.get()) {
-            rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.primitives[ct]->mIndexBuffer.get());
+        if (mHal.state.indexBuffers[ct]) {
+            rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.indexBuffers[ct]);
         }
     }
 }
@@ -290,7 +297,7 @@
     rsAssert(vtxDataCount == sm->mHal.state.vertexBuffersCount);
 
     for (uint32_t ct = 0; ct < vtxDataCount; ct ++) {
-        vtxData[ct] = sm->mHal.state.vertexBuffers[ct].get();
+        vtxData[ct] = sm->mHal.state.vertexBuffers[ct];
         sm->mHal.state.vertexBuffers[ct]->incUserRef();
     }
 }
@@ -300,10 +307,10 @@
     rsAssert(idxDataCount == sm->mHal.state.primitivesCount);
 
     for (uint32_t ct = 0; ct < idxDataCount; ct ++) {
-        va[ct] = sm->mHal.state.primitives[ct]->mIndexBuffer.get();
-        primType[ct] = sm->mHal.state.primitives[ct]->mPrimitive;
-        if (sm->mHal.state.primitives[ct]->mIndexBuffer.get()) {
-            sm->mHal.state.primitives[ct]->mIndexBuffer->incUserRef();
+        va[ct] = sm->mHal.state.indexBuffers[ct];
+        primType[ct] = sm->mHal.state.primitives[ct];
+        if (sm->mHal.state.indexBuffers[ct]) {
+            sm->mHal.state.indexBuffers[ct]->incUserRef();
         }
     }
 }
diff --git a/libs/rs/rsMesh.h b/libs/rs/rsMesh.h
index ed1e93d..0fc73fb 100644
--- a/libs/rs/rsMesh.h
+++ b/libs/rs/rsMesh.h
@@ -32,13 +32,6 @@
     Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount);
     ~Mesh();
 
-    // Either mIndexBuffer, mPrimitiveBuffer or both could have a NULL reference
-    // If both are null, mPrimitive only would be used to render the mesh
-    struct Primitive_t {
-        ObjectBaseRef<Allocation> mIndexBuffer;
-        RsPrimitive mPrimitive;
-    };
-
     virtual void serialize(OStream *stream) const;
     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
     static Mesh *createFromStream(Context *rsc, IStream *stream);
@@ -51,10 +44,13 @@
             // Contains vertex data
             // Position, normal, texcoord, etc could either be strided in one allocation
             // of provided separetely in multiple ones
-            ObjectBaseRef<Allocation> *vertexBuffers;
+            Allocation **vertexBuffers;
             uint32_t vertexBuffersCount;
 
-            Primitive_t ** primitives;
+            // indexBuffers[i] could be NULL, in which case only primitives[i] is used
+            Allocation **indexBuffers;
+            uint32_t indexBuffersCount;
+            RsPrimitive *primitives;
             uint32_t primitivesCount;
         };
         State state;
@@ -62,12 +58,14 @@
     Hal mHal;
 
     void setVertexBuffer(Allocation *vb, uint32_t index) {
-        mHal.state.vertexBuffers[index].set(vb);
+        mVertexBuffers[index].set(vb);
+        mHal.state.vertexBuffers[index] = vb;
     }
 
     void setPrimitive(Allocation *idx, RsPrimitive prim, uint32_t index) {
-        mHal.state.primitives[index]->mIndexBuffer.set(idx);
-        mHal.state.primitives[index]->mPrimitive = prim;
+        mIndexBuffers[index].set(idx);
+        mHal.state.indexBuffers[index] = idx;
+        mHal.state.primitives[index] = prim;
     }
 
     void render(Context *) const;
@@ -80,6 +78,8 @@
     float mBBoxMax[3];
     void computeBBox();
 protected:
+    ObjectBaseRef<Allocation> *mVertexBuffers;
+    ObjectBaseRef<Allocation> *mIndexBuffers;
     bool mInitialized;
 };
 
diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp
index 4178aa5..a9fd877 100644
--- a/libs/rs/rsProgram.cpp
+++ b/libs/rs/rsProgram.cpp
@@ -37,22 +37,33 @@
         }
     }
 
-    mHal.state.textures = new ObjectBaseRef<Allocation>[mHal.state.texturesCount];
-    mHal.state.samplers = new ObjectBaseRef<Sampler>[mHal.state.texturesCount];
+    mTextures = new ObjectBaseRef<Allocation>[mHal.state.texturesCount];
+    mSamplers = new ObjectBaseRef<Sampler>[mHal.state.texturesCount];
+    mInputElements = new ObjectBaseRef<Element>[mHal.state.inputElementsCount];
+    mConstantTypes = new ObjectBaseRef<Type>[mHal.state.constantsCount];
+    mConstants = new ObjectBaseRef<Allocation>[mHal.state.constantsCount];
+
+    mHal.state.textures = new Allocation*[mHal.state.texturesCount];
+    mHal.state.samplers = new Sampler*[mHal.state.texturesCount];
     mHal.state.textureTargets = new RsTextureTarget[mHal.state.texturesCount];
-    mHal.state.inputElements = new ObjectBaseRef<Element>[mHal.state.inputElementsCount];
-    mHal.state.constantTypes = new ObjectBaseRef<Type>[mHal.state.constantsCount];
-    mHal.state.constants = new ObjectBaseRef<Allocation>[mHal.state.constantsCount];
+    mHal.state.inputElements = new Element*[mHal.state.inputElementsCount];
+    mHal.state.constantTypes = new Type*[mHal.state.constantsCount];
+    mHal.state.constants = new Allocation*[mHal.state.constantsCount];
+
+    // Will initialize everything
+    freeChildren();
 
     uint32_t input = 0;
     uint32_t constant = 0;
     uint32_t texture = 0;
     for (uint32_t ct=0; ct < paramLength; ct+=2) {
         if (params[ct] == RS_PROGRAM_PARAM_INPUT) {
-            mHal.state.inputElements[input++].set(reinterpret_cast<Element *>(params[ct+1]));
+            mInputElements[input].set(reinterpret_cast<Element *>(params[ct+1]));
+            mHal.state.inputElements[input++] = reinterpret_cast<Element *>(params[ct+1]);
         }
         if (params[ct] == RS_PROGRAM_PARAM_CONSTANT) {
-            mHal.state.constantTypes[constant++].set(reinterpret_cast<Type *>(params[ct+1]));
+            mConstantTypes[constant].set(reinterpret_cast<Type *>(params[ct+1]));
+            mHal.state.constantTypes[constant++] = reinterpret_cast<Type *>(params[ct+1]);
         }
         if (params[ct] == RS_PROGRAM_PARAM_TEXTURE_TYPE) {
             mHal.state.textureTargets[texture++] = (RsTextureTarget)params[ct+1];
@@ -72,6 +83,12 @@
 Program::~Program() {
     freeChildren();
 
+    delete[] mTextures;
+    delete[] mSamplers;
+    delete[] mInputElements;
+    delete[] mConstantTypes;
+    delete[] mConstants;
+
     delete[] mHal.state.textures;
     delete[] mHal.state.samplers;
     delete[] mHal.state.textureTargets;
@@ -110,6 +127,12 @@
     mHal.state.constantsCount = 0;
     mHal.state.texturesCount = 0;
 
+    mTextures = NULL;
+    mSamplers = NULL;
+    mInputElements = NULL;
+    mConstantTypes = NULL;
+    mConstants = NULL;
+
     mIsInternal = false;
 }
 
@@ -121,20 +144,21 @@
             rsc->setError(RS_ERROR_BAD_SHADER, "Cannot bind allocation");
             return;
         }
-        if (alloc->getType() != mHal.state.constantTypes[slot].get()) {
+        if (alloc->getType() != mConstantTypes[slot].get()) {
             LOGE("Attempt to bind alloc at slot %u, on shader id %u, but types mismatch",
                  slot, (uint32_t)this);
             rsc->setError(RS_ERROR_BAD_SHADER, "Cannot bind allocation");
             return;
         }
     }
-    if (mHal.state.constants[slot].get() == alloc) {
+    if (mConstants[slot].get() == alloc) {
         return;
     }
-    if (mHal.state.constants[slot].get()) {
-        mHal.state.constants[slot].get()->removeProgramToDirty(this);
+    if (mConstants[slot].get()) {
+        mConstants[slot]->removeProgramToDirty(this);
     }
-    mHal.state.constants[slot].set(alloc);
+    mConstants[slot].set(alloc);
+    mHal.state.constants[slot] = alloc;
     if (alloc) {
         alloc->addProgramToDirty(this);
     }
@@ -154,7 +178,9 @@
         return;
     }
 
-    mHal.state.textures[slot].set(a);
+    mTextures[slot].set(a);
+    mHal.state.textures[slot] = a;
+
     mDirty = true;
 }
 
@@ -165,7 +191,8 @@
         return;
     }
 
-    mHal.state.samplers[slot].set(s);
+    mSamplers[slot].set(s);
+    mHal.state.samplers[slot] = s;
     mDirty = true;
 }
 
diff --git a/libs/rs/rsProgram.h b/libs/rs/rsProgram.h
index 3237a72..06fc3ec 100644
--- a/libs/rs/rsProgram.h
+++ b/libs/rs/rsProgram.h
@@ -30,6 +30,33 @@
 
 class Program : public ProgramBase {
 public:
+    struct Hal {
+        mutable void *drv;
+
+        struct State {
+            // The difference between Textures and Constants is how they are accessed
+            // Texture lookups go though a sampler which in effect converts normalized
+            // coordinates into type specific.  Multiple samples may also be taken
+            // and filtered.
+            //
+            // Constants are strictly accessed by the shader code
+            Allocation **textures;
+            RsTextureTarget *textureTargets;
+            uint32_t texturesCount;
+
+            Sampler **samplers;
+            uint32_t samplersCount;
+
+            Allocation **constants;
+            Type **constantTypes;
+            uint32_t constantsCount;
+
+            Element **inputElements;
+            uint32_t inputElementsCount;
+        };
+        State state;
+    };
+    Hal mHal;
 
     Program(Context *, const char * shaderText, uint32_t shaderLength,
                        const uint32_t * params, uint32_t paramLength);
@@ -43,35 +70,13 @@
     void bindTexture(Context *, uint32_t slot, Allocation *);
     void bindSampler(Context *, uint32_t slot, Sampler *);
 
-    struct Hal {
-        mutable void *drv;
-
-        struct State {
-            // The difference between Textures and Constants is how they are accessed
-            // Texture lookups go though a sampler which in effect converts normalized
-            // coordinates into type specific.  Multiple samples may also be taken
-            // and filtered.
-            //
-            // Constants are strictly accessed by the shader code
-            ObjectBaseRef<Allocation> *textures;
-            RsTextureTarget *textureTargets;
-            uint32_t texturesCount;
-
-            ObjectBaseRef<Sampler> *samplers;
-            uint32_t samplersCount;
-
-            ObjectBaseRef<Allocation> *constants;
-            ObjectBaseRef<Type> *constantTypes;
-            uint32_t constantsCount;
-
-            ObjectBaseRef<Element> *inputElements;
-            uint32_t inputElementsCount;
-        };
-        State state;
-    };
-    Hal mHal;
-
 protected:
+    ObjectBaseRef<Allocation> *mTextures;
+    ObjectBaseRef<Sampler> *mSamplers;
+    ObjectBaseRef<Allocation> *mConstants;
+    ObjectBaseRef<Type> *mConstantTypes;
+    ObjectBaseRef<Element> *mInputElements;
+
     bool mIsInternal;
     String8 mUserShader;
     void initMemberVars();
diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp
index ff29520..81eedc4 100644
--- a/libs/rs/rsProgramFragment.cpp
+++ b/libs/rs/rsProgramFragment.cpp
@@ -42,7 +42,7 @@
         rsc->setError(RS_ERROR_BAD_SHADER, "Cannot  set fixed function emulation color on user program");
         return;
     }
-    if (mHal.state.constants[0].get() == NULL) {
+    if (mHal.state.constants[0] == NULL) {
         LOGE("Unable to set fixed function emulation color because allocation is missing");
         rsc->setError(RS_ERROR_BAD_SHADER, "Unable to set fixed function emulation color because allocation is missing");
         return;
@@ -62,7 +62,7 @@
     state->mLast.set(this);
 
     for (uint32_t ct=0; ct < mHal.state.texturesCount; ct++) {
-        if (!mHal.state.textures[ct].get()) {
+        if (!mHal.state.textures[ct]) {
             LOGE("No texture bound for shader id %u, texture unit %u", (uint)this, ct);
             rsc->setError(RS_ERROR_BAD_SHADER, "No texture bound");
             continue;
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index 51cb2a8a..4a13622 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -38,7 +38,7 @@
     }
 
     if (!isUserProgram()) {
-        if (mHal.state.constants[0].get() == NULL) {
+        if (mHal.state.constants[0] == NULL) {
             rsc->setError(RS_ERROR_FATAL_UNKNOWN,
                           "Unable to set fixed function emulation matrices because allocation is missing");
             return;
@@ -65,7 +65,7 @@
                       "Attempting to set fixed function emulation matrix projection on user program");
         return;
     }
-    if (mHal.state.constants[0].get() == NULL) {
+    if (mHal.state.constants[0] == NULL) {
         rsc->setError(RS_ERROR_FATAL_UNKNOWN,
                       "Unable to set fixed function emulation matrix projection because allocation is missing");
         return;
@@ -81,7 +81,7 @@
                       "Attempting to set fixed function emulation matrix modelview on user program");
         return;
     }
-    if (mHal.state.constants[0].get() == NULL) {
+    if (mHal.state.constants[0] == NULL) {
         rsc->setError(RS_ERROR_FATAL_UNKNOWN,
                       "Unable to set fixed function emulation matrix modelview because allocation is missing");
         return;
@@ -97,7 +97,7 @@
                       "Attempting to set fixed function emulation matrix texture on user program");
         return;
     }
-    if (mHal.state.constants[0].get() == NULL) {
+    if (mHal.state.constants[0] == NULL) {
         rsc->setError(RS_ERROR_FATAL_UNKNOWN,
                       "Unable to set fixed function emulation matrix texture because allocation is missing");
         return;
@@ -113,7 +113,7 @@
                       "Attempting to get fixed function emulation matrix projection on user program");
         return;
     }
-    if (mHal.state.constants[0].get() == NULL) {
+    if (mHal.state.constants[0] == NULL) {
         rsc->setError(RS_ERROR_FATAL_UNKNOWN,
                       "Unable to get fixed function emulation matrix projection because allocation is missing");
         return;
diff --git a/libs/rs/scriptc/rs_quaternion.rsh b/libs/rs/scriptc/rs_quaternion.rsh
index 23945ae..4e08d2f 100644
--- a/libs/rs/scriptc/rs_quaternion.rsh
+++ b/libs/rs/scriptc/rs_quaternion.rsh
@@ -66,19 +66,6 @@
 }
 
 /**
- * Multiply quaternion by another quaternion
- * @param q destination quaternion
- * @param rhs right hand side quaternion to multiply by
- */
-static void __attribute__((overloadable))
-rsQuaternionMultiply(rs_quaternion *q, const rs_quaternion *rhs) {
-    q->w = -q->x*rhs->x - q->y*rhs->y - q->z*rhs->z + q->w*rhs->w;
-    q->x =  q->x*rhs->w + q->y*rhs->z - q->z*rhs->y + q->w*rhs->x;
-    q->y = -q->x*rhs->z + q->y*rhs->w + q->z*rhs->x + q->w*rhs->y;
-    q->z =  q->x*rhs->y - q->y*rhs->x + q->z*rhs->w + q->w*rhs->z;
-}
-
-/**
  * Add two quaternions
  * @param q destination quaternion to add to
  * @param rsh right hand side quaternion to add
@@ -168,6 +155,23 @@
 }
 
 /**
+ * Multiply quaternion by another quaternion
+ * @param q destination quaternion
+ * @param rhs right hand side quaternion to multiply by
+ */
+static void __attribute__((overloadable))
+rsQuaternionMultiply(rs_quaternion *q, const rs_quaternion *rhs) {
+    rs_quaternion qtmp;
+    rsQuaternionSet(&qtmp, q);
+
+    q->w = qtmp.w*rhs->w - qtmp.x*rhs->x - qtmp.y*rhs->y - qtmp.z*rhs->z;
+    q->x = qtmp.w*rhs->x + qtmp.x*rhs->w + qtmp.y*rhs->z - qtmp.z*rhs->y;
+    q->y = qtmp.w*rhs->y + qtmp.y*rhs->w + qtmp.z*rhs->x - qtmp.x*rhs->z;
+    q->z = qtmp.w*rhs->z + qtmp.z*rhs->w + qtmp.x*rhs->y - qtmp.y*rhs->x;
+    rsQuaternionNormalize(q);
+}
+
+/**
  * Performs spherical linear interpolation between two quaternions
  * @param q result quaternion from interpolation
  * @param q0 first param
@@ -222,34 +226,26 @@
  * @param p normalized quaternion
  */
 static void rsQuaternionGetMatrixUnit(rs_matrix4x4 *m, const rs_quaternion *q) {
-    float x2 = 2.0f * q->x * q->x;
-    float y2 = 2.0f * q->y * q->y;
-    float z2 = 2.0f * q->z * q->z;
-    float xy = 2.0f * q->x * q->y;
-    float wz = 2.0f * q->w * q->z;
-    float xz = 2.0f * q->x * q->z;
-    float wy = 2.0f * q->w * q->y;
-    float wx = 2.0f * q->w * q->x;
-    float yz = 2.0f * q->y * q->z;
+    float xx = q->x * q->x;
+    float xy = q->x * q->y;
+    float xz = q->x * q->z;
+    float xw = q->x * q->w;
+    float yy = q->y * q->y;
+    float yz = q->y * q->z;
+    float yw = q->y * q->w;
+    float zz = q->z * q->z;
+    float zw = q->z * q->w;
 
-    m->m[0] = 1.0f - y2 - z2;
-    m->m[1] = xy - wz;
-    m->m[2] = xz + wy;
-    m->m[3] = 0.0f;
-
-    m->m[4] = xy + wz;
-    m->m[5] = 1.0f - x2 - z2;
-    m->m[6] = yz - wx;
-    m->m[7] = 0.0f;
-
-    m->m[8] = xz - wy;
-    m->m[9] = yz - wx;
-    m->m[10] = 1.0f - x2 - y2;
-    m->m[11] = 0.0f;
-
-    m->m[12] = 0.0f;
-    m->m[13] = 0.0f;
-    m->m[14] = 0.0f;
+    m->m[0]  = 1.0f - 2.0f * ( yy + zz );
+    m->m[4]  =        2.0f * ( xy - zw );
+    m->m[8]  =        2.0f * ( xz + yw );
+    m->m[1]  =        2.0f * ( xy + zw );
+    m->m[5]  = 1.0f - 2.0f * ( xx + zz );
+    m->m[9]  =        2.0f * ( yz - xw );
+    m->m[2]  =        2.0f * ( xz - yw );
+    m->m[6]  =        2.0f * ( yz + xw );
+    m->m[10] = 1.0f - 2.0f * ( xx + yy );
+    m->m[3]  = m->m[7] = m->m[11] = m->m[12] = m->m[13] = m->m[14] = 0.0f;
     m->m[15] = 1.0f;
 }
 
diff --git a/libs/utils/Android.mk b/libs/utils/Android.mk
index 638f72f..831d9e3 100644
--- a/libs/utils/Android.mk
+++ b/libs/utils/Android.mk
@@ -71,6 +71,10 @@
 endif
 endif
 
+ifeq ($(TARGET_OS),linux)
+LOCAL_LDLIBS += -lrt -ldl
+endif
+
 include $(BUILD_HOST_STATIC_LIBRARY)
 
 
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java b/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java
index de156c9..26bd697 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewBase.java
@@ -47,29 +47,34 @@
     private AudioManager mAudioManager;
     private TelephonyManager mTelephonyManager = null;
 
+    // This is a faster way to draw the background on devices without hardware acceleration
+    Drawable mBackgroundDrawable = new Drawable() {
+        @Override
+        public void draw(Canvas canvas) {
+            canvas.drawColor(BACKGROUND_COLOR, PorterDuff.Mode.SRC);
+        }
+
+        @Override
+        public void setAlpha(int alpha) {
+        }
+
+        @Override
+        public void setColorFilter(ColorFilter cf) {
+        }
+
+        @Override
+        public int getOpacity() {
+            return PixelFormat.TRANSLUCENT;
+        }
+    };
+
     public KeyguardViewBase(Context context) {
         super(context);
+        resetBackground();
+    }
 
-        // This is a faster way to draw the background on devices without hardware acceleration
-        setBackgroundDrawable(new Drawable() {
-            @Override
-            public void draw(Canvas canvas) {
-                canvas.drawColor(BACKGROUND_COLOR, PorterDuff.Mode.SRC);
-            }
-
-            @Override
-            public void setAlpha(int alpha) {
-            }
-
-            @Override
-            public void setColorFilter(ColorFilter cf) {
-            }
-
-            @Override
-            public int getOpacity() {
-                return PixelFormat.TRANSLUCENT;
-            }
-        });
+    public void resetBackground() {
+        setBackgroundDrawable(mBackgroundDrawable);
     }
 
     // used to inject callback
diff --git a/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java
index 7a72dcf..b4db01d 100644
--- a/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java
+++ b/policy/src/com/android/internal/policy/impl/LockPatternKeyguardView.java
@@ -254,7 +254,7 @@
 
             // TODO: examine all widgets to derive clock status
             mUpdateMonitor.reportClockVisible(true);
-            setBackgroundDrawable(null);
+            resetBackground();
         }
 
         public boolean isVisible(View self) {
diff --git a/services/java/com/android/server/TextServicesManagerService.java b/services/java/com/android/server/TextServicesManagerService.java
index a653322..1976eba 100644
--- a/services/java/com/android/server/TextServicesManagerService.java
+++ b/services/java/com/android/server/TextServicesManagerService.java
@@ -701,7 +701,7 @@
         public void onServiceDisconnected(ComponentName name) {
             synchronized(mSpellCheckerMap) {
                 final SpellCheckerBindGroup group = mSpellCheckerBindGroups.get(mSciId);
-                if (this == group.mInternalConnection) {
+                if (group != null && this == group.mInternalConnection) {
                     mSpellCheckerBindGroups.remove(mSciId);
                 }
             }
diff --git a/services/java/com/android/server/wm/Session.java b/services/java/com/android/server/wm/Session.java
index 03b7546..ee62a56 100644
--- a/services/java/com/android/server/wm/Session.java
+++ b/services/java/com/android/server/wm/Session.java
@@ -306,7 +306,15 @@
         synchronized (mService.mWindowMap) {
             long ident = Binder.clearCallingIdentity();
             try {
-                if (mService.mDragState == null || mService.mDragState.mToken != token) {
+                if (mService.mDragState == null) {
+                    // Most likely the drop recipient ANRed and we ended the drag
+                    // out from under it.  Log the issue and move on.
+                    Slog.w(WindowManagerService.TAG, "Drop result given but no drag in progress");
+                    return;
+                }
+
+                if (mService.mDragState.mToken != token) {
+                    // We're in a drag, but the wrong window has responded.
                     Slog.w(WindowManagerService.TAG, "Invalid drop-result claim by " + window);
                     throw new IllegalStateException("reportDropResult() by non-recipient");
                 }
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 1905a68..dc47a03 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1560,8 +1560,15 @@
         result.append(buffer);
         snprintf(buffer, SIZE,
                 "  last eglSwapBuffers() time: %f us\n"
-                "  last transaction time     : %f us\n",
-                mLastSwapBufferTime/1000.0, mLastTransactionTime/1000.0);
+                "  last transaction time     : %f us\n"
+                "  refresh-rate              : %f fps\n"
+                "  x-dpi                     : %f\n"
+                "  y-dpi                     : %f\n",
+                mLastSwapBufferTime/1000.0,
+                mLastTransactionTime/1000.0,
+                hw.getRefreshRate(),
+                hw.getDpiX(),
+                hw.getDpiY());
         result.append(buffer);
 
         if (inSwapBuffersDuration || !locked) {
diff --git a/telephony/java/com/android/internal/telephony/CommandsInterface.java b/telephony/java/com/android/internal/telephony/CommandsInterface.java
index 33eed38..9b42dbe 100644
--- a/telephony/java/com/android/internal/telephony/CommandsInterface.java
+++ b/telephony/java/com/android/internal/telephony/CommandsInterface.java
@@ -292,7 +292,7 @@
     void setOnNewGsmBroadcastSms(Handler h, int what, Object obj);
     void unSetOnNewGsmBroadcastSms(Handler h);
 
-   /**
+    /**
      * Register for NEW_SMS_ON_SIM unsolicited message
      *
      * AsyncResult.result is an int array containing the index of new SMS
@@ -1116,9 +1116,20 @@
     void acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message response);
 
     /**
+     * Acknowledge successful or failed receipt of last incoming SMS,
+     * including acknowledgement TPDU to send as the RP-User-Data element
+     * of the RP-ACK or RP-ERROR PDU.
+     *
+     * @param success true to send RP-ACK, false to send RP-ERROR
+     * @param ackPdu the acknowledgement TPDU in hexadecimal format
+     * @param response sent when operation completes.
+     */
+    void acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message response);
+
+    /**
      * parameters equivalent to 27.007 AT+CRSM command
      * response.obj will be an AsyncResult
-     * response.obj.userObj will be a IccIoResult on success
+     * response.obj.result will be an IccIoResult on success
      */
     void iccIO (int command, int fileid, String path, int p1, int p2, int p3,
             String data, String pin2, Message response);
@@ -1386,6 +1397,22 @@
     public void sendEnvelope(String contents, Message response);
 
     /**
+     * Send ENVELOPE to the SIM, such as an SMS-PP data download envelope
+     * for a SIM data download message. This method has one difference
+     * from {@link #sendEnvelope}: The SW1 and SW2 status bytes from the UICC response
+     * are returned along with the response data.
+     *
+     * response.obj will be an AsyncResult
+     * response.obj.result will be an IccIoResult on success
+     *
+     * @param contents  String containing SAT/USAT response in hexadecimal
+     *                  format starting with command tag. See TS 102 223 for
+     *                  details.
+     * @param response  Callback message
+     */
+    public void sendEnvelopeWithStatus(String contents, Message response);
+
+    /**
      * Accept or reject the call setup request from SIM.
      *
      * @param accept   true if the call is to be accepted, false otherwise.
diff --git a/telephony/java/com/android/internal/telephony/IccRecords.java b/telephony/java/com/android/internal/telephony/IccRecords.java
index 84bfc40..51ebd99 100644
--- a/telephony/java/com/android/internal/telephony/IccRecords.java
+++ b/telephony/java/com/android/internal/telephony/IccRecords.java
@@ -57,7 +57,6 @@
     protected int mailboxIndex = 0; // 0 is no mailbox dailing number associated
 
     protected String spn;
-    protected int spnDisplayCondition;
 
     // ***** Constants
 
diff --git a/telephony/java/com/android/internal/telephony/IccServiceTable.java b/telephony/java/com/android/internal/telephony/IccServiceTable.java
new file mode 100644
index 0000000..ed74a11
--- /dev/null
+++ b/telephony/java/com/android/internal/telephony/IccServiceTable.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony;
+
+import android.util.Log;
+
+/**
+ * Wrapper class for an ICC EF containing a bit field of enabled services.
+ */
+public abstract class IccServiceTable {
+    protected final byte[] mServiceTable;
+
+    protected IccServiceTable(byte[] table) {
+        mServiceTable = table;
+    }
+
+    // Get the class name to use for log strings
+    protected abstract String getTag();
+
+    // Get the array of enums to use for toString
+    protected abstract Object[] getValues();
+
+    /**
+     * Returns if the specified service is available.
+     * @param service the service number as a zero-based offset (the enum ordinal)
+     * @return true if the service is available; false otherwise
+     */
+    protected boolean isAvailable(int service) {
+        int offset = service / 8;
+        if (offset >= mServiceTable.length) {
+            // Note: Enums are zero-based, but the TS service numbering is one-based
+            Log.e(getTag(), "isAvailable for service " + (service + 1) + " fails, max service is " +
+                    (mServiceTable.length * 8));
+            return false;
+        }
+        int bit = service % 8;
+        return (mServiceTable[offset] & (1 << bit)) != 0;
+    }
+
+    public String toString() {
+        Object[] values = getValues();
+        int numBytes = mServiceTable.length;
+        StringBuilder builder = new StringBuilder(getTag()).append('[')
+                .append(numBytes * 8).append("]={ ");
+
+        boolean addComma = false;
+        for (int i = 0; i < numBytes; i++) {
+            byte currentByte = mServiceTable[i];
+            for (int bit = 0; bit < 8; bit++) {
+                if ((currentByte & (1 << bit)) != 0) {
+                    if (addComma) {
+                        builder.append(", ");
+                    } else {
+                        addComma = true;
+                    }
+                    int ordinal = (i * 8) + bit;
+                    if (ordinal < values.length) {
+                        builder.append(values[ordinal]);
+                    } else {
+                        builder.append('#').append(ordinal + 1);    // service number (one-based)
+                    }
+                }
+            }
+        }
+        return builder.append(" }").toString();
+    }
+}
diff --git a/telephony/java/com/android/internal/telephony/RIL.java b/telephony/java/com/android/internal/telephony/RIL.java
index 8aae0d4..e8d85de 100644
--- a/telephony/java/com/android/internal/telephony/RIL.java
+++ b/telephony/java/com/android/internal/telephony/RIL.java
@@ -1407,6 +1407,20 @@
         send(rr);
     }
 
+    public void
+    acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result) {
+        RILRequest rr
+                = RILRequest.obtain(RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, result);
+
+        rr.mp.writeInt(2);
+        rr.mp.writeString(success ? "1" : "0");
+        rr.mp.writeString(ackPdu);
+
+        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
+                + ' ' + success + " [" + ackPdu + ']');
+
+        send(rr);
+    }
 
     public void
     iccIO (int command, int fileid, String path, int p1, int p2, int p3,
@@ -1777,6 +1791,20 @@
     /**
      * {@inheritDoc}
      */
+    public void sendEnvelopeWithStatus(String contents, Message response) {
+        RILRequest rr = RILRequest.obtain(
+                RILConstants.RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS, response);
+
+        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
+                + '[' + contents + ']');
+
+        rr.mp.writeString(contents);
+        send(rr);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public void handleCallSetupRequestFromSim(
             boolean accept, Message response) {
 
@@ -2245,6 +2273,8 @@
             case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: ret = responseVoid(p); break;
             case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: ret =  responseInts(p); break;
             case RIL_REQUEST_ISIM_AUTHENTICATION: ret =  responseString(p); break;
+            case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: ret = responseVoid(p); break;
+            case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: ret = responseICC_IO(p); break;
             default:
                 throw new RuntimeException("Unrecognized solicited response: " + rr.mRequest);
             //break;
@@ -2870,7 +2900,7 @@
 
 
     private Object
-     responseICC_IO(Parcel p) {
+    responseICC_IO(Parcel p) {
         int sw1, sw2;
         byte data[] = null;
         Message ret;
@@ -3112,8 +3142,8 @@
         return ret;
     }
 
-   private Object
-   responseCellList(Parcel p) {
+    private Object
+    responseCellList(Parcel p) {
        int num, rssi;
        String location;
        ArrayList<NeighboringCellInfo> response;
@@ -3452,6 +3482,8 @@
             case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING";
             case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE";
             case RIL_REQUEST_ISIM_AUTHENTICATION: return "RIL_REQUEST_ISIM_AUTHENTICATION";
+            case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
+            case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
             default: return "<unknown request>";
         }
     }
diff --git a/telephony/java/com/android/internal/telephony/RILConstants.java b/telephony/java/com/android/internal/telephony/RILConstants.java
index 7fb7f41..ba9d07a 100644
--- a/telephony/java/com/android/internal/telephony/RILConstants.java
+++ b/telephony/java/com/android/internal/telephony/RILConstants.java
@@ -262,6 +262,8 @@
     int RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING = 103;
     int RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE = 104;
     int RIL_REQUEST_ISIM_AUTHENTICATION = 105;
+    int RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU = 106;
+    int RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS = 107;
     int RIL_UNSOL_RESPONSE_BASE = 1000;
     int RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED = 1000;
     int RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED = 1001;
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java b/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java
index 47c638f..0a285b9 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java
@@ -282,6 +282,9 @@
                 obtainMessage(EVENT_GET_MSISDN_DONE));
         recordsToLoad++;
 
+        iccFh.loadEFTransparent(EF_SST, obtainMessage(EVENT_GET_SST_DONE));
+        recordsToLoad++;
+
         iccFh.loadEFTransparent(EF_CSIM_LI,
                 obtainMessage(EVENT_GET_ICC_RECORD_DONE, new EfCsimLiLoaded()));
         recordsToLoad++;
@@ -384,12 +387,12 @@
 
     @Override
     protected void log(String s) {
-        if (DBG) Log.d(LOG_TAG, "[CSIM] " + s);
+        Log.d(LOG_TAG, "[CSIM] " + s);
     }
 
     @Override
     protected void loge(String s) {
-        if (DBG) Log.e(LOG_TAG, "[CSIM] " + s);
+        Log.e(LOG_TAG, "[CSIM] " + s);
     }
 
     public String getMdn() {
diff --git a/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java b/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
index 5d6f181..8e965a3 100755
--- a/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
@@ -91,6 +91,8 @@
 
     String pnnHomeName = null;
 
+    UsimServiceTable mUsimServiceTable;
+
     // ***** Constants
 
     // Bitmasks for SPN display rules.
@@ -134,7 +136,7 @@
     private static final int EVENT_GET_SPDI_DONE = 13;
     private static final int EVENT_UPDATE_DONE = 14;
     private static final int EVENT_GET_PNN_DONE = 15;
-    private static final int EVENT_GET_SST_DONE = 17;
+    protected static final int EVENT_GET_SST_DONE = 17;
     private static final int EVENT_GET_ALL_SMS_DONE = 18;
     private static final int EVENT_MARK_SMS_READ_DONE = 19;
     private static final int EVENT_SET_MBDN_DONE = 20;
@@ -246,6 +248,10 @@
         return msisdn;
     }
 
+    public UsimServiceTable getUsimServiceTable() {
+        return mUsimServiceTable;
+    }
+
     /**
      * Set subscriber number to SIM record
      *
@@ -961,8 +967,9 @@
                     break;
                 }
 
-                //Log.d(LOG_TAG, "SST: " + IccUtils.bytesToHexString(data));
-            break;
+                mUsimServiceTable = new UsimServiceTable(data);
+                if (DBG) log("SST: " + mUsimServiceTable);
+                break;
 
             case EVENT_GET_INFO_CPHS_DONE:
                 isRecordLoadResponse = true;
diff --git a/telephony/java/com/android/internal/telephony/gsm/UsimServiceTable.java b/telephony/java/com/android/internal/telephony/gsm/UsimServiceTable.java
new file mode 100644
index 0000000..3fe200b
--- /dev/null
+++ b/telephony/java/com/android/internal/telephony/gsm/UsimServiceTable.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony.gsm;
+
+import com.android.internal.telephony.IccServiceTable;
+
+/**
+ * Wrapper class for the USIM Service Table EF.
+ * See 3GPP TS 31.102 Release 10 section 4.2.8
+ */
+public final class UsimServiceTable extends IccServiceTable {
+    public enum UsimService {
+        PHONEBOOK,
+        FDN,                                // Fixed Dialing Numbers
+        FDN_EXTENSION,                      // FDN extension data in EF_EXT2
+        SDN,                                // Service Dialing Numbers
+        SDN_EXTENSION,                      // SDN extension data in EF_EXT3
+        BDN,                                // Barred Dialing Numbers
+        BDN_EXTENSION,                      // BDN extension data in EF_EXT4
+        OUTGOING_CALL_INFO,
+        INCOMING_CALL_INFO,
+        SM_STORAGE,
+        SM_STATUS_REPORTS,
+        SM_SERVICE_PARAMS,
+        ADVICE_OF_CHARGE,
+        CAP_CONFIG_PARAMS_2,
+        CB_MESSAGE_ID,
+        CB_MESSAGE_ID_RANGES,
+        GROUP_ID_LEVEL_1,
+        GROUP_ID_LEVEL_2,
+        SPN,                                // Service Provider Name
+        USER_PLMN_SELECT,
+        MSISDN,
+        IMAGE,
+        LOCALISED_SERVICE_AREAS,
+        EMLPP,                              // Enhanced Multi-Level Precedence and Preemption
+        EMLPP_AUTO_ANSWER,
+        RFU,
+        GSM_ACCESS,
+        DATA_DL_VIA_SMS_PP,
+        DATA_DL_VIA_SMS_CB,
+        CALL_CONTROL_BY_USIM,
+        MO_SMS_CONTROL_BY_USIM,
+        RUN_AT_COMMAND,
+        IGNORED_1,
+        ENABLED_SERVICES_TABLE,
+        APN_CONTROL_LIST,
+        DEPERSONALISATION_CONTROL_KEYS,
+        COOPERATIVE_NETWORK_LIST,
+        GSM_SECURITY_CONTEXT,
+        CPBCCH_INFO,
+        INVESTIGATION_SCAN,
+        MEXE,
+        OPERATOR_PLMN_SELECT,
+        HPLMN_SELECT,
+        EXTENSION_5,                        // Extension data for ICI, OCI, MSISDN in EF_EXT5
+        PLMN_NETWORK_NAME,
+        OPERATOR_PLMN_LIST,
+        MBDN,                               // Mailbox Dialing Numbers
+        MWI_STATUS,                         // Message Waiting Indication status
+        CFI_STATUS,                         // Call Forwarding Indication status
+        IGNORED_2,
+        SERVICE_PROVIDER_DISPLAY_INFO,
+        MMS_NOTIFICATION,
+        MMS_NOTIFICATION_EXTENSION,         // MMS Notification extension data in EF_EXT8
+        GPRS_CALL_CONTROL_BY_USIM,
+        MMS_CONNECTIVITY_PARAMS,
+        NETWORK_INDICATION_OF_ALERTING,
+        VGCS_GROUP_ID_LIST,
+        VBS_GROUP_ID_LIST,
+        PSEUDONYM,
+        IWLAN_USER_PLMN_SELECT,
+        IWLAN_OPERATOR_PLMN_SELECT,
+        USER_WSID_LIST,
+        OPERATOR_WSID_LIST,
+        VGCS_SECURITY,
+        VBS_SECURITY,
+        WLAN_REAUTH_IDENTITY,
+        MM_STORAGE,
+        GBA,                                // Generic Bootstrapping Architecture
+        MBMS_SECURITY,
+        DATA_DL_VIA_USSD,
+        EQUIVALENT_HPLMN,
+        TERMINAL_PROFILE_AFTER_UICC_ACTIVATION,
+        EQUIVALENT_HPLMN_PRESENTATION,
+        LAST_RPLMN_SELECTION_INDICATION,
+        OMA_BCAST_PROFILE,
+        GBA_LOCAL_KEY_ESTABLISHMENT,
+        TERMINAL_APPLICATIONS,
+        SPN_ICON,
+        PLMN_NETWORK_NAME_ICON,
+        USIM_IP_CONNECTION_PARAMS,
+        IWLAN_HOME_ID_LIST,
+        IWLAN_EQUIVALENT_HPLMN_PRESENTATION,
+        IWLAN_HPLMN_PRIORITY_INDICATION,
+        IWLAN_LAST_REGISTERED_PLMN,
+        EPS_MOBILITY_MANAGEMENT_INFO,
+        ALLOWED_CSG_LISTS_AND_INDICATIONS,
+        CALL_CONTROL_ON_EPS_PDN_CONNECTION_BY_USIM,
+        HPLMN_DIRECT_ACCESS,
+        ECALL_DATA,
+        OPERATOR_CSG_LISTS_AND_INDICATIONS,
+        SM_OVER_IP,
+        CSG_DISPLAY_CONTROL,
+        IMS_COMMUNICATION_CONTROL_BY_USIM,
+        EXTENDED_TERMINAL_APPLICATIONS,
+        UICC_ACCESS_TO_IMS,
+        NAS_CONFIG_BY_USIM
+    }
+
+    public UsimServiceTable(byte[] table) {
+        super(table);
+    }
+
+    public boolean isAvailable(UsimService service) {
+        return super.isAvailable(service.ordinal());
+    }
+
+    @Override
+    protected String getTag() {
+        return "UsimServiceTable";
+    }
+
+    @Override
+    protected Object[] getValues() {
+        return UsimService.values();
+    }
+}
diff --git a/telephony/java/com/android/internal/telephony/sip/SipCommandInterface.java b/telephony/java/com/android/internal/telephony/sip/SipCommandInterface.java
index 85ce6e0..ab01012 100644
--- a/telephony/java/com/android/internal/telephony/sip/SipCommandInterface.java
+++ b/telephony/java/com/android/internal/telephony/sip/SipCommandInterface.java
@@ -206,6 +206,9 @@
             Message result) {
     }
 
+    public void acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu,
+            Message result) {
+    }
 
     public void iccIO (int command, int fileid, String path, int p1, int p2,
             int p3, String data, String pin2, Message result) {
@@ -298,6 +301,9 @@
     public void sendEnvelope(String contents, Message response) {
     }
 
+    public void sendEnvelopeWithStatus(String contents, Message response) {
+    }
+
     public void handleCallSetupRequestFromSim(
             boolean accept, Message response) {
     }
diff --git a/telephony/java/com/android/internal/telephony/test/SimulatedCommands.java b/telephony/java/com/android/internal/telephony/test/SimulatedCommands.java
index a2a344f..a0c7d5d 100644
--- a/telephony/java/com/android/internal/telephony/test/SimulatedCommands.java
+++ b/telephony/java/com/android/internal/telephony/test/SimulatedCommands.java
@@ -810,6 +810,13 @@
     /**
      * {@inheritDoc}
      */
+    public void sendEnvelopeWithStatus(String contents, Message response) {
+        resultSuccess(response, null);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public void handleCallSetupRequestFromSim(
             boolean accept, Message response) {
         resultSuccess(response, null);
@@ -1037,6 +1044,11 @@
         unimplemented(result);
     }
 
+    public void acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu,
+            Message result) {
+        unimplemented(result);
+    }
+
     /**
      * parameters equivalent to 27.007 AT+CRSM command
      * response.obj will be an AsyncResult
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/IccServiceTableTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/IccServiceTableTest.java
new file mode 100644
index 0000000..c89f33a
--- /dev/null
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/IccServiceTableTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+/**
+ * Test IccServiceTable class.
+ */
+public class IccServiceTableTest extends AndroidTestCase {
+
+    static class TestIccServiceTable extends IccServiceTable {
+        public enum TestIccService {
+            SERVICE1,
+            SERVICE2,
+            SERVICE3,
+            SERVICE4
+        }
+
+        public TestIccServiceTable(byte[] table) {
+            super(table);
+        }
+
+        public boolean isAvailable(TestIccService service) {
+            return super.isAvailable(service.ordinal());
+        }
+
+        @Override
+        protected String getTag() {
+            return "TestIccServiceTable";
+        }
+
+        @Override
+        protected Object[] getValues() {
+            return TestIccService.values();
+        }
+    }
+
+    @SmallTest
+    public void testIccServiceTable() {
+        byte[] noServices = {0x00};
+        byte[] service1 = {0x01};
+        byte[] service4 = {0x08};
+        byte[] allServices = {0x0f};
+
+        TestIccServiceTable testTable1 = new TestIccServiceTable(noServices);
+        assertFalse(testTable1.isAvailable(TestIccServiceTable.TestIccService.SERVICE1));
+        assertFalse(testTable1.isAvailable(TestIccServiceTable.TestIccService.SERVICE2));
+        assertFalse(testTable1.isAvailable(TestIccServiceTable.TestIccService.SERVICE3));
+        assertFalse(testTable1.isAvailable(TestIccServiceTable.TestIccService.SERVICE4));
+
+        TestIccServiceTable testTable2 = new TestIccServiceTable(service1);
+        assertTrue(testTable2.isAvailable(TestIccServiceTable.TestIccService.SERVICE1));
+        assertFalse(testTable2.isAvailable(TestIccServiceTable.TestIccService.SERVICE2));
+        assertFalse(testTable2.isAvailable(TestIccServiceTable.TestIccService.SERVICE3));
+        assertFalse(testTable2.isAvailable(TestIccServiceTable.TestIccService.SERVICE4));
+
+        TestIccServiceTable testTable3 = new TestIccServiceTable(service4);
+        assertFalse(testTable3.isAvailable(TestIccServiceTable.TestIccService.SERVICE1));
+        assertFalse(testTable3.isAvailable(TestIccServiceTable.TestIccService.SERVICE2));
+        assertFalse(testTable3.isAvailable(TestIccServiceTable.TestIccService.SERVICE3));
+        assertTrue(testTable3.isAvailable(TestIccServiceTable.TestIccService.SERVICE4));
+
+        TestIccServiceTable testTable4 = new TestIccServiceTable(allServices);
+        assertTrue(testTable4.isAvailable(TestIccServiceTable.TestIccService.SERVICE1));
+        assertTrue(testTable4.isAvailable(TestIccServiceTable.TestIccService.SERVICE2));
+        assertTrue(testTable4.isAvailable(TestIccServiceTable.TestIccService.SERVICE3));
+        assertTrue(testTable4.isAvailable(TestIccServiceTable.TestIccService.SERVICE4));
+    }
+}
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/UsimServiceTableTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/UsimServiceTableTest.java
new file mode 100644
index 0000000..56854ed
--- /dev/null
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/UsimServiceTableTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony.gsm;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+/**
+ * Test UsimServiceTable class.
+ */
+public class UsimServiceTableTest extends AndroidTestCase {
+
+    @SmallTest
+    public void testUsimServiceTable() {
+        byte[] noServices = {0x00};
+        byte[] service1 = {0x01, 0x00};
+        byte[] service8 = {(byte) 0x80, 0x00, 0x00};
+        byte[] service8And9 = {(byte) 0x80, 0x01};
+        byte[] service28 = {0x00, 0x00, 0x00, 0x08};
+        byte[] service89To96 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, (byte) 0xff};
+
+        UsimServiceTable testTable1 = new UsimServiceTable(noServices);
+        assertFalse(testTable1.isAvailable(UsimServiceTable.UsimService.PHONEBOOK));
+        assertFalse(testTable1.isAvailable(UsimServiceTable.UsimService.FDN));
+        assertFalse(testTable1.isAvailable(UsimServiceTable.UsimService.NAS_CONFIG_BY_USIM));
+
+        UsimServiceTable testTable2 = new UsimServiceTable(service1);
+        assertTrue(testTable2.isAvailable(UsimServiceTable.UsimService.PHONEBOOK));
+        assertFalse(testTable2.isAvailable(UsimServiceTable.UsimService.FDN));
+        assertFalse(testTable2.isAvailable(UsimServiceTable.UsimService.NAS_CONFIG_BY_USIM));
+
+        UsimServiceTable testTable3 = new UsimServiceTable(service8);
+        assertFalse(testTable3.isAvailable(UsimServiceTable.UsimService.PHONEBOOK));
+        assertFalse(testTable3.isAvailable(UsimServiceTable.UsimService.BDN_EXTENSION));
+        assertTrue(testTable3.isAvailable(UsimServiceTable.UsimService.OUTGOING_CALL_INFO));
+        assertFalse(testTable3.isAvailable(UsimServiceTable.UsimService.INCOMING_CALL_INFO));
+        assertFalse(testTable3.isAvailable(UsimServiceTable.UsimService.NAS_CONFIG_BY_USIM));
+
+        UsimServiceTable testTable4 = new UsimServiceTable(service8And9);
+        assertFalse(testTable4.isAvailable(UsimServiceTable.UsimService.PHONEBOOK));
+        assertFalse(testTable4.isAvailable(UsimServiceTable.UsimService.BDN_EXTENSION));
+        assertTrue(testTable4.isAvailable(UsimServiceTable.UsimService.OUTGOING_CALL_INFO));
+        assertTrue(testTable4.isAvailable(UsimServiceTable.UsimService.INCOMING_CALL_INFO));
+        assertFalse(testTable4.isAvailable(UsimServiceTable.UsimService.SM_STORAGE));
+        assertFalse(testTable4.isAvailable(UsimServiceTable.UsimService.NAS_CONFIG_BY_USIM));
+
+        UsimServiceTable testTable5 = new UsimServiceTable(service28);
+        assertFalse(testTable5.isAvailable(UsimServiceTable.UsimService.PHONEBOOK));
+        assertTrue(testTable5.isAvailable(UsimServiceTable.UsimService.DATA_DL_VIA_SMS_PP));
+        assertFalse(testTable5.isAvailable(UsimServiceTable.UsimService.NAS_CONFIG_BY_USIM));
+
+        UsimServiceTable testTable6 = new UsimServiceTable(service89To96);
+        assertFalse(testTable6.isAvailable(UsimServiceTable.UsimService.PHONEBOOK));
+        assertFalse(testTable6.isAvailable(UsimServiceTable.UsimService.HPLMN_DIRECT_ACCESS));
+        assertTrue(testTable6.isAvailable(UsimServiceTable.UsimService.ECALL_DATA));
+        assertTrue(testTable6.isAvailable(UsimServiceTable.UsimService.SM_OVER_IP));
+        assertTrue(testTable6.isAvailable(UsimServiceTable.UsimService.UICC_ACCESS_TO_IMS));
+        assertTrue(testTable6.isAvailable(UsimServiceTable.UsimService.NAS_CONFIG_BY_USIM));
+    }
+}
diff --git a/tests/HwAccelerationTest/res/drawable-hdpi/appwidget_bg.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/appwidget_bg.9.png
similarity index 100%
rename from tests/HwAccelerationTest/res/drawable-hdpi/appwidget_bg.9.png
rename to tests/HwAccelerationTest/res/drawable-nodpi/appwidget_bg.9.png
Binary files differ
diff --git a/tests/HwAccelerationTest/res/drawable-hdpi/appwidget_bg_focus.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/appwidget_bg_focus.9.png
similarity index 100%
rename from tests/HwAccelerationTest/res/drawable-hdpi/appwidget_bg_focus.9.png
rename to tests/HwAccelerationTest/res/drawable-nodpi/appwidget_bg_focus.9.png
Binary files differ
diff --git a/tests/HwAccelerationTest/res/drawable-hdpi/appwidget_bg_press.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/appwidget_bg_press.9.png
similarity index 100%
rename from tests/HwAccelerationTest/res/drawable-hdpi/appwidget_bg_press.9.png
rename to tests/HwAccelerationTest/res/drawable-nodpi/appwidget_bg_press.9.png
Binary files differ
diff --git a/tests/HwAccelerationTest/res/drawable-hdpi/green_gradient.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/green_gradient.9.png
similarity index 100%
rename from tests/HwAccelerationTest/res/drawable-hdpi/green_gradient.9.png
rename to tests/HwAccelerationTest/res/drawable-nodpi/green_gradient.9.png
Binary files differ
diff --git a/tests/HwAccelerationTest/res/drawable-hdpi/patch.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/patch.9.png
similarity index 100%
rename from tests/HwAccelerationTest/res/drawable-hdpi/patch.9.png
rename to tests/HwAccelerationTest/res/drawable-nodpi/patch.9.png
Binary files differ
diff --git a/tests/HwAccelerationTest/res/drawable-nodpi/patch2.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/patch2.9.png
new file mode 100644
index 0000000..f65a3559
--- /dev/null
+++ b/tests/HwAccelerationTest/res/drawable-nodpi/patch2.9.png
Binary files differ
diff --git a/tests/HwAccelerationTest/res/drawable-hdpi/widget_title_bg.9.png b/tests/HwAccelerationTest/res/drawable-nodpi/widget_title_bg.9.png
similarity index 100%
rename from tests/HwAccelerationTest/res/drawable-hdpi/widget_title_bg.9.png
rename to tests/HwAccelerationTest/res/drawable-nodpi/widget_title_bg.9.png
Binary files differ
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ThinPatchesActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ThinPatchesActivity.java
index cfad6da..656f2b1 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ThinPatchesActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ThinPatchesActivity.java
@@ -44,7 +44,7 @@
     }
 
     private class PatchView extends View {
-        private Drawable mPatch1, mPatch2;
+        private Drawable mPatch1, mPatch2, mPatch3;
         private Bitmap mTexture;
 
         public PatchView(Activity activity) {
@@ -53,6 +53,7 @@
             final Resources resources = activity.getResources();
             mPatch1 = resources.getDrawable(R.drawable.patch);
             mPatch2 = resources.getDrawable(R.drawable.btn_toggle_on);
+            mPatch3 = resources.getDrawable(R.drawable.patch2);
 
             mTexture = Bitmap.createBitmap(4, 3, Bitmap.Config.ARGB_8888);
             mTexture.setPixel(0, 0, 0xffff0000);
@@ -77,6 +78,14 @@
             final int left = (getWidth() - width) / 2;
             final int top  = (getHeight() - height) / 2;
 
+            canvas.save();
+            canvas.translate(0.0f, -height * 2 - 20.0f);
+
+            mPatch3.setBounds(left, top, left + height, top + width);
+            mPatch3.draw(canvas);
+            
+            canvas.restore();
+            
             mPatch1.setBounds(left, top, left + width, top + height);
             mPatch1.draw(canvas);
 
diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_program_raster.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_program_raster.java
index 1fbf97a..2bfb6b1 100644
--- a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_program_raster.java
+++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_program_raster.java
@@ -25,6 +25,9 @@
 public class UT_program_raster extends UnitTest {
     private Resources mRes;
 
+    ProgramRaster pointSpriteEnabled;
+    ProgramRaster cullMode;
+
     protected UT_program_raster(RSTestCore rstc, Resources res, Context ctx) {
         super(rstc, "ProgramRaster", ctx);
         mRes = res;
@@ -39,20 +42,41 @@
 
     private void initializeGlobals(RenderScript RS, ScriptC_program_raster s) {
         ProgramRaster.Builder b = getDefaultBuilder(RS);
-        s.set_pointSpriteEnabled(b.setPointSpriteEnabled(true).create());
+        pointSpriteEnabled = b.setPointSpriteEnabled(true).create();
         b = getDefaultBuilder(RS);
-        s.set_cullMode(b.setCullMode(CullMode.FRONT).create());
-        return;
+        cullMode = b.setCullMode(CullMode.FRONT).create();
+
+        s.set_pointSpriteEnabled(pointSpriteEnabled);
+        s.set_cullMode(cullMode);
     }
 
-    public void run() {
-        RenderScript pRS = RenderScript.create(mCtx);
+    private void testScriptSide(RenderScript pRS) {
         ScriptC_program_raster s = new ScriptC_program_raster(pRS, mRes, R.raw.program_raster);
         pRS.setMessageHandler(mRsMessage);
         initializeGlobals(pRS, s);
         s.invoke_program_raster_test();
         pRS.finish();
         waitForMessage();
+    }
+
+    private void testJavaSide(RenderScript RS) {
+        _RS_ASSERT("pointSpriteEnabled.getPointSpriteEnabled() == true",
+                    pointSpriteEnabled.getPointSpriteEnabled() == true);
+        _RS_ASSERT("pointSpriteEnabled.getCullMode() == ProgramRaster.CullMode.BACK",
+                    pointSpriteEnabled.getCullMode() == ProgramRaster.CullMode.BACK);
+
+        _RS_ASSERT("cullMode.getPointSpriteEnabled() == false",
+                    cullMode.getPointSpriteEnabled() == false);
+        _RS_ASSERT("cullMode.getCullMode() == ProgramRaster.CullMode.FRONT",
+                    cullMode.getCullMode() == ProgramRaster.CullMode.FRONT);
+
+        updateUI();
+    }
+
+    public void run() {
+        RenderScript pRS = RenderScript.create(mCtx);
+        testScriptSide(pRS);
+        testJavaSide(pRS);
         pRS.destroy();
     }
 }
diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_program_store.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_program_store.java
index e06112c..72a401d 100644
--- a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_program_store.java
+++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_program_store.java
@@ -27,6 +27,16 @@
 public class UT_program_store extends UnitTest {
     private Resources mRes;
 
+    ProgramStore ditherEnable;
+    ProgramStore colorRWriteEnable;
+    ProgramStore colorGWriteEnable;
+    ProgramStore colorBWriteEnable;
+    ProgramStore colorAWriteEnable;
+    ProgramStore blendSrc;
+    ProgramStore blendDst;
+    ProgramStore depthWriteEnable;
+    ProgramStore depthFunc;
+
     protected UT_program_store(RSTestCore rstc, Resources res, Context ctx) {
         super(rstc, "ProgramStore", ctx);
         mRes = res;
@@ -44,44 +54,122 @@
 
     private void initializeGlobals(RenderScript RS, ScriptC_program_store s) {
         ProgramStore.Builder b = getDefaultBuilder(RS);
-        s.set_ditherEnable(b.setDitherEnabled(true).create());
+        ditherEnable = b.setDitherEnabled(true).create();
 
         b = getDefaultBuilder(RS);
-        s.set_colorRWriteEnable(b.setColorMaskEnabled(true,  false, false, false).create());
+        colorRWriteEnable = b.setColorMaskEnabled(true,  false, false, false).create();
 
         b = getDefaultBuilder(RS);
-        s.set_colorGWriteEnable(b.setColorMaskEnabled(false, true,  false, false).create());
+        colorGWriteEnable = b.setColorMaskEnabled(false, true,  false, false).create();
 
         b = getDefaultBuilder(RS);
-        s.set_colorBWriteEnable(b.setColorMaskEnabled(false, false, true,  false).create());
+        colorBWriteEnable = b.setColorMaskEnabled(false, false, true,  false).create();
 
         b = getDefaultBuilder(RS);
-        s.set_colorAWriteEnable(b.setColorMaskEnabled(false, false, false, true).create());
+        colorAWriteEnable = b.setColorMaskEnabled(false, false, false, true).create();
 
         b = getDefaultBuilder(RS);
-        s.set_blendSrc(b.setBlendFunc(ProgramStore.BlendSrcFunc.DST_COLOR,
-                                      ProgramStore.BlendDstFunc.ZERO).create());
+        blendSrc = b.setBlendFunc(ProgramStore.BlendSrcFunc.DST_COLOR,
+                                  ProgramStore.BlendDstFunc.ZERO).create();
 
         b = getDefaultBuilder(RS);
-        s.set_blendDst(b.setBlendFunc(ProgramStore.BlendSrcFunc.ZERO,
-                                      ProgramStore.BlendDstFunc.DST_ALPHA).create());
+        blendDst = b.setBlendFunc(ProgramStore.BlendSrcFunc.ZERO,
+                                  ProgramStore.BlendDstFunc.DST_ALPHA).create();
 
         b = getDefaultBuilder(RS);
-        s.set_depthWriteEnable(b.setDepthMaskEnabled(true).create());
+        depthWriteEnable = b.setDepthMaskEnabled(true).create();
 
         b = getDefaultBuilder(RS);
-        s.set_depthFunc(b.setDepthFunc(ProgramStore.DepthFunc.GREATER).create());
-        return;
+        depthFunc = b.setDepthFunc(ProgramStore.DepthFunc.GREATER).create();
+
+        s.set_ditherEnable(ditherEnable);
+        s.set_colorRWriteEnable(colorRWriteEnable);
+        s.set_colorGWriteEnable(colorGWriteEnable);
+        s.set_colorBWriteEnable(colorBWriteEnable);
+        s.set_colorAWriteEnable(colorAWriteEnable);
+        s.set_blendSrc(blendSrc);
+        s.set_blendDst(blendDst);
+        s.set_depthWriteEnable(depthWriteEnable);
+        s.set_depthFunc(depthFunc);
     }
 
-    public void run() {
-        RenderScript pRS = RenderScript.create(mCtx);
+    private void testScriptSide(RenderScript pRS) {
         ScriptC_program_store s = new ScriptC_program_store(pRS, mRes, R.raw.program_store);
         pRS.setMessageHandler(mRsMessage);
         initializeGlobals(pRS, s);
         s.invoke_program_store_test();
         pRS.finish();
         waitForMessage();
+    }
+
+    void checkObject(ProgramStore ps,
+                     boolean depthMask,
+                     DepthFunc df,
+                     BlendSrcFunc bsf,
+                     BlendDstFunc bdf,
+                     boolean R,
+                     boolean G,
+                     boolean B,
+                     boolean A,
+                     boolean dither) {
+        _RS_ASSERT("ps.getDepthMaskEnabled() == depthMask", ps.getDepthMaskEnabled() == depthMask);
+        _RS_ASSERT("ps.getDepthFunc() == df", ps.getDepthFunc() == df);
+        _RS_ASSERT("ps.getBlendSrcFunc() == bsf", ps.getBlendSrcFunc() == bsf);
+        _RS_ASSERT("ps.getBlendDstFunc() == bdf", ps.getBlendDstFunc() == bdf);
+        _RS_ASSERT("ps.getColorMaskREnabled() == R", ps.getColorMaskREnabled() == R);
+        _RS_ASSERT("ps.getColorMaskGEnabled() == G", ps.getColorMaskGEnabled() == G);
+        _RS_ASSERT("ps.getColorMaskBEnabled() == B", ps.getColorMaskBEnabled() == B);
+        _RS_ASSERT("ps.getColorMaskAEnabled() == A", ps.getColorMaskAEnabled() == A);
+        _RS_ASSERT("ps.getDitherEnabled() == dither", ps.getDitherEnabled() == dither);
+    }
+
+    void varyBuilderColorAndDither(ProgramStore.Builder pb,
+                                   boolean depthMask,
+                                   DepthFunc df,
+                                   BlendSrcFunc bsf,
+                                   BlendDstFunc bdf) {
+        for (int r = 0; r <= 1; r++) {
+            boolean isR = (r == 1);
+            for (int g = 0; g <= 1; g++) {
+                boolean isG = (g == 1);
+                for (int b = 0; b <= 1; b++) {
+                    boolean isB = (b == 1);
+                    for (int a = 0; a <= 1; a++) {
+                        boolean isA = (a == 1);
+                        for (int dither = 0; dither <= 1; dither++) {
+                            boolean isDither = (dither == 1);
+                            pb.setDitherEnabled(isDither);
+                            pb.setColorMaskEnabled(isR, isG, isB, isA);
+                            ProgramStore ps = pb.create();
+                            checkObject(ps, depthMask, df, bsf, bdf, isR, isG, isB, isA, isDither);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    public void testJavaSide(RenderScript RS) {
+        for (int depth = 0; depth <= 1; depth++) {
+            boolean depthMask = (depth == 1);
+            for (DepthFunc df : DepthFunc.values()) {
+                for (BlendSrcFunc bsf : BlendSrcFunc.values()) {
+                    for (BlendDstFunc bdf : BlendDstFunc.values()) {
+                        ProgramStore.Builder b = new ProgramStore.Builder(RS);
+                        b.setDepthFunc(df);
+                        b.setDepthMaskEnabled(depthMask);
+                        b.setBlendFunc(bsf, bdf);
+                        varyBuilderColorAndDither(b, depthMask, df, bsf, bdf);
+                    }
+                }
+            }
+        }
+    }
+
+    public void run() {
+        RenderScript pRS = RenderScript.create(mCtx);
+        testJavaSide(pRS);
+        testScriptSide(pRS);
         pRS.destroy();
     }
 }
diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_sampler.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_sampler.java
index b0ccf9d..030b3ff 100644
--- a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_sampler.java
+++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_sampler.java
@@ -25,6 +25,12 @@
 public class UT_sampler extends UnitTest {
     private Resources mRes;
 
+    Sampler minification;
+    Sampler magnification;
+    Sampler wrapS;
+    Sampler wrapT;
+    Sampler anisotropy;
+
     protected UT_sampler(RSTestCore rstc, Resources res, Context ctx) {
         super(rstc, "Sampler", ctx);
         mRes = res;
@@ -43,34 +49,103 @@
     private void initializeGlobals(RenderScript RS, ScriptC_sampler s) {
         Sampler.Builder b = getDefaultBuilder(RS);
         b.setMinification(Value.LINEAR_MIP_LINEAR);
-        s.set_minification(b.create());
+        minification = b.create();
 
         b = getDefaultBuilder(RS);
         b.setMagnification(Value.LINEAR);
-        s.set_magnification(b.create());
+        magnification = b.create();
 
         b = getDefaultBuilder(RS);
         b.setWrapS(Value.WRAP);
-        s.set_wrapS(b.create());
+        wrapS = b.create();
 
         b = getDefaultBuilder(RS);
         b.setWrapT(Value.WRAP);
-        s.set_wrapT(b.create());
+        wrapT = b.create();
 
         b = getDefaultBuilder(RS);
         b.setAnisotropy(8.0f);
-        s.set_anisotropy(b.create());
-        return;
+        anisotropy = b.create();
+
+        s.set_minification(minification);
+        s.set_magnification(magnification);
+        s.set_wrapS(wrapS);
+        s.set_wrapT(wrapT);
+        s.set_anisotropy(anisotropy);
     }
 
-    public void run() {
-        RenderScript pRS = RenderScript.create(mCtx);
+    private void testScriptSide(RenderScript pRS) {
         ScriptC_sampler s = new ScriptC_sampler(pRS, mRes, R.raw.sampler);
         pRS.setMessageHandler(mRsMessage);
         initializeGlobals(pRS, s);
         s.invoke_sampler_test();
         pRS.finish();
         waitForMessage();
+    }
+
+    private void testJavaSide(RenderScript RS) {
+        _RS_ASSERT("minification.getMagnification() == Sampler.Value.NEAREST",
+                    minification.getMagnification() == Sampler.Value.NEAREST);
+        _RS_ASSERT("minification.getMinification() == Sampler.Value.LINEAR_MIP_LINEAR",
+                    minification.getMinification() == Sampler.Value.LINEAR_MIP_LINEAR);
+        _RS_ASSERT("minification.getWrapS() == Sampler.Value.CLAMP",
+                    minification.getWrapS() == Sampler.Value.CLAMP);
+        _RS_ASSERT("minification.getWrapT() == Sampler.Value.CLAMP",
+                    minification.getWrapT() == Sampler.Value.CLAMP);
+        _RS_ASSERT("minification.getAnisotropy() == 1.0f",
+                    minification.getAnisotropy() == 1.0f);
+
+        _RS_ASSERT("magnification.getMagnification() == Sampler.Value.LINEAR",
+                    magnification.getMagnification() == Sampler.Value.LINEAR);
+        _RS_ASSERT("magnification.getMinification() == Sampler.Value.NEAREST",
+                    magnification.getMinification() == Sampler.Value.NEAREST);
+        _RS_ASSERT("magnification.getWrapS() == Sampler.Value.CLAMP",
+                    magnification.getWrapS() == Sampler.Value.CLAMP);
+        _RS_ASSERT("magnification.getWrapT() == Sampler.Value.CLAMP",
+                    magnification.getWrapT() == Sampler.Value.CLAMP);
+        _RS_ASSERT("magnification.getAnisotropy() == 1.0f",
+                    magnification.getAnisotropy() == 1.0f);
+
+        _RS_ASSERT("wrapS.getMagnification() == Sampler.Value.NEAREST",
+                    wrapS.getMagnification() == Sampler.Value.NEAREST);
+        _RS_ASSERT("wrapS.getMinification() == Sampler.Value.NEAREST",
+                    wrapS.getMinification() == Sampler.Value.NEAREST);
+        _RS_ASSERT("wrapS.getWrapS() == Sampler.Value.WRAP",
+                    wrapS.getWrapS() == Sampler.Value.WRAP);
+        _RS_ASSERT("wrapS.getWrapT() == Sampler.Value.CLAMP",
+                    wrapS.getWrapT() == Sampler.Value.CLAMP);
+        _RS_ASSERT("wrapS.getAnisotropy() == 1.0f",
+                    wrapS.getAnisotropy() == 1.0f);
+
+        _RS_ASSERT("wrapT.getMagnification() == Sampler.Value.NEAREST",
+                    wrapT.getMagnification() == Sampler.Value.NEAREST);
+        _RS_ASSERT("wrapT.getMinification() == Sampler.Value.NEAREST",
+                    wrapT.getMinification() == Sampler.Value.NEAREST);
+        _RS_ASSERT("wrapT.getWrapS() == Sampler.Value.CLAMP",
+                    wrapT.getWrapS() == Sampler.Value.CLAMP);
+        _RS_ASSERT("wrapT.getWrapT() == Sampler.Value.WRAP",
+                    wrapT.getWrapT() == Sampler.Value.WRAP);
+        _RS_ASSERT("wrapT.getAnisotropy() == 1.0f",
+                    wrapT.getAnisotropy() == 1.0f);
+
+        _RS_ASSERT("anisotropy.getMagnification() == Sampler.Value.NEAREST",
+                    anisotropy.getMagnification() == Sampler.Value.NEAREST);
+        _RS_ASSERT("anisotropy.getMinification() == Sampler.Value.NEAREST",
+                    anisotropy.getMinification() == Sampler.Value.NEAREST);
+        _RS_ASSERT("anisotropy.getWrapS() == Sampler.Value.CLAMP",
+                    anisotropy.getWrapS() == Sampler.Value.CLAMP);
+        _RS_ASSERT("anisotropy.getWrapT() == Sampler.Value.CLAMP",
+                    anisotropy.getWrapT() == Sampler.Value.CLAMP);
+        _RS_ASSERT("anisotropy.getAnisotropy() == 1.0f",
+                    anisotropy.getAnisotropy() == 8.0f);
+
+        updateUI();
+    }
+
+    public void run() {
+        RenderScript pRS = RenderScript.create(mCtx);
+        testScriptSide(pRS);
+        testJavaSide(pRS);
         pRS.destroy();
     }
 }
diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/UnitTest.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/UnitTest.java
index 6151431..a97ffa7 100644
--- a/tests/RenderScriptTests/tests/src/com/android/rs/test/UnitTest.java
+++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/UnitTest.java
@@ -16,6 +16,7 @@
 
 package com.android.rs.test;
 import android.content.Context;
+import android.util.Log;
 import android.renderscript.RenderScript.RSMessageHandler;
 
 public class UnitTest extends Thread {
@@ -55,6 +56,28 @@
         this (null, ctx);
     }
 
+    protected void _RS_ASSERT(String message, boolean b) {
+        if(b == false) {
+            result = -1;
+            Log.e(name, message + " FAILED");
+        }
+    }
+
+    protected void updateUI() {
+        if (mItem != null) {
+            mItem.result = result;
+            msgHandled = true;
+            try {
+                mRSTC.refreshTestResults();
+            }
+            catch (IllegalStateException e) {
+                /* Ignore the case where our message receiver has been
+                   disconnected. This happens when we leave the application
+                   before it finishes running all of the unit tests. */
+            }
+        }
+    }
+
     protected RSMessageHandler mRsMessage = new RSMessageHandler() {
         public void run() {
             if (result == 0) {
@@ -71,18 +94,7 @@
                 }
             }
 
-            if (mItem != null) {
-                mItem.result = result;
-                msgHandled = true;
-                try {
-                    mRSTC.refreshTestResults();
-                }
-                catch (IllegalStateException e) {
-                    /* Ignore the case where our message receiver has been
-                       disconnected. This happens when we leave the application
-                       before it finishes running all of the unit tests. */
-                }
-            }
+            updateUI();
         }
     };
 
diff --git a/tools/aapt/Android.mk b/tools/aapt/Android.mk
index a3e5d9a..cb55a9c 100644
--- a/tools/aapt/Android.mk
+++ b/tools/aapt/Android.mk
@@ -44,7 +44,7 @@
 	libpng
 
 ifeq ($(HOST_OS),linux)
-LOCAL_LDLIBS += -lrt -lpthread
+LOCAL_LDLIBS += -lrt -ldl -lpthread
 endif
 
 # Statically link libz for MinGW (Win SDK under Linux),
diff --git a/tools/localize/Android.mk b/tools/localize/Android.mk
index f284e86..5ec9feb 100644
--- a/tools/localize/Android.mk
+++ b/tools/localize/Android.mk
@@ -34,7 +34,7 @@
 	libcutils
     
 ifeq ($(HOST_OS),linux)
-LOCAL_LDLIBS += -lrt -lpthread
+LOCAL_LDLIBS += -lrt -ldl -lpthread
 endif
 
 
diff --git a/tools/obbtool/Android.mk b/tools/obbtool/Android.mk
index d118bd7..72a9858 100644
--- a/tools/obbtool/Android.mk
+++ b/tools/obbtool/Android.mk
@@ -22,7 +22,7 @@
 	libcutils
 
 ifeq ($(HOST_OS),linux)
-LOCAL_LDLIBS += -lpthread
+LOCAL_LDLIBS += -ldl -lpthread
 endif
 
 LOCAL_MODULE := obbtool
diff --git a/tools/validatekeymaps/Android.mk b/tools/validatekeymaps/Android.mk
index 90979e1..1368a07 100644
--- a/tools/validatekeymaps/Android.mk
+++ b/tools/validatekeymaps/Android.mk
@@ -23,7 +23,7 @@
 	libcutils
 
 ifeq ($(HOST_OS),linux)
-LOCAL_LDLIBS += -lpthread
+LOCAL_LDLIBS += -ldl -lpthread
 endif
 
 LOCAL_MODULE := validatekeymaps
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index b76f8b9..e981da7 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -3043,9 +3043,14 @@
                         deferMessage(message);
                     }
                     break;
-                    /* Handle in  DisconnectedState */
                 case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
+                    /* If we get a SUPPLICANT_STATE_CHANGE_EVENT before NETWORK_DISCONNECTION_EVENT
+                     * we have missed the network disconnection, transition to mDisconnectedState
+                     * and handle the rest of the events there
+                     */
                     deferMessage(message);
+                    handleNetworkDisconnect();
+                    transitionTo(mDisconnectedState);
                     break;
                 default:
                     return NOT_HANDLED;