Merge "To remove log spam in the Forward Lock DRM plugin. Fix for bug 4619159."
diff --git a/api/current.txt b/api/current.txt
index 569b206..0116ad3 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -5821,6 +5821,8 @@
     field public static final java.lang.String FEATURE_LOCATION_NETWORK = "android.hardware.location.network";
     field public static final java.lang.String FEATURE_MICROPHONE = "android.hardware.microphone";
     field public static final java.lang.String FEATURE_NFC = "android.hardware.nfc";
+    field public static final java.lang.String FEATURE_SCREEN_LANDSCAPE = "android.hardware.screen.landscape";
+    field public static final java.lang.String FEATURE_SCREEN_PORTRAIT = "android.hardware.screen.portrait";
     field public static final java.lang.String FEATURE_SENSOR_ACCELEROMETER = "android.hardware.sensor.accelerometer";
     field public static final java.lang.String FEATURE_SENSOR_BAROMETER = "android.hardware.sensor.barometer";
     field public static final java.lang.String FEATURE_SENSOR_COMPASS = "android.hardware.sensor.compass";
@@ -13590,6 +13592,7 @@
 
   public class Build {
     ctor public Build();
+    method public static java.lang.String getRadioVersion();
     field public static final java.lang.String BOARD;
     field public static final java.lang.String BOOTLOADER;
     field public static final java.lang.String BRAND;
@@ -13604,7 +13607,7 @@
     field public static final java.lang.String MANUFACTURER;
     field public static final java.lang.String MODEL;
     field public static final java.lang.String PRODUCT;
-    field public static final java.lang.String RADIO;
+    field public static final deprecated java.lang.String RADIO;
     field public static final java.lang.String SERIAL;
     field public static final java.lang.String TAGS;
     field public static final long TIME;
@@ -16497,6 +16500,7 @@
     method public void copy1DRangeFrom(int, int, short[]);
     method public void copy1DRangeFrom(int, int, byte[]);
     method public void copy1DRangeFrom(int, int, float[]);
+    method public void copy1DRangeFrom(int, int, android.renderscript.Allocation, int);
     method public void copy1DRangeFromUnchecked(int, int, int[]);
     method public void copy1DRangeFromUnchecked(int, int, short[]);
     method public void copy1DRangeFromUnchecked(int, int, byte[]);
@@ -16505,6 +16509,7 @@
     method public void copy2DRangeFrom(int, int, int, int, short[]);
     method public void copy2DRangeFrom(int, int, int, int, int[]);
     method public void copy2DRangeFrom(int, int, int, int, float[]);
+    method public void copy2DRangeFrom(int, int, int, int, android.renderscript.Allocation, int, int);
     method public void copy2DRangeFrom(int, int, android.graphics.Bitmap);
     method public void copyFrom(android.renderscript.BaseObj[]);
     method public void copyFrom(int[]);
@@ -16569,8 +16574,10 @@
     method public void subData1D(int, int, short[]);
     method public void subData1D(int, int, byte[]);
     method public void subData1D(int, int, float[]);
+    method public void subData1D(int, int, android.renderscript.AllocationAdapter, int);
     method public void subData2D(int, int, int, int, int[]);
     method public void subData2D(int, int, int, int, float[]);
+    method public void subData2D(int, int, int, int, android.renderscript.AllocationAdapter, int, int);
     method public void subElementData(int, int, android.renderscript.FieldPacker);
   }
 
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 33c2937..1cd8ec0 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -925,6 +925,26 @@
 
     /**
      * Feature for {@link #getSystemAvailableFeatures} and
+     * {@link #hasSystemFeature}: The device supports portrait orientation
+     * screens.  For backwards compatibility, you can assume that if neither
+     * this nor {@link #FEATURE_SCREEN_LANDSCAPE} is set then the device supports
+     * both portrait and landscape.
+     */
+    @SdkConstant(SdkConstantType.FEATURE)
+    public static final String FEATURE_SCREEN_PORTRAIT = "android.hardware.screen.portrait";
+
+    /**
+     * Feature for {@link #getSystemAvailableFeatures} and
+     * {@link #hasSystemFeature}: The device supports landscape orientation
+     * screens.  For backwards compatibility, you can assume that if neither
+     * this nor {@link #FEATURE_SCREEN_PORTRAIT} is set then the device supports
+     * both portrait and landscape.
+     */
+    @SdkConstant(SdkConstantType.FEATURE)
+    public static final String FEATURE_SCREEN_LANDSCAPE = "android.hardware.screen.landscape";
+
+    /**
+     * Feature for {@link #getSystemAvailableFeatures} and
      * {@link #hasSystemFeature}: The device supports live wallpapers.
      */
     @SdkConstant(SdkConstantType.FEATURE)
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index 8ff5beb..1b28aa2 100644
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -16,6 +16,8 @@
 
 package android.os;
 
+import com.android.internal.telephony.TelephonyProperties;
+
 /**
  * Information about the current build, extracted from system properties.
  */
@@ -56,8 +58,16 @@
     /** The system bootloader version number. */
     public static final String BOOTLOADER = getString("ro.bootloader");
 
-    /** The radio firmware version number. */
-    public static final String RADIO = getString("gsm.version.baseband");
+    /**
+     * The radio firmware version number.
+     *
+     * @deprecated The radio firmware version is frequently not
+     * available when this class is initialized, leading to a blank or
+     * "unknown" value for this string.  Use
+     * {@link #getRadioVersion} instead.
+     */
+    @Deprecated
+    public static final String RADIO = getString(TelephonyProperties.PROPERTY_BASEBAND_VERSION);
 
     /** The name of the hardware (from the kernel command line or /proc). */
     public static final String HARDWARE = getString("ro.hardware");
@@ -243,6 +253,26 @@
          * later.  Applications that don't support a screen size at least as
          * large as the current screen will provide the user with a UI to
          * switch them in to screen size compatibility mode.</p>
+         *
+         * <p>This version introduces new screen size resource qualifiers
+         * based on the screen size in dp: see
+         * {@link android.content.res.Configuration#screenWidthDp},
+         * {@link android.content.res.Configuration#screenHeightDp}, and
+         * {@link android.content.res.Configuration#smallestScreenWidthDp}.
+         * Supplying these in &lt;supports-screens&gt; as per
+         * {@link android.content.pm.ApplicationInfo#requiresSmallestWidthDp},
+         * {@link android.content.pm.ApplicationInfo#compatibleWidthLimitDp}, and
+         * {@link android.content.pm.ApplicationInfo#largestWidthLimitDp} is
+         * preferred over the older screen size buckets and for older devices
+         * the appropriate buckets will be inferred from them.</p>
+         *
+         * <p>New {@link android.content.pm.PackageManager#FEATURE_SCREEN_PORTRAIT}
+         * and {@link android.content.pm.PackageManager#FEATURE_SCREEN_LANDSCAPE}
+         * features are introduced in this release.  Applications that target
+         * previous platform versions are assumed to require both portrait and
+         * landscape support in the device; when targeting Honeycomb MR1 or
+         * greater the application is responsible for specifying any specific
+         * orientation it requires.</p>
          */
         public static final int HONEYCOMB_MR2 = 13;
 
@@ -266,6 +296,14 @@
     public static final String USER = getString("ro.build.user");
     public static final String HOST = getString("ro.build.host");
 
+    /**
+     * Returns the version string for the radio firmware.  May return
+     * null (if, for instance, the radio is not currently on).
+     */
+    public static String getRadioVersion() {
+        return SystemProperties.get(TelephonyProperties.PROPERTY_BASEBAND_VERSION, null);
+    }
+
     private static String getString(String property) {
         return SystemProperties.get(property, UNKNOWN);
     }
diff --git a/core/java/android/pim/RecurrenceSet.java b/core/java/android/pim/RecurrenceSet.java
index fdd0783..b7fb320 100644
--- a/core/java/android/pim/RecurrenceSet.java
+++ b/core/java/android/pim/RecurrenceSet.java
@@ -18,7 +18,7 @@
 
 import android.content.ContentValues;
 import android.database.Cursor;
-import android.provider.Calendar;
+import android.provider.CalendarContract;
 import android.text.TextUtils;
 import android.text.format.Time;
 import android.util.Log;
@@ -50,10 +50,10 @@
      */
     public RecurrenceSet(ContentValues values)
             throws EventRecurrence.InvalidFormatException {
-        String rruleStr = values.getAsString(Calendar.Events.RRULE);
-        String rdateStr = values.getAsString(Calendar.Events.RDATE);
-        String exruleStr = values.getAsString(Calendar.Events.EXRULE);
-        String exdateStr = values.getAsString(Calendar.Events.EXDATE);
+        String rruleStr = values.getAsString(CalendarContract.Events.RRULE);
+        String rdateStr = values.getAsString(CalendarContract.Events.RDATE);
+        String exruleStr = values.getAsString(CalendarContract.Events.EXRULE);
+        String exdateStr = values.getAsString(CalendarContract.Events.EXDATE);
         init(rruleStr, rdateStr, exruleStr, exdateStr);
     }
 
@@ -68,10 +68,10 @@
      */
     public RecurrenceSet(Cursor cursor)
             throws EventRecurrence.InvalidFormatException {
-        int rruleColumn = cursor.getColumnIndex(Calendar.Events.RRULE);
-        int rdateColumn = cursor.getColumnIndex(Calendar.Events.RDATE);
-        int exruleColumn = cursor.getColumnIndex(Calendar.Events.EXRULE);
-        int exdateColumn = cursor.getColumnIndex(Calendar.Events.EXDATE);
+        int rruleColumn = cursor.getColumnIndex(CalendarContract.Events.RRULE);
+        int rdateColumn = cursor.getColumnIndex(CalendarContract.Events.RDATE);
+        int exruleColumn = cursor.getColumnIndex(CalendarContract.Events.EXRULE);
+        int exdateColumn = cursor.getColumnIndex(CalendarContract.Events.EXDATE);
         String rruleStr = cursor.getString(rruleColumn);
         String rdateStr = cursor.getString(rdateColumn);
         String exruleStr = cursor.getString(exruleColumn);
@@ -208,7 +208,7 @@
             start.timezone = Time.TIMEZONE_UTC;
         }
         long millis = start.toMillis(false /* use isDst */);
-        values.put(Calendar.Events.DTSTART, millis);
+        values.put(CalendarContract.Events.DTSTART, millis);
         if (millis == -1) {
             if (false) {
                 Log.d(TAG, "DTSTART is out of range: " + component.toString());
@@ -216,13 +216,13 @@
             return false;
         }
         
-        values.put(Calendar.Events.RRULE, rrule);
-        values.put(Calendar.Events.RDATE, rdate);
-        values.put(Calendar.Events.EXRULE, exrule);
-        values.put(Calendar.Events.EXDATE, exdate);
-        values.put(Calendar.Events.EVENT_TIMEZONE, tzid);
-        values.put(Calendar.Events.DURATION, duration);
-        values.put(Calendar.Events.ALL_DAY, allDay ? 1 : 0);
+        values.put(CalendarContract.Events.RRULE, rrule);
+        values.put(CalendarContract.Events.RDATE, rdate);
+        values.put(CalendarContract.Events.EXRULE, exrule);
+        values.put(CalendarContract.Events.EXDATE, exdate);
+        values.put(CalendarContract.Events.EVENT_TIMEZONE, tzid);
+        values.put(CalendarContract.Events.DURATION, duration);
+        values.put(CalendarContract.Events.ALL_DAY, allDay ? 1 : 0);
         return true;
     }
 
@@ -230,14 +230,14 @@
     public static boolean populateComponent(Cursor cursor,
                                             ICalendar.Component component) {
         
-        int dtstartColumn = cursor.getColumnIndex(Calendar.Events.DTSTART);
-        int durationColumn = cursor.getColumnIndex(Calendar.Events.DURATION);
-        int tzidColumn = cursor.getColumnIndex(Calendar.Events.EVENT_TIMEZONE);
-        int rruleColumn = cursor.getColumnIndex(Calendar.Events.RRULE);
-        int rdateColumn = cursor.getColumnIndex(Calendar.Events.RDATE);
-        int exruleColumn = cursor.getColumnIndex(Calendar.Events.EXRULE);
-        int exdateColumn = cursor.getColumnIndex(Calendar.Events.EXDATE);
-        int allDayColumn = cursor.getColumnIndex(Calendar.Events.ALL_DAY);
+        int dtstartColumn = cursor.getColumnIndex(CalendarContract.Events.DTSTART);
+        int durationColumn = cursor.getColumnIndex(CalendarContract.Events.DURATION);
+        int tzidColumn = cursor.getColumnIndex(CalendarContract.Events.EVENT_TIMEZONE);
+        int rruleColumn = cursor.getColumnIndex(CalendarContract.Events.RRULE);
+        int rdateColumn = cursor.getColumnIndex(CalendarContract.Events.RDATE);
+        int exruleColumn = cursor.getColumnIndex(CalendarContract.Events.EXRULE);
+        int exdateColumn = cursor.getColumnIndex(CalendarContract.Events.EXDATE);
+        int allDayColumn = cursor.getColumnIndex(CalendarContract.Events.ALL_DAY);
 
 
         long dtstart = -1;
@@ -299,16 +299,16 @@
 public static boolean populateComponent(ContentValues values,
                                             ICalendar.Component component) {
         long dtstart = -1;
-        if (values.containsKey(Calendar.Events.DTSTART)) {
-            dtstart = values.getAsLong(Calendar.Events.DTSTART);
+        if (values.containsKey(CalendarContract.Events.DTSTART)) {
+            dtstart = values.getAsLong(CalendarContract.Events.DTSTART);
         }
-        String duration = values.getAsString(Calendar.Events.DURATION);
-        String tzid = values.getAsString(Calendar.Events.EVENT_TIMEZONE);
-        String rruleStr = values.getAsString(Calendar.Events.RRULE);
-        String rdateStr = values.getAsString(Calendar.Events.RDATE);
-        String exruleStr = values.getAsString(Calendar.Events.EXRULE);
-        String exdateStr = values.getAsString(Calendar.Events.EXDATE);
-        Integer allDayInteger = values.getAsInteger(Calendar.Events.ALL_DAY);
+        String duration = values.getAsString(CalendarContract.Events.DURATION);
+        String tzid = values.getAsString(CalendarContract.Events.EVENT_TIMEZONE);
+        String rruleStr = values.getAsString(CalendarContract.Events.RRULE);
+        String rdateStr = values.getAsString(CalendarContract.Events.RDATE);
+        String exruleStr = values.getAsString(CalendarContract.Events.EXRULE);
+        String exdateStr = values.getAsString(CalendarContract.Events.EXDATE);
+        Integer allDayInteger = values.getAsInteger(CalendarContract.Events.ALL_DAY);
         boolean allDay = (null != allDayInteger) ? (allDayInteger == 1) : false;
 
         if ((dtstart == -1) ||
diff --git a/core/java/android/provider/Calendar.java b/core/java/android/provider/CalendarContract.java
similarity index 99%
rename from core/java/android/provider/Calendar.java
rename to core/java/android/provider/CalendarContract.java
index 8359144..3db1827 100644
--- a/core/java/android/provider/Calendar.java
+++ b/core/java/android/provider/CalendarContract.java
@@ -84,10 +84,10 @@
  * {@link SyncState}, which contains free-form data maintained by the sync
  * adapters</li>
  * </ul>
- * 
+ *
  * @hide
  */
-public final class Calendar {
+public final class CalendarContract {
     private static final String TAG = "Calendar";
 
     /**
@@ -528,7 +528,7 @@
          */
         public static int deleteCalendarsForAccount(ContentResolver cr, Account account) {
             // delete all calendars that match this account
-            return Calendar.Calendars.delete(cr,
+            return CalendarContract.Calendars.delete(cr,
                     WHERE_DELETE_FOR_ACCOUNT,
                     new String[] { account.name, account.type });
         }
@@ -1774,7 +1774,7 @@
      * Fields and helpers for accessing reminders for an event.
      */
     public static final class Reminders implements BaseColumns, RemindersColumns, EventsColumns {
-        private static final String REMINDERS_WHERE = Calendar.Reminders.EVENT_ID + "=?";
+        private static final String REMINDERS_WHERE = CalendarContract.Reminders.EVENT_ID + "=?";
         /**
          * The projection used by the reminders query.
          */
@@ -2066,7 +2066,7 @@
             }
 
             Intent intent = new Intent(EVENT_REMINDER_ACTION);
-            intent.setData(ContentUris.withAppendedId(Calendar.CONTENT_URI, alarmTime));
+            intent.setData(ContentUris.withAppendedId(CalendarContract.CONTENT_URI, alarmTime));
             intent.putExtra(ALARM_TIME, alarmTime);
             PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
             manager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
@@ -2165,7 +2165,7 @@
          * The content:// style URI for this table
          */
         public static final Uri CONTENT_URI =
-                Uri.withAppendedPath(Calendar.CONTENT_URI, CONTENT_DIRECTORY);
+                Uri.withAppendedPath(CalendarContract.CONTENT_URI, CONTENT_DIRECTORY);
     }
 
     /**
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java
index 6c14119..00e2998 100644
--- a/core/java/android/provider/ContactsContract.java
+++ b/core/java/android/provider/ContactsContract.java
@@ -6300,9 +6300,10 @@
      * <p>
      * Example:
      * <pre>
-     * Uri uri = DataUsageFeedback.UPDATE_URI.buildUpon()
+     * Uri uri = DataUsageFeedback.FEEDBACK_URI.buildUpon()
      *         .appendPath(TextUtils.join(",", dataIds))
-     *         .appendQueryParameter(DataUsageFeedback.METHOD, DataUsageFeedback.METHOD_CALL)
+     *         .appendQueryParameter(DataUsageFeedback.USAGE_TYPE,
+     *                 DataUsageFeedback.USAGE_TYPE_CALL)
      *         .build();
      * boolean successful = resolver.update(uri, new ContentValues(), null, null) > 0;
      * </pre>
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index e3286dd..9d8d361 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -302,6 +302,9 @@
     }
 
     public void setEmbeddedTabView(ScrollingTabContainerView tabs) {
+        if (mTabScrollView != null) {
+            removeView(mTabScrollView);
+        }
         mTabScrollView = tabs;
         mIncludeTabs = tabs != null;
         if (mIncludeTabs && mNavigationMode == ActionBar.NAVIGATION_MODE_TABS) {
diff --git a/core/jni/android/graphics/ParcelSurfaceTexture.cpp b/core/jni/android/graphics/ParcelSurfaceTexture.cpp
index 517d7e2..40966e1 100644
--- a/core/jni/android/graphics/ParcelSurfaceTexture.cpp
+++ b/core/jni/android/graphics/ParcelSurfaceTexture.cpp
@@ -19,6 +19,7 @@
 #include <gui/SurfaceTextureClient.h>
 
 #include <android_runtime/AndroidRuntime.h>
+#include <android_runtime/android_graphics_SurfaceTexture.h>
 
 #include <utils/Log.h>
 
@@ -27,7 +28,6 @@
 #include "android_util_Binder.h"
 #include "jni.h"
 #include "JNIHelp.h"
-#include "SurfaceTexture.h"
 
 // ----------------------------------------------------------------------------
 
@@ -59,7 +59,7 @@
     env->SetIntField(thiz, fields.iSurfaceTexture, (int)iSurfaceTexture.get());
 }
 
-static sp<ISurfaceTexture> ParcelSurfaceTexture_getISurfaceTexture(
+sp<ISurfaceTexture> ParcelSurfaceTexture_getISurfaceTexture(
         JNIEnv* env, jobject thiz)
 {
     sp<ISurfaceTexture> iSurfaceTexture(
diff --git a/core/jni/android/graphics/SurfaceTexture.h b/core/jni/android/graphics/SurfaceTexture.h
deleted file mode 100644
index 79d8dd3..0000000
--- a/core/jni/android/graphics/SurfaceTexture.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _ANDROID_GRAPHICS_SURFACETEXTURE_H
-#define _ANDROID_GRAPHICS_SURFACETEXTURE_H
-
-#include <gui/SurfaceTexture.h>
-#include <utils/StrongPointer.h>
-#include "jni.h"
-
-namespace android {
-
-/* Gets the underlying SurfaceTexture from a SurfaceTexture Java object. */
-sp<SurfaceTexture> SurfaceTexture_getSurfaceTexture(JNIEnv* env, jobject thiz);
-
-} // namespace android
-
-#endif // _ANDROID_GRAPHICS_SURFACETEXTURE_H
diff --git a/core/tests/coretests/src/android/pim/RecurrenceSetTest.java b/core/tests/coretests/src/android/pim/RecurrenceSetTest.java
index 5d01ba0..e5ab179 100644
--- a/core/tests/coretests/src/android/pim/RecurrenceSetTest.java
+++ b/core/tests/coretests/src/android/pim/RecurrenceSetTest.java
@@ -21,7 +21,7 @@
 import android.pim.RecurrenceSet;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.util.Log;
-import android.provider.Calendar;
+import android.provider.CalendarContract;
 import junit.framework.TestCase;
 
 /**
@@ -69,14 +69,14 @@
         RecurrenceSet.populateContentValues(recurrenceComponent, values);
         Log.d("KS", "values " + values);
 
-        assertEquals(rrule, values.get(android.provider.Calendar.Events.RRULE));
-        assertEquals(rdate, values.get(android.provider.Calendar.Events.RDATE));
-        assertEquals(exrule, values.get(android.provider.Calendar.Events.EXRULE));
-        assertEquals(exdate, values.get(android.provider.Calendar.Events.EXDATE));
-        assertEquals(dtstart, (long) values.getAsLong(Calendar.Events.DTSTART));
-        assertEquals(tzid, values.get(android.provider.Calendar.Events.EVENT_TIMEZONE));
-        assertEquals(duration, values.get(android.provider.Calendar.Events.DURATION));
+        assertEquals(rrule, values.get(android.provider.CalendarContract.Events.RRULE));
+        assertEquals(rdate, values.get(android.provider.CalendarContract.Events.RDATE));
+        assertEquals(exrule, values.get(android.provider.CalendarContract.Events.EXRULE));
+        assertEquals(exdate, values.get(android.provider.CalendarContract.Events.EXDATE));
+        assertEquals(dtstart, (long) values.getAsLong(CalendarContract.Events.DTSTART));
+        assertEquals(tzid, values.get(android.provider.CalendarContract.Events.EVENT_TIMEZONE));
+        assertEquals(duration, values.get(android.provider.CalendarContract.Events.DURATION));
         assertEquals(allDay,
-                (int) values.getAsInteger(android.provider.Calendar.Events.ALL_DAY));
+                (int) values.getAsInteger(android.provider.CalendarContract.Events.ALL_DAY));
     }
 }
diff --git a/data/etc/handheld_core_hardware.xml b/data/etc/handheld_core_hardware.xml
index 7f87b79..9d2a0cb 100644
--- a/data/etc/handheld_core_hardware.xml
+++ b/data/etc/handheld_core_hardware.xml
@@ -31,6 +31,8 @@
     <feature name="android.hardware.bluetooth" />
     <feature name="android.hardware.touchscreen" />
     <feature name="android.hardware.microphone" />
+    <feature name="android.hardware.screen.portrait" />
+    <feature name="android.hardware.screen.landscape" />
     <!-- devices with GPS must include android.hardware.location.gps.xml -->
     <!-- devices with an autofocus camera and/or flash must include either
          android.hardware.camera.autofocus.xml or 
diff --git a/data/etc/tablet_core_hardware.xml b/data/etc/tablet_core_hardware.xml
index 952d0782..bf29fe4 100644
--- a/data/etc/tablet_core_hardware.xml
+++ b/data/etc/tablet_core_hardware.xml
@@ -32,6 +32,8 @@
     <feature name="android.hardware.touchscreen.multitouch" />
     <feature name="android.hardware.touchscreen.multitouch.distinct" />
     <feature name="android.hardware.microphone" />
+    <feature name="android.hardware.screen.portrait" />
+    <feature name="android.hardware.screen.landscape" />
     <!-- devices with GPS must include android.hardware.location.gps.xml -->
     <!-- devices with a rear-facing camera must include one of these as appropriate:
          android.hardware.camera.xml or 
diff --git a/docs/html/guide/topics/graphics/animation.jd b/docs/html/guide/topics/graphics/animation.jd
index 0b02ee76..31e7c4b 100644
--- a/docs/html/guide/topics/graphics/animation.jd
+++ b/docs/html/guide/topics/graphics/animation.jd
@@ -81,6 +81,12 @@
   If view animation accomplishes everything that you need to do, or if your existing code already
   works the way you want, there is no need to use the property animation system.</p>
   
+    <p class="note"><strong>Tip:</strong> To see how the ADT layout editor allows you to develop and
+preview animations in your layout, watch the <a
+href="http://www.youtube.com/watch?v=Oq05KqjXTvs&feature=player_detailpage#t=1709s">Android
+Developer Tools session</a> from Google I/O '11</p>
+
+
   <h2 id="what">What is Property Animation?</h2>
   A property animation changes a property's (a field in
   an object) value over a specified length of time. To animate something, you specify the
@@ -108,6 +114,7 @@
     default is set to  refresh every 10 ms, but the speed in which your application can refresh frames is
     ultimately dependent on how busy the system is overall and how fast the system can service the underlying timer.</li>
   </ul>
+  
 
   <h3 id="how">How the property animation system works</h3>
 
@@ -894,99 +901,5 @@
     <li>{@link android.animation.AnimatorSet} - <code>&lt;set&gt;</code></li>
   </ul>
 
-  <p>Both <code>&lt;animator&gt;</code> ({@link android.animation.ValueAnimator}) and
-  <code>&lt;objectAnimator&gt;</code> ({@link android.animation.ObjectAnimator}) have the following
-  attributes:</p>
+<p>See <a href="{@docRoot}guide/topics/resources/animation-resource.html#Property">Animation Resources</a>
 
-  <dl>
-    <dt><code>android:duration</code></dt>
-
-    <dd>The number of milliseconds that the animation runs. The default is 300 ms.</dd>
-
-    <dt><code>android:valueFrom</code> and <code>android:valueTo</code></dt>
-
-    <dd>The values being animated between. These are restricted to numbers (<code>float</code> or
-    <code>int</code>) and color values (such as #00ff00). They can be <code>float</code>, <code>int</code>, colors, 
-    or any kind of <code>Object</code> when creating animations programmatically.</dd>
-
-    <dt><code>android:valueType</code></dt>
-
-    <dd>Set to either <code>"floatType"</code> or <code>"intType"</code>. The default is 
-    <code>"floatType"</code> unless you specify something else or if the <code>valuesFrom</code>
-    and <code>valuesTo</code> values are colors.</dd>
-
-    <dt><code>android:startOffset</code></dt>
-
-    <dd>The delay, in milliseconds, before the animation begins playing (after calling {@link
-    android.animation.ValueAnimator#start start()}).</dd>
-
-    <dt><code>android:repeatCount</code></dt>
-
-    <dd>How many times to repeat an animation. Set to <code>"-1"</code> to infinitely repeat or
-    to a positive integer. For example, a value of <code>"1"</code> means that the animation is
-    repeated once after the initial run of the animation, so the animation plays a total of two
-    times. The default value is <code>"0"</code>, which means no repetition.</dd>
-
-    <dt><code>android:repeatMode</code></dt>
-
-    <dd>How an animation behaves when it reaches the end of the animation.
-    <code>android:repeatCount</code> must be set to a positive integer or <code>"-1"</code> for
-    this attribute to have an effect. Set to <code>"reverse"</code> to have the animation reverse
-    direction with each iteration or <code>"repeat"</code> to have the animation loop from the
-    beginning each time.</dd>
-  </dl>
-
-  <p>The <code>&lt;objectAnimator&gt;</code> ({@link android.animation.ObjectAnimator}) element has the
-  additional attribute <code>android:propertyName</code>, that lets you specify the name of the
-property
-  being animated. The <code>&lt;objectAnimator&gt;</code> element does not expose a <code>target</code>
-  attribute, however, so you cannot set the object to animate in the XML declaration. You have to
-  inflate the XML resource by calling {@link android.animation.AnimatorInflater#loadAnimator
-  loadAnimator()} and call {@link android.animation.ObjectAnimator#setTarget setTarget()} to set
-  the target object unlike the underlying {@link android.animation.ObjectAnimator},
-  before calling {@link android.animation.ObjectAnimator#start start()}.</p>
-
-  <p>The <code>&lt;set&gt;</code> element ({@link android.animation.AnimatorSet}) exposes a single
-  attribute, <code>android:ordering</code>. Set this attribute to <code>"together"</code> (default)
-to play
-  all the animations in this set at once. Set this attribute to <code>"sequentially"</code> to play
-  the animations in the order they are declared.</p>
-
-  <p>You can specify nested <code>&lt;set&gt;</code> elements to further group animations together.
-The
-  animations that you want to group together should be children of the <code>&lt;set&gt;</code> tag and can
-  define their own <code>ordering</code> attribute.</p>
-
-  <p>As an example, this XML code creates an {@link android.animation.AnimatorSet} object that
-  animates x and y at the same time, then runs an animation that fades an object out:</p>
-  <pre>
-&lt;set android:ordering="sequentially"&gt;
-    &lt;set&gt;
-        &lt;objectAnimator
-            android:propertyName="x"
-            android:duration="500"
-            android:valueTo="400"
-            android:valueType="int"/&gt;
-        &lt;objectAnimator
-            android:propertyName="y"
-            android:duration="500"
-            android:valueTo="300"
-            android:valueType="int"/&gt;
-    &lt;/set&gt;
-    &lt;objectAnimator
-        android:propertyName="alpha"
-        android:duration="500"
-        android:valueTo="0f"/&gt;
-&lt;/set&gt;
-</pre>
-
-  <p>In order to run this animation, you must inflate the XML resources in your code to an {@link
-  android.animation.AnimatorSet} object, and then set the target objects for all of the animations
-  before starting the animation set. Calling {@link android.animation.AnimatorSet#setTarget
-  setTarget()} sets a single target object for all children of the {@link
-  android.animation.AnimatorSet}.</p>
-
-<p class="note"><strong>Tip:</strong> To see how the ADT layout editor allows you to develop and
-preview animations in your layout, watch the <a
-href="http://www.youtube.com/watch?v=Oq05KqjXTvs&feature=player_detailpage#t=1709s">Android
-Developer Tools session</a> from Google I/O '11</p>
diff --git a/docs/html/guide/topics/resources/animation-resource.jd b/docs/html/guide/topics/resources/animation-resource.jd
index 972dd72..3df669c 100644
--- a/docs/html/guide/topics/resources/animation-resource.jd
+++ b/docs/html/guide/topics/resources/animation-resource.jd
@@ -5,28 +5,348 @@
 
 <div id="qv-wrapper">
   <div id="qv">
+   <h2>In this document</h2>
+    <ol>
+      <li><a href="#Property">Property Animation</a></li>
+      <li><a href="#View">View Animation</a>
+        <ol>
+          <li><a href="Tween">Tween animation</li>
+          <li><a href="Frame">Frame animation</li>
+        </ol>      
+      </li>
+    </ol>
     <h2>See also</h2>
     <ol>
-      <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html#tween-animation">2D
-Graphics</a></li>
+      <li><a href="{@docRoot}guide/topics/graphics/view-animation.html">View Animation</a></li>
+      <li><a href="{@docRoot}guide/topics/graphics/animation.html">Property Animation</a></li>
     </ol>
   </div>
 </div>
 
 
 <p>An animation resource can define one of two types of animations:</p>
+
 <dl>
-  <dt><a href="#Tween">Tween Animation</a></dt>
-  <dd>Creates an animation by performing a series of transformations on a single image.
-    An {@link android.view.animation.Animation}.</dd>
-  <dt><a href="#Frame">Frame Animation</a></dt>
-  <dd>Creates an animation by showing a sequence of images in order.
-    An {@link android.graphics.drawable.AnimationDrawable}.</dd>
+  <dt><a href="#Property">Property Animation</a></dt>
+  <dd>Creates an animation by modifying an object's property values over a set period
+  of time with an {@link android.animation.Animator}.</dd>
+  <dt><a href="#View">View Animation</a></dt>
+  <dd>
+  <p>There are two types of animations that you can do with the view animation framework:</p>
+  <ul>
+    <li><a href="#Tween">Tween animation</a>: Creates an animation by performing a series of transformations on a single image
+    with an {@link android.view.animation.Animation}</li>
+    <li><a href="#Frame">Frame animation</a>: or creates an animation by showing a sequence of images in order
+    with an {@link android.graphics.drawable.AnimationDrawable}.</li>
+  </ul>
+  </dd>
 </dl>
 
 
+<h2 id="Property">Property Animation</h2>
+<p>An animation defined in XML that modifies properties of the target object, such as
+background color or alpha value, over a set amount of time.</p>
 
-<h2 id="Tween">Tween Animation</h2>
+<dl class="xml">
+
+<dt>file location:</dt>
+<dd><code>res/animator/<em>filename</em>.xml</code><br/>
+The filename will be used as the resource ID.</dd>
+
+<dt>compiled resource datatype:</dt>
+<dd>Resource pointer to a {@link android.animation.ValueAnimator}, {@link android.animation.ObjectAnimator},
+or {@link android.animation.AnimatorSet}.</dd>
+
+<dt>resource reference:</dt>
+<dd>
+In Java: <code>R.animator.<em>filename</em></code><br/>
+In XML: <code>@[<em>package</em>:]animator/<em>filename</em></code>
+</dd>
+
+<dt>syntax:</dt>
+<dd>
+<pre class="stx">
+&lt;<a href="#animator-set-element">set</a>
+  android:ordering=["together" | "sequentially"]&gt;
+
+    &lt;<a href="#obj-animator-element">objectAnimator</a>
+        android:propertyName="<em>string</em>"
+        android:duration="<em>int</em>"
+        android:valueFrom="<em>float</em> | <em>int</em> | <em>color</em>"
+        android:valueTo="<em>float</em> | <em>int</em> | <em>color</em>"
+        android:startOffset="<em>int</em>"
+        android:repeatCount="<em>int</em>"
+        android:repeatMode=["repeat" | "reverse"]
+        android:valueType=["intType" | "floatType"]/&gt;
+
+    &lt;<a href="#val-animator-element">animator</a>
+        android:duration="<em>int</em>"
+        android:valueFrom="<em>float</em> | <em>int</em> | <em>color</em>"
+        android:valueTo="<em>float</em> | <em>int</em> | <em>color</em>"
+        android:startOffset="<em>int</em>"
+        android:repeatCount="<em>int</em>"
+        android:repeatMode=["repeat" | "reverse"]
+        android:valueType=["intType" | "floatType"]/&gt;
+
+    &lt;<a href="#animator-set-element">set</a>&gt;
+        ...
+    &lt;/set&gt;
+&lt;/set&gt;
+</pre>
+
+<p>The file must have a single root element: either 
+<code>&lt;set&gt;</code>, <code>&lt;objectAnimator&gt;</code>, or <code>&lt;valueAnimator&gt;</code>. You can
+group animation elements together inside the <code>&lt;set&gt;</code> element, including other
+<code>&lt;set&gt;</code> elements.
+</p>
+</dd>
+
+<dt>elements:</dt>
+  <dd>
+  <dl class="tag-list">
+    <dt id="animator-set-element"><code>&lt;set&gt;</code></dt>
+    <dd>A container that holds other animation elements (<code>&lt;objectAnimator&gt;</code>,
+    <code>&lt;valueAnimator&gt;</code>, or other <code>&lt;set&gt;</code> elements).  Represents
+    an {@link android.animation.AnimatorSet}.
+    <p>You can specify nested <code>&lt;set&gt;</code> tags to further
+    group animations together. Each <code>&lt;set&gt;</code> can define its own 
+    <code>ordering</code> attribute.</p>
+
+      <p class="caps">attributes:</p>
+      <dl class="atn-list">
+        <dt>
+          <code>android:ordering</code>
+        </dt>
+        <dd>
+          <em>Keyword</em>. Specifies the play ordering of animations in this set.
+          <table> 
+            <tr><th>Value</th><th>Description</th></tr> 
+            <tr><td><code>sequentially</code></td><td>Play animations in this set sequentially</td></tr> 
+            <tr><td><code>together</code> (default)</td><td>Play animations in this set at the same time.</td></tr> 
+          </table> 
+        </dd>
+      </dl>
+    </dd>
+
+  <dt id="obj-animator-element"><code>&lt;objectAnimator&gt;</code></dt>
+    <dd>Animates a specific property of an object over a specific amount of time. Represents
+    an {@link android.animation.ObjectAnimator}.</p>
+    
+      <p class="caps">attributes:</p>
+      <dl class="atn-list">
+        <dt>
+          <code>android:propertyName</code> 
+        </dt>
+        <dd>
+          <em>String</em>. <strong>Required</strong>. The object's property to animate, referenced by its name. For example you can specify
+          <code>"alpha"</code> or <code>"backgroundColor"</code> for a View object.
+          The <code>objectAnimator</code> element does not expose a <code>target</code>
+          attribute, however, so you cannot set the object to animate in the XML declaration. You have to
+          inflate your animation XML resource by calling {@link android.animation.AnimatorInflater#loadAnimator
+          loadAnimator()} and call {@link android.animation.ObjectAnimator#setTarget setTarget()} to set
+          the target object that contains this property.
+        </dd>
+
+        <dt>
+          <code>android:valueTo</code>
+        </dt>
+        <dd>
+          <em>float, int, or color</em>. <strong>Required</strong>. The value where the animated property ends. Colors are represented
+          as six digit hexadecimal numbers (for example, #333333).
+        </dd>
+
+        <dt>
+          <code>android:valueFrom</code>
+        </dt>
+        <dd>
+          <em>float, int, or color</em>. The value where the animated property starts. If not
+          specified, the animation starts at the value obtained by the property's get method. Colors are represented
+          as six digit hexadecimal numbers (for example, #333333).
+        </dd>
+
+        <dt>
+          <code>android:duration</code>
+        </dt>
+        <dd>
+          <em>int</em>. The time in milliseconds of the animation. 300 milliseconds is the default.
+        </dd>
+
+        <dt>
+          <code>android:startOffset</code>
+        </dt>
+        <dd>
+          <em>int</em>. The amount of milliseconds the animation delays after
+          {@link android.animation.ObjectAnimator#start start()} is called.
+        </dd>
+
+        <dt>
+          <code>android:repeatCount</code>
+        </dt>
+        <dd>
+          <em>int</em>. How many times to repeat an animation. Set to <code>"-1"</code> to infinitely
+          repeat or to a positive integer. For example, a value of <code>"1"</code> means that the animation
+          is repeated once after the initial run of the animation, so the animation plays a total
+          of two times. The default value is <code>"0"</code>, which means no repetition.
+
+        </dd>
+
+        <dt>
+          <code>android:repeatMode</code>
+        </dt>
+        <dd>
+          <em>int</em>. How an animation behaves when it reaches the end of the animation. <code>android:repeatCount</code>
+          must be set to a positive integer or <code>"-1"</code> for this attribute to have an effect. Set to <code>"reverse"</code>
+          to have the animation reverse direction with each iteration or <code>"repeat"</code> to have the animation
+          loop from the beginning each time.
+        </dd>
+
+        <dt>
+          <code>android:valueType</code>
+        </dt>
+        <dd>
+          <em>Keyword</em>. Do not specify this attribute if the value is a color. The animation framework automatically handles color
+          values
+          <table> 
+            <tr><th>Value</th><th>Description</th></tr> 
+            <tr><td><code>intType</code></td><td>Specifies that the animated values are integers</td></tr> 
+            <tr><td><code>floatType</code> (default)</td><td>Specifies that the animated values are floats</td></tr> 
+          </table> 
+        </dd>
+
+      </dl>
+    </dd>
+
+<dt id="val-animator-element"><code>&lt;animator&gt;</code></dt>
+    <dd>Animates a over a specified amount of time.
+    Represents a {@link android.animation.ValueAnimator}.
+
+      <p class="caps">attributes:</p>
+      <dl class="atn-list">
+        <dt>
+          <code>android:valueTo</code>
+        </dt>
+        <dd>
+          <em>float, int, or color</em>. <strong>Required</strong>. The value where the animation ends. Colors are represented
+          as six digit hexadecimal numbers (for example, #333333).
+        </dd>
+
+        <dt>
+          <code>android:valueFrom</code>
+        </dt>
+        <dd>
+          <em>float, int, or color</em>. <strong>Required</strong>. The value where the animation starts. Colors are represented
+          as six digit hexadecimal numbers (for example, #333333).
+        </dd>
+
+        <dt>
+          <code>android:duration</code>
+        </dt>
+        <dd>
+          <em>int</em>. The time in milliseconds of the animation. 300ms is the default.
+        </dd>
+
+        <dt>
+          <code>android:startOffset</code>
+        </dt>
+        <dd>
+          <em>int</em>. The amount of milliseconds the animation delays after
+          {@link android.animation.ValueAnimator#start start()} is called.
+        </dd>
+
+        <dt>
+          <code>android:repeatCount</code>
+        </dt>
+        <dd>
+          <em>int</em>. How many times to repeat an animation. Set to <code>"-1"</code> to infinitely
+          repeat or to a positive integer. For example, a value of <code>"1"</code> means that the animation
+          is repeated once after the initial run of the animation, so the animation plays a total
+          of two times. The default value is <code>"0"</code>, which means no repetition.
+        </dd>
+
+        <dt>
+          <code>android:repeatMode</code>
+        </dt>
+        <dd>
+          <em>int</em>. How an animation behaves when it reaches the end of the animation. <code>android:repeatCount</code>
+          must be set to a positive integer or <code>"-1"</code> for this attribute to have an effect. Set to <code>"reverse"</code>
+          to have the animation reverse direction with each iteration or <code>"repeat"</code> to have the animation
+          loop from the beginning each time.
+        </dd>
+
+        <dt>
+          <code>android:valueType</code>
+        </dt>
+        <dd>
+          <em>Keyword</em>. Do not specify this attribute if the value is a color. The animation framework automatically handles color
+          values.
+          <table> 
+            <tr><th>Value</th><th>Description</th></tr> 
+            <tr><td><code>intType</code></td><td>Specifies that the animated values are integers</td></tr> 
+            <tr><td><code>floatType</code> (default)</td><td>Specifies that the animated values are floats</td></tr> 
+          </table> 
+        </dd>
+
+      </dl>
+    </dd>
+  </dl>
+
+</dd> <!-- end  elements and attributes -->
+
+<dt>example:</dt>
+<dd>
+  <pp>XML file saved at <code>res/animator/property_animator.xml</code>:</p>
+<pre>
+&lt;set android:ordering="sequentially"&gt;
+    &lt;set&gt;
+        &lt;objectAnimator
+            android:propertyName="x"
+            android:duration="500"
+            android:valueTo="400"
+            android:valueType="intType"/&gt;
+        &lt;objectAnimator
+            android:propertyName="y"
+            android:duration="500"
+            android:valueTo="300"
+            android:valueType="intType"/&gt;
+    &lt;/set&gt;
+    &lt;objectAnimator
+        android:propertyName="alpha"
+        android:duration="500"
+        android:valueTo="1f"/&gt;
+&lt;/set&gt;
+</pre>
+  <p>In order to run this animation, you must inflate the XML resources in your code to an {@link
+  android.animation.AnimatorSet} object, and then set the target objects for all of the animations
+  before starting the animation set. Calling {@link android.animation.AnimatorSet#setTarget
+  setTarget()} sets a single target object for all children of the {@link
+  android.animation.AnimatorSet} as a convenience. The following code shows how to do this:</p>
+  
+<pre>
+AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,
+    R.anim.property_animator);
+set.setTarget(myObject);
+set.start();
+</pre>
+
+
+</dd> <!-- end example -->
+
+<dt>see also:</dt>
+<dd>
+<ul>
+  <li><a href="{@docRoot}guide/topics/graphics/animation.html">Property Animation</a></li>
+  <li><a href="http://zoso:8080/resources/samples/ApiDemos/src/com/example/android/apis/animation/index.html">API Demos</a> for examples
+  on how to use the property animation system.</li>
+</ul>
+</dd>
+
+</dl>
+
+<h2 id="View">View Animation</h2>
+The view animation framework supports both tween and frame by frame animations, which can both be declared
+in XML. The following sections describe how to use both methods.
+
+<h3 id="Tween">Tween animation</h3>
 
 <p>An animation defined in XML that performs transitions such as rotating,
 fading, moving, and stretching on a graphic.
@@ -254,18 +574,14 @@
 <dt>see also:</dt>
 <dd>
 <ul>
-  <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html#tween-animation">2D
+  <li><a href="{@docRoot}guide/topics/graphics/view-animation.html#tween-animation">2D
 Graphics: Tween Animation</a></li>
 </ul>
 </dd>
 
 </dl>
 
-
-
-
-
-<h3 id="Interpolators">Interpolators</h3>
+<h4 id="Interpolators">Interpolators</h4>
 
 <p>An interpolator is an animation modifier defined in XML that affects the rate of change in an
 animation. This allows your existing animation effects to be accelerated, decelerated, repeated,
@@ -456,22 +772,7 @@
 </dl>
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-<h2 id="Frame">Frame Animation</h2>
+<h3 id="Frame">Frame animation</h3>
 
 <p>An animation defined in XML that shows a sequence of images in order (like a film).
 </p>
@@ -562,7 +863,11 @@
   </dl>
 </dd> <!-- end example -->
 
+<dt>see also:</dt>
+<dd>
+<ul>
+  <li><a href="{@docRoot}guide/topics/graphics/view-animation.html#frame-animation">2D
+Graphics: Frame Animation</a></li>
+</ul>
+</dd>
 </dl>
-
-
-
diff --git a/docs/html/guide/topics/resources/providing-resources.jd b/docs/html/guide/topics/resources/providing-resources.jd
index 59f2e73..a996ccc 100644
--- a/docs/html/guide/topics/resources/providing-resources.jd
+++ b/docs/html/guide/topics/resources/providing-resources.jd
@@ -333,6 +333,86 @@
 indicates the current locale.</p>
       </td>
     </tr>
+    <tr id="SmallestScreenWidthQualifier">
+      <td>Smallest screen width</td>
+      <td>Examples:<br/>
+        <code>sw320dp</code><br/>
+        <code>sw600dp</code><br/>
+        <code>sw720dp</code><br/>
+        etc.
+      </td>
+      <td>
+        <p>Specifies a minimum "smallest screen width," in "dp" units, at which the resource
+          should be used.  This configuration value represents the base screen size
+          of the device, regardless of the orientation of the display.  It is based
+          on the smallest width the application will have in which to perform its
+          UI layout (in dp units) regardless of the orientation of the screen.  The
+          value here takes into account screen decorations so if the device has some
+          persistent UI elements on the left or right edge of the display it must
+          present a value here that is smaller than the real screen size, accounting
+          for these UI elements reducing the application's available space.</p>
+        <p>Some values you may use here for common screen sizes:</p>
+        <ul>
+          <li>240x320 ldpi (QVGA phone): 320
+          <li>320x480 mdpi (phone): 320
+          <li>480x800 hdpi (high density phone): 320
+          <li>480x800 mdpi (tablet/phone): 480
+          <li>600x1024 mdpi (7" tablet): 600
+          <li>720x1280 mdpi (10" tablet): 720
+        </ul>
+        <p><em>Added in API Level 13.</em></p>
+        <p>Also see the {@link android.content.res.Configuration#smallestScreenWidthDp}
+          configuration field, which holds the current smallest screen width.</p>
+      </td>
+    </tr>
+    <tr id="ScreenWidthQualifier">
+      <td>Screen width</td>
+      <td>Examples:<br/>
+        <code>w720dp</code><br/>
+        <code>w1024dp</code><br/>
+        etc.
+      </td>
+      <td>
+        <p>Specifies a minimum screen width, in "dp" units, at which the resource
+          should be used.  This configuration value will change when the orientation
+          changes between landscape and portrait to match the current actual width.
+          When multiple screen width configurations are available, the closest to
+          the current screen width will be used.  The
+          value here takes into account screen decorations so if the device has some
+          persistent UI elements on the left or right edge of the display it must
+          present a value here that is smaller than the real screen size, accounting
+          for these UI elements reducing the application's available space.</p>
+        <p><em>Added in API Level 13.</em></p>
+        <p>Also see the {@link android.content.res.Configuration#screenWidthDp}
+          configuration field, which holds the current screen width.</p>
+      </td>
+    </tr>
+    <tr id="ScreenHeightQualifier">
+      <td>Screen height</td>
+      <td>Examples:<br/>
+        <code>h720dp</code><br/>
+        <code>h1024dp</code><br/>
+        etc.
+      </td>
+      <td>
+        <p>Specifies a minimum screen height, in "dp" units, at which the resource
+          should be used.  This configuration value will change when the orientation
+          changes between landscape and portrait to match the current actual height.
+          When multiple screen height configurations are available, the closest to
+          the current screen height will be used.  The
+          value here takes into account screen decorations so if the device has some
+          persistent UI elements on the left or right edge of the display it must
+          present a value here that is smaller than the real screen size, accounting
+          for these UI elements reducing the application's available space.  Screen
+          decorations that are not fixed (such as a phone status bar that can be
+          hidden when full screen) are <em>not</em> accounted for here, nor are
+          window decorations like title bar, so applications must be prepared to
+          deal with a somewhat smaller space than they specify.
+        <p><em>Added in API Level 13.</em></p>
+        <p>Also see the {@link android.content.res.Configuration#screenHeightDp}
+          configuration field, which holds the current screen width.</p>
+      </td>
+    </tr>
     <tr id="ScreenSizeQualifier">
       <td>Screen size</td>
       <td>
@@ -392,46 +472,6 @@
 which indicates whether the screen is long.</p>
       </td>
     </tr>
-    <tr id="ScreenWidthQualifier">
-      <td>Screen width</td>
-      <td>Examples:<br/>
-        <code>w720dp</code><br/>
-        <code>w1024dp</code><br/>
-        etc.
-      </td>
-      <td>
-        <p>Specifies a minimum screen width, in "dp" units, at which the resource
-          should be used.  This configuration value will change when the orientation
-          changes between landscape and portrait to match the current actual width.
-          When multiple screen width configurations are available, the closest to
-          the current screen width will be used.  The value specified here is
-          approximate; screen decorations like a status bar or system bar may cause
-          the actual space available in your UI to be slightly smaller.
-        <p><em>Added in API Level 13.</em></p>
-        <p>Also see the {@link android.content.res.Configuration#screenWidthDp}
-          configuration field, which holds the current screen width.</p>
-      </td>
-    </tr>
-    <tr id="ScreenHeightQualifier">
-      <td>Screen height</td>
-      <td>Examples:<br/>
-        <code>h720dp</code><br/>
-        <code>h1024dp</code><br/>
-        etc.
-      </td>
-      <td>
-        <p>Specifies a minimum screen height, in "dp" units, at which the resource
-          should be used.  This configuration value will change when the orientation
-          changes between landscape and portrait to match the current actual height.
-          When multiple screen height configurations are available, the closest to
-          the current screen height will be used.  The value specified here is
-          approximate; screen decorations like a status bar or system bar may cause
-          the actual space available in your UI to be slightly smaller.
-        <p><em>Added in API Level 13.</em></p>
-        <p>Also see the {@link android.content.res.Configuration#screenHeightDp}
-          configuration field, which holds the current screen width.</p>
-      </td>
-    </tr>
     <tr id="OrientationQualifier">
       <td>Screen orientation</td>
       <td>
diff --git a/docs/html/guide/topics/usb/adk.jd b/docs/html/guide/topics/usb/adk.jd
index 8aaa65c..6f23a174 100644
--- a/docs/html/guide/topics/usb/adk.jd
+++ b/docs/html/guide/topics/usb/adk.jd
@@ -55,9 +55,7 @@
           </ol>
         </li>
       </ol>
-
       
-
       <h2>See also</h2>
 
       <ol>
@@ -68,6 +66,12 @@
       <h2>Where to buy</h2>
 
       <ol>
+      <li><a href="http://shop.moderndevice.com/products/freeduino-usb-host-board">
+        Modern Device</a></li>
+
+      <li><a href="http://www.seeedstudio.com/depot/seeeduino-adk-main-board-p-846.html">
+        Seeed Studio</a></li>
+
         <li><a href=
         "http://www.rt-net.jp/shop/index.php?main_page=product_info&cPath=3_4&products_id=1">
         RT Corp</a></li>
@@ -78,6 +82,7 @@
 
         <li><a href="https://store.diydrones.com/ProductDetails.asp?ProductCode=BR-PhoneDrone">
         DIY Drones</a></li>
+
       </ol>
     </div>
   </div>
@@ -105,13 +110,25 @@
   development boards:</p>
 
   <ul>
+    <li><a href="http://shop.moderndevice.com/products/freeduino-usb-host-board">Modern
+    Device</a> provides an Arduino-compatible board that supports the ADK firmware.</li>
+
+    <li><a href="http://www.seeedstudio.com/depot/seeeduino-adk-main-board-p-846.html">
+    Seeed Studio</a> provides an Arduino-compatible board that supports the ADK firmware.</li>
+
     <li><a href="http://www.rt-net.jp/shop/index.php?main_page=product_info&cPath=3_4&products_id=1">
     RT Corp</a> provides an Arduino-compatible board based on the Android ADK board design.</li>
+
     <li><a href="http://www.microchip.com/android">Microchip</a> provides a A PIC based USB
     microcontroller board.</li>
+
     <li><a href="https://store.diydrones.com/ProductDetails.asp?ProductCode=BR-PhoneDrone">DIY
     Drones</a> provides an Arduino-compatible board geared towards RC (radio controlled) and UAV
     (unmanned aerial vehicle) enthusiasts.</li>
+<<<<<<< HEAD
+=======
+
+>>>>>>> c38ed22... doc change: add link to seeedstudio board
   </ul>
 
   <p>We expect more hardware distributers to create a variety of kits, so please stay tuned for
@@ -122,7 +139,7 @@
   accessory that is based on the <a href="http://www.arduino.cc/">Arduino open source electronics
   prototyping platform</a>, the accessory's hardware design files, code that implements the
   accessory's firmware, and the Android application that interacts with the accessory. The hardware
-  design files and firmware code are contained in the <a href=
+  design files and firmware code are contained in the <a href=ctive 
   "https://dl-ssl.google.com/android/adk/adk_release_0512.zip">ADK package download</a>.</p>
   <p>The main hardware and software components of the ADK include:</p>
 
diff --git a/docs/html/sdk/sdk_toc.cs b/docs/html/sdk/sdk_toc.cs
index 5b90551..d02c13d 100644
--- a/docs/html/sdk/sdk_toc.cs
+++ b/docs/html/sdk/sdk_toc.cs
@@ -175,7 +175,8 @@
       <span style="display:none" class="zh-TW"></span>
     </h2>
     <ul>
-      <li><a href="<?cs var:toroot ?>sdk/ndk/index.html">Android NDK, r5b</a>
+      <li><a href="<?cs var:toroot ?>sdk/ndk/index.html">Android NDK, r5c <span
+       class="new">new!</span></a>
         </li>
       <li><a href="<?cs var:toroot ?>sdk/ndk/overview.html">What is the NDK?</a></li>
     </ul>
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 3c8aba3..a63abb9 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -588,13 +588,29 @@
      *
      * @param off The offset of the first element to be copied.
      * @param count The number of elements to be copied.
-     * @param d the source data array
+     * @param d the source data array.
      */
     public void copy1DRangeFrom(int off, int count, float[] d) {
         validateIsFloat32();
         copy1DRangeFromUnchecked(off, count, d);
     }
 
+     /**
+     * Copy part of an allocation from another allocation.
+     *
+     * @param off The offset of the first element to be copied.
+     * @param count The number of elements to be copied.
+     * @param data the source data allocation.
+     * @param dataOff off The offset of the first element in data to
+     *          be copied.
+     */
+    public void copy1DRangeFrom(int off, int count, Allocation data, int dataOff) {
+        mRS.nAllocationData2D(getID(), off, 0,
+                              0, Type.CubemapFace.POSITVE_X.mID,
+                              count, 1, data.getID(), dataOff, 0,
+                              0, Type.CubemapFace.POSITVE_X.mID);
+    }
+
     private void validate2DRange(int xoff, int yoff, int w, int h) {
         if (xoff < 0 || yoff < 0) {
             throw new RSIllegalArgumentException("Offset cannot be negative.");
@@ -609,9 +625,8 @@
     }
 
     /**
-     * Copy a rectanglular region from the array into the
-     * allocation.  The incoming array is assumed to be tightly
-     * packed.
+     * Copy a rectangular region from the array into the allocation.
+     * The incoming array is assumed to be tightly packed.
      *
      * @param xoff X offset of the region to update
      * @param yoff Y offset of the region to update
@@ -644,6 +659,28 @@
     }
 
     /**
+     * Copy a rectangular region into the allocation from another
+     * allocation.
+     *
+     * @param xoff X offset of the region to update.
+     * @param yoff Y offset of the region to update.
+     * @param w Width of the incoming region to update.
+     * @param h Height of the incoming region to update.
+     * @param data source allocation.
+     * @param dataXoff X offset in data of the region to update.
+     * @param dataYoff Y offset in data of the region to update.
+     */
+    public void copy2DRangeFrom(int xoff, int yoff, int w, int h,
+                                Allocation data, int dataXoff, int dataYoff) {
+        mRS.validate();
+        validate2DRange(xoff, yoff, w, h);
+        mRS.nAllocationData2D(getID(), xoff, yoff,
+                              0, Type.CubemapFace.POSITVE_X.mID,
+                              w, h, data.getID(), dataXoff, dataYoff,
+                              0, Type.CubemapFace.POSITVE_X.mID);
+    }
+
+    /**
      * Copy a bitmap into an allocation.  The height and width of
      * the update will use the height and width of the incoming
      * bitmap.
diff --git a/graphics/java/android/renderscript/AllocationAdapter.java b/graphics/java/android/renderscript/AllocationAdapter.java
index f2fedea..07a1f5d 100644
--- a/graphics/java/android/renderscript/AllocationAdapter.java
+++ b/graphics/java/android/renderscript/AllocationAdapter.java
@@ -33,7 +33,7 @@
     private Allocation mAlloc;
 
     private int mSelectedLOD = 0;
-    private Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITVE_X;;
+    private Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITVE_X;
 
     AllocationAdapter(int id, RenderScript rs, Allocation alloc) {
         super(id, rs, null, alloc.mUsage);
@@ -163,15 +163,54 @@
         mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
     }
 
+    /**
+     * Copy part of an allocation from another allocation.
+     *
+     * @param off The offset of the first element to be copied.
+     * @param count The number of elements to be copied.
+     * @param data the source data allocation.
+     * @param dataOff off The offset of the first element in data to
+     *          be copied.
+     */
+    public void subData1D(int off, int count, AllocationAdapter data, int dataOff) {
+        mRS.nAllocationData2D(getID(), off, 0,
+                              mSelectedLOD, mSelectedFace.mID,
+                              count, 1, data.getID(), dataOff, 0,
+                              data.mSelectedLOD, data.mSelectedFace.mID);
+    }
+
 
     public void subData2D(int xoff, int yoff, int w, int h, int[] d) {
         mRS.validate();
-        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4);
+        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+                              w, h, d, d.length * 4);
     }
 
     public void subData2D(int xoff, int yoff, int w, int h, float[] d) {
         mRS.validate();
-        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4);
+        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+                              w, h, d, d.length * 4);
+    }
+
+    /**
+     * Copy a rectangular region into the allocation from another
+     * allocation.
+     *
+     * @param xoff X offset of the region to update.
+     * @param yoff Y offset of the region to update.
+     * @param w Width of the incoming region to update.
+     * @param h Height of the incoming region to update.
+     * @param data source allocation.
+     * @param dataXoff X offset in data of the region to update.
+     * @param dataYoff Y offset in data of the region to update.
+     */
+    public void subData2D(int xoff, int yoff, int w, int h,
+                          AllocationAdapter data, int dataXoff, int dataYoff) {
+        mRS.validate();
+        mRS.nAllocationData2D(getID(), xoff, yoff,
+                              mSelectedLOD, mSelectedFace.mID,
+                              w, h, data.getID(), dataXoff, dataYoff,
+                              data.mSelectedLOD, data.mSelectedFace.mID);
     }
 
     public void readData(int[] d) {
@@ -185,12 +224,15 @@
     }
 
     public void setLOD(int lod) {
+        mSelectedLOD = lod;
     }
 
     public void setFace(Type.CubemapFace cf) {
+        mSelectedFace = cf;
     }
 
     public void setY(int y) {
+        mSelectedDimY = y;
     }
 
     public void setZ(int z) {
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 17f0fa6..2110e37 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -295,6 +295,26 @@
         rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes);
     }
 
+    native void rsnAllocationData2D(int con,
+                                    int dstAlloc, int dstXoff, int dstYoff,
+                                    int dstMip, int dstFace,
+                                    int width, int height,
+                                    int srcAlloc, int srcXoff, int srcYoff,
+                                    int srcMip, int srcFace);
+    synchronized void nAllocationData2D(int dstAlloc, int dstXoff, int dstYoff,
+                                        int dstMip, int dstFace,
+                                        int width, int height,
+                                        int srcAlloc, int srcXoff, int srcYoff,
+                                        int srcMip, int srcFace) {
+        validate();
+        rsnAllocationData2D(mContext,
+                            dstAlloc, dstXoff, dstYoff,
+                            dstMip, dstFace,
+                            width, height,
+                            srcAlloc, srcXoff, srcYoff,
+                            srcMip, srcFace);
+    }
+
     native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes);
     synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes) {
         validate();
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 60b39b0..7e53cc4 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -468,7 +468,7 @@
     bitmap.lockPixels();
     const void* ptr = bitmap.getPixels();
     rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
-                       0, RS_ALLOCATION_CUBMAP_FACE_POSITVE_X,
+                       0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
                        w, h, ptr, bitmap.getSize());
     bitmap.unlockPixels();
 }
@@ -589,6 +589,30 @@
 }
 
 static void
+nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
+                        jint dstAlloc, jint dstXoff, jint dstYoff,
+                        jint dstMip, jint dstFace,
+                        jint width, jint height,
+                        jint srcAlloc, jint srcXoff, jint srcYoff,
+                        jint srcMip, jint srcFace)
+{
+    LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff, dstYoff,"
+            " dstMip(%i), dstFace(%i), width(%i), height(%i),"
+            " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
+            con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
+            width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
+
+    rsAllocationCopy2DRange(con,
+                            (RsAllocation)dstAlloc,
+                            dstXoff, dstYoff,
+                            dstMip, dstFace,
+                            width, height,
+                            (RsAllocation)srcAlloc,
+                            srcXoff, srcYoff,
+                            srcMip, srcFace);
+}
+
+static void
 nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
 {
     jint len = _env->GetArrayLength(data);
@@ -1217,6 +1241,7 @@
 {"rsnAllocationData2D",              "(IIIIIIII[SI)V",                        (void*)nAllocationData2D_s },
 {"rsnAllocationData2D",              "(IIIIIIII[BI)V",                        (void*)nAllocationData2D_b },
 {"rsnAllocationData2D",              "(IIIIIIII[FI)V",                        (void*)nAllocationData2D_f },
+{"rsnAllocationData2D",              "(IIIIIIIIIIIII)V",                      (void*)nAllocationData2D_alloc },
 {"rsnAllocationRead",                "(II[I)V",                               (void*)nAllocationRead_i },
 {"rsnAllocationRead",                "(II[S)V",                               (void*)nAllocationRead_s },
 {"rsnAllocationRead",                "(II[B)V",                               (void*)nAllocationRead_b },
diff --git a/include/android_runtime/android_graphics_ParcelSurfaceTexture.h b/include/android_runtime/android_graphics_ParcelSurfaceTexture.h
index 22f1c12..b94ac9b 100644
--- a/include/android_runtime/android_graphics_ParcelSurfaceTexture.h
+++ b/include/android_runtime/android_graphics_ParcelSurfaceTexture.h
@@ -23,10 +23,15 @@
 
 namespace android {
 
+class ISurfaceTexture;
+
 extern sp<ANativeWindow> android_ParcelSurfaceTexture_getNativeWindow(
         JNIEnv* env, jobject thiz);
 extern bool android_ParcelSurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz);
 
+/* Gets the underlying ISurfaceTexture from a ParcelSurfaceTexture Java object. */
+extern sp<ISurfaceTexture> ParcelSurfaceTexture_getISurfaceTexture(JNIEnv* env, jobject thiz);
+
 } // namespace android
 
 #endif // _ANDROID_GRAPHICS_PARCELSURFACETEXTURE_H
diff --git a/include/android_runtime/android_graphics_SurfaceTexture.h b/include/android_runtime/android_graphics_SurfaceTexture.h
index acf1ca8..badf22c 100644
--- a/include/android_runtime/android_graphics_SurfaceTexture.h
+++ b/include/android_runtime/android_graphics_SurfaceTexture.h
@@ -23,10 +23,14 @@
 
 namespace android {
 
+class SurfaceTexture;
+
 extern sp<ANativeWindow> android_SurfaceTexture_getNativeWindow(
         JNIEnv* env, jobject thiz);
 extern bool android_SurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz);
 
+/* Gets the underlying SurfaceTexture from a SurfaceTexture Java object. */
+extern sp<SurfaceTexture> SurfaceTexture_getSurfaceTexture(JNIEnv* env, jobject thiz);
 
 } // namespace android
 
diff --git a/include/utils/RefBase.h b/include/utils/RefBase.h
index f8c3216..ca17082 100644
--- a/include/utils/RefBase.h
+++ b/include/utils/RefBase.h
@@ -119,6 +119,7 @@
     // used to override the RefBase destruction.
     class Destroyer {
         friend class RefBase;
+        friend class weakref_type;
     public:
         virtual ~Destroyer();
     private:
diff --git a/libs/gui/tests/SurfaceTextureClient_test.cpp b/libs/gui/tests/SurfaceTextureClient_test.cpp
index e1a85f3..a4c5b36 100644
--- a/libs/gui/tests/SurfaceTextureClient_test.cpp
+++ b/libs/gui/tests/SurfaceTextureClient_test.cpp
@@ -32,6 +32,7 @@
     virtual void SetUp() {
         mST = new SurfaceTexture(123);
         mSTC = new SurfaceTextureClient(mST);
+        mANW = mSTC;
 
         // We need a valid GL context so we can test updateTexImage()
         // This initializes EGL and create a dummy GL context with a
@@ -69,6 +70,8 @@
     virtual void TearDown() {
         mST.clear();
         mSTC.clear();
+        mANW.clear();
+
         eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
         eglDestroyContext(mEglDisplay, mEglContext);
         eglDestroySurface(mEglDisplay, mEglSurface);
@@ -86,6 +89,8 @@
 
     sp<SurfaceTexture> mST;
     sp<SurfaceTextureClient> mSTC;
+    sp<ANativeWindow> mANW;
+
     EGLDisplay mEglDisplay;
     EGLSurface mEglSurface;
     EGLContext mEglContext;
@@ -97,31 +102,26 @@
 }
 
 TEST_F(SurfaceTextureClientTest, QueuesToWindowCompositorIsFalse) {
-    sp<ANativeWindow> anw(mSTC);
     int result = -123;
-    int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
+    int err = mANW->query(mANW.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
             &result);
     EXPECT_EQ(NO_ERROR, err);
     EXPECT_EQ(0, result);
 }
 
 TEST_F(SurfaceTextureClientTest, ConcreteTypeIsSurfaceTextureClient) {
-    sp<ANativeWindow> anw(mSTC);
     int result = -123;
-    int err = anw->query(anw.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
+    int err = mANW->query(mANW.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
     EXPECT_EQ(NO_ERROR, err);
     EXPECT_EQ(NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT, result);
 }
 
 TEST_F(SurfaceTextureClientTest, ANativeWindowLockFails) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindow_Buffer buf;
-    ASSERT_EQ(BAD_VALUE, ANativeWindow_lock(anw.get(), &buf, NULL));
+    ASSERT_EQ(BAD_VALUE, ANativeWindow_lock(mANW.get(), &buf, NULL));
 }
 
 TEST_F(SurfaceTextureClientTest, EglCreateWindowSurfaceSucceeds) {
-    sp<ANativeWindow> anw(mSTC);
-
     EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
     ASSERT_EQ(EGL_SUCCESS, eglGetError());
     ASSERT_NE(EGL_NO_DISPLAY, dpy);
@@ -147,7 +147,7 @@
             &numConfigs));
     ASSERT_EQ(EGL_SUCCESS, eglGetError());
 
-    EGLSurface eglSurface = eglCreateWindowSurface(dpy, myConfig, anw.get(),
+    EGLSurface eglSurface = eglCreateWindowSurface(dpy, myConfig, mANW.get(),
             NULL);
     EXPECT_NE(EGL_NO_SURFACE, eglSurface);
     EXPECT_EQ(EGL_SUCCESS, eglGetError());
@@ -156,269 +156,246 @@
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometryInvalidSizesFail) {
-    sp<ANativeWindow> anw(mSTC);
-
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), -1,  0,  0));
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(),  0, -1,  0));
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(),  0,  0, -1));
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), -1, -1,  0));
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(),  0,  8,  0));
-    EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(),  8,  0,  0));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), -1,  0,  0));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(),  0, -1,  0));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(),  0,  0, -1));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(), -1, -1,  0));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(),  0,  8,  0));
+    EXPECT_GT(OK, native_window_set_buffers_geometry(mANW.get(),  8,  0,  0));
 }
 
 TEST_F(SurfaceTextureClientTest, DefaultGeometryValues) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(1, buf->width);
     EXPECT_EQ(1, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometryCanBeSet) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, PIXEL_FORMAT_RGB_565));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, PIXEL_FORMAT_RGB_565));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(16, buf->width);
     EXPECT_EQ(8, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometryDefaultSizeSetFormat) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, PIXEL_FORMAT_RGB_565));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, PIXEL_FORMAT_RGB_565));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(1, buf->width);
     EXPECT_EQ(1, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometrySetSizeDefaultFormat) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(16, buf->width);
     EXPECT_EQ(8, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometrySizeCanBeUnset) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(16, buf->width);
     EXPECT_EQ(8, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, 0));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(1, buf->width);
     EXPECT_EQ(1, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, BufferGeometrySizeCanBeChangedWithoutFormat) {
-    sp<ANativeWindow> anw(mSTC);
     ANativeWindowBuffer* buf;
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, PIXEL_FORMAT_RGB_565));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 0, 0, PIXEL_FORMAT_RGB_565));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(1, buf->width);
     EXPECT_EQ(1, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 16, 8, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(16, buf->width);
     EXPECT_EQ(8, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSize) {
-    sp<ANativeWindow> anw(mSTC);
     sp<SurfaceTexture> st(mST);
     ANativeWindowBuffer* buf;
     EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf));
     EXPECT_EQ(16, buf->width);
     EXPECT_EQ(8, buf->height);
     EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf));
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSizeAfterDequeue) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     ANativeWindowBuffer* buf[2];
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
     EXPECT_NE(buf[0], buf[1]);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
-    EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
+    EXPECT_EQ(OK, mST->setDefaultBufferSize(16, 8));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_EQ(16, buf[0]->width);
     EXPECT_EQ(16, buf[1]->width);
     EXPECT_EQ(8, buf[0]->height);
     EXPECT_EQ(8, buf[1]->height);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSizeVsGeometry) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     ANativeWindowBuffer* buf[2];
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
-    EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    EXPECT_EQ(OK, mST->setDefaultBufferSize(16, 8));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_EQ(16, buf[0]->width);
     EXPECT_EQ(16, buf[1]->width);
     EXPECT_EQ(8, buf[0]->height);
     EXPECT_EQ(8, buf[1]->height);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
-    EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 12, 24, 0));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
+    EXPECT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 12, 24, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_EQ(12, buf[0]->width);
     EXPECT_EQ(12, buf[1]->width);
     EXPECT_EQ(24, buf[0]->height);
     EXPECT_EQ(24, buf[1]->height);
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[1]));
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureTooManyUpdateTexImage) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(false));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
+    ASSERT_EQ(OK, mST->setSynchronousMode(false));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(OK, st->updateTexImage());
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(OK, mST->updateTexImage());
 
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
 
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(OK, st->updateTexImage());
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(OK, mST->updateTexImage());
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeSlowRetire) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_NE(buf[1], buf[2]);
     EXPECT_NE(buf[2], buf[0]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[0]);
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[2]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeFastRetire) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_NE(buf[1], buf[2]);
     EXPECT_NE(buf[2], buf[0]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[0]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[2]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeDQQR) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[0]);
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[0]);
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
     EXPECT_NE(buf[0], buf[1]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
     EXPECT_NE(buf[1], buf[2]);
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[2]);
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[2]);
 }
 
 // XXX: We currently have no hardware that properly handles dequeuing the
 // buffer that is currently bound to the texture.
 TEST_F(SurfaceTextureClientTest, DISABLED_SurfaceTextureSyncModeDequeueCurrent) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
     android_native_buffer_t* firstBuf;
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &firstBuf));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), firstBuf));
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), firstBuf);
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &firstBuf));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), firstBuf));
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), firstBuf);
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
     EXPECT_NE(buf[0], buf[1]);
     EXPECT_NE(buf[1], buf[2]);
     EXPECT_NE(buf[2], buf[0]);
@@ -426,41 +403,36 @@
 }
 
 TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeMinUndequeued) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
 
-    // We should be able to dequeue all the buffers before we've queued any.
-    EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+    // We should be able to dequeue all the buffers before we've queued mANWy.
+    EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
 
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[2]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[2]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
 
-    EXPECT_EQ(OK, st->updateTexImage());
-    EXPECT_EQ(st->getCurrentBuffer().get(), buf[1]);
+    EXPECT_EQ(OK, mST->updateTexImage());
+    EXPECT_EQ(mST->getCurrentBuffer().get(), buf[1]);
 
-    EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+    EXPECT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
 
     // Once we've queued a buffer, however we should not be able to dequeue more
     // than (buffer-count - MIN_UNDEQUEUED_BUFFERS), which is 2 in this case.
-    EXPECT_EQ(-EBUSY, anw->dequeueBuffer(anw.get(), &buf[1]));
+    EXPECT_EQ(-EBUSY, mANW->dequeueBuffer(mANW.get(), &buf[1]));
 
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[2]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->cancelBuffer(mANW.get(), buf[2]));
 }
 
 // XXX: This is not expected to pass until the synchronization hacks are removed
 // from the SurfaceTexture class.
 TEST_F(SurfaceTextureClientTest, DISABLED_SurfaceTextureSyncModeWaitRetire) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
-
     class MyThread : public Thread {
-        sp<SurfaceTexture> st;
+        sp<SurfaceTexture> mST;
         EGLContext ctx;
         EGLSurface sur;
         EGLDisplay dpy;
@@ -470,14 +442,14 @@
             eglMakeCurrent(dpy, sur, sur, ctx);
             usleep(20000);
             Mutex::Autolock _l(mLock);
-            st->updateTexImage();
+            mST->updateTexImage();
             mBufferRetired = true;
             eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
             return false;
         }
     public:
-        MyThread(const sp<SurfaceTexture>& st)
-            : st(st), mBufferRetired(false) {
+        MyThread(const sp<SurfaceTexture>& mST)
+            : mST(mST), mBufferRetired(false) {
             ctx = eglGetCurrentContext();
             sur = eglGetCurrentSurface(EGL_DRAW);
             dpy = eglGetCurrentDisplay();
@@ -493,37 +465,35 @@
     };
 
     android_native_buffer_t* buf[3];
-    ASSERT_EQ(OK, st->setSynchronousMode(true));
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+    ASSERT_EQ(OK, mST->setSynchronousMode(true));
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 3));
     // dequeue/queue/update so we have a current buffer
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    st->updateTexImage();
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    mST->updateTexImage();
 
-    MyThread* thread = new MyThread(st);
+    MyThread* thread = new MyThread(mST);
     sp<Thread> threadBase(thread);
 
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
     thread->run();
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
-    //ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
-    //ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[2]));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[1]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[1]));
+    //ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[2]));
+    //ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[2]));
     thread->bufferDequeued();
     thread->requestExitAndWait();
 }
 
 TEST_F(SurfaceTextureClientTest, GetTransformMatrixReturnsVerticalFlip) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
     float mtx[16] = {};
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, st->updateTexImage());
-    st->getTransformMatrix(mtx);
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mST->updateTexImage());
+    mST->getTransformMatrix(mtx);
 
     EXPECT_EQ(1.f, mtx[0]);
     EXPECT_EQ(0.f, mtx[1]);
@@ -547,16 +517,14 @@
 }
 
 TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffers) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
     float mtx[16] = {};
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, st->updateTexImage());
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 6)); // frees buffers
-    st->getTransformMatrix(mtx);
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mST->updateTexImage());
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 6)); // frees buffers
+    mST->getTransformMatrix(mtx);
 
     EXPECT_EQ(1.f, mtx[0]);
     EXPECT_EQ(0.f, mtx[1]);
@@ -580,8 +548,6 @@
 }
 
 TEST_F(SurfaceTextureClientTest, GetTransformMatrixSucceedsAfterFreeingBuffersWithCrop) {
-    sp<ANativeWindow> anw(mSTC);
-    sp<SurfaceTexture> st(mST);
     android_native_buffer_t* buf[3];
     float mtx[16] = {};
     android_native_rect_t crop;
@@ -590,14 +556,14 @@
     crop.right = 5;
     crop.bottom = 5;
 
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 4));
-    ASSERT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 8, 8, 0));
-    ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
-    ASSERT_EQ(OK, native_window_set_crop(anw.get(), &crop));
-    ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[0]));
-    ASSERT_EQ(OK, st->updateTexImage());
-    ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 6)); // frees buffers
-    st->getTransformMatrix(mtx);
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 4));
+    ASSERT_EQ(OK, native_window_set_buffers_geometry(mANW.get(), 8, 8, 0));
+    ASSERT_EQ(OK, mANW->dequeueBuffer(mANW.get(), &buf[0]));
+    ASSERT_EQ(OK, native_window_set_crop(mANW.get(), &crop));
+    ASSERT_EQ(OK, mANW->queueBuffer(mANW.get(), buf[0]));
+    ASSERT_EQ(OK, mST->updateTexImage());
+    ASSERT_EQ(OK, native_window_set_buffer_count(mANW.get(), 6)); // frees buffers
+    mST->getTransformMatrix(mtx);
 
     // This accounts for the 1 texel shrink for each edge that's included in the
     // transform matrix to avoid texturing outside the crop region.
@@ -622,4 +588,29 @@
     EXPECT_EQ(1.f, mtx[15]);
 }
 
+// This test verifies that the buffer format can be queried immediately after
+// it is set.
+TEST_F(SurfaceTextureClientTest, DISABLED_QueryFormatAfterSettingWorks) {
+    sp<ANativeWindow> anw(mSTC);
+    int fmts[] = {
+        // RGBA_8888 should not come first, as it's the default
+        HAL_PIXEL_FORMAT_RGBX_8888,
+        HAL_PIXEL_FORMAT_RGBA_8888,
+        HAL_PIXEL_FORMAT_RGB_888,
+        HAL_PIXEL_FORMAT_RGB_565,
+        HAL_PIXEL_FORMAT_BGRA_8888,
+        HAL_PIXEL_FORMAT_RGBA_5551,
+        HAL_PIXEL_FORMAT_RGBA_4444,
+        HAL_PIXEL_FORMAT_YV12,
+    };
+
+    const int numFmts = (sizeof(fmts) / sizeof(fmts[0]));
+    for (int i = 0; i < numFmts; i++) {
+      int fmt = -1;
+      ASSERT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, fmts[i]));
+      ASSERT_EQ(OK, anw->query(anw.get(), NATIVE_WINDOW_FORMAT, &fmt));
+      EXPECT_EQ(fmts[i], fmt);
+    }
+}
+
 } // namespace android
diff --git a/libs/gui/tests/SurfaceTexture_test.cpp b/libs/gui/tests/SurfaceTexture_test.cpp
index 56c1702..50af3bb 100644
--- a/libs/gui/tests/SurfaceTexture_test.cpp
+++ b/libs/gui/tests/SurfaceTexture_test.cpp
@@ -46,8 +46,6 @@
     }
 
     virtual void SetUp() {
-        EGLBoolean returnValue;
-
         mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
         ASSERT_EQ(EGL_SUCCESS, eglGetError());
         ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
@@ -59,9 +57,8 @@
         RecordProperty("EglVersionMajor", majorVersion);
         RecordProperty("EglVersionMajor", minorVersion);
 
-        EGLConfig myConfig = {0};
         EGLint numConfigs = 0;
-        EXPECT_TRUE(eglChooseConfig(mEglDisplay, getConfigAttribs(), &myConfig,
+        EXPECT_TRUE(eglChooseConfig(mEglDisplay, getConfigAttribs(), &mGlConfig,
                 1, &numConfigs));
         ASSERT_EQ(EGL_SUCCESS, eglGetError());
 
@@ -88,12 +85,12 @@
             ASSERT_TRUE(mSurfaceControl->isValid());
 
             ASSERT_EQ(NO_ERROR, mComposerClient->openTransaction());
-            ASSERT_EQ(NO_ERROR, mSurfaceControl->setLayer(30000));
+            ASSERT_EQ(NO_ERROR, mSurfaceControl->setLayer(0x7FFFFFFF));
             ASSERT_EQ(NO_ERROR, mSurfaceControl->show());
             ASSERT_EQ(NO_ERROR, mComposerClient->closeTransaction());
 
             sp<ANativeWindow> window = mSurfaceControl->getSurface();
-            mEglSurface = eglCreateWindowSurface(mEglDisplay, myConfig,
+            mEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig,
                     window.get(), NULL);
         } else {
             EGLint pbufferAttribs[] = {
@@ -101,13 +98,13 @@
                 EGL_HEIGHT, getSurfaceHeight(),
                 EGL_NONE };
 
-            mEglSurface = eglCreatePbufferSurface(mEglDisplay, myConfig,
+            mEglSurface = eglCreatePbufferSurface(mEglDisplay, mGlConfig,
                     pbufferAttribs);
         }
         ASSERT_EQ(EGL_SUCCESS, eglGetError());
         ASSERT_NE(EGL_NO_SURFACE, mEglSurface);
 
-        mEglContext = eglCreateContext(mEglDisplay, myConfig, EGL_NO_CONTEXT,
+        mEglContext = eglCreateContext(mEglDisplay, mGlConfig, EGL_NO_CONTEXT,
                 getContextAttribs());
         ASSERT_EQ(EGL_SUCCESS, eglGetError());
         ASSERT_NE(EGL_NO_CONTEXT, mEglContext);
@@ -329,6 +326,7 @@
     EGLDisplay mEglDisplay;
     EGLSurface mEglSurface;
     EGLContext mEglContext;
+    EGLConfig  mGlConfig;
 };
 
 // XXX: Code above this point should live elsewhere
@@ -401,6 +399,18 @@
         glBindTexture(GL_TEXTURE_EXTERNAL_OES, TEX_ID);
         ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
 
+        // XXX: These calls are not needed for GL_TEXTURE_EXTERNAL_OES as
+        // they're setting the defautls for that target, but when hacking things
+        // to use GL_TEXTURE_2D they are needed to achieve the same behavior.
+        glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+        glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+        glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+        glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        ASSERT_EQ(GLenum(GL_NO_ERROR), glGetError());
+
         GLfloat texMatrix[16];
         mST->getTransformMatrix(texMatrix);
         glUniformMatrix4fv(mTexMatrixHandle, 1, GL_FALSE, texMatrix);
@@ -474,12 +484,26 @@
     }
 }
 
+void fillRGBA8Buffer(uint8_t* buf, int w, int h, int stride) {
+    const size_t PIXEL_SIZE = 4;
+    for (int x = 0; x < w; x++) {
+        for (int y = 0; y < h; y++) {
+            off_t offset = (y * stride + x) * PIXEL_SIZE;
+            for (int c = 0; c < 4; c++) {
+                int parityX = (x / (1 << (c+2))) & 1;
+                int parityY = (y / (1 << (c+2))) & 1;
+                buf[offset + c] = (parityX ^ parityY) ? 231 : 35;
+            }
+        }
+    }
+}
+
 TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledYV12BufferNpot) {
-    const int yuvTexWidth = 64;
-    const int yuvTexHeight = 66;
+    const int texWidth = 64;
+    const int texHeight = 66;
 
     ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
-            yuvTexWidth, yuvTexHeight, HAL_PIXEL_FORMAT_YV12));
+            texWidth, texHeight, HAL_PIXEL_FORMAT_YV12));
     ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
             GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
 
@@ -493,7 +517,7 @@
     // Fill the buffer with the a checkerboard pattern
     uint8_t* img = NULL;
     buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
-    fillYV12Buffer(img, yuvTexWidth, yuvTexHeight, buf->getStride());
+    fillYV12Buffer(img, texWidth, texHeight, buf->getStride());
     buf->unlock();
     ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
 
@@ -523,11 +547,11 @@
 // I just copied them from the npot test above and haven't bothered to figure
 // out the correct values.
 TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledYV12BufferPow2) {
-    const int yuvTexWidth = 64;
-    const int yuvTexHeight = 64;
+    const int texWidth = 64;
+    const int texHeight = 64;
 
     ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
-            yuvTexWidth, yuvTexHeight, HAL_PIXEL_FORMAT_YV12));
+            texWidth, texHeight, HAL_PIXEL_FORMAT_YV12));
     ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
             GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
 
@@ -541,7 +565,7 @@
     // Fill the buffer with the a checkerboard pattern
     uint8_t* img = NULL;
     buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
-    fillYV12Buffer(img, yuvTexWidth, yuvTexHeight, buf->getStride());
+    fillYV12Buffer(img, texWidth, texHeight, buf->getStride());
     buf->unlock();
     ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
 
@@ -567,11 +591,11 @@
 }
 
 TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledYV12BufferWithCrop) {
-    const int yuvTexWidth = 64;
-    const int yuvTexHeight = 66;
+    const int texWidth = 64;
+    const int texHeight = 66;
 
     ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
-            yuvTexWidth, yuvTexHeight, HAL_PIXEL_FORMAT_YV12));
+            texWidth, texHeight, HAL_PIXEL_FORMAT_YV12));
     ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
             GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
 
@@ -579,8 +603,8 @@
         {4, 6, 22, 36},
         {0, 6, 22, 36},
         {4, 0, 22, 36},
-        {4, 6, yuvTexWidth, 36},
-        {4, 6, 22, yuvTexHeight},
+        {4, 6, texWidth, 36},
+        {4, 6, 22, texHeight},
     };
 
     for (int i = 0; i < 5; i++) {
@@ -599,7 +623,7 @@
 
         uint8_t* img = NULL;
         buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
-        fillYV12BufferRect(img, yuvTexWidth, yuvTexHeight, buf->getStride(), crop);
+        fillYV12BufferRect(img, texWidth, texHeight, buf->getStride(), crop);
         buf->unlock();
         ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
 
@@ -625,6 +649,189 @@
     }
 }
 
+// XXX: This test is disabled because there are currently no drivers that can
+// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
+TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledRGBABufferNpot) {
+    const int texWidth = 64;
+    const int texHeight = 66;
+
+    ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+            texWidth, texHeight, HAL_PIXEL_FORMAT_RGBA_8888));
+    ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+            GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+    android_native_buffer_t* anb;
+    ASSERT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
+    ASSERT_TRUE(anb != NULL);
+
+    sp<GraphicBuffer> buf(new GraphicBuffer(anb, false));
+    ASSERT_EQ(NO_ERROR, mANW->lockBuffer(mANW.get(), buf->getNativeBuffer()));
+
+    // Fill the buffer with the a checkerboard pattern
+    uint8_t* img = NULL;
+    buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
+    fillRGBA8Buffer(img, texWidth, texHeight, buf->getStride());
+    buf->unlock();
+    ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
+
+    mST->updateTexImage();
+
+    glClearColor(0.2, 0.2, 0.2, 0.2);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    drawTexture();
+
+    EXPECT_TRUE(checkPixel( 0,  0,  35,  35,  35,  35));
+    EXPECT_TRUE(checkPixel(63,  0, 231, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(63, 63, 231, 231, 231, 231));
+    EXPECT_TRUE(checkPixel( 0, 63,  35,  35,  35,  35));
+
+    EXPECT_TRUE(checkPixel(15, 10,  35, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(24, 63,  35, 231, 231,  35));
+    EXPECT_TRUE(checkPixel(19, 40,  87, 179,  35,  35));
+    EXPECT_TRUE(checkPixel(38, 30, 231,  35,  35,  35));
+    EXPECT_TRUE(checkPixel(42, 54,  35,  35,  35, 231));
+    EXPECT_TRUE(checkPixel(37, 33,  35, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(31,  8, 231,  35,  35, 231));
+    EXPECT_TRUE(checkPixel(36, 47, 231,  35, 231, 231));
+    EXPECT_TRUE(checkPixel(24, 63,  35, 231, 231,  35));
+    EXPECT_TRUE(checkPixel(48,  3, 231, 231,  35,  35));
+    EXPECT_TRUE(checkPixel(54, 50,  35, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(24, 25, 191, 191, 231, 231));
+    EXPECT_TRUE(checkPixel(10,  9,  93,  93, 231, 231));
+    EXPECT_TRUE(checkPixel(29,  4,  35,  35,  35, 231));
+    EXPECT_TRUE(checkPixel(56, 31,  35, 231, 231,  35));
+    EXPECT_TRUE(checkPixel(58, 55,  35,  35, 231, 231));
+}
+
+// XXX: This test is disabled because there are currently no drivers that can
+// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
+TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledRGBABufferPow2) {
+    const int texWidth = 64;
+    const int texHeight = 64;
+
+    ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+            texWidth, texHeight, HAL_PIXEL_FORMAT_RGBA_8888));
+    ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+            GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+    android_native_buffer_t* anb;
+    ASSERT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
+    ASSERT_TRUE(anb != NULL);
+
+    sp<GraphicBuffer> buf(new GraphicBuffer(anb, false));
+    ASSERT_EQ(NO_ERROR, mANW->lockBuffer(mANW.get(), buf->getNativeBuffer()));
+
+    // Fill the buffer with the a checkerboard pattern
+    uint8_t* img = NULL;
+    buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
+    fillRGBA8Buffer(img, texWidth, texHeight, buf->getStride());
+    buf->unlock();
+    ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
+
+    mST->updateTexImage();
+
+    glClearColor(0.2, 0.2, 0.2, 0.2);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    drawTexture();
+
+    EXPECT_TRUE(checkPixel( 0,  0, 231, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(63,  0,  35,  35,  35,  35));
+    EXPECT_TRUE(checkPixel(63, 63, 231, 231, 231, 231));
+    EXPECT_TRUE(checkPixel( 0, 63,  35,  35,  35,  35));
+
+    EXPECT_TRUE(checkPixel(12, 46, 231, 231, 231,  35));
+    EXPECT_TRUE(checkPixel(16,  1, 231, 231,  35, 231));
+    EXPECT_TRUE(checkPixel(21, 12, 231,  35,  35, 231));
+    EXPECT_TRUE(checkPixel(26, 51, 231,  35, 231,  35));
+    EXPECT_TRUE(checkPixel( 5, 32,  35, 231, 231,  35));
+    EXPECT_TRUE(checkPixel(13,  8,  35, 231, 231, 231));
+    EXPECT_TRUE(checkPixel(46,  3,  35,  35, 231,  35));
+    EXPECT_TRUE(checkPixel(30, 33,  35,  35,  35,  35));
+    EXPECT_TRUE(checkPixel( 6, 52, 231, 231,  35,  35));
+    EXPECT_TRUE(checkPixel(55, 33,  35, 231,  35, 231));
+    EXPECT_TRUE(checkPixel(16, 29,  35,  35, 231, 231));
+    EXPECT_TRUE(checkPixel( 1, 30,  35,  35,  35, 231));
+    EXPECT_TRUE(checkPixel(41, 37,  35,  35, 231, 231));
+    EXPECT_TRUE(checkPixel(46, 29, 231, 231,  35,  35));
+    EXPECT_TRUE(checkPixel(15, 25,  35, 231,  35, 231));
+    EXPECT_TRUE(checkPixel( 3, 52,  35, 231,  35,  35));
+}
+
+// XXX: This test is disabled because there are currently no drivers that can
+// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
+TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromGLFilledRGBABufferPow2) {
+    const int texWidth = 64;
+    const int texHeight = 64;
+
+    mST->setDefaultBufferSize(texWidth, texHeight);
+
+    // Do the producer side of things
+    EGLSurface stcEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig,
+            mANW.get(), NULL);
+    ASSERT_EQ(EGL_SUCCESS, eglGetError());
+    ASSERT_NE(EGL_NO_SURFACE, mEglSurface);
+
+    EXPECT_TRUE(eglMakeCurrent(mEglDisplay, stcEglSurface, stcEglSurface,
+            mEglContext));
+    ASSERT_EQ(EGL_SUCCESS, eglGetError());
+
+    glClearColor(0.6, 0.6, 0.6, 0.6);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    glEnable(GL_SCISSOR_TEST);
+    glScissor(4, 4, 4, 4);
+    glClearColor(1.0, 0.0, 0.0, 1.0);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    glScissor(24, 48, 4, 4);
+    glClearColor(0.0, 1.0, 0.0, 1.0);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    glScissor(37, 17, 4, 4);
+    glClearColor(0.0, 0.0, 1.0, 1.0);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    eglSwapBuffers(mEglDisplay, stcEglSurface);
+
+    // Do the consumer side of things
+    EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
+            mEglContext));
+    ASSERT_EQ(EGL_SUCCESS, eglGetError());
+
+    glDisable(GL_SCISSOR_TEST);
+
+    mST->updateTexImage();
+
+    glClearColor(0.2, 0.2, 0.2, 0.2);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    drawTexture();
+
+    EXPECT_TRUE(checkPixel( 0,  0, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(63,  0, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(63, 63, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel( 0, 63, 153, 153, 153, 153));
+
+    EXPECT_TRUE(checkPixel( 4,  7, 255,   0,   0, 255));
+    EXPECT_TRUE(checkPixel(25, 51,   0, 255,   0, 255));
+    EXPECT_TRUE(checkPixel(40, 19,   0,   0, 255, 255));
+    EXPECT_TRUE(checkPixel(29, 51, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel( 5, 32, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(13,  8, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(46,  3, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(30, 33, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel( 6, 52, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(55, 33, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(16, 29, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel( 1, 30, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(41, 37, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(46, 29, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel(15, 25, 153, 153, 153, 153));
+    EXPECT_TRUE(checkPixel( 3, 52, 153, 153, 153, 153));
+}
+
 /*
  * This test is for testing GL -> GL texture streaming via SurfaceTexture.  It
  * contains functionality to create a producer thread that will perform GL
diff --git a/libs/rs/RenderScriptDefines.h b/libs/rs/RenderScriptDefines.h
index ee9645c..d092520 100644
--- a/libs/rs/RenderScriptDefines.h
+++ b/libs/rs/RenderScriptDefines.h
@@ -110,12 +110,12 @@
 };
 
 enum RsAllocationCubemapFace {
-    RS_ALLOCATION_CUBMAP_FACE_POSITVE_X = 0,
-    RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_X = 1,
-    RS_ALLOCATION_CUBMAP_FACE_POSITVE_Y = 2,
-    RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_Y = 3,
-    RS_ALLOCATION_CUBMAP_FACE_POSITVE_Z = 4,
-    RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_Z = 5
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X = 0,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_X = 1,
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Y = 2,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Y = 3,
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Z = 4,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Z = 5
 };
 
 enum RsDataType {
diff --git a/libs/rs/driver/rsdAllocation.cpp b/libs/rs/driver/rsdAllocation.cpp
index 2e13e9d..8bfc185 100644
--- a/libs/rs/driver/rsdAllocation.cpp
+++ b/libs/rs/driver/rsdAllocation.cpp
@@ -378,6 +378,32 @@
 
 }
 
+void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstLod, uint32_t count,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcLod){
+}
+
+void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
+                               RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
+                               RsAllocationCubemapFace srcFace) {
+}
+
+void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
+                               uint32_t dstLod, RsAllocationCubemapFace dstFace,
+                               uint32_t w, uint32_t h, uint32_t d,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
+                               uint32_t srcLod, RsAllocationCubemapFace srcFace) {
+}
+
 void rsdAllocationElementData1D(const Context *rsc, const Allocation *alloc,
                                 uint32_t x,
                                 const void *data, uint32_t cIdx, uint32_t sizeBytes) {
diff --git a/libs/rs/driver/rsdAllocation.h b/libs/rs/driver/rsdAllocation.h
index d7385ce..7555c4a 100644
--- a/libs/rs/driver/rsdAllocation.h
+++ b/libs/rs/driver/rsdAllocation.h
@@ -80,6 +80,27 @@
                          uint32_t lod, RsAllocationCubemapFace face,
                          uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
 
+void rsdAllocationData1D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstLod, uint32_t count,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcLod);
+void rsdAllocationData2D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
+                               RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
+                               RsAllocationCubemapFace srcFace);
+void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc,
+                               const android::renderscript::Allocation *dstAlloc,
+                               uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
+                               uint32_t dstLod, RsAllocationCubemapFace dstFace,
+                               uint32_t w, uint32_t h, uint32_t d,
+                               const android::renderscript::Allocation *srcAlloc,
+                               uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
+                               uint32_t srcLod, RsAllocationCubemapFace srcFace);
+
 void rsdAllocationElementData1D(const android::renderscript::Context *rsc,
                                 const android::renderscript::Allocation *alloc,
                                 uint32_t x,
diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp
index 01cc369..38f6895 100644
--- a/libs/rs/driver/rsdCore.cpp
+++ b/libs/rs/driver/rsdCore.cpp
@@ -74,6 +74,9 @@
         rsdAllocationData1D,
         rsdAllocationData2D,
         rsdAllocationData3D,
+        rsdAllocationData1D_alloc,
+        rsdAllocationData2D_alloc,
+        rsdAllocationData3D_alloc,
         rsdAllocationElementData1D,
         rsdAllocationElementData2D
     },
diff --git a/libs/rs/driver/rsdRuntimeStubs.cpp b/libs/rs/driver/rsdRuntimeStubs.cpp
index 9cbff95..bd8b3c3 100644
--- a/libs/rs/driver/rsdRuntimeStubs.cpp
+++ b/libs/rs/driver/rsdRuntimeStubs.cpp
@@ -88,6 +88,26 @@
     rsrAllocationSyncAll(rsc, sc, a, RS_ALLOCATION_USAGE_SCRIPT);
 }
 
+static void SC_AllocationCopy1DRange(Allocation *dstAlloc,
+                                     uint32_t dstOff,
+                                     uint32_t dstMip,
+                                     uint32_t count,
+                                     Allocation *srcAlloc,
+                                     uint32_t srcOff, uint32_t srcMip) {
+    GET_TLS();
+}
+
+static void SC_AllocationCopy2DRange(Allocation *dstAlloc,
+                                     uint32_t dstXoff, uint32_t dstYoff,
+                                     uint32_t dstMip, uint32_t dstFace,
+                                     uint32_t width, uint32_t height,
+                                     Allocation *srcAlloc,
+                                     uint32_t srcXoff, uint32_t srcYoff,
+                                     uint32_t srcMip, uint32_t srcFace) {
+    GET_TLS();
+}
+
+
 const Allocation * SC_getAllocation(const void *ptr) {
     GET_TLS();
     return rsrGetAllocation(rsc, sc, ptr);
@@ -566,8 +586,11 @@
     { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_AllocationSyncAll, true },
     { "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_AllocationSyncAll, false },
     { "_Z20rsgAllocationSyncAll13rs_allocationj", (void *)&SC_AllocationSyncAll2, false },
+    { "_Z20rsgAllocationSyncAll13rs_allocation24rs_allocation_usage_type", (void *)&SC_AllocationSyncAll2, false },
     { "_Z15rsGetAllocationPKv", (void *)&SC_GetAllocation, true },
 
+    { "_Z23rsAllocationCopy1DRange13rs_allocationjjjS_jj", (void *)&SC_AllocationCopy1DRange, false },
+    { "_Z23rsAllocationCopy2DRange13rs_allocationjjj26rs_allocation_cubemap_facejjS_jjjS0_", (void *)&SC_AllocationCopy2DRange, false },
 
     // Messaging
 
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 87d764d..963a6e7 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -209,6 +209,21 @@
 	param uint32_t dimY
 	}
 
+AllocationCopy2DRange {
+	param RsAllocation dest
+	param uint32_t destXoff
+	param uint32_t destYoff
+	param uint32_t destMip
+	param uint32_t destFace
+	param uint32_t width
+	param uint32_t height
+	param RsAllocation src
+	param uint32_t srcXoff
+	param uint32_t srcYoff
+	param uint32_t srcMip
+	param uint32_t srcFace
+	}
+
 SamplerCreate {
     param RsSamplerValue magFilter
     param RsSamplerValue minFilter
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index bff3660..f3e0c0a 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -532,6 +532,23 @@
     return texAlloc;
 }
 
+void rsi_AllocationCopy2DRange(Context *rsc,
+                               RsAllocation dstAlloc,
+                               uint32_t dstXoff, uint32_t dstYoff,
+                               uint32_t dstMip, uint32_t dstFace,
+                               uint32_t width, uint32_t height,
+                               RsAllocation srcAlloc,
+                               uint32_t srcXoff, uint32_t srcYoff,
+                               uint32_t srcMip, uint32_t srcFace) {
+    Allocation *dst = static_cast<Allocation *>(dstAlloc);
+    Allocation *src= static_cast<Allocation *>(srcAlloc);
+    rsc->mHal.funcs.allocation.allocData2D(rsc, dst, dstXoff, dstYoff, dstMip,
+                                           (RsAllocationCubemapFace)dstFace,
+                                           width, height,
+                                           src, srcXoff, srcYoff,srcMip,
+                                           (RsAllocationCubemapFace)srcFace);
+}
+
 }
 }
 
diff --git a/libs/rs/rsRuntime.h b/libs/rs/rsRuntime.h
index 6d45285..cb962a8 100644
--- a/libs/rs/rsRuntime.h
+++ b/libs/rs/rsRuntime.h
@@ -85,6 +85,21 @@
 void rsrColor(Context *, Script *, float r, float g, float b, float a);
 void rsrFinish(Context *, Script *);
 void rsrAllocationSyncAll(Context *, Script *, Allocation *);
+
+void rsrAllocationCopy1DRange(Context *, Allocation *dstAlloc,
+                              uint32_t dstOff,
+                              uint32_t dstMip,
+                              uint32_t count,
+                              Allocation *srcAlloc,
+                              uint32_t srcOff, uint32_t srcMip);
+void rsrAllocationCopy2DRange(Context *, Allocation *dstAlloc,
+                              uint32_t dstXoff, uint32_t dstYoff,
+                              uint32_t dstMip, uint32_t dstFace,
+                              uint32_t width, uint32_t height,
+                              Allocation *srcAlloc,
+                              uint32_t srcXoff, uint32_t srcYoff,
+                              uint32_t srcMip, uint32_t srcFace);
+
 void rsrClearColor(Context *, Script *, float r, float g, float b, float a);
 void rsrClearDepth(Context *, Script *, float v);
 uint32_t rsrGetWidth(Context *, Script *);
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index 4ee0a3e..ec15bc0 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -164,6 +164,29 @@
     a->syncAll(rsc, usage);
 }
 
+void rsrAllocationCopy1DRange(Context *rsc, Allocation *dstAlloc,
+                              uint32_t dstOff,
+                              uint32_t dstMip,
+                              uint32_t count,
+                              Allocation *srcAlloc,
+                              uint32_t srcOff, uint32_t srcMip) {
+    rsi_AllocationCopy2DRange(rsc, dstAlloc, dstOff, 0,
+                              dstMip, 0, count, 1,
+                              srcAlloc, srcOff, 0, srcMip, 0);
+}
+
+void rsrAllocationCopy2DRange(Context *rsc, Allocation *dstAlloc,
+                              uint32_t dstXoff, uint32_t dstYoff,
+                              uint32_t dstMip, uint32_t dstFace,
+                              uint32_t width, uint32_t height,
+                              Allocation *srcAlloc,
+                              uint32_t srcXoff, uint32_t srcYoff,
+                              uint32_t srcMip, uint32_t srcFace) {
+    rsi_AllocationCopy2DRange(rsc, dstAlloc, dstXoff, dstYoff,
+                              dstMip, dstFace, width, height,
+                              srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
+}
+
 const Allocation * rsrGetAllocation(Context *rsc, Script *s, const void *ptr) {
     ScriptC *sc = (ScriptC *)s;
     return sc->ptrToAllocation(ptr);
diff --git a/libs/rs/rs_hal.h b/libs/rs/rs_hal.h
index 7bb09bb..928dca5 100644
--- a/libs/rs/rs_hal.h
+++ b/libs/rs/rs_hal.h
@@ -112,6 +112,27 @@
                        uint32_t lod, RsAllocationCubemapFace face,
                        uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
 
+        // Allocation to allocation copies
+        void (*allocData1D)(const Context *rsc,
+                            const Allocation *dstAlloc,
+                            uint32_t dstXoff, uint32_t dstLod, uint32_t count,
+                            const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
+        void (*allocData2D)(const Context *rsc,
+                            const Allocation *dstAlloc,
+                            uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
+                            RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
+                            const Allocation *srcAlloc,
+                            uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
+                            RsAllocationCubemapFace srcFace);
+        void (*allocData3D)(const Context *rsc,
+                            const Allocation *dstAlloc,
+                            uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
+                            uint32_t dstLod, RsAllocationCubemapFace dstFace,
+                            uint32_t w, uint32_t h, uint32_t d,
+                            const Allocation *srcAlloc,
+                            uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
+                            uint32_t srcLod, RsAllocationCubemapFace srcFace);
+
         void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
                               const void *data, uint32_t elementOff, uint32_t sizeBytes);
         void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
diff --git a/libs/rs/scriptc/rs_graphics.rsh b/libs/rs/scriptc/rs_graphics.rsh
index d53bc95..9a8a4e6 100644
--- a/libs/rs/scriptc/rs_graphics.rsh
+++ b/libs/rs/scriptc/rs_graphics.rsh
@@ -144,6 +144,17 @@
     rsgAllocationSyncAll(rs_allocation alloc);
 
 /**
+ * Sync the contents of an allocation from memory space
+ * specified by source.
+ *
+ * @param alloc
+ * @param source
+ */
+extern void __attribute__((overloadable))
+    rsgAllocationSyncAll(rs_allocation alloc,
+                         rs_allocation_usage_type source);
+
+/**
  * Low performance utility function for drawing a simple rectangle.  Not
  * intended for drawing large quantities of geometry.
  *
diff --git a/libs/rs/scriptc/rs_math.rsh b/libs/rs/scriptc/rs_math.rsh
index 6e3cfdb..584317e 100644
--- a/libs/rs/scriptc/rs_math.rsh
+++ b/libs/rs/scriptc/rs_math.rsh
@@ -136,6 +136,58 @@
 extern uint32_t __attribute__((overloadable))
     rsAllocationGetDimFaces(rs_allocation);
 
+/**
+ * Copy part of an allocation from another allocation.
+ *
+ * @param dstAlloc Allocation to copy data into.
+ * @param dstOff The offset of the first element to be copied in
+ *               the destination allocation.
+ * @param dstMip Mip level in the destination allocation.
+ * @param count The number of elements to be copied.
+ * @param srcAlloc The source data allocation.
+ * @param srcOff The offset of the first element in data to be
+ *               copied in the source allocation.
+ * @param srcMip Mip level in the source allocation.
+ */
+extern void __attribute__((overloadable))
+    rsAllocationCopy1DRange(rs_allocation dstAlloc,
+                            uint32_t dstOff, uint32_t dstMip,
+                            uint32_t count,
+                            rs_allocation srcAlloc,
+                            uint32_t srcOff, uint32_t srcMip);
+
+/**
+ * Copy a rectangular region into the allocation from another
+ * allocation.
+ *
+ * @param dstAlloc allocation to copy data into.
+ * @param dstXoff X offset of the region to update in the
+ *                destination allocation.
+ * @param dstYoff Y offset of the region to update in the
+ *                destination allocation.
+ * @param dstMip Mip level in the destination allocation.
+ * @param dstFace Cubemap face of the destination allocation,
+ *                ignored for allocations that aren't cubemaps.
+ * @param width Width of the incoming region to update.
+ * @param height Height of the incoming region to update.
+ * @param srcAlloc The source data allocation.
+ * @param srcXoff X offset in data of the source allocation.
+ * @param srcYoff Y offset in data of the source allocation.
+ * @param srcMip Mip level in the source allocation.
+ * @param srcFace Cubemap face of the source allocation,
+ *                ignored for allocations that aren't cubemaps.
+ */
+extern void __attribute__((overloadable))
+    rsAllocationCopy2DRange(rs_allocation dstAlloc,
+                            uint32_t dstXoff, uint32_t dstYoff,
+                            uint32_t dstMip,
+                            rs_allocation_cubemap_face dstFace,
+                            uint32_t width, uint32_t height,
+                            rs_allocation srcAlloc,
+                            uint32_t srcXoff, uint32_t srcYoff,
+                            uint32_t srcMip,
+                            rs_allocation_cubemap_face srcFace);
+
 // Extract a single element from an allocation.
 extern const void * __attribute__((overloadable))
     rsGetElementAt(rs_allocation, uint32_t x);
diff --git a/libs/rs/scriptc/rs_types.rsh b/libs/rs/scriptc/rs_types.rsh
index d9f4b4b..536d1f0 100644
--- a/libs/rs/scriptc/rs_types.rsh
+++ b/libs/rs/scriptc/rs_types.rsh
@@ -88,4 +88,21 @@
 
 #define RS_PACKED __attribute__((packed, aligned(4)))
 
+typedef enum {
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X = 0,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_X = 1,
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Y = 2,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Y = 3,
+    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Z = 4,
+    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Z = 5
+} rs_allocation_cubemap_face;
+
+typedef enum {
+    RS_ALLOCATION_USAGE_SCRIPT = 0x0001,
+    RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002,
+    RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004,
+    RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008,
+    RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010
+} rs_allocation_usage_type;
+
 #endif
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index 8f7dd60..e34d75cc 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -30,6 +30,7 @@
 import android.view.Surface;
 import android.view.SurfaceHolder;
 import android.graphics.Bitmap;
+import android.graphics.ParcelSurfaceTexture;
 import android.graphics.SurfaceTexture;
 import android.media.AudioManager;
 
@@ -509,7 +510,7 @@
     private int mListenerContext; // accessed by native methods
     private Surface mSurface; // accessed by native methods
     private SurfaceHolder  mSurfaceHolder;
-    private SurfaceTexture mSurfaceTexture; // accessed by native methods
+    private ParcelSurfaceTexture mParcelSurfaceTexture; // accessed by native methods
     private EventHandler mEventHandler;
     private PowerManager.WakeLock mWakeLock = null;
     private boolean mScreenOnWhilePlaying;
@@ -541,7 +542,7 @@
 
     /*
      * Update the MediaPlayer ISurface and ISurfaceTexture.
-     * Call after updating mSurface and/or mSurfaceTexture.
+     * Call after updating mSurface and/or mParcelSurfaceTexture.
      */
     private native void _setVideoSurfaceOrSurfaceTexture();
 
@@ -607,7 +608,7 @@
         } else {
             mSurface = null;
         }
-        mSurfaceTexture = null;
+        mParcelSurfaceTexture = null;
         _setVideoSurfaceOrSurfaceTexture();
         updateSurfaceScreenOn();
     }
@@ -630,12 +631,32 @@
      * program.
      */
     public void setTexture(SurfaceTexture st) {
-        if (mScreenOnWhilePlaying && st != null && mSurfaceTexture == null) {
+        ParcelSurfaceTexture pst = null;
+        if (st != null) {
+            pst = ParcelSurfaceTexture.fromSurfaceTexture(st);
+        }
+        setParcelSurfaceTexture(pst);
+    }
+
+    /**
+     * Sets the {@link ParcelSurfaceTexture} to be used as the sink for the video portion of
+     * the media. This is similar to {@link #setTexture(SurfaceTexture)}, but supports using
+     * a {@link ParcelSurfaceTexture} to transport the texture to be used via Binder. Setting
+     * a parceled surface texture will un-set any surface or surface texture that was previously
+     * set. See {@link #setTexture(SurfaceTexture)} for more details.
+     *
+     * @param pst The {@link ParcelSurfaceTexture} to be used as the sink for
+     * the video portion of the media.
+     *
+     * @hide Pending review by API council.
+     */
+    public void setParcelSurfaceTexture(ParcelSurfaceTexture pst) {
+        if (mScreenOnWhilePlaying && pst != null && mParcelSurfaceTexture == null) {
             Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective for SurfaceTexture");
         }
         mSurfaceHolder = null;
         mSurface = null;
-        mSurfaceTexture = st;
+        mParcelSurfaceTexture = pst;
         _setVideoSurfaceOrSurfaceTexture();
         updateSurfaceScreenOn();
     }
@@ -962,7 +983,7 @@
      */
     public void setScreenOnWhilePlaying(boolean screenOn) {
         if (mScreenOnWhilePlaying != screenOn) {
-            if (screenOn && mSurfaceTexture != null) {
+            if (screenOn && mParcelSurfaceTexture != null) {
                 Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective for SurfaceTexture");
             }
             mScreenOnWhilePlaying = screenOn;
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index b03aa38..5663683 100644
--- a/media/jni/android_media_MediaPlayer.cpp
+++ b/media/jni/android_media_MediaPlayer.cpp
@@ -30,6 +30,7 @@
 #include "jni.h"
 #include "JNIHelp.h"
 #include "android_runtime/AndroidRuntime.h"
+#include "android_runtime/android_graphics_ParcelSurfaceTexture.h"
 #include "utils/Errors.h"  // for status_t
 #include "utils/KeyedVector.h"
 #include "utils/String8.h"
@@ -37,7 +38,6 @@
 
 #include "android_util_Binder.h"
 #include <binder/Parcel.h>
-#include <gui/SurfaceTexture.h>
 #include <gui/ISurfaceTexture.h>
 #include <surfaceflinger/Surface.h>
 #include <binder/IPCThreadState.h>
@@ -52,11 +52,9 @@
 struct fields_t {
     jfieldID    context;
     jfieldID    surface;
-    jfieldID    surfaceTexture;
+    jfieldID    parcelSurfaceTexture;
     /* actually in android.view.Surface XXX */
     jfieldID    surface_native;
-    // actually in android.graphics.SurfaceTexture
-    jfieldID    surfaceTexture_native;
 
     jmethodID   post_event;
 };
@@ -130,13 +128,6 @@
     return (Surface*)env->GetIntField(clazz, fields.surface_native);
 }
 
-sp<ISurfaceTexture> getSurfaceTexture(JNIEnv* env, jobject clazz)
-{
-    sp<ISurfaceTexture> surfaceTexture(
-        (ISurfaceTexture*)env->GetIntField(clazz, fields.surfaceTexture_native));
-    return surfaceTexture;
-}
-
 static sp<MediaPlayer> getMediaPlayer(JNIEnv* env, jobject thiz)
 {
     Mutex::Autolock l(sLock);
@@ -257,8 +248,8 @@
         const sp<MediaPlayer>& mp, JNIEnv *env, jobject thiz, const char *prefix)
 {
     // The Java MediaPlayer class makes sure that at most one of mSurface and
-    // mSurfaceTexture is non-null.  But just in case, we give priority to
-    // mSurface over mSurfaceTexture.
+    // mParcelSurfaceTexture is non-null.  But just in case, we give priority to
+    // mSurface over mParcelSurfaceTexture.
     jobject surface = env->GetObjectField(thiz, fields.surface);
     if (surface != NULL) {
         sp<Surface> native_surface(get_surface(env, surface));
@@ -266,10 +257,10 @@
              native_surface.get(), native_surface->getIdentity());
         mp->setVideoSurface(native_surface);
     } else {
-        jobject surfaceTexture = env->GetObjectField(thiz, fields.surfaceTexture);
-        if (surfaceTexture != NULL) {
+        jobject parcelSurfaceTexture = env->GetObjectField(thiz, fields.parcelSurfaceTexture);
+        if (parcelSurfaceTexture != NULL) {
             sp<ISurfaceTexture> native_surfaceTexture(
-                    getSurfaceTexture(env, surfaceTexture));
+                    ParcelSurfaceTexture_getISurfaceTexture(env, parcelSurfaceTexture));
             LOGV("%s: texture=%p", prefix, native_surfaceTexture.get());
             mp->setVideoSurfaceTexture(native_surfaceTexture);
         }
@@ -610,23 +601,11 @@
         return;
     }
 
-    fields.surfaceTexture = env->GetFieldID(clazz, "mSurfaceTexture",
-            "Landroid/graphics/SurfaceTexture;");
-    if (fields.surfaceTexture == NULL) {
+    fields.parcelSurfaceTexture = env->GetFieldID(clazz, "mParcelSurfaceTexture",
+            "Landroid/graphics/ParcelSurfaceTexture;");
+    if (fields.parcelSurfaceTexture == NULL) {
         return;
     }
-
-    jclass surfaceTexture = env->FindClass("android/graphics/SurfaceTexture");
-    if (surfaceTexture == NULL) {
-        return;
-    }
-
-    fields.surfaceTexture_native = env->GetFieldID(surfaceTexture,
-            ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "I");
-    if (fields.surfaceTexture_native == NULL) {
-        return;
-    }
-
 }
 
 static void
diff --git a/services/jni/com_android_server_connectivity_Vpn.cpp b/services/jni/com_android_server_connectivity_Vpn.cpp
index b3d38dc..206df25 100644
--- a/services/jni/com_android_server_connectivity_Vpn.cpp
+++ b/services/jni/com_android_server_connectivity_Vpn.cpp
@@ -46,14 +46,6 @@
     return &((sockaddr_in *)sa)->sin_addr.s_addr;
 }
 
-static inline in_addr_t *as_in_addr(sockaddr_storage *ss) {
-    return &((sockaddr_in *)ss)->sin_addr.s_addr;
-}
-
-static inline in6_addr *as_in6_addr(sockaddr_storage *ss) {
-    return &((sockaddr_in6 *)&ss)->sin6_addr;
-}
-
 //------------------------------------------------------------------------------
 
 #define SYSTEM_ERROR -1
@@ -193,7 +185,6 @@
     rt4.rt_flags = RTF_UP;
     rt4.rt_dst.sa_family = AF_INET;
     rt4.rt_genmask.sa_family = AF_INET;
-    rt4.rt_gateway.sa_family = AF_INET;
 
     in6_rtmsg rt6;
     memset(&rt6, 0, sizeof(rt6));
@@ -202,60 +193,50 @@
 
     char address[65];
     int prefix;
-    char gateway[65];
 
     int chars;
     int count = 0;
 
-    while (sscanf(routes, " %64[^/]/%d>%64[^ ] %n",
-            address, &prefix, gateway, &chars) == 3) {
+    while (sscanf(routes, " %64[^/]/%d %n", address, &prefix, &chars) == 2) {
         routes += chars;
 
         if (strchr(address, ':')) {
             // Add an IPv6 route.
-            if (inet_pton(AF_INET6, gateway, &rt6.rtmsg_gateway) != 1 ||
-                    inet_pton(AF_INET6, address, &rt6.rtmsg_dst) != 1 ||
-                    prefix < 0 || prefix > 128) {
+            if (inet_pton(AF_INET6, address, &rt6.rtmsg_dst) != 1 ||
+                    prefix < 1 || prefix > 128) {
                 count = BAD_ARGUMENT;
                 break;
             }
 
             rt6.rtmsg_dst_len = prefix;
-            if (memcmp(&rt6.rtmsg_gateway, &in6addr_any, sizeof(in6addr_any))) {
-                rt6.rtmsg_flags |= RTF_GATEWAY;
-            }
             if (ioctl(inet6, SIOCADDRT, &rt6) && errno != EEXIST) {
                 count = (errno == EINVAL) ? BAD_ARGUMENT : SYSTEM_ERROR;
                 break;
             }
         } else {
             // Add an IPv4 route.
-            if (inet_pton(AF_INET, gateway, as_in_addr(&rt4.rt_gateway)) != 1 ||
-                    inet_pton(AF_INET, address, as_in_addr(&rt4.rt_dst)) != 1 ||
-                    prefix < 0 || prefix > 32) {
+            if (inet_pton(AF_INET, address, as_in_addr(&rt4.rt_dst)) != 1 ||
+                    prefix < 1 || prefix > 32) {
                 count = BAD_ARGUMENT;
                 break;
             }
 
             in_addr_t mask = prefix ? (~0 << (32 - prefix)) : 0;
             *as_in_addr(&rt4.rt_genmask) = htonl(mask);
-            if (*as_in_addr(&rt4.rt_gateway)) {
-                rt4.rt_flags |= RTF_GATEWAY;
-            }
             if (ioctl(inet4, SIOCADDRT, &rt4) && errno != EEXIST) {
                 count = (errno == EINVAL) ? BAD_ARGUMENT : SYSTEM_ERROR;
                 break;
             }
         }
-        LOGV("Route added on %s: %s/%d -> %s", name, address, prefix, gateway);
+        LOGV("Route added on %s: %s/%d", name, address, prefix);
         ++count;
     }
 
     if (count == BAD_ARGUMENT) {
-        LOGE("Invalid route: %s/%d -> %s", address, prefix, gateway);
+        LOGE("Invalid route: %s/%d", address, prefix);
     } else if (count == SYSTEM_ERROR) {
-        LOGE("Cannot add route: %s/%d -> %s: %s",
-                address, prefix, gateway, strerror(errno));
+        LOGE("Cannot add route: %s/%d: %s",
+                address, prefix, strerror(errno));
     } else if (*routes) {
         LOGE("Invalid route: %s", routes);
         count = BAD_ARGUMENT;
diff --git a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
index 2c26f62..977b412 100644
--- a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
@@ -145,8 +145,10 @@
 
     public static final String APN_TYPE_KEY = "apnType";
 
-    /** Delay between APN attempts */
-    protected static final int APN_DELAY_MILLIS = 5000;
+    /** Delay between APN attempts.
+        Note the property override mechanism is there just for testing purpose only. */
+    protected static final int APN_DELAY_MILLIS =
+                                SystemProperties.getInt("persist.radio.apn_delay", 5000);
 
     // responds to the setInternalDataEnabled call - used internally to turn off data
     // for example during emergency calls
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
index abd87b8..318cf37 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
@@ -125,6 +125,8 @@
                 }
             }
 
+            // Not sure if this is needed in CDMALTE phone.
+            // mDataRoaming = regCodeIsRoaming(regState);
             mLteSS.setRadioTechnology(type);
             mLteSS.setState(regCodeToServiceState(regState));
         } else {
@@ -210,12 +212,6 @@
 
         if (DBG) log("pollStateDone: oldSS=[" + ss + "] newSS=[" + newSS + "]");
 
-        if (cm.getSimState().isSIMReady()) {
-            // If CSIM is used, check roaming status according to SID/NID
-            // on EFcdmahome record.
-            newSS.setRoaming(!isInHomeSidNid(newSS.getSystemId(), newSS.getNetworkId()));
-        }
-
         boolean hasRegistered = ss.getState() != ServiceState.STATE_IN_SERVICE
                 && newSS.getState() == ServiceState.STATE_IN_SERVICE;
 
@@ -468,33 +464,6 @@
         return provisioningState;
     }
 
-    /**
-     * Check whether the specified SID and NID pair appears in the HOME SID/NID list
-     * read from NV or SIM.
-     *
-     * @return true if provided sid/nid pair belongs to operator's home network.
-     */
-    private boolean isInHomeSidNid(int sid, int nid) {
-        // if SID/NID is not available, do not declare roaming.
-        if (isSidsAllZeros()) return true;
-
-        // length of SID/NID shold be same
-        if (mHomeSystemId.length != mHomeNetworkId.length) return true;
-
-        if (sid == 0) return true;
-
-        for (int i = 0; i < mHomeSystemId.length; i++) {
-            // Use SID only if NID is a reserved value.
-            // SID 0 and NID 0 and 65535 are reserved. (C.0005 2.6.5.2)
-            if ((mHomeSystemId[i] == sid) &&
-                ((mHomeNetworkId[i] == 0) || (mHomeNetworkId[i] == 65535) ||
-                 (nid == 0) || (nid == 65535) || (mHomeNetworkId[i] == nid))) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     @Override
     protected void log(String s) {
         Log.d(LOG_TAG, "[CdmaLteSST] " + s);
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java b/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java
index 58ef747..73b5d97 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteUiccRecords.java
@@ -17,6 +17,7 @@
 
 import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA;
 import com.android.internal.telephony.GsmAlphabet;
+import com.android.internal.telephony.IccCardApplication.AppType;
 import com.android.internal.telephony.IccFileHandler;
 import com.android.internal.telephony.IccUtils;
 import com.android.internal.telephony.MccTable;
@@ -438,9 +439,14 @@
 
     @Override
     public boolean isProvisioned() {
-        // Look for MDN and MIN field to determine if the SIM is provisioned.
-        if ((mMdn != null) && (mMin != null)) return true;
-
-        return false;
+        // If UICC card has CSIM app, look for MDN and MIN field
+        // to determine if the SIM is provisioned.  Otherwise,
+        // consider the SIM is provisioned. (for case of ordinal
+        // USIM only UICC.)
+        if (phone.mIccCard.isApplicationOnIcc(AppType.APPTYPE_CSIM) &&
+            ((mMdn == null) || (mMin == null))) {
+            return false;
+        }
+        return true;
     }
 }
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
index e41985e..5ebdd22 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
@@ -130,8 +130,8 @@
     private String curPlmn = null;
 
     protected String mMdn;
-    protected int mHomeSystemId[] = null;
-    protected int mHomeNetworkId[] = null;
+    private int mHomeSystemId[] = null;
+    private int mHomeNetworkId[] = null;
     protected String mMin;
     protected String mPrlVersion;
     protected boolean mIsMinInfoReady = false;
@@ -1481,7 +1481,7 @@
         }
     }
 
-    protected boolean isSidsAllZeros() {
+    private boolean isSidsAllZeros() {
         if (mHomeSystemId != null) {
             for (int i=0; i < mHomeSystemId.length; i++) {
                 if (mHomeSystemId[i] != 0) {
diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp
index 8ac7590..223b1fa 100644
--- a/tools/aapt/Command.cpp
+++ b/tools/aapt/Command.cpp
@@ -343,6 +343,9 @@
     REQUIRED_ATTR = 0x0101028e,
     SCREEN_SIZE_ATTR = 0x010102ca,
     SCREEN_DENSITY_ATTR = 0x010102cb,
+    REQUIRES_SMALLEST_WIDTH_DP_ATTR = 0x01010364,
+    COMPATIBLE_WIDTH_LIMIT_DP_ATTR = 0x01010365,
+    LARGEST_WIDTH_LIMIT_DP_ATTR = 0x01010366,
 };
 
 const char *getComponentName(String8 &pkgName, String8 &componentName) {
@@ -423,6 +426,24 @@
         return 1;
     }
 
+    // Make a dummy config for retrieving resources...  we need to supply
+    // non-default values for some configs so that we can retrieve resources
+    // in the app that don't have a default.  The most important of these is
+    // the API version because key resources like icons will have an implicit
+    // version if they are using newer config types like density.
+    ResTable_config config;
+    config.language[0] = 'e';
+    config.language[1] = 'n';
+    config.country[0] = 'U';
+    config.country[1] = 'S';
+    config.orientation = ResTable_config::ORIENTATION_PORT;
+    config.density = ResTable_config::DENSITY_MEDIUM;
+    config.sdkVersion = 10000; // Very high.
+    config.screenWidthDp = 320;
+    config.screenHeightDp = 480;
+    config.smallestScreenWidthDp = 320;
+    assets.setConfiguration(config);
+
     const ResTable& res = assets.getResources(false);
     if (&res == NULL) {
         fprintf(stderr, "ERROR: dump failed because no resource table was found\n");
@@ -542,6 +563,19 @@
                 }
             }
         } else if (strcmp("badging", option) == 0) {
+            Vector<String8> locales;
+            res.getLocales(&locales);
+
+            Vector<ResTable_config> configs;
+            res.getConfigurations(&configs);
+            SortedVector<int> densities;
+            const size_t NC = configs.size();
+            for (size_t i=0; i<NC; i++) {
+                int dens = configs[i].density;
+                if (dens == 0) dens = 160;
+                densities.add(dens);
+            }
+
             size_t len;
             ResXMLTree::event_code_t code;
             int depth = 0;
@@ -598,6 +632,8 @@
             bool specTouchscreenFeature = false; // touchscreen-related
             bool specMultitouchFeature = false;
             bool reqDistinctMultitouchFeature = false;
+            bool specScreenPortraitFeature = false;
+            bool specScreenLandscapeFeature = false;
             // 2.2 also added some other features that apps can request, but that
             // have no corresponding permission, so we cannot implement any
             // back-compatibility heuristic for them. The below are thus unnecessary
@@ -614,6 +650,9 @@
             int largeScreen = 1;
             int xlargeScreen = 1;
             int anyDensity = 1;
+            int requiresSmallestWidthDp = 0;
+            int compatibleWidthLimitDp = 0;
+            int largestWidthLimitDp = 0;
             String8 pkg;
             String8 activityName;
             String8 activityLabel;
@@ -628,10 +667,11 @@
                     } else if (depth < 3) {
                         if (withinActivity && isMainActivity && isLauncherActivity) {
                             const char *aName = getComponentName(pkg, activityName);
+                            printf("launchable-activity:");
                             if (aName != NULL) {
-                                printf("launchable activity name='%s'", aName);
+                                printf(" name='%s' ", aName);
                             }
-                            printf("label='%s' icon='%s'\n",
+                            printf(" label='%s' icon='%s'\n",
                                     activityLabel.string(),
                                     activityIcon.string());
                         }
@@ -696,23 +736,51 @@
                     withinApplication = false;
                     if (tag == "application") {
                         withinApplication = true;
-                        String8 label = getResolvedAttribute(&res, tree, LABEL_ATTR, &error);
-                         if (error != "") {
-                             fprintf(stderr, "ERROR getting 'android:label' attribute: %s\n", error.string());
-                             goto bail;
+
+                        String8 label;
+                        const size_t NL = locales.size();
+                        for (size_t i=0; i<NL; i++) {
+                            const char* localeStr =  locales[i].string();
+                            assets.setLocale(localeStr != NULL ? localeStr : "");
+                            String8 llabel = getResolvedAttribute(&res, tree, LABEL_ATTR, &error);
+                            if (llabel != "") {
+                                if (localeStr == NULL || strlen(localeStr) == 0) {
+                                    label = llabel;
+                                    printf("application-label:'%s'\n", llabel.string());
+                                } else {
+                                    if (label == "") {
+                                        label = llabel;
+                                    }
+                                    printf("application-label-%s:'%s'\n", localeStr,
+                                            llabel.string());
+                                }
+                            }
                         }
-                        printf("application: label='%s' ", label.string());
+
+                        ResTable_config tmpConfig = config;
+                        const size_t ND = densities.size();
+                        for (size_t i=0; i<ND; i++) {
+                            tmpConfig.density = densities[i];
+                            assets.setConfiguration(tmpConfig);
+                            String8 icon = getResolvedAttribute(&res, tree, ICON_ATTR, &error);
+                            if (icon != "") {
+                                printf("application-icon-%d:'%s'\n", densities[i], icon.string());
+                            }
+                        }
+                        assets.setConfiguration(config);
+
                         String8 icon = getResolvedAttribute(&res, tree, ICON_ATTR, &error);
                         if (error != "") {
                             fprintf(stderr, "ERROR getting 'android:icon' attribute: %s\n", error.string());
                             goto bail;
                         }
-                        printf("icon='%s'\n", icon.string());
                         int32_t testOnly = getIntegerAttribute(tree, TEST_ONLY_ATTR, &error, 0);
                         if (error != "") {
                             fprintf(stderr, "ERROR getting 'android:testOnly' attribute: %s\n", error.string());
                             goto bail;
                         }
+                        printf("application: label='%s' ", label.string());
+                        printf("icon='%s'\n", icon.string());
                         if (testOnly != 0) {
                             printf("testOnly='%d'\n", testOnly);
                         }
@@ -792,6 +860,12 @@
                                 XLARGE_SCREEN_ATTR, NULL, 1);
                         anyDensity = getIntegerAttribute(tree,
                                 ANY_DENSITY_ATTR, NULL, 1);
+                        requiresSmallestWidthDp = getIntegerAttribute(tree,
+                                REQUIRES_SMALLEST_WIDTH_DP_ATTR, NULL, 0);
+                        compatibleWidthLimitDp = getIntegerAttribute(tree,
+                                COMPATIBLE_WIDTH_LIMIT_DP_ATTR, NULL, 0);
+                        largestWidthLimitDp = getIntegerAttribute(tree,
+                                LARGEST_WIDTH_LIMIT_DP_ATTR, NULL, 0);
                     } else if (tag == "uses-feature") {
                         String8 name = getAttribute(tree, NAME_ATTR, &error);
 
@@ -837,6 +911,10 @@
                                 // these have no corresponding permission to check for,
                                 // but should imply the foundational telephony permission
                                 reqTelephonySubFeature = true;
+                            } else if (name == "android.hardware.screen.portrait") {
+                                specScreenPortraitFeature = true;
+                            } else if (name == "android.hardware.screen.landscape") {
+                                specScreenLandscapeFeature = true;
                             }
                             printf("uses-feature%s:'%s'\n",
                                     req ? "" : "-not-required", name.string());
@@ -1103,6 +1181,15 @@
                 printf("uses-feature:'android.hardware.touchscreen.multitouch'\n");
             }
 
+            // Landscape/portrait-related compatibility logic
+            if (!specScreenLandscapeFeature && !specScreenPortraitFeature && (targetSdk < 13)) {
+                // If app has not specified whether it requires portrait or landscape
+                // and is targeting an API before Honeycomb MR2, then assume it requires
+                // both.
+                printf("uses-feature:'android.hardware.screen.portrait'\n");
+                printf("uses-feature:'android.hardware.screen.landscape'\n");
+            }
+
             if (hasMainActivity) {
                 printf("main\n");
             }
@@ -1128,6 +1215,34 @@
                 printf("other-services\n");
             }
 
+            // For modern apps, if screen size buckets haven't been specified
+            // but the new width ranges have, then infer the buckets from them.
+            if (smallScreen > 0 && normalScreen > 0 && largeScreen > 0 && xlargeScreen > 0
+                    && requiresSmallestWidthDp > 0) {
+                int compatWidth = compatibleWidthLimitDp;
+                if (compatWidth <= 0) compatWidth = requiresSmallestWidthDp;
+                if (requiresSmallestWidthDp <= 240 && compatWidth >= 240) {
+                    smallScreen = -1;
+                } else {
+                    smallScreen = 0;
+                }
+                if (requiresSmallestWidthDp <= 320 && compatWidth >= 320) {
+                    normalScreen = -1;
+                } else {
+                    normalScreen = 0;
+                }
+                if (requiresSmallestWidthDp <= 480 && compatWidth >= 480) {
+                    largeScreen = -1;
+                } else {
+                    largeScreen = 0;
+                }
+                if (requiresSmallestWidthDp <= 720 && compatWidth >= 720) {
+                    xlargeScreen = -1;
+                } else {
+                    xlargeScreen = 0;
+                }
+            }
+
             // Determine default values for any unspecified screen sizes,
             // based on the target SDK of the package.  As of 4 (donut)
             // the screen size support was introduced, so all default to
@@ -1146,7 +1261,8 @@
                 xlargeScreen = targetSdk >= 9 ? -1 : 0;
             }
             if (anyDensity > 0) {
-                anyDensity = targetSdk >= 4 ? -1 : 0;
+                anyDensity = (targetSdk >= 4 || requiresSmallestWidthDp > 0
+                        || compatibleWidthLimitDp > 0) ? -1 : 0;
             }
             printf("supports-screens:");
             if (smallScreen != 0) printf(" 'small'");
@@ -1154,12 +1270,18 @@
             if (largeScreen != 0) printf(" 'large'");
             if (xlargeScreen != 0) printf(" 'xlarge'");
             printf("\n");
-
             printf("supports-any-density: '%s'\n", anyDensity ? "true" : "false");
+            if (requiresSmallestWidthDp > 0) {
+                printf("requires-smallest-width:'%d'\n", requiresSmallestWidthDp);
+            }
+            if (compatibleWidthLimitDp > 0) {
+                printf("compatible-width-limit:'%d'\n", compatibleWidthLimitDp);
+            }
+            if (largestWidthLimitDp > 0) {
+                printf("largest-width-limit:'%d'\n", largestWidthLimitDp);
+            }
 
             printf("locales:");
-            Vector<String8> locales;
-            res.getLocales(&locales);
             const size_t NL = locales.size();
             for (size_t i=0; i<NL; i++) {
                 const char* localeStr =  locales[i].string();
@@ -1170,16 +1292,6 @@
             }
             printf("\n");
 
-            Vector<ResTable_config> configs;
-            res.getConfigurations(&configs);
-            SortedVector<int> densities;
-            const size_t NC = configs.size();
-            for (size_t i=0; i<NC; i++) {
-                int dens = configs[i].density;
-                if (dens == 0) dens = 160;
-                densities.add(dens);
-            }
-
             printf("densities:");
             const size_t ND = densities.size();
             for (size_t i=0; i<ND; i++) {