Merge "NumberPicker not redrawn when current value is changed via an IME."
diff --git a/api/current.txt b/api/current.txt
index bb313cd..53bd92f 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -17993,15 +17993,24 @@
     method public static android.renderscript.Allocation createTyped(android.renderscript.RenderScript, android.renderscript.Type, int);
     method public static android.renderscript.Allocation createTyped(android.renderscript.RenderScript, android.renderscript.Type);
     method public void generateMipmaps();
+    method public int getBytesSize();
+    method public android.renderscript.Element getElement();
+    method public android.view.Surface getSurface();
     method public android.renderscript.Type getType();
+    method public int getUsage();
+    method public void ioReceive();
+    method public void ioSend();
     method public synchronized void resize(int);
     method public void setFromFieldPacker(int, android.renderscript.FieldPacker);
     method public void setFromFieldPacker(int, int, android.renderscript.FieldPacker);
+    method public void setSurface(android.view.Surface);
     method public void syncAll(int);
     field public static final int USAGE_GRAPHICS_CONSTANTS = 8; // 0x8
     field public static final int USAGE_GRAPHICS_RENDER_TARGET = 16; // 0x10
     field public static final int USAGE_GRAPHICS_TEXTURE = 2; // 0x2
     field public static final int USAGE_GRAPHICS_VERTEX = 4; // 0x4
+    field public static final int USAGE_IO_INPUT = 32; // 0x20
+    field public static final int USAGE_IO_OUTPUT = 64; // 0x40
     field public static final int USAGE_SCRIPT = 1; // 0x1
   }
 
@@ -18089,6 +18098,7 @@
     method public static android.renderscript.Element F64_2(android.renderscript.RenderScript);
     method public static android.renderscript.Element F64_3(android.renderscript.RenderScript);
     method public static android.renderscript.Element F64_4(android.renderscript.RenderScript);
+    method public static android.renderscript.Element FONT(android.renderscript.RenderScript);
     method public static android.renderscript.Element I16(android.renderscript.RenderScript);
     method public static android.renderscript.Element I16_2(android.renderscript.RenderScript);
     method public static android.renderscript.Element I16_3(android.renderscript.RenderScript);
@@ -18140,6 +18150,15 @@
     method public static android.renderscript.Element U8_4(android.renderscript.RenderScript);
     method public static android.renderscript.Element createPixel(android.renderscript.RenderScript, android.renderscript.Element.DataType, android.renderscript.Element.DataKind);
     method public static android.renderscript.Element createVector(android.renderscript.RenderScript, android.renderscript.Element.DataType, int);
+    method public int getBytesSize();
+    method public android.renderscript.Element.DataKind getDataKind();
+    method public android.renderscript.Element.DataType getDataType();
+    method public android.renderscript.Element getSubElement(int);
+    method public int getSubElementArraySize(int);
+    method public int getSubElementCount();
+    method public java.lang.String getSubElementName(int);
+    method public int getSubElementOffsetBytes(int);
+    method public int getVectorSize();
     method public boolean isCompatible(android.renderscript.Element);
     method public boolean isComplex();
   }
@@ -18172,8 +18191,10 @@
     enum_constant public static final android.renderscript.Element.DataType MATRIX_2X2;
     enum_constant public static final android.renderscript.Element.DataType MATRIX_3X3;
     enum_constant public static final android.renderscript.Element.DataType MATRIX_4X4;
+    enum_constant public static final android.renderscript.Element.DataType NONE;
     enum_constant public static final android.renderscript.Element.DataType RS_ALLOCATION;
     enum_constant public static final android.renderscript.Element.DataType RS_ELEMENT;
+    enum_constant public static final android.renderscript.Element.DataType RS_FONT;
     enum_constant public static final android.renderscript.Element.DataType RS_MESH;
     enum_constant public static final android.renderscript.Element.DataType RS_PROGRAM_FRAGMENT;
     enum_constant public static final android.renderscript.Element.DataType RS_PROGRAM_RASTER;
@@ -18486,12 +18507,18 @@
     method public void bindConstants(android.renderscript.Allocation, int);
     method public void bindSampler(android.renderscript.Sampler, int) throws java.lang.IllegalArgumentException;
     method public void bindTexture(android.renderscript.Allocation, int) throws java.lang.IllegalArgumentException;
+    method public android.renderscript.Type getConstant(int);
+    method public int getConstantCount();
+    method public int getTextureCount();
+    method public java.lang.String getTextureName(int);
+    method public android.renderscript.Program.TextureType getTextureType(int);
   }
 
   public static class Program.BaseProgramBuilder {
     ctor protected Program.BaseProgramBuilder(android.renderscript.RenderScript);
     method public android.renderscript.Program.BaseProgramBuilder addConstant(android.renderscript.Type) throws java.lang.IllegalStateException;
     method public android.renderscript.Program.BaseProgramBuilder addTexture(android.renderscript.Program.TextureType) throws java.lang.IllegalArgumentException;
+    method public android.renderscript.Program.BaseProgramBuilder addTexture(android.renderscript.Program.TextureType, java.lang.String) throws java.lang.IllegalArgumentException;
     method public int getCurrentConstantIndex();
     method public int getCurrentTextureIndex();
     method protected void initProgram(android.renderscript.Program);
@@ -18547,6 +18574,8 @@
     method public static android.renderscript.ProgramRaster CULL_BACK(android.renderscript.RenderScript);
     method public static android.renderscript.ProgramRaster CULL_FRONT(android.renderscript.RenderScript);
     method public static android.renderscript.ProgramRaster CULL_NONE(android.renderscript.RenderScript);
+    method public android.renderscript.ProgramRaster.CullMode getCullMode();
+    method public boolean isPointSpriteEnabled();
   }
 
   public static class ProgramRaster.Builder {
@@ -18569,6 +18598,15 @@
     method public static android.renderscript.ProgramStore BLEND_ALPHA_DEPTH_TEST(android.renderscript.RenderScript);
     method public static android.renderscript.ProgramStore BLEND_NONE_DEPTH_NONE(android.renderscript.RenderScript);
     method public static android.renderscript.ProgramStore BLEND_NONE_DEPTH_TEST(android.renderscript.RenderScript);
+    method public android.renderscript.ProgramStore.BlendDstFunc getBlendDstFunc();
+    method public android.renderscript.ProgramStore.BlendSrcFunc getBlendSrcFunc();
+    method public android.renderscript.ProgramStore.DepthFunc getDepthFunc();
+    method public boolean isColorMaskAlphaEnabled();
+    method public boolean isColorMaskBlueEnabled();
+    method public boolean isColorMaskGreenEnabled();
+    method public boolean isColorMaskRedEnabled();
+    method public boolean isDepthMaskEnabled();
+    method public boolean isDitherEnabled();
   }
 
   public static final class ProgramStore.BlendDstFunc extends java.lang.Enum {
@@ -18621,6 +18659,8 @@
   }
 
   public class ProgramVertex extends android.renderscript.Program {
+    method public android.renderscript.Element getInput(int);
+    method public int getInputCount();
   }
 
   public static class ProgramVertex.Builder extends android.renderscript.Program.BaseProgramBuilder {
@@ -18758,6 +18798,11 @@
     method public static android.renderscript.Sampler WRAP_LINEAR(android.renderscript.RenderScript);
     method public static android.renderscript.Sampler WRAP_LINEAR_MIP_LINEAR(android.renderscript.RenderScript);
     method public static android.renderscript.Sampler WRAP_NEAREST(android.renderscript.RenderScript);
+    method public float getAnisotropy();
+    method public android.renderscript.Sampler.Value getMagnification();
+    method public android.renderscript.Sampler.Value getMinification();
+    method public android.renderscript.Sampler.Value getWrapS();
+    method public android.renderscript.Sampler.Value getWrapT();
   }
 
   public static class Sampler.Builder {
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index 2af58be..c682852 100755
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -32,7 +32,6 @@
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.util.Slog;
-import android.util.SparseArray;
 import android.util.TypedValue;
 import android.util.LongSparseArray;
 
@@ -86,8 +85,8 @@
     // single-threaded, and after that these are immutable.
     private static final LongSparseArray<Drawable.ConstantState> sPreloadedDrawables
             = new LongSparseArray<Drawable.ConstantState>();
-    private static final SparseArray<ColorStateList> mPreloadedColorStateLists
-            = new SparseArray<ColorStateList>();
+    private static final LongSparseArray<ColorStateList> sPreloadedColorStateLists
+            = new LongSparseArray<ColorStateList>();
     private static final LongSparseArray<Drawable.ConstantState> sPreloadedColorDrawables
             = new LongSparseArray<Drawable.ConstantState>();
     private static boolean mPreloaded;
@@ -98,8 +97,8 @@
     // These are protected by the mTmpValue lock.
     private final LongSparseArray<WeakReference<Drawable.ConstantState> > mDrawableCache
             = new LongSparseArray<WeakReference<Drawable.ConstantState> >();
-    private final SparseArray<WeakReference<ColorStateList> > mColorStateListCache
-            = new SparseArray<WeakReference<ColorStateList> >();
+    private final LongSparseArray<WeakReference<ColorStateList> > mColorStateListCache
+            = new LongSparseArray<WeakReference<ColorStateList> >();
     private final LongSparseArray<WeakReference<Drawable.ConstantState> > mColorDrawableCache
             = new LongSparseArray<WeakReference<Drawable.ConstantState> >();
     private boolean mPreloading;
@@ -118,22 +117,6 @@
     
     private CompatibilityInfo mCompatibilityInfo;
 
-    private static final LongSparseArray<Object> EMPTY_ARRAY = new LongSparseArray<Object>(0) {
-        @Override
-        public void put(long k, Object o) {
-            throw new UnsupportedOperationException();
-        }
-        @Override
-        public void append(long k, Object o) {
-            throw new UnsupportedOperationException();
-        }
-    };
-
-    @SuppressWarnings("unchecked")
-    private static <T> LongSparseArray<T> emptySparseArray() {
-        return (LongSparseArray<T>) EMPTY_ARRAY;
-    }
-
     /** @hide */
     public static int selectDefaultTheme(int curTheme, int targetSdkVersion) {
         return selectSystemTheme(curTheme, targetSdkVersion,
@@ -180,9 +163,8 @@
      * @param config Desired device configuration to consider when 
      *               selecting/computing resource values (optional).
      */
-    public Resources(AssetManager assets, DisplayMetrics metrics,
-            Configuration config) {
-        this(assets, metrics, config, (CompatibilityInfo) null);
+    public Resources(AssetManager assets, DisplayMetrics metrics, Configuration config) {
+        this(assets, metrics, config, null);
     }
 
     /**
@@ -1883,7 +1865,8 @@
             return dr;
         }
 
-        Drawable.ConstantState cs = isColorDrawable ? sPreloadedColorDrawables.get(key) : sPreloadedDrawables.get(key);
+        Drawable.ConstantState cs = isColorDrawable ?
+                sPreloadedColorDrawables.get(key) : sPreloadedDrawables.get(key);
         if (cs != null) {
             dr = cs.newDrawable(this);
         } else {
@@ -2005,21 +1988,21 @@
             }
         }
 
-        final int key = (value.assetCookie << 24) | value.data;
+        final long key = (((long) value.assetCookie) << 32) | value.data;
 
         ColorStateList csl;
 
         if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
                 value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
 
-            csl = mPreloadedColorStateLists.get(key);
+            csl = sPreloadedColorStateLists.get(key);
             if (csl != null) {
                 return csl;
             }
 
             csl = ColorStateList.valueOf(value.data);
             if (mPreloading) {
-                mPreloadedColorStateLists.put(key, csl);
+                sPreloadedColorStateLists.put(key, csl);
             }
 
             return csl;
@@ -2030,7 +2013,7 @@
             return csl;
         }
 
-        csl = mPreloadedColorStateLists.get(key);
+        csl = sPreloadedColorStateLists.get(key);
         if (csl != null) {
             return csl;
         }
@@ -2063,14 +2046,13 @@
 
         if (csl != null) {
             if (mPreloading) {
-                mPreloadedColorStateLists.put(key, csl);
+                sPreloadedColorStateLists.put(key, csl);
             } else {
                 synchronized (mTmpValue) {
                     //Log.i(TAG, "Saving cached color state list @ #" +
                     //        Integer.toHexString(key.intValue())
                     //        + " in " + this + ": " + csl);
-                    mColorStateListCache.put(
-                        key, new WeakReference<ColorStateList>(csl));
+                    mColorStateListCache.put(key, new WeakReference<ColorStateList>(csl));
                 }
             }
         }
@@ -2078,7 +2060,7 @@
         return csl;
     }
 
-    private ColorStateList getCachedColorStateList(int key) {
+    private ColorStateList getCachedColorStateList(long key) {
         synchronized (mTmpValue) {
             WeakReference<ColorStateList> wr = mColorStateListCache.get(key);
             if (wr != null) {   // we have the key
@@ -2088,8 +2070,7 @@
                     //        Integer.toHexString(((Integer)key).intValue())
                     //        + " in " + this + ": " + entry);
                     return entry;
-                }
-                else {  // our entry has been purged
+                } else {  // our entry has been purged
                     mColorStateListCache.delete(key);
                 }
             }
diff --git a/core/java/android/text/SpannableStringBuilder.java b/core/java/android/text/SpannableStringBuilder.java
index 6056c75..11c169e 100644
--- a/core/java/android/text/SpannableStringBuilder.java
+++ b/core/java/android/text/SpannableStringBuilder.java
@@ -75,7 +75,7 @@
                 if (spans[i] instanceof NoCopySpan) {
                     continue;
                 }
-                
+
                 int st = sp.getSpanStart(spans[i]) - start;
                 int en = sp.getSpanEnd(spans[i]) - start;
                 int fl = sp.getSpanFlags(spans[i]);
@@ -212,7 +212,7 @@
 
         if (mGapLength > 2 * length())
             resizeFor(length());
-        
+
         return ret; // == this
     }
 
@@ -220,7 +220,7 @@
     public void clear() {
         replace(0, length(), "", 0, 0);
     }
-    
+
     // Documentation from interface
     public void clearSpans() {
         for (int i = mSpanCount - 1; i >= 0; i--) {
@@ -257,45 +257,50 @@
         return append(String.valueOf(text));
     }
 
-    private void change(int start, int end, CharSequence tb, int tbstart, int tbend) {
-        checkRange("replace", start, end);
+    private void change(int start, int end, CharSequence cs, int csStart, int csEnd) {
+        // Can be negative
+        final int nbNewChars = (csEnd - csStart) - (end - start);
 
         for (int i = mSpanCount - 1; i >= 0; i--) {
+            int spanStart = mSpanStarts[i];
+            if (spanStart > mGapStart)
+                spanStart -= mGapLength;
+
+            int spanEnd = mSpanEnds[i];
+            if (spanEnd > mGapStart)
+                spanEnd -= mGapLength;
+
             if ((mSpanFlags[i] & SPAN_PARAGRAPH) == SPAN_PARAGRAPH) {
-                int st = mSpanStarts[i];
-                if (st > mGapStart)
-                    st -= mGapLength;
-
-                int en = mSpanEnds[i];
-                if (en > mGapStart)
-                    en -= mGapLength;
-
-                int ost = st;
-                int oen = en;
+                int ost = spanStart;
+                int oen = spanEnd;
                 int clen = length();
 
-                if (st > start && st <= end) {
-                    for (st = end; st < clen; st++)
-                        if (st > end && charAt(st - 1) == '\n')
+                if (spanStart > start && spanStart <= end) {
+                    for (spanStart = end; spanStart < clen; spanStart++)
+                        if (spanStart > end && charAt(spanStart - 1) == '\n')
                             break;
                 }
 
-                if (en > start && en <= end) {
-                    for (en = end; en < clen; en++)
-                        if (en > end && charAt(en - 1) == '\n')
+                if (spanEnd > start && spanEnd <= end) {
+                    for (spanEnd = end; spanEnd < clen; spanEnd++)
+                        if (spanEnd > end && charAt(spanEnd - 1) == '\n')
                             break;
                 }
 
-                if (st != ost || en != oen)
-                    setSpan(false, mSpans[i], st, en, mSpanFlags[i]);
+                if (spanStart != ost || spanEnd != oen)
+                    setSpan(false, mSpans[i], spanStart, spanEnd, mSpanFlags[i]);
             }
+
+            int flags = 0;
+            if (spanStart == start) flags |= SPAN_START_AT_START;
+            else if (spanStart == end + nbNewChars) flags |= SPAN_START_AT_END;
+            if (spanEnd == start) flags |= SPAN_END_AT_START;
+            else if (spanEnd == end + nbNewChars) flags |= SPAN_END_AT_END;
+            mSpanFlags[i] |= flags;
         }
 
         moveGapTo(end);
 
-        // Can be negative
-        final int nbNewChars = (tbend - tbstart) - (end - start);
-
         if (nbNewChars >= mGapLength) {
             resizeFor(mText.length + nbNewChars - mGapLength);
         }
@@ -306,7 +311,7 @@
         if (mGapLength < 1)
             new Exception("mGapLength < 1").printStackTrace();
 
-        TextUtils.getChars(tb, tbstart, tbend, mText, start);
+        TextUtils.getChars(cs, csStart, csEnd, mText, start);
 
         if (end > start) {
             // no need for span fixup on pure insertion
@@ -340,21 +345,23 @@
             }
         }
 
-        if (tb instanceof Spanned) {
-            Spanned sp = (Spanned) tb;
-            Object[] spans = sp.getSpans(tbstart, tbend, Object.class);
+        mSpanCountBeforeAdd = mSpanCount;
+
+        if (cs instanceof Spanned) {
+            Spanned sp = (Spanned) cs;
+            Object[] spans = sp.getSpans(csStart, csEnd, Object.class);
 
             for (int i = 0; i < spans.length; i++) {
                 int st = sp.getSpanStart(spans[i]);
                 int en = sp.getSpanEnd(spans[i]);
 
-                if (st < tbstart) st = tbstart;
-                if (en > tbend) en = tbend;
+                if (st < csStart) st = csStart;
+                if (en > csEnd) en = csEnd;
 
                 // Add span only if this object is not yet used as a span in this string
-                if (getSpanStart(spans[i]) < 0) {
-                        setSpan(false, spans[i], st - tbstart + start, en - tbstart + start,
-                                sp.getSpanFlags(spans[i]));
+                if (getSpanStart(spans[i]) < 0 && !(spans[i] instanceof SpanWatcher)) {
+                    setSpan(false, spans[i], st - csStart + start, en - csStart + start,
+                            sp.getSpanFlags(spans[i]));
                 }
             }
         }
@@ -390,6 +397,8 @@
     // Documentation from interface
     public SpannableStringBuilder replace(final int start, final int end,
             CharSequence tb, int tbstart, int tbend) {
+        checkRange("replace", start, end);
+
         int filtercount = mFilters.length;
         for (int i = 0; i < filtercount; i++) {
             CharSequence repl = mFilters[i].filter(tb, tbstart, tbend, this, start, end);
@@ -404,10 +413,6 @@
         final int origLen = end - start;
         final int newLen = tbend - tbstart;
 
-        if (origLen == 0 && newLen == 0) {
-            return this;
-        }
-
         TextWatcher[] textWatchers = getSpans(start, start + origLen, TextWatcher.class);
         sendBeforeTextChanged(textWatchers, start, origLen, newLen);
 
@@ -415,43 +420,101 @@
         // a text replacement. If replaced or replacement text length is zero, this
         // is already taken care of.
         boolean adjustSelection = origLen != 0 && newLen != 0;
-        int selstart = 0;
-        int selend = 0;
+        int selectionStart = 0;
+        int selectionEnd = 0;
         if (adjustSelection) {
-            selstart = Selection.getSelectionStart(this);
-            selend = Selection.getSelectionEnd(this);
+            selectionStart = Selection.getSelectionStart(this);
+            selectionEnd = Selection.getSelectionEnd(this);
         }
 
-        checkRange("replace", start, end);
-
         change(start, end, tb, tbstart, tbend);
 
         if (adjustSelection) {
-            if (selstart > start && selstart < end) {
-                long off = selstart - start;
+            if (selectionStart > start && selectionStart < end) {
+                final int offset = (selectionStart - start) * newLen / origLen;
+                selectionStart = start + offset;
 
-                off = off * newLen / origLen;
-                selstart = (int) off + start;
-
-                setSpan(false, Selection.SELECTION_START, selstart, selstart,
+                setSpan(false, Selection.SELECTION_START, selectionStart, selectionStart,
                         Spanned.SPAN_POINT_POINT);
             }
-            if (selend > start && selend < end) {
-                long off = selend - start;
+            if (selectionEnd > start && selectionEnd < end) {
+                final int offset = (selectionEnd - start) * newLen / origLen;
+                selectionEnd = start + offset;
 
-                off = off * newLen / origLen;
-                selend = (int) off + start;
-
-                setSpan(false, Selection.SELECTION_END, selend, selend, Spanned.SPAN_POINT_POINT);
+                setSpan(false, Selection.SELECTION_END, selectionEnd, selectionEnd,
+                        Spanned.SPAN_POINT_POINT);
             }
         }
 
         sendTextChanged(textWatchers, start, origLen, newLen);
         sendAfterTextChanged(textWatchers);
 
+        // Span watchers need to be called after text watchers, which may update the layout
+        sendToSpanWatchers(start, end, newLen - origLen);
+
         return this; 
     }
 
+    private void sendToSpanWatchers(int replaceStart, int replaceEnd, int nbNewChars) {
+        for (int i = 0; i < mSpanCountBeforeAdd; i++) {
+            int spanStart = mSpanStarts[i];
+            int spanEnd = mSpanEnds[i];
+            if (spanStart > mGapStart) spanStart -= mGapLength;
+            if (spanEnd > mGapStart) spanEnd -= mGapLength;
+            int spanFlags = mSpanFlags[i];
+
+            int newReplaceEnd = replaceEnd + nbNewChars;
+            boolean spanChanged = false;
+            int previousSpanStart = spanStart;
+            if (spanStart > newReplaceEnd) {
+                if (nbNewChars != 0) {
+                    previousSpanStart -= nbNewChars;
+                    spanChanged = true;
+                }
+            } else if (spanStart >= replaceStart) {
+                // No change if span start was already at replace interval boundaries before replace
+                if ((spanStart != replaceStart ||
+                        ((spanFlags & SPAN_START_AT_START) != SPAN_START_AT_START)) &&
+                        (spanStart != newReplaceEnd ||
+                        ((spanFlags & SPAN_START_AT_END) != SPAN_START_AT_END))) {
+                    // TODO previousSpanStart is incorrect, but we would need to save all the
+                    // previous spans' positions before replace to provide it
+                    spanChanged = true;
+                }
+            }
+            int previousSpanEnd = spanEnd;
+            if (spanEnd > newReplaceEnd) {
+                if (nbNewChars != 0) {
+                    previousSpanEnd -= nbNewChars;
+                    spanChanged = true;
+                }
+            } else if (spanEnd >= replaceStart) {
+                // No change if span start was already at replace interval boundaries before replace
+                if ((spanEnd != replaceStart ||
+                        ((spanFlags & SPAN_END_AT_START) != SPAN_END_AT_START)) &&
+                        (spanEnd != newReplaceEnd ||
+                        ((spanFlags & SPAN_END_AT_END) != SPAN_END_AT_END))) {
+                    // TODO same as above for previousSpanEnd
+                    spanChanged = true;
+                }
+            }
+
+            if (spanChanged) {
+                sendSpanChanged(mSpans[i], previousSpanStart, previousSpanEnd, spanStart, spanEnd);
+            }
+            mSpanFlags[i] &= ~SPAN_START_END_MASK;
+        }
+
+        // The spans starting at mIntermediateSpanCount were added from the replacement text
+        for (int i = mSpanCountBeforeAdd; i < mSpanCount; i++) {
+            int spanStart = mSpanStarts[i];
+            int spanEnd = mSpanEnds[i];
+            if (spanStart > mGapStart) spanStart -= mGapLength;
+            if (spanEnd > mGapStart) spanEnd -= mGapLength;
+            sendSpanAdded(mSpans[i], spanStart, spanEnd);
+        }
+    }
+
     /**
      * Mark the specified range of text with the specified object.
      * The flags determine how the span will behave when text is
@@ -788,13 +851,12 @@
         if (end <= mGapStart) {
             System.arraycopy(mText, start, dest, destoff, end - start);
         } else if (start >= mGapStart) {
-            System.arraycopy(mText, start + mGapLength,
-                             dest, destoff, end - start);
+            System.arraycopy(mText, start + mGapLength, dest, destoff, end - start);
         } else {
             System.arraycopy(mText, start, dest, destoff, mGapStart - start);
             System.arraycopy(mText, mGapStart + mGapLength,
-                             dest, destoff + (mGapStart - start),
-                             end - mGapStart);
+                    dest, destoff + (mGapStart - start),
+                    end - mGapStart);
         }
     }
 
@@ -863,12 +925,14 @@
         }
     }
 
-    private void sendSpanChanged(Object what, int s, int e, int st, int en) {
-        SpanWatcher[] recip = getSpans(Math.min(s, st), Math.max(e, en), SpanWatcher.class);
-        int n = recip.length;
-
+    private void sendSpanChanged(Object what, int oldStart, int oldEnd, int start, int end) {
+        // The bounds of a possible SpanWatcher are guaranteed to be set before this method is
+        // called, so that the order of the span does not affect this broadcast.
+        SpanWatcher[] spanWatchers = getSpans(Math.min(oldStart, start),
+                Math.min(Math.max(oldEnd, end), length()), SpanWatcher.class);
+        int n = spanWatchers.length;
         for (int i = 0; i < n; i++) {
-            recip[i].onSpanChanged(this, what, s, e, st, en);
+            spanWatchers[i].onSpanChanged(this, what, oldStart, oldEnd, start, end);
         }
     }
 
@@ -879,26 +943,23 @@
     private void checkRange(final String operation, int start, int end) {
         if (end < start) {
             throw new IndexOutOfBoundsException(operation + " " +
-                                                region(start, end) +
-                                                " has end before start");
+                    region(start, end) + " has end before start");
         }
 
         int len = length();
 
         if (start > len || end > len) {
             throw new IndexOutOfBoundsException(operation + " " +
-                                                region(start, end) +
-                                                " ends beyond length " + len);
+                    region(start, end) + " ends beyond length " + len);
         }
 
         if (start < 0 || end < 0) {
             throw new IndexOutOfBoundsException(operation + " " +
-                                                region(start, end) +
-                                                " starts before 0");
+                    region(start, end) + " starts before 0");
         }
     }
 
-/*
+    /*
     private boolean isprint(char c) { // XXX
         if (c >= ' ' && c <= '~')
             return true;
@@ -977,7 +1038,7 @@
 
         System.out.print("\n");
     }
-*/
+     */
 
     /**
      * Don't call this yourself -- exists for Canvas to use internally.
@@ -1023,7 +1084,7 @@
         }
     }
 
-   /**
+    /**
      * Don't call this yourself -- exists for Paint to use internally.
      * {@hide}
      */
@@ -1059,8 +1120,7 @@
         if (end <= mGapStart) {
             ret = p.getTextWidths(mText, start, end - start, widths);
         } else if (start >= mGapStart) {
-            ret = p.getTextWidths(mText, start + mGapLength, end - start,
-                                  widths);
+            ret = p.getTextWidths(mText, start + mGapLength, end - start, widths);
         } else {
             char[] buf = TextUtils.obtain(end - start);
 
@@ -1205,6 +1265,7 @@
     private int[] mSpanEnds;
     private int[] mSpanFlags;
     private int mSpanCount;
+    private int mSpanCountBeforeAdd;
 
     // TODO These value are tightly related to the public SPAN_MARK/POINT values in {@link Spanned}
     private static final int MARK = 1;
@@ -1214,4 +1275,11 @@
     private static final int START_MASK = 0xF0;
     private static final int END_MASK = 0x0F;
     private static final int START_SHIFT = 4;
+
+    // These bits are not (currently) used by SPANNED flags
+    private static final int SPAN_START_AT_START = 0x1000;
+    private static final int SPAN_START_AT_END = 0x2000;
+    private static final int SPAN_END_AT_START = 0x4000;
+    private static final int SPAN_END_AT_END = 0x8000;
+    private static final int SPAN_START_END_MASK = 0xF000;
 }
diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java
index 66bdc5d..27baaea 100644
--- a/core/java/android/view/WindowManagerPolicy.java
+++ b/core/java/android/view/WindowManagerPolicy.java
@@ -667,7 +667,7 @@
     /**
      * Create and return an animation to re-display a force hidden window.
      */
-    public Animation createForceHideEnterAnimation();
+    public Animation createForceHideEnterAnimation(boolean onWallpaper);
     
     /**
      * Called from the input reader thread before a key is enqueued.
diff --git a/core/java/android/webkit/WebViewClassic.java b/core/java/android/webkit/WebViewClassic.java
index 9895a87..851fd22 100644
--- a/core/java/android/webkit/WebViewClassic.java
+++ b/core/java/android/webkit/WebViewClassic.java
@@ -828,6 +828,13 @@
     // if AUTO_REDRAW_HACK is true, then the CALL key will toggle redrawing
     // the screen all-the-time. Good for profiling our drawing code
     static private final boolean AUTO_REDRAW_HACK = false;
+
+    // The rate at which edit text is scrolled in content pixels per millisecond
+    static private final float TEXT_SCROLL_RATE = 0.01f;
+
+    // The presumed scroll rate for the first scroll of edit text
+    static private final long TEXT_SCROLL_FIRST_SCROLL_MS = 16;
+
     // true means redraw the screen all-the-time. Only with AUTO_REDRAW_HACK
     private boolean mAutoRedraw;
 
@@ -853,6 +860,7 @@
     boolean mIsEditingText = false;
     ArrayList<Message> mBatchedTextChanges = new ArrayList<Message>();
     boolean mIsBatchingTextChanges = false;
+    private long mLastEditScroll = 0;
 
     private static class OnTrimMemoryListener implements ComponentCallbacks2 {
         private static OnTrimMemoryListener sInstance = null;
@@ -1037,9 +1045,6 @@
     // pages with the space bar, in pixels.
     private static final int PAGE_SCROLL_OVERLAP = 24;
 
-    // Time between successive calls to text scroll fling animation
-    private static final int TEXT_SCROLL_ANIMATION_DELAY_MS = 16;
-
     /**
      * These prevent calling requestLayout if either dimension is fixed. This
      * depends on the layout parameters and the measure specs.
@@ -1207,7 +1212,7 @@
     static final int RELOCATE_AUTO_COMPLETE_POPUP       = 146;
     static final int FOCUS_NODE_CHANGED                 = 147;
     static final int AUTOFILL_FORM                      = 148;
-    static final int ANIMATE_TEXT_SCROLL                = 149;
+    static final int SCROLL_EDIT_TEXT                   = 149;
     static final int EDIT_TEXT_SIZE_CHANGED             = 150;
     static final int SHOW_CARET_HANDLE                  = 151;
     static final int UPDATE_CONTENT_BOUNDS              = 152;
@@ -6002,9 +6007,9 @@
                     data.mNativeLayer = nativeScrollableLayer(
                             contentX, contentY, data.mNativeLayerRect, null);
                     data.mSlop = viewToContentDimension(mNavSlop);
-                    mTouchHighlightRegion.setEmpty();
+                    removeTouchHighlight();
                     if (!mBlockWebkitViewMessages) {
-                        mTouchHighlightRequested = System.currentTimeMillis();
+                        mTouchHighlightRequested = SystemClock.uptimeMillis();
                         mWebViewCore.sendMessageAtFrontOfQueue(
                                 EventHub.HIT_TEST, data);
                     }
@@ -6091,6 +6096,11 @@
                                 mSelectDraggingTextQuad.containsPoint(handleX, handleY);
                         boolean inEditBounds = mEditTextContentBounds
                                 .contains(handleX, handleY);
+                        if (mIsEditingText && !inEditBounds) {
+                            beginScrollEdit();
+                        } else {
+                            endScrollEdit();
+                        }
                         if (inCursorText || (mIsEditingText && !inEditBounds)) {
                             snapDraggingCursor();
                         }
@@ -6240,6 +6250,7 @@
                 break;
             }
             case MotionEvent.ACTION_UP: {
+                endScrollEdit();
                 if (!mConfirmMove && mIsEditingText && mSelectionStarted &&
                         mIsCaretSelection) {
                     showPasteWindow();
@@ -6335,6 +6346,86 @@
         }
     }
 
+    /**
+     * Returns the text scroll speed in content pixels per millisecond based on
+     * the touch location.
+     * @param coordinate The x or y touch coordinate in content space
+     * @param min The minimum coordinate (x or y) of the edit content bounds
+     * @param max The maximum coordinate (x or y) of the edit content bounds
+     */
+    private static float getTextScrollSpeed(int coordinate, int min, int max) {
+        if (coordinate < min) {
+            return (coordinate - min) * TEXT_SCROLL_RATE;
+        } else if (coordinate >= max) {
+            return (coordinate - max + 1) * TEXT_SCROLL_RATE;
+        } else {
+            return 0.0f;
+        }
+    }
+
+    private void beginScrollEdit() {
+        if (mLastEditScroll == 0) {
+            mLastEditScroll = SystemClock.uptimeMillis() -
+                    TEXT_SCROLL_FIRST_SCROLL_MS;
+            scrollEditWithCursor();
+        }
+    }
+
+    private void endScrollEdit() {
+        mLastEditScroll = 0;
+    }
+
+    private static int getTextScrollDelta(float speed, long deltaT) {
+        float distance = speed * deltaT;
+        int intDistance = (int)Math.floor(distance);
+        float probability = distance - intDistance;
+        if (Math.random() < probability) {
+            intDistance++;
+        }
+        return intDistance;
+    }
+    /**
+     * Scrolls edit text a distance based on the last touch point,
+     * the last scroll time, and the edit text content bounds.
+     */
+    private void scrollEditWithCursor() {
+        if (mLastEditScroll != 0) {
+            int x = viewToContentX(mLastTouchX + getScrollX() + mSelectDraggingOffset.x);
+            float scrollSpeedX = getTextScrollSpeed(x, mEditTextContentBounds.left,
+                    mEditTextContentBounds.right);
+            int y = viewToContentY(mLastTouchY + getScrollY() + mSelectDraggingOffset.y);
+            float scrollSpeedY = getTextScrollSpeed(y, mEditTextContentBounds.top,
+                    mEditTextContentBounds.bottom);
+            if (scrollSpeedX == 0.0f && scrollSpeedY == 0.0f) {
+                endScrollEdit();
+            } else {
+                long currentTime = SystemClock.uptimeMillis();
+                long timeSinceLastUpdate = currentTime - mLastEditScroll;
+                int deltaX = getTextScrollDelta(scrollSpeedX, timeSinceLastUpdate);
+                int deltaY = getTextScrollDelta(scrollSpeedY, timeSinceLastUpdate);
+                mLastEditScroll = currentTime;
+                if (deltaX == 0 && deltaY == 0) {
+                    // By probability no text scroll this time. Try again later.
+                    mPrivateHandler.sendEmptyMessageDelayed(SCROLL_EDIT_TEXT,
+                            TEXT_SCROLL_FIRST_SCROLL_MS);
+                } else {
+                    int scrollX = getTextScrollX() + deltaX;
+                    scrollX = Math.min(getMaxTextScrollX(), scrollX);
+                    scrollX = Math.max(0, scrollX);
+                    int scrollY = getTextScrollY() + deltaY;
+                    scrollY = Math.min(getMaxTextScrollY(), scrollY);
+                    scrollY = Math.max(0, scrollY);
+                    scrollEditText(scrollX, scrollY);
+                    int cursorX = mSelectDraggingCursor.x;
+                    int cursorY = mSelectDraggingCursor.y;
+                    mSelectDraggingCursor.set(x - deltaX, y - deltaY);
+                    updateWebkitSelection();
+                    mSelectDraggingCursor.set(cursorX, cursorY);
+                }
+            }
+        }
+    }
+
     private void startTouch(float x, float y, long eventTime) {
         // Remember where the motion event started
         mStartTouchX = mLastTouchX = Math.round(x);
@@ -7673,10 +7764,6 @@
                             msg.arg1, /* unused */0);
                     break;
 
-                case ANIMATE_TEXT_SCROLL:
-                    computeEditTextScroll();
-                    break;
-
                 case EDIT_TEXT_SIZE_CHANGED:
                     if (msg.arg1 == mFieldPointer) {
                         mEditTextContent.set((Rect)msg.obj);
@@ -7695,6 +7782,10 @@
                     mEditTextContentBounds.set((Rect) msg.obj);
                     break;
 
+                case SCROLL_EDIT_TEXT:
+                    scrollEditWithCursor();
+                    break;
+
                 default:
                     super.handleMessage(msg);
                     break;
@@ -7777,13 +7868,16 @@
         if (mFocusedNode.mHasFocus && mFocusedNode.mEditable) {
             return false;
         }
-        long delay = System.currentTimeMillis() - mTouchHighlightRequested;
+        long delay = SystemClock.uptimeMillis() - mTouchHighlightRequested;
         if (delay < ViewConfiguration.getTapTimeout()) {
             Rect r = mTouchHighlightRegion.getBounds();
             mWebView.postInvalidateDelayed(delay, r.left, r.top, r.right, r.bottom);
             return false;
         }
-        return true;
+        if (mInputDispatcher == null) {
+            return false;
+        }
+        return mInputDispatcher.shouldShowTapHighlight();
     }
 
 
@@ -7893,8 +7987,8 @@
                 if (viewRect.width() < getWidth() >> 1
                         || viewRect.height() < getHeight() >> 1) {
                     mTouchHighlightRegion.union(viewRect);
-                } else {
-                    Log.w(LOGTAG, "Skip the huge selection rect:"
+                } else if (DebugFlags.WEB_VIEW) {
+                    Log.d(LOGTAG, "Skip the huge selection rect:"
                             + viewRect);
                 }
             }
@@ -8005,6 +8099,7 @@
         if (isPictureAfterFirstLayout) {
             mViewManager.postReadyToDrawAll();
         }
+        scrollEditWithCursor();
     }
 
     /**
@@ -8047,13 +8142,6 @@
         invalidate();
     }
 
-    private void computeEditTextScroll() {
-        if (mEditTextScroller.computeScrollOffset()) {
-            scrollEditText(mEditTextScroller.getCurrX(),
-                    mEditTextScroller.getCurrY());
-        }
-    }
-
     private void scrollEditText(int scrollX, int scrollY) {
         // Scrollable edit text. Scroll it.
         float maxScrollX = getMaxTextScrollX();
@@ -8061,8 +8149,6 @@
         mEditTextContent.offsetTo(-scrollX, -scrollY);
         mWebViewCore.sendMessageAtFrontOfQueue(EventHub.SCROLL_TEXT_INPUT, 0,
                 scrollY, (Float)scrollPercentX);
-        mPrivateHandler.sendEmptyMessageDelayed(ANIMATE_TEXT_SCROLL,
-                TEXT_SCROLL_ANIMATION_DELAY_MS);
     }
 
     private void beginTextBatch() {
diff --git a/core/java/android/webkit/WebViewInputDispatcher.java b/core/java/android/webkit/WebViewInputDispatcher.java
index e7024d9..c8677ec 100644
--- a/core/java/android/webkit/WebViewInputDispatcher.java
+++ b/core/java/android/webkit/WebViewInputDispatcher.java
@@ -349,6 +349,12 @@
         }
     }
 
+    public boolean shouldShowTapHighlight() {
+        synchronized (mLock) {
+            return mPostLongPressScheduled || mPostClickScheduled;
+        }
+    }
+
     private void postLongPress() {
         synchronized (mLock) {
             if (!mPostLongPressScheduled) {
diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java
index 582a62f..b2321d9 100644
--- a/core/java/android/widget/NumberPicker.java
+++ b/core/java/android/widget/NumberPicker.java
@@ -579,7 +579,7 @@
             throw new IllegalArgumentException("minWidth > maxWidth");
         }
 
-        mComputeMaxWidth = (mMaxWidth == Integer.MAX_VALUE);
+        mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED);
 
         attributesArray.recycle();
 
@@ -771,6 +771,8 @@
                 mLastDownEventTime = event.getEventTime();
                 mIngonreMoveEvents = false;
                 mShowSoftInputOnTap = false;
+                // Make sure we wupport flinging inside scrollables.
+                getParent().requestDisallowInterceptTouchEvent(true);
                 if (!mFlingScroller.isFinished()) {
                     mFlingScroller.forceFinished(true);
                     mAdjustScroller.forceFinished(true);
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 879b9d2..b877071 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -549,6 +549,10 @@
     opt.optionString = heapsizeOptsBuf;
     mOptions.add(opt);
 
+    // Increase the main thread's interpreter stack size for bug 6315322.
+    opt.optionString = "-XX:mainThreadStackSize=24K";
+    mOptions.add(opt);
+
     strcpy(heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
     property_get("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf+20, "");
     if (heapgrowthlimitOptsBuf[20] != '\0') {
diff --git a/core/res/res/anim/lock_screen_behind_enter.xml b/core/res/res/anim/lock_screen_behind_enter.xml
index 4f58be4..6b06456 100644
--- a/core/res/res/anim/lock_screen_behind_enter.xml
+++ b/core/res/res/anim/lock_screen_behind_enter.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
 /*
-** Copyright 2007, The Android Open Source Project
+** Copyright 2012, 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.
@@ -18,7 +18,7 @@
 -->
 
 <set xmlns:android="http://schemas.android.com/apk/res/android"
-    android:detachWallpaper="true" android:shareInterpolator="false">
+    android:background="#ff000000" android:shareInterpolator="false">
     <scale
         android:fromXScale="0.95" android:toXScale="1.0"
         android:fromYScale="0.95" android:toYScale="1.0"
diff --git a/core/res/res/anim/lock_screen_wallpaper_behind_enter.xml b/core/res/res/anim/lock_screen_wallpaper_behind_enter.xml
new file mode 100644
index 0000000..a354fae
--- /dev/null
+++ b/core/res/res/anim/lock_screen_wallpaper_behind_enter.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2007, 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.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+    android:detachWallpaper="true" android:shareInterpolator="false">
+    <scale
+        android:fromXScale="0.95" android:toXScale="1.0"
+        android:fromYScale="0.95" android:toYScale="1.0"
+        android:pivotX="50%p" android:pivotY="50%p"
+        android:fillEnabled="true" android:fillBefore="true"
+        android:interpolator="@interpolator/decelerate_cubic"
+        android:startOffset="@android:integer/config_shortAnimTime"
+        android:duration="@android:integer/config_shortAnimTime" />
+    <alpha
+        android:fromAlpha="0.0" android:toAlpha="1.0"
+        android:fillEnabled="true" android:fillBefore="true"
+        android:interpolator="@interpolator/decelerate_quad"
+        android:startOffset="@android:integer/config_shortAnimTime"
+        android:duration="@android:integer/config_shortAnimTime"/>
+</set>
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index a769868..d7def44 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1125,6 +1125,7 @@
   <!-- From android.policy -->
   <java-symbol type="anim" name="app_starting_exit" />
   <java-symbol type="anim" name="lock_screen_behind_enter" />
+  <java-symbol type="anim" name="lock_screen_wallpaper_behind_enter" />
   <java-symbol type="anim" name="dock_top_enter" />
   <java-symbol type="anim" name="dock_top_exit" />
   <java-symbol type="anim" name="dock_bottom_enter" />
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index cd5300d..10ccb87 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -136,7 +136,6 @@
      * consumer.  This usage will cause the allocation to be created
      * read only.
      *
-     * @hide
      */
     public static final int USAGE_IO_INPUT = 0x0020;
 
@@ -145,7 +144,6 @@
      * SurfaceTexture producer.  The dimensions and format of the
      * SurfaceTexture will be forced to those of the allocation.
      *
-     * @hide
      */
     public static final int USAGE_IO_OUTPUT = 0x0040;
 
@@ -193,8 +191,8 @@
    /**
      * Get the element of the type of the Allocation.
      *
-     * @hide
-     * @return Element
+     * @return Element that describes the structure of data in the
+     *         allocation
      *
      */
     public Element getElement() {
@@ -204,8 +202,8 @@
     /**
      * Get the usage flags of the Allocation.
      *
-     * @hide
-     * @return usage
+     * @return usage flags associated with the allocation. e.g.
+     *         script, texture, etc.
      *
      */
     public int getUsage() {
@@ -215,12 +213,11 @@
     /**
      * Get the size of the Allocation in bytes.
      *
-     * @hide
-     * @return sizeInBytes
+     * @return size of the Allocation in bytes.
      *
      */
-    public int getSizeBytes() {
-        return mType.getCount() * mType.getElement().getSizeBytes();
+    public int getBytesSize() {
+        return mType.getCount() * mType.getElement().getBytesSize();
     }
 
     private void updateCacheInfo(Type t) {
@@ -362,8 +359,6 @@
      * Send a buffer to the output stream.  The contents of the
      * Allocation will be undefined after this operation.
      *
-     * @hide
-     *
      */
     public void ioSend() {
         if ((mUsage & USAGE_IO_OUTPUT) == 0) {
@@ -385,8 +380,6 @@
     /**
      * Receive the latest input into the Allocation.
      *
-     * @hide
-     *
      */
     public void ioReceive() {
         if ((mUsage & USAGE_IO_INPUT) == 0) {
@@ -424,37 +417,37 @@
                 throw new RSIllegalArgumentException("Allocation kind is " +
                                                      mType.getElement().mKind + ", type " +
                                                      mType.getElement().mType +
-                                                     " of " + mType.getElement().getSizeBytes() +
+                                                     " of " + mType.getElement().getBytesSize() +
                                                      " bytes, passed bitmap was " + bc);
             }
             break;
         case ARGB_8888:
             if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGBA) ||
-                (mType.getElement().getSizeBytes() != 4)) {
+                (mType.getElement().getBytesSize() != 4)) {
                 throw new RSIllegalArgumentException("Allocation kind is " +
                                                      mType.getElement().mKind + ", type " +
                                                      mType.getElement().mType +
-                                                     " of " + mType.getElement().getSizeBytes() +
+                                                     " of " + mType.getElement().getBytesSize() +
                                                      " bytes, passed bitmap was " + bc);
             }
             break;
         case RGB_565:
             if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGB) ||
-                (mType.getElement().getSizeBytes() != 2)) {
+                (mType.getElement().getBytesSize() != 2)) {
                 throw new RSIllegalArgumentException("Allocation kind is " +
                                                      mType.getElement().mKind + ", type " +
                                                      mType.getElement().mType +
-                                                     " of " + mType.getElement().getSizeBytes() +
+                                                     " of " + mType.getElement().getBytesSize() +
                                                      " bytes, passed bitmap was " + bc);
             }
             break;
         case ARGB_4444:
             if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGBA) ||
-                (mType.getElement().getSizeBytes() != 2)) {
+                (mType.getElement().getBytesSize() != 2)) {
                 throw new RSIllegalArgumentException("Allocation kind is " +
                                                      mType.getElement().mKind + ", type " +
                                                      mType.getElement().mType +
-                                                     " of " + mType.getElement().getSizeBytes() +
+                                                     " of " + mType.getElement().getBytesSize() +
                                                      " bytes, passed bitmap was " + bc);
             }
             break;
@@ -583,7 +576,7 @@
      */
     public void setFromFieldPacker(int xoff, FieldPacker fp) {
         mRS.validate();
-        int eSize = mType.mElement.getSizeBytes();
+        int eSize = mType.mElement.getBytesSize();
         final byte[] data = fp.getData();
 
         int count = data.length / eSize;
@@ -612,7 +605,7 @@
         }
 
         final byte[] data = fp.getData();
-        int eSize = mType.mElement.mElements[component_number].getSizeBytes();
+        int eSize = mType.mElement.mElements[component_number].getBytesSize();
         eSize *= mType.mElement.mArraySizes[component_number];
 
         if (data.length != eSize) {
@@ -665,7 +658,7 @@
      * @param d the source data array
      */
     public void copy1DRangeFromUnchecked(int off, int count, int[] d) {
-        int dataSize = mType.mElement.getSizeBytes() * count;
+        int dataSize = mType.mElement.getBytesSize() * count;
         data1DChecks(off, count, d.length * 4, dataSize);
         mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
     }
@@ -679,7 +672,7 @@
      * @param d the source data array
      */
     public void copy1DRangeFromUnchecked(int off, int count, short[] d) {
-        int dataSize = mType.mElement.getSizeBytes() * count;
+        int dataSize = mType.mElement.getBytesSize() * count;
         data1DChecks(off, count, d.length * 2, dataSize);
         mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
     }
@@ -693,7 +686,7 @@
      * @param d the source data array
      */
     public void copy1DRangeFromUnchecked(int off, int count, byte[] d) {
-        int dataSize = mType.mElement.getSizeBytes() * count;
+        int dataSize = mType.mElement.getBytesSize() * count;
         data1DChecks(off, count, d.length, dataSize);
         mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
     }
@@ -707,7 +700,7 @@
      * @param d the source data array
      */
     public void copy1DRangeFromUnchecked(int off, int count, float[] d) {
-        int dataSize = mType.mElement.getSizeBytes() * count;
+        int dataSize = mType.mElement.getBytesSize() * count;
         data1DChecks(off, count, d.length * 4, dataSize);
         mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
     }
@@ -1030,30 +1023,6 @@
     }
 
     /**
-     * @hide
-     * This API is hidden and only intended to be used for
-     * transitional purposes.
-     *
-     * @param type renderscript type describing data layout
-     * @param mips specifies desired mipmap behaviour for the
-     *             allocation
-     * @param usage bit field specifying how the allocation is
-     *              utilized
-     */
-    static public Allocation createTyped(RenderScript rs, Type type, MipmapControl mips,
-                                         int usage, int pointer) {
-        rs.validate();
-        if (type.getID(rs) == 0) {
-            throw new RSInvalidStateException("Bad Type");
-        }
-        int id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, pointer);
-        if (id == 0) {
-            throw new RSRuntimeException("Allocation creation failed.");
-        }
-        return new Allocation(id, rs, type, usage);
-    }
-
-    /**
      * Creates a renderscript allocation with the size specified by
      * the type and no mipmaps generated by default
      *
@@ -1194,8 +1163,11 @@
     }
 
     /**
+     * For allocations used with io operations, returns the handle
+     * onto a raw buffer that is being managed by the screen
+     * compositor.
      *
-     * @hide
+     * @return Surface object associated with allocation
      *
      */
     public Surface getSurface() {
@@ -1203,7 +1175,9 @@
     }
 
     /**
-     * @hide
+     * Associate a surface for io output with this allocation
+     *
+     * @param sur Surface to associate with allocation
      */
     public void setSurface(Surface sur) {
         mRS.validate();
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index d75c951..28914ce 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -85,13 +85,13 @@
     }
 
     /**
-    * @hide
     * @return element size in bytes
     */
-    public int getSizeBytes() {return mSize;}
+    public int getBytesSize() {return mSize;}
 
     /**
-    * @hide
+    * Returns the number of vector components. 2 for float2, 4 for
+    * float4, etc.
     * @return element vector size
     */
     public int getVectorSize() {return mVectorSize;}
@@ -114,10 +114,6 @@
      * RS_* objects.  32 bit opaque handles.
      */
     public enum DataType {
-        /**
-        * @hide
-        * new enum
-        */
         NONE (0, 0),
         //FLOAT_16 (1, 2),
         FLOAT_32 (2, 4),
@@ -150,7 +146,8 @@
         RS_PROGRAM_FRAGMENT (1006, 4),
         RS_PROGRAM_VERTEX (1007, 4),
         RS_PROGRAM_RASTER (1008, 4),
-        RS_PROGRAM_STORE (1009, 4);
+        RS_PROGRAM_STORE (1009, 4),
+        RS_FONT (1010, 4);
 
         int mID;
         int mSize;
@@ -201,7 +198,10 @@
     }
 
     /**
-    * @hide
+    * Elements could be simple, such as an int or a float, or a
+    * structure with multiple sub elements, such as a collection of
+    * floats, float2, float4. This function returns zero for simple
+    * elements or the number of sub-elements otherwise.
     * @return number of sub-elements in this element
     */
     public int getSubElementCount() {
@@ -212,7 +212,8 @@
     }
 
     /**
-    * @hide
+    * For complex elements, this function will return the
+    * sub-element at index
     * @param index index of the sub-element to return
     * @return sub-element in this element at given index
     */
@@ -227,7 +228,8 @@
     }
 
     /**
-    * @hide
+    * For complex elements, this function will return the
+    * sub-element name at index
     * @param index index of the sub-element
     * @return sub-element in this element at given index
     */
@@ -242,7 +244,9 @@
     }
 
     /**
-    * @hide
+    * For complex elements, some sub-elements could be statically
+    * sized arrays. This function will return the array size for
+    * sub-element at index
     * @param index index of the sub-element
     * @return array size of sub-element in this element at given index
     */
@@ -257,7 +261,8 @@
     }
 
     /**
-    * @hide
+    * This function specifies the location of a sub-element within
+    * the element
     * @param index index of the sub-element
     * @return offset in bytes of sub-element in this element at given index
     */
@@ -272,7 +277,6 @@
     }
 
     /**
-    * @hide
     * @return element data type
     */
     public DataType getDataType() {
@@ -280,7 +284,6 @@
     }
 
     /**
-    * @hide
     * @return element data kind
     */
     public DataKind getDataKind() {
@@ -455,6 +458,13 @@
         return rs.mElement_PROGRAM_STORE;
     }
 
+    public static Element FONT(RenderScript rs) {
+        if(rs.mElement_FONT == null) {
+            rs.mElement_FONT = createUser(rs, DataType.RS_FONT);
+        }
+        return rs.mElement_FONT;
+    }
+
 
     public static Element A_8(RenderScript rs) {
         if(rs.mElement_A_8 == null) {
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java
index 104d1cd..d9f64c6 100644
--- a/graphics/java/android/renderscript/Program.java
+++ b/graphics/java/android/renderscript/Program.java
@@ -78,14 +78,20 @@
     }
 
     /**
-     * @hide
+     * Program object can have zero or more constant allocations
+     * associated with it. This method returns the total count.
+     * @return number of constant input types
      */
     public int getConstantCount() {
         return mConstants != null ? mConstants.length : 0;
     }
 
     /**
-     * @hide
+     * Returns the type of the constant buffer used in the program
+     * object. It could be used to query internal elements or create
+     * an allocation to store constant data.
+     * @param slot index of the constant input type to return
+     * @return constant input type
      */
     public Type getConstant(int slot) {
         if (slot < 0 || slot >= mConstants.length) {
@@ -95,14 +101,17 @@
     }
 
     /**
-     * @hide
+     * Returns the number of textures used in this program object
+     * @return number of texture inputs
      */
     public int getTextureCount() {
         return mTextureCount;
     }
 
     /**
-     * @hide
+     * Returns the type of texture at a given slot. e.g. 2D or Cube
+     * @param slot index of the texture input
+     * @return texture input type
      */
     public TextureType getTextureType(int slot) {
         if ((slot < 0) || (slot >= mTextureCount)) {
@@ -112,7 +121,10 @@
     }
 
     /**
-     * @hide
+     * Returns the name of the texture input at a given slot. e.g.
+     * tex0, diffuse, spec
+     * @param slot index of the texture input
+     * @return texture input name
      */
     public String getTextureName(int slot) {
         if ((slot < 0) || (slot >= mTextureCount)) {
@@ -318,7 +330,6 @@
         }
 
         /**
-         * @hide
          * Adds a texture input to the Program
          *
          * @param texType describes that the texture to append it (2D,
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java
index 93ee0ce..e40751f 100644
--- a/graphics/java/android/renderscript/ProgramRaster.java
+++ b/graphics/java/android/renderscript/ProgramRaster.java
@@ -48,15 +48,16 @@
     }
 
     /**
-     * @hide
+     * Specifies whether vertices are rendered as screen aligned
+     * elements of a specified size
      * @return whether point sprites are enabled
      */
-    public boolean getPointSpriteEnabled() {
+    public boolean isPointSpriteEnabled() {
         return mPointSprite;
     }
 
     /**
-     * @hide
+     * Specifies how triangles are culled based on their orientation
      * @return cull mode
      */
     public CullMode getCullMode() {
diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java
index 677dadd..d0fd6e5 100644
--- a/graphics/java/android/renderscript/ProgramStore.java
+++ b/graphics/java/android/renderscript/ProgramStore.java
@@ -150,7 +150,8 @@
     }
 
     /**
-    * @hide
+    * Returns the function used to test writing into the depth
+    * buffer
     * @return depth function
     */
     public DepthFunc getDepthFunc() {
@@ -158,47 +159,47 @@
     }
 
     /**
-    * @hide
-    * @return whether depth writes are enabled
+    * Queries whether writes are enabled into the depth buffer
+    * @return depth mask
     */
-    public boolean getDepthMaskEnabled() {
+    public boolean isDepthMaskEnabled() {
         return mDepthMask;
     }
 
     /**
-    * @hide
+    * Queries whether red channel is written
     * @return red color channel mask
     */
-    public boolean getColorMaskREnabled() {
+    public boolean isColorMaskRedEnabled() {
         return mColorMaskR;
     }
 
     /**
-    * @hide
+    * Queries whether green channel is written
     * @return green color channel mask
     */
-    public boolean getColorMaskGEnabled() {
+    public boolean isColorMaskGreenEnabled() {
         return mColorMaskG;
     }
 
     /**
-    * @hide
+    * Queries whether blue channel is written
     * @return blue color channel mask
     */
-    public boolean getColorMaskBEnabled() {
+    public boolean isColorMaskBlueEnabled() {
         return mColorMaskB;
     }
 
     /**
-    * @hide
+    * Queries whether alpha channel is written
     * @return alpha channel mask
     */
-    public boolean getColorMaskAEnabled() {
+    public boolean isColorMaskAlphaEnabled() {
         return mColorMaskA;
     }
 
     /**
-    * @hide
+    * Specifies how the source blending factor is computed
     * @return source blend function
     */
     public BlendSrcFunc getBlendSrcFunc() {
@@ -206,7 +207,7 @@
     }
 
     /**
-    * @hide
+    * Specifies how the destination blending factor is computed
     * @return destination blend function
     */
     public BlendDstFunc getBlendDstFunc() {
@@ -214,10 +215,11 @@
     }
 
     /**
-    * @hide
+    * Specifies whether colors are dithered before writing into the
+    * framebuffer
     * @return whether dither is enabled
     */
-    public boolean getDitherEnabled() {
+    public boolean isDitherEnabled() {
         return mDither;
     }
 
diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java
index 32c908e..74d666b 100644
--- a/graphics/java/android/renderscript/ProgramVertex.java
+++ b/graphics/java/android/renderscript/ProgramVertex.java
@@ -55,14 +55,15 @@
     }
 
     /**
-     * @hide
+     * @return number of input attribute elements
      */
     public int getInputCount() {
         return mInputs != null ? mInputs.length : 0;
     }
 
     /**
-     * @hide
+     * @param slot location of the input to return
+     * @return input attribute element
      */
     public Element getInput(int slot) {
         if (slot < 0 || slot >= mInputs.length) {
diff --git a/graphics/java/android/renderscript/ProgramVertexFixedFunction.java b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java
index fac4c3d..54f21b8 100644
--- a/graphics/java/android/renderscript/ProgramVertexFixedFunction.java
+++ b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java
@@ -204,7 +204,7 @@
         public Constants(RenderScript rs) {
             Type constInputType = ProgramVertexFixedFunction.Builder.getConstantInputType(rs);
             mAlloc = Allocation.createTyped(rs, constInputType);
-            int bufferSize = constInputType.getElement().getSizeBytes()*
+            int bufferSize = constInputType.getElement().getBytesSize()*
                              constInputType.getCount();
             mIOBuffer = new FieldPacker(bufferSize);
             mModel = new Matrix4f();
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 03294b5..abbcdd9 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -664,6 +664,7 @@
     Element mElement_PROGRAM_VERTEX;
     Element mElement_PROGRAM_RASTER;
     Element mElement_PROGRAM_STORE;
+    Element mElement_FONT;
 
     Element mElement_A_8;
     Element mElement_RGB_565;
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index 0a3c91d..0df1012 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -59,7 +59,6 @@
     }
 
     /**
-     * @hide
      * @return minification setting for the sampler
      */
     public Value getMinification() {
@@ -67,7 +66,6 @@
     }
 
     /**
-     * @hide
      * @return magnification setting for the sampler
      */
     public Value getMagnification() {
@@ -75,7 +73,6 @@
     }
 
     /**
-     * @hide
      * @return S wrapping mode for the sampler
      */
     public Value getWrapS() {
@@ -83,7 +80,6 @@
     }
 
     /**
-     * @hide
      * @return T wrapping mode for the sampler
      */
     public Value getWrapT() {
@@ -91,7 +87,6 @@
     }
 
     /**
-     * @hide
      * @return anisotropy setting for the sampler
      */
     public float getAnisotropy() {
@@ -288,7 +283,7 @@
 
         public Sampler create() {
             mRS.validate();
-            int id = mRS.nSamplerCreate(mMag.mID, mMin.mID, 
+            int id = mRS.nSamplerCreate(mMag.mID, mMin.mID,
                                         mWrapS.mID, mWrapT.mID, mWrapR.mID, mAniso);
             Sampler sampler = new Sampler(id, mRS);
             sampler.mMin = mMin;
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index 9f2bacd..3910739 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -818,7 +818,10 @@
         indent[i] = ' ';
     }
     indent[count] = '\0';
-    DISPLAY_LIST_LOGD("%sStart display list (%p, %s)", (char*) indent + 2, this, mName.string());
+    Rect* clipRect = renderer.getClipRect();
+    DISPLAY_LIST_LOGD("%sStart display list (%p, %s), clipRect: %.0f, %.f, %.0f, %.0f",
+            (char*) indent + 2, this, mName.string(), clipRect->left, clipRect->top,
+            clipRect->right, clipRect->bottom);
 #endif
 
     renderer.startMark(mName.string());
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 06928df..ebb8eb7 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -520,6 +520,7 @@
     layer->texCoords.set(0.0f, bounds.getHeight() / float(layer->getHeight()),
             bounds.getWidth() / float(layer->getWidth()), 0.0f);
     layer->setColorFilter(mColorFilter);
+    layer->setBlend(true);
 
     // Save the layer in the snapshot
     snapshot->flags |= Snapshot::kFlagIsLayer;
@@ -1058,6 +1059,10 @@
     return !mSnapshot->clipRect->isEmpty();
 }
 
+Rect* OpenGLRenderer::getClipRect() {
+    return mSnapshot->clipRect;
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // Drawing commands
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index b52d2b0..47927bb 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -101,6 +101,7 @@
     ANDROID_API const Rect& getClipBounds();
     ANDROID_API bool quickReject(float left, float top, float right, float bottom);
     virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
+    virtual Rect* getClipRect();
 
     virtual status_t drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
             Rect& dirty, int32_t flags, uint32_t level = 0);
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 9ff8ee3..0a63840 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -1628,9 +1628,10 @@
         return 0;
     }
 
-    public Animation createForceHideEnterAnimation() {
-        return AnimationUtils.loadAnimation(mContext,
-                com.android.internal.R.anim.lock_screen_behind_enter);
+    public Animation createForceHideEnterAnimation(boolean onWallpaper) {
+        return AnimationUtils.loadAnimation(mContext, onWallpaper
+                ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
+                : com.android.internal.R.anim.lock_screen_behind_enter);
     }
     
     static ITelephony getTelephonyService() {
diff --git a/services/java/com/android/server/wm/WindowAnimator.java b/services/java/com/android/server/wm/WindowAnimator.java
index e5843ad..fa009eb 100644
--- a/services/java/com/android/server/wm/WindowAnimator.java
+++ b/services/java/com/android/server/wm/WindowAnimator.java
@@ -22,6 +22,7 @@
 import com.android.internal.policy.impl.PhoneWindowManager;
 
 import java.io.PrintWriter;
+import java.util.ArrayList;
 import java.util.HashSet;
 
 /**
@@ -172,6 +173,9 @@
     private void updateWindowsAndWallpaperLocked() {
         ++mTransactionSequence;
 
+        ArrayList<WindowStateAnimator> unForceHiding = null;
+        boolean wallpaperInUnForceHiding = false;
+
         for (int i = mService.mWindows.size() - 1; i >= 0; i--) {
             WindowState win = mService.mWindows.get(i);
             WindowStateAnimator winAnimator = win.mWinAnimator;
@@ -267,13 +271,12 @@
                         if (changed) {
                             if ((mBulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0
                                     && win.isVisibleNow() /*w.isReadyForDisplay()*/) {
-                                // Assume we will need to animate.  If
-                                // we don't (because the wallpaper will
-                                // stay with the lock screen), then we will
-                                // clean up later.
-                                Animation a = mPolicy.createForceHideEnterAnimation();
-                                if (a != null) {
-                                    winAnimator.setAnimation(a);
+                                if (unForceHiding == null) {
+                                    unForceHiding = new ArrayList<WindowStateAnimator>();
+                                }
+                                unForceHiding.add(winAnimator);
+                                if ((win.mAttrs.flags&WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) {
+                                    wallpaperInUnForceHiding = true;
                                 }
                             }
                             if (mCurrentFocus == null || mCurrentFocus.mLayer < win.mLayer) {
@@ -356,6 +359,17 @@
                 }
             }
         } // end forall windows
+
+        // If we have windows that are being show due to them no longer
+        // being force-hidden, apply the appropriate animation to them.
+        if (unForceHiding != null) {
+            for (int i=unForceHiding.size()-1; i>=0; i--) {
+                Animation a = mPolicy.createForceHideEnterAnimation(wallpaperInUnForceHiding);
+                if (a != null) {
+                    unForceHiding.get(i).setAnimation(a);
+                }
+            }
+        }
     }
 
     private void testTokenMayBeDrawnLocked() {
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index f48b56d1..b0e017f 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -7894,28 +7894,6 @@
         if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper
                 + " NEW: " + mWallpaperTarget
                 + " LOWER: " + mLowerWallpaperTarget);
-        if (mLowerWallpaperTarget == null) {
-            // Whoops, we don't need a special wallpaper animation.
-            // Clear them out.
-            mAnimator.mForceHiding = false;
-            for (int i=mWindows.size()-1; i>=0; i--) {
-                WindowState w = mWindows.get(i);
-                if (w.mHasSurface) {
-                    final WindowManager.LayoutParams attrs = w.mAttrs;
-                    if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) {
-                        if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows");
-                        mAnimator.mForceHiding = true;
-                    } else if (mPolicy.canBeForceHidden(w, attrs)) {
-                        if (!w.mWinAnimator.mAnimating) {
-                            // We set the animation above so it
-                            // is not yet running.
-                            // TODO(cmautner): We lose the enter animation when this occurs.
-                            w.mWinAnimator.clearAnimation();
-                        }
-                    }
-                }
-            }
-        }
         return changes;
     }
 
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
index 98a106a0..ff7a0810 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
@@ -28,6 +28,7 @@
 import android.telephony.cdma.CdmaCellLocation;
 import android.os.AsyncResult;
 import android.os.Message;
+import android.os.SystemProperties;
 import android.provider.Telephony.Intents;
 
 import android.text.TextUtils;
@@ -370,14 +371,23 @@
             phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ALPHA,
                     ss.getOperatorAlphaLong());
 
+            String prevOperatorNumeric =
+                    SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
             operatorNumeric = ss.getOperatorNumeric();
             phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);
 
             if (operatorNumeric == null) {
+                if (DBG) {
+                    log("pollStateDone: operatorNumeric=" + operatorNumeric +
+                            " prevOperatorNumeric=" + prevOperatorNumeric +
+                            " mNeedFixZone=" + mNeedFixZone +
+                            " clear PROPERTY_OPERATOR_ISO_COUNTRY");
+                }
                 phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
                 mGotCountryCode = false;
             } else {
                 String isoCountryCode = "";
+                String mcc = operatorNumeric.substring(0, 3);
                 try {
                     isoCountryCode = MccTable.countryCodeForMcc(Integer.parseInt(operatorNumeric
                             .substring(0, 3)));
@@ -386,11 +396,20 @@
                 } catch (StringIndexOutOfBoundsException ex) {
                     loge("countryCodeForMcc error" + ex);
                 }
+                if (DBG) {
+                    log("pollStateDone: operatorNumeric=" + operatorNumeric +
+                            " prevOperatorNumeric=" + prevOperatorNumeric +
+                            " mNeedFixZone=" + mNeedFixZone +
+                            " mcc=" + mcc + " iso-cc=" + isoCountryCode);
+                }
 
                 phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY,
                         isoCountryCode);
                 mGotCountryCode = true;
-                if (mNeedFixZone) {
+
+                // Fix the time zone If the operator changed or we need to fix it because
+                // when the NITZ time came in we didn't know the country code.
+                if ( ! operatorNumeric.equals(prevOperatorNumeric) || mNeedFixZone) {
                     fixTimeZone(isoCountryCode);
                 }
             }
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
index 9f27696..b694e0a 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
@@ -866,6 +866,12 @@
         // If the offset is (0, false) and the time zone property
         // is set, use the time zone property rather than GMT.
         String zoneName = SystemProperties.get(TIMEZONE_PROPERTY);
+        if (DBG) {
+            log("fixTimeZone zoneName='" + zoneName +
+                "' mZoneOffset=" + mZoneOffset + " mZoneDst=" + mZoneDst +
+                " iso-cc='" + isoCountryCode +
+                "' iso-cc-idx=" + Arrays.binarySearch(GMT_COUNTRY_CODES, isoCountryCode));
+        }
         if ((mZoneOffset == 0) && (mZoneDst == false) && (zoneName != null)
                 && (zoneName.length() > 0)
                 && (Arrays.binarySearch(GMT_COUNTRY_CODES, isoCountryCode) < 0)) {
@@ -880,19 +886,25 @@
                 // Adjust the saved NITZ time to account for tzOffset.
                 mSavedTime = mSavedTime - tzOffset;
             }
+            if (DBG) log("fixTimeZone: using default TimeZone");
         } else if (isoCountryCode.equals("")) {
             // Country code not found. This is likely a test network.
             // Get a TimeZone based only on the NITZ parameters (best guess).
             zone = getNitzTimeZone(mZoneOffset, mZoneDst, mZoneTime);
+            if (DBG) log("fixTimeZone: using NITZ TimeZone");
         } else {
             zone = TimeUtils.getTimeZone(mZoneOffset, mZoneDst, mZoneTime, isoCountryCode);
+            if (DBG) log("fixTimeZone: using getTimeZone(off, dst, time, iso)");
         }
 
         mNeedFixZone = false;
 
         if (zone != null) {
+            log("fixTimeZone: zone != null zone.getID=" + zone.getID());
             if (getAutoTimeZone()) {
                 setAndBroadcastNetworkSetTimeZone(zone.getID());
+            } else {
+                log("fixTimeZone: zone == null");
             }
             saveNitzTimeZone(zone.getID());
         }
@@ -985,14 +997,23 @@
             phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ALPHA,
                     ss.getOperatorAlphaLong());
 
+            String prevOperatorNumeric =
+                    SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
             operatorNumeric = ss.getOperatorNumeric();
             phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);
 
             if (operatorNumeric == null) {
+                if (DBG) {
+                    log("pollStateDone: operatorNumeric=" + operatorNumeric +
+                            " prevOperatorNumeric=" + prevOperatorNumeric +
+                            " mNeedFixZone=" + mNeedFixZone +
+                            " clear PROPERTY_OPERATOR_ISO_COUNTRY");
+                }
                 phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
                 mGotCountryCode = false;
             } else {
                 String isoCountryCode = "";
+                String mcc = operatorNumeric.substring(0, 3);
                 try{
                     isoCountryCode = MccTable.countryCodeForMcc(Integer.parseInt(
                             operatorNumeric.substring(0,3)));
@@ -1001,11 +1022,20 @@
                 } catch ( StringIndexOutOfBoundsException ex) {
                     loge("pollStateDone: countryCodeForMcc error" + ex);
                 }
+                if (DBG) {
+                    log("pollStateDone: operatorNumeric=" + operatorNumeric +
+                            " prevOperatorNumeric=" + prevOperatorNumeric +
+                            " mNeedFixZone=" + mNeedFixZone +
+                            " mcc=" + mcc + " iso-cc=" + isoCountryCode);
+                }
 
                 phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY,
                         isoCountryCode);
                 mGotCountryCode = true;
-                if (mNeedFixZone) {
+
+                // Fix the time zone If the operator changed or we need to fix it because
+                // when the NITZ time came in we didn't know the country code.
+                if ( ! operatorNumeric.equals(prevOperatorNumeric) || mNeedFixZone) {
                     fixTimeZone(isoCountryCode);
                 }
             }
@@ -1316,7 +1346,6 @@
             String iso = SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY);
 
             if (zone == null) {
-
                 if (mGotCountryCode) {
                     if (iso != null && iso.length() > 0) {
                         zone = TimeUtils.getTimeZone(tzOffset, dst != 0,
@@ -1332,16 +1361,21 @@
                 }
             }
 
-            if (zone == null) {
-                // We got the time before the country, so we don't know
-                // how to identify the DST rules yet.  Save the information
-                // and hope to fix it up later.
+            if ((zone == null) || (mZoneOffset != tzOffset) || (mZoneDst != (dst != 0))){
+                // We got the time before the country or the zone has changed
+                // so we don't know how to identify the DST rules yet.  Save
+                // the information and hope to fix it up later.
 
                 mNeedFixZone = true;
                 mZoneOffset  = tzOffset;
                 mZoneDst     = dst != 0;
                 mZoneTime    = c.getTimeInMillis();
             }
+            if (DBG) {
+                log("NITZ: tzOffset=" + tzOffset + " dst=" + dst + " zone=" + zone.getID() +
+                        " iso=" + iso + " mGotCountryCode=" + mGotCountryCode +
+                        " mNeedFixZone=" + mNeedFixZone);
+            }
 
             if (zone != null) {
                 if (getAutoTimeZone()) {
@@ -1461,6 +1495,7 @@
      * @param zoneId timezone set by carrier
      */
     private void setAndBroadcastNetworkSetTimeZone(String zoneId) {
+        if (DBG) log("setAndBroadcastNetworkSetTimeZone: setTimeZone=" + zoneId);
         AlarmManager alarm =
             (AlarmManager) phone.getContext().getSystemService(Context.ALARM_SERVICE);
         alarm.setTimeZone(zoneId);
@@ -1477,6 +1512,7 @@
      * @param time time set by network
      */
     private void setAndBroadcastNetworkSetTime(long time) {
+        if (DBG) log("setAndBroadcastNetworkSetTime: time=" + time + "ms");
         SystemClock.setCurrentTimeMillis(time);
         Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIME);
         intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
index 662f1f6..c0acf5b 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
@@ -852,12 +852,16 @@
             phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ALPHA,
                 ss.getOperatorAlphaLong());
 
+            String prevOperatorNumeric =
+                    SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
             operatorNumeric = ss.getOperatorNumeric();
             phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);
 
             if (operatorNumeric == null) {
                 if (DBG) {
-                    log("pollStateDone: operatorNumeric is null:" +
+                    log("pollStateDone: operatorNumeric=" + operatorNumeric +
+                            " prevOperatorNumeric=" + prevOperatorNumeric +
+                            " mNeedFixZone=" + mNeedFixZone +
                             " clear PROPERTY_OPERATOR_ISO_COUNTRY");
                 }
                 phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
@@ -875,7 +879,9 @@
                 }
                 if (DBG) {
                     log("pollStateDone: operatorNumeric=" + operatorNumeric +
-                            " mcc=" + mcc + " iso=" + iso);
+                            " prevOperatorNumeric=" + prevOperatorNumeric +
+                            " mNeedFixZone=" + mNeedFixZone +
+                            " mcc=" + mcc + " iso-cc=" + iso);
                 }
 
                 phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso);
@@ -895,7 +901,7 @@
                     if ((uniqueZones.size() == 1) || testOneUniqueOffsetPath) {
                         zone = uniqueZones.get(0);
                         if (DBG) {
-                           log("pollStateDone: no nitz but one TZ for iso=" + iso +
+                           log("pollStateDone: no nitz but one TZ for iso-cc=" + iso +
                                    " with zone.getID=" + zone.getID() +
                                    " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath);
                         }
@@ -903,22 +909,24 @@
                     } else {
                         if (DBG) {
                             log("pollStateDone: there are " + uniqueZones.size() +
-                                " unique offsets for iso='" + iso +
+                                " unique offsets for iso-cc='" + iso +
                                 " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath +
                                 "', do nothing");
                         }
                     }
                 }
 
-                if (mNeedFixZone) {
+                // Fix the time zone If the operator changed or we need to fix it because
+                // when the NITZ time came in we didn't know the country code.
+                if ( ! operatorNumeric.equals(prevOperatorNumeric) || mNeedFixZone) {
                     // If the offset is (0, false) and the timezone property
                     // is set, use the timezone property rather than
                     // GMT.
                     String zoneName = SystemProperties.get(TIMEZONE_PROPERTY);
                     if (DBG) {
-                        log("pollStateDone: mNeedFixZone==true zoneName='" + zoneName +
+                        log("pollStateDone: fix time zone zoneName='" + zoneName +
                             "' mZoneOffset=" + mZoneOffset + " mZoneDst=" + mZoneDst +
-                            " iso='" + iso +
+                            " iso-cc='" + iso +
                             "' iso-cc-idx=" + Arrays.binarySearch(GMT_COUNTRY_CODES, iso));
                     }
                     if ((mZoneOffset == 0) && (mZoneDst == false) &&
@@ -957,15 +965,6 @@
                     } else {
                         log("pollStateDone: zone == null");
                     }
-                } else {
-                    if (DBG) {
-                        String zoneName = SystemProperties.get(TIMEZONE_PROPERTY);
-                        zone = TimeZone.getDefault();
-                        log("pollStateDone: mNeedFixZone==false zoneName='" + zoneName +
-                                "' mZoneOffset=" + mZoneOffset + " mZoneDst=" + mZoneDst +
-                                " iso='" + iso +
-                                "' iso-cc-idx=" + Arrays.binarySearch(GMT_COUNTRY_CODES, iso));
-                    }
                 }
             }
 
@@ -1442,10 +1441,10 @@
                 }
             }
 
-            if (zone == null) {
-                // We got the time before the country, so we don't know
-                // how to identify the DST rules yet.  Save the information
-                // and hope to fix it up later.
+            if ((zone == null) || (mZoneOffset != tzOffset) || (mZoneDst != (dst != 0))){
+                // We got the time before the country or the zone has changed
+                // so we don't know how to identify the DST rules yet.  Save
+                // the information and hope to fix it up later.
 
                 mNeedFixZone = true;
                 mZoneOffset  = tzOffset;
@@ -1556,6 +1555,7 @@
      * @param zoneId timezone set by carrier
      */
     private void setAndBroadcastNetworkSetTimeZone(String zoneId) {
+        if (DBG) log("setAndBroadcastNetworkSetTimeZone: setTimeZone=" + zoneId);
         AlarmManager alarm =
             (AlarmManager) phone.getContext().getSystemService(Context.ALARM_SERVICE);
         alarm.setTimeZone(zoneId);
@@ -1576,6 +1576,7 @@
      * @param time time set by network
      */
     private void setAndBroadcastNetworkSetTime(long time) {
+        if (DBG) log("setAndBroadcastNetworkSetTime: time=" + time + "ms");
         SystemClock.setCurrentTimeMillis(time);
         Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIME);
         intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_element.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_element.java
index 3e2a2ca..f52fe6f 100644
--- a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_element.java
+++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_element.java
@@ -108,7 +108,7 @@
         _RS_ASSERT("complexElemsimpleElem.getDataType() == NONE",
                    complexElem.getDataType() == DataType.NONE);
         _RS_ASSERT("complexElem.getSizeBytes() == ScriptField_ComplexStruct.Item.sizeof",
-                   complexElem.getSizeBytes() == ScriptField_ComplexStruct.Item.sizeof);
+                   complexElem.getBytesSize() == ScriptField_ComplexStruct.Item.sizeof);
 
         for (int i = 0; i < subElemCount; i ++) {
             _RS_ASSERT("complexElem.getSubElement(i) != null",
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 1de4d71..ca54ac4 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
@@ -60,13 +60,13 @@
     }
 
     private void testJavaSide(RenderScript RS) {
-        _RS_ASSERT("pointSpriteEnabled.getPointSpriteEnabled() == true",
-                    pointSpriteEnabled.getPointSpriteEnabled() == true);
+        _RS_ASSERT("pointSpriteEnabled.isPointSpriteEnabled() == true",
+                    pointSpriteEnabled.isPointSpriteEnabled() == true);
         _RS_ASSERT("pointSpriteEnabled.getCullMode() == ProgramRaster.CullMode.BACK",
                     pointSpriteEnabled.getCullMode() == ProgramRaster.CullMode.BACK);
 
-        _RS_ASSERT("cullMode.getPointSpriteEnabled() == false",
-                    cullMode.getPointSpriteEnabled() == false);
+        _RS_ASSERT("cullMode.isPointSpriteEnabled() == false",
+                    cullMode.isPointSpriteEnabled() == false);
         _RS_ASSERT("cullMode.getCullMode() == ProgramRaster.CullMode.FRONT",
                     cullMode.getCullMode() == ProgramRaster.CullMode.FRONT);
     }
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 72a401d..4410ee3 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
@@ -112,15 +112,15 @@
                      boolean B,
                      boolean A,
                      boolean dither) {
-        _RS_ASSERT("ps.getDepthMaskEnabled() == depthMask", ps.getDepthMaskEnabled() == depthMask);
+        _RS_ASSERT("ps.isDepthMaskEnabled() == depthMask", ps.isDepthMaskEnabled() == 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);
+        _RS_ASSERT("ps.isColorMaskRedEnabled() == R", ps.isColorMaskRedEnabled() == R);
+        _RS_ASSERT("ps.isColorMaskGreenEnabled() == G", ps.isColorMaskGreenEnabled() == G);
+        _RS_ASSERT("ps.isColorMaskBlueEnabled () == B", ps.isColorMaskBlueEnabled () == B);
+        _RS_ASSERT("ps.isColorMaskAlphaEnabled() == A", ps.isColorMaskAlphaEnabled() == A);
+        _RS_ASSERT("ps.isDitherEnabled() == dither", ps.isDitherEnabled() == dither);
     }
 
     void varyBuilderColorAndDither(ProgramStore.Builder pb,