Merge "Fix crash in bug 4259574"
diff --git a/api/current.xml b/api/current.xml
index 31b1353..2b10d42 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -10025,6 +10025,39 @@
  visibility="public"
 >
 </field>
+<field name="textEditSuggestionItemLayout"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843626"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="textEditSuggestionsBottomWindowLayout"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843624"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="textEditSuggestionsTopWindowLayout"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843625"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="textFilterEnabled"
  type="int"
  transient="false"
@@ -10146,6 +10179,17 @@
  visibility="public"
 >
 </field>
+<field name="textSuggestionsWindowStyle"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843623"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="textViewStyle"
  type="int"
  transient="false"
@@ -57955,6 +57999,17 @@
  visibility="public"
 >
 </field>
+<field name="CONFIG_SCREEN_SIZE"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="1024"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="CONFIG_TOUCHSCREEN"
  type="int"
  transient="false"
@@ -64017,6 +64072,28 @@
  visibility="public"
 >
 </field>
+<field name="SCREEN_HEIGHT_DP_UNDEFINED"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SCREEN_WIDTH_DP_UNDEFINED"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="TOUCHSCREEN_FINGER"
  type="int"
  transient="false"
@@ -64260,6 +64337,16 @@
  visibility="public"
 >
 </field>
+<field name="screenHeightDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="screenLayout"
  type="int"
  transient="false"
@@ -64270,6 +64357,16 @@
  visibility="public"
 >
 </field>
+<field name="screenWidthDp"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="touchscreen"
  type="int"
  transient="false"
@@ -144074,6 +144171,17 @@
  visibility="public"
 >
 </field>
+<field name="ICE_CREAM_SANDWICH"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="10000"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 </class>
 <class name="Bundle"
  extends="java.lang.Object"
@@ -180231,6 +180339,17 @@
  visibility="public"
 >
 </field>
+<field name="EXTRA_CONFIDENCE_SCORES"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.speech.extra.CONFIDENCE_SCORES&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="EXTRA_LANGUAGE"
  type="java.lang.String"
  transient="false"
@@ -180286,6 +180405,17 @@
  visibility="public"
 >
 </field>
+<field name="EXTRA_ORIGIN"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;android.speech.extra.ORIGIN&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="EXTRA_PARTIAL_RESULTS"
  type="java.lang.String"
  transient="false"
@@ -180668,6 +180798,17 @@
  visibility="public"
 >
 </method>
+<field name="CONFIDENCE_SCORES"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;confidence_scores&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="ERROR_AUDIO"
  type="int"
  transient="false"
@@ -213028,6 +213169,17 @@
  visibility="public"
 >
 </method>
+<method name="getModifiers"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="getNumber"
  return="char"
  abstract="false"
diff --git a/cmds/installd/Android.mk b/cmds/installd/Android.mk
index 8641c30..d7a9ef6 100644
--- a/cmds/installd/Android.mk
+++ b/cmds/installd/Android.mk
@@ -1,13 +1,34 @@
 ifneq ($(TARGET_SIMULATOR),true)
 
 LOCAL_PATH := $(call my-dir)
+
+common_src_files := \
+    commands.c utils.c
+
+#
+# Static library used in testing and executable
+#
+
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
-    installd.c commands.c utils.c
+    $(common_src_files)
 
-#LOCAL_C_INCLUDES := \
-#    $(call include-path-for, system-core)/cutils
+LOCAL_MODULE := libinstalld
+
+LOCAL_MODULE_TAGS := eng tests
+
+include $(BUILD_STATIC_LIBRARY)
+
+#
+# Executable
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+    installd.c \
+    $(common_src_files)
 
 LOCAL_SHARED_LIBRARIES := \
     libcutils
diff --git a/cmds/installd/commands.c b/cmds/installd/commands.c
index 4d49c30..80ba1e9 100644
--- a/cmds/installd/commands.c
+++ b/cmds/installd/commands.c
@@ -17,6 +17,13 @@
 #include "installd.h"
 #include <diskusage/dirsize.h>
 
+/* Directory records that are used in execution of commands. */
+dir_rec_t android_data_dir;
+dir_rec_t android_asec_dir;
+dir_rec_t android_app_dir;
+dir_rec_t android_app_private_dir;
+dir_rec_array_t android_system_dirs;
+
 int install(const char *pkgname, uid_t uid, gid_t gid)
 {
     char pkgdir[PKG_PATH_MAX];
@@ -27,10 +34,15 @@
         return -1;
     }
 
-    if (create_pkg_path(pkgdir, PKG_DIR_PREFIX, pkgname, PKG_DIR_POSTFIX))
+    if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, 0)) {
+        LOGE("cannot create package path\n");
         return -1;
-    if (create_pkg_path(libdir, PKG_LIB_PREFIX, pkgname, PKG_LIB_POSTFIX))
+    }
+
+    if (create_pkg_path(libdir, pkgname, PKG_LIB_POSTFIX, 0)) {
+        LOGE("cannot create package lib path\n");
         return -1;
+    }
 
     if (mkdir(pkgdir, 0751) < 0) {
         LOGE("cannot create dir '%s': %s\n", pkgdir, strerror(errno));
@@ -59,7 +71,7 @@
 {
     char pkgdir[PKG_PATH_MAX];
 
-    if (create_pkg_path(pkgdir, PKG_DIR_PREFIX, pkgname, PKG_DIR_POSTFIX))
+    if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, 0))
         return -1;
 
         /* delete contents AND directory, no exceptions */
@@ -71,9 +83,9 @@
     char oldpkgdir[PKG_PATH_MAX];
     char newpkgdir[PKG_PATH_MAX];
 
-    if (create_pkg_path(oldpkgdir, PKG_DIR_PREFIX, oldpkgname, PKG_DIR_POSTFIX))
+    if (create_pkg_path(oldpkgdir, oldpkgname, PKG_DIR_POSTFIX, 0))
         return -1;
-    if (create_pkg_path(newpkgdir, PKG_DIR_PREFIX, newpkgname, PKG_DIR_POSTFIX))
+    if (create_pkg_path(newpkgdir, newpkgname, PKG_DIR_POSTFIX, 0))
         return -1;
 
     if (rename(oldpkgdir, newpkgdir) < 0) {
@@ -87,7 +99,7 @@
 {
     char pkgdir[PKG_PATH_MAX];
 
-    if (create_pkg_path(pkgdir, PKG_DIR_PREFIX, pkgname, PKG_DIR_POSTFIX))
+    if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, 0))
         return -1;
 
         /* delete contents, excluding "lib", but not the directory itself */
@@ -98,7 +110,7 @@
 {
     char cachedir[PKG_PATH_MAX];
 
-    if (create_pkg_path(cachedir, CACHE_DIR_PREFIX, pkgname, CACHE_DIR_POSTFIX))
+    if (create_pkg_path(cachedir, pkgname, CACHE_DIR_POSTFIX, 0))
         return -1;
 
         /* delete contents, not the directory, no exceptions */
@@ -108,10 +120,10 @@
 static int64_t disk_free()
 {
     struct statfs sfs;
-    if (statfs(PKG_DIR_PREFIX, &sfs) == 0) {
+    if (statfs(android_data_dir.path, &sfs) == 0) {
         return sfs.f_bavail * sfs.f_bsize;
     } else {
-        LOGE("Couldn't statfs " PKG_DIR_PREFIX ": %s\n", strerror(errno));
+        LOGE("Couldn't statfs %s: %s\n", android_data_dir.path, strerror(errno));
         return -1;
     }
 }
@@ -137,9 +149,9 @@
     LOGI("free_cache(%" PRId64 ") avail %" PRId64 "\n", free_size, avail);
     if (avail >= free_size) return 0;
 
-    d = opendir(PKG_DIR_PREFIX);
+    d = opendir(android_data_dir.path);
     if (d == NULL) {
-        LOGE("cannot open %s: %s\n", PKG_DIR_PREFIX, strerror(errno));
+        LOGE("cannot open %s: %s\n", android_data_dir.path, strerror(errno));
         return -1;
     }
     dfd = dirfd(d);
@@ -172,43 +184,13 @@
     return -1;
 }
 
-/* used by move_dex, rm_dex, etc to ensure that the provided paths
- * don't point anywhere other than at the APK_DIR_PREFIX
- */
-static int is_valid_apk_path(const char *path)
-{
-    int len = strlen(APK_DIR_PREFIX);
-int nosubdircheck = 0;
-    if (strncmp(path, APK_DIR_PREFIX, len)) {
-        len = strlen(PROTECTED_DIR_PREFIX);
-        if (strncmp(path, PROTECTED_DIR_PREFIX, len)) {
-            len = strlen(SDCARD_DIR_PREFIX);
-            if (strncmp(path, SDCARD_DIR_PREFIX, len)) {
-                LOGE("invalid apk path '%s' (bad prefix)\n", path);
-                return 0;
-            } else {
-                nosubdircheck = 1;
-            }
-        }
-    }
-    if ((nosubdircheck != 1) && strchr(path + len, '/')) {
-        LOGE("invalid apk path '%s' (subdir?)\n", path);
-        return 0;
-    }
-    if (path[len] == '.') {
-        LOGE("invalid apk path '%s' (trickery)\n", path);
-        return 0;
-    }
-    return 1;
-}
-
 int move_dex(const char *src, const char *dst)
 {
     char src_dex[PKG_PATH_MAX];
     char dst_dex[PKG_PATH_MAX];
 
-    if (!is_valid_apk_path(src)) return -1;
-    if (!is_valid_apk_path(dst)) return -1;
+    if (validate_apk_path(src)) return -1;
+    if (validate_apk_path(dst)) return -1;
 
     if (create_cache_path(src_dex, src)) return -1;
     if (create_cache_path(dst_dex, dst)) return -1;
@@ -226,7 +208,7 @@
 {
     char dex_path[PKG_PATH_MAX];
 
-    if (!is_valid_apk_path(path)) return -1;
+    if (validate_apk_path(path)) return -1;
     if (create_cache_path(dex_path, path)) return -1;
 
     LOGI("unlink %s\n", dex_path);
@@ -245,7 +227,7 @@
 
     if (gid < AID_SYSTEM) return -1;
 
-    if (create_pkg_path(pkgpath, PROTECTED_DIR_PREFIX, pkgname, ".apk"))
+    if (create_pkg_path_in_dir(pkgpath, &android_app_private_dir, pkgname, ".apk"))
         return -1;
 
     if (stat(pkgpath, &s) < 0) return -1;
@@ -280,8 +262,8 @@
         /* count the source apk as code -- but only if it's not
          * on the /system partition and its not on the sdcard.
          */
-    if (strncmp(apkpath, "/system", 7) != 0 &&
-            strncmp(apkpath, SDCARD_DIR_PREFIX, 7) != 0) {
+    if (validate_system_app_path(apkpath) &&
+            strncmp(apkpath, android_asec_dir.path, android_asec_dir.len) != 0) {
         if (stat(apkpath, &s) == 0) {
             codesize += stat_size(&s);
         }
@@ -300,7 +282,7 @@
         }
     }
 
-    if (create_pkg_path(path, PKG_DIR_PREFIX, pkgname, PKG_DIR_POSTFIX)) {
+    if (create_pkg_path(path, pkgname, PKG_DIR_POSTFIX, 0)) {
         goto done;
     }
 
@@ -310,10 +292,10 @@
     }
     dfd = dirfd(d);
 
-        /* most stuff in the pkgdir is data, except for the "cache"
-         * directory and below, which is cache, and the "lib" directory
-         * and below, which is code...
-         */
+    /* most stuff in the pkgdir is data, except for the "cache"
+     * directory and below, which is cache, and the "lib" directory
+     * and below, which is code...
+     */
     while ((de = readdir(d))) {
         const char *name = de->d_name;
 
@@ -544,15 +526,15 @@
 }
 
 int create_move_path(char path[PKG_PATH_MAX],
-    const char* prefix,
     const char* pkgname,
-    const char* leaf)
+    const char* leaf,
+    uid_t persona)
 {
-    if ((strlen(prefix) + strlen(pkgname) + strlen(leaf) + 1) >= PKG_PATH_MAX) {
+    if ((android_data_dir.len + strlen(pkgname) + strlen(leaf) + 1) >= PKG_PATH_MAX) {
         return -1;
     }
     
-    sprintf(path, "%s%s/%s", prefix, pkgname, leaf);
+    sprintf(path, "%s%s%s/%s", android_data_dir.path, PRIMARY_USER_PREFIX, pkgname, leaf);
     return 0;
 }
 
@@ -720,8 +702,8 @@
                             // Skip -- source package no longer exists.
                         } else {
                             LOGV("Move file: %s (from %s to %s)\n", buf+bufp, srcpkg, dstpkg);
-                            if (!create_move_path(srcpath, PKG_DIR_PREFIX, srcpkg, buf+bufp) &&
-                                    !create_move_path(dstpath, PKG_DIR_PREFIX, dstpkg, buf+bufp)) {
+                            if (!create_move_path(srcpath, srcpkg, buf+bufp, 0) &&
+                                    !create_move_path(dstpath, dstpkg, buf+bufp, 0)) {
                                 movefileordir(srcpath, dstpath,
                                         strlen(dstpath)-strlen(buf+bufp),
                                         dstuid, dstgid, &s);
@@ -750,8 +732,7 @@
                                         UPDATE_COMMANDS_DIR_PREFIX, name, div);
                             }
                             if (srcpkg[0] != 0) {
-                                if (!create_pkg_path(srcpath, PKG_DIR_PREFIX, srcpkg,
-                                        PKG_DIR_POSTFIX)) {
+                                if (!create_pkg_path(srcpath, srcpkg, PKG_DIR_POSTFIX, 0)) {
                                     if (lstat(srcpath, &s) < 0) {
                                         // Package no longer exists -- skip.
                                         srcpkg[0] = 0;
@@ -762,8 +743,7 @@
                                             div, UPDATE_COMMANDS_DIR_PREFIX, name);
                                 }
                                 if (srcpkg[0] != 0) {
-                                    if (!create_pkg_path(dstpath, PKG_DIR_PREFIX, dstpkg,
-                                            PKG_DIR_POSTFIX)) {
+                                    if (!create_pkg_path(dstpath, dstpkg, PKG_DIR_POSTFIX, 0)) {
                                         if (lstat(dstpath, &s) == 0) {
                                             dstuid = s.st_uid;
                                             dstgid = s.st_gid;
diff --git a/cmds/installd/installd.c b/cmds/installd/installd.c
index d2b2f7f..e0d0f97 100644
--- a/cmds/installd/installd.c
+++ b/cmds/installd/installd.c
@@ -21,7 +21,6 @@
 #define TOKEN_MAX     8     /* max number of arguments in buffer */
 #define REPLY_MAX     256   /* largest reply allowed */
 
-
 static int do_ping(char **arg, char reply[REPLY_MAX])
 {
     return 0;
@@ -235,12 +234,77 @@
     return 0;
 }
 
-int main(const int argc, const char *argv[]) {    
+/**
+ * Initialize all the global variables that are used elsewhere. Returns 0 upon
+ * success and -1 on error.
+ */
+void free_globals() {
+    size_t i;
+
+    for (i = 0; i < android_system_dirs.count; i++) {
+        if (android_system_dirs.dirs[i].path != NULL) {
+            free(android_system_dirs.dirs[i].path);
+        }
+    }
+
+    free(android_system_dirs.dirs);
+}
+
+int initialize_globals() {
+    // Get the android data directory.
+    if (get_path_from_env(&android_data_dir, "ANDROID_DATA") < 0) {
+        return -1;
+    }
+
+    // Get the android app directory.
+    if (copy_and_append(&android_app_dir, &android_data_dir, APP_SUBDIR) < 0) {
+        return -1;
+    }
+
+    // Get the android protected app directory.
+    if (copy_and_append(&android_app_private_dir, &android_data_dir, PRIVATE_APP_SUBDIR) < 0) {
+        return -1;
+    }
+
+    // Get the sd-card ASEC mount point.
+    if (get_path_from_env(&android_asec_dir, "ASEC_MOUNTPOINT") < 0) {
+        return -1;
+    }
+
+    // Take note of the system and vendor directories.
+    android_system_dirs.count = 2;
+
+    android_system_dirs.dirs = calloc(android_system_dirs.count, sizeof(dir_rec_t));
+    if (android_system_dirs.dirs == NULL) {
+        LOGE("Couldn't allocate array for dirs; aborting\n");
+        return -1;
+    }
+
+    // system
+    if (get_path_from_env(&android_system_dirs.dirs[0], "ANDROID_ROOT") < 0) {
+        free_globals();
+        return -1;
+    }
+
+    // vendor
+    // TODO replace this with an environment variable (doesn't exist yet)
+    android_system_dirs.dirs[1].path = "/vendor/";
+    android_system_dirs.dirs[1].len = strlen(android_system_dirs.dirs[1].path);
+
+    return 0;
+}
+
+int main(const int argc, const char *argv[]) {
     char buf[BUFFER_MAX];
     struct sockaddr addr;
     socklen_t alen;
     int lsocket, s, count;
 
+    if (initialize_globals() < 0) {
+        LOGE("Could not initialize globals; exiting.\n");
+        exit(1);
+    }
+
     lsocket = android_get_control_socket(SOCKET_PATH);
     if (lsocket < 0) {
         LOGE("Failed to get socket from environment: %s\n", strerror(errno));
diff --git a/cmds/installd/installd.h b/cmds/installd/installd.h
index 77b58ec..cbca135 100644
--- a/cmds/installd/installd.h
+++ b/cmds/installd/installd.h
@@ -49,37 +49,60 @@
 
 /* elements combined with a valid package name to form paths */
 
-#define PKG_DIR_PREFIX         "/data/data/"
+#define PRIMARY_USER_PREFIX    "data/"
+#define SECONDARY_USER_PREFIX  "user/"
+
 #define PKG_DIR_POSTFIX        ""
 
-#define PKG_LIB_PREFIX         "/data/data/"
 #define PKG_LIB_POSTFIX        "/lib"
 
-#define CACHE_DIR_PREFIX       "/data/data/"
 #define CACHE_DIR_POSTFIX      "/cache"
 
-#define APK_DIR_PREFIX         "/data/app/"
+#define APP_SUBDIR             "app/" // sub-directory under ANDROID_DATA
 
 /* other handy constants */
 
-#define PROTECTED_DIR_PREFIX  "/data/app-private/"
-#define SDCARD_DIR_PREFIX  getenv("ASEC_MOUNTPOINT")
+#define PRIVATE_APP_SUBDIR     "app-private/" // sub-directory under ANDROID_DATA
 
-#define DALVIK_CACHE_PREFIX   "/data/dalvik-cache/"
-#define DALVIK_CACHE_POSTFIX  "/classes.dex"
+#define DALVIK_CACHE_PREFIX    "/data/dalvik-cache/"
+#define DALVIK_CACHE_POSTFIX   "/classes.dex"
 
 #define UPDATE_COMMANDS_DIR_PREFIX  "/system/etc/updatecmds/"
 
 #define PKG_NAME_MAX  128   /* largest allowed package name */
 #define PKG_PATH_MAX  256   /* max size of any path we use */
 
+/* data structures */
+
+typedef struct {
+    char* path;
+    size_t len;
+} dir_rec_t;
+
+typedef struct {
+    size_t count;
+    dir_rec_t* dirs;
+} dir_rec_array_t;
+
+extern dir_rec_t android_app_dir;
+extern dir_rec_t android_app_private_dir;
+extern dir_rec_t android_data_dir;
+extern dir_rec_t android_asec_dir;
+extern dir_rec_array_t android_system_dirs;
 
 /* util.c */
 
+int create_pkg_path_in_dir(char path[PKG_PATH_MAX],
+                                const dir_rec_t* dir,
+                                const char* pkgname,
+                                const char* postfix);
+
 int create_pkg_path(char path[PKG_PATH_MAX],
-                    const char *prefix,
                     const char *pkgname,
-                    const char *postfix);
+                    const char *postfix,
+                    uid_t persona);
+
+int is_valid_package_name(const char* pkgname);
 
 int create_cache_path(char path[PKG_PATH_MAX], const char *src);
 
@@ -89,6 +112,18 @@
 
 int delete_dir_contents_fd(int dfd, const char *name);
 
+int validate_system_app_path(const char* path);
+
+int get_path_from_env(dir_rec_t* rec, const char* var);
+
+int get_path_from_string(dir_rec_t* rec, const char* path);
+
+int copy_and_append(dir_rec_t* dst, const dir_rec_t* src, const char* suffix);
+
+int validate_apk_path(const char *path);
+
+int append_and_increment(char** dst, const char* src, size_t* dst_size);
+
 /* commands.c */
 
 int install(const char *pkgname, uid_t uid, gid_t gid);
diff --git a/cmds/installd/tests/Android.mk b/cmds/installd/tests/Android.mk
new file mode 100644
index 0000000..e53378d
--- /dev/null
+++ b/cmds/installd/tests/Android.mk
@@ -0,0 +1,42 @@
+# Build the unit tests for installd
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+ifneq ($(TARGET_SIMULATOR),true)
+
+# Build the unit tests.
+test_src_files := \
+    installd_utils_test.cpp
+
+shared_libraries := \
+    libutils \
+    libcutils \
+    libstlport
+
+static_libraries := \
+    libinstalld \
+    libdiskusage \
+    libgtest \
+    libgtest_main
+
+c_includes := \
+    frameworks/base/cmds/installd \
+    bionic \
+    bionic/libstdc++/include \
+    external/gtest/include \
+    external/stlport/stlport
+
+module_tags := eng tests
+
+$(foreach file,$(test_src_files), \
+    $(eval include $(CLEAR_VARS)) \
+    $(eval LOCAL_SHARED_LIBRARIES := $(shared_libraries)) \
+    $(eval LOCAL_STATIC_LIBRARIES := $(static_libraries)) \
+    $(eval LOCAL_SRC_FILES := $(file)) \
+    $(eval LOCAL_C_INCLUDES := $(c_includes)) \
+    $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \
+    $(eval LOCAL_MODULE_TAGS := $(module_tags)) \
+    $(eval include $(BUILD_EXECUTABLE)) \
+)
+
+endif
diff --git a/cmds/installd/tests/installd_utils_test.cpp b/cmds/installd/tests/installd_utils_test.cpp
new file mode 100644
index 0000000..1128fce
--- /dev/null
+++ b/cmds/installd/tests/installd_utils_test.cpp
@@ -0,0 +1,383 @@
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#define LOG_TAG "utils_test"
+#include <utils/Log.h>
+
+#include <gtest/gtest.h>
+
+extern "C" {
+#include "installd.h"
+}
+
+#define TEST_DATA_DIR "/data/"
+#define TEST_APP_DIR "/data/app/"
+#define TEST_APP_PRIVATE_DIR "/data/app-private/"
+#define TEST_ASEC_DIR "/mnt/asec/"
+
+#define TEST_SYSTEM_DIR1 "/system/app/"
+#define TEST_SYSTEM_DIR2 "/vendor/app/"
+
+namespace android {
+
+class UtilsTest : public testing::Test {
+protected:
+    virtual void SetUp() {
+        android_app_dir.path = TEST_APP_DIR;
+        android_app_dir.len = strlen(TEST_APP_DIR);
+
+        android_app_private_dir.path = TEST_APP_PRIVATE_DIR;
+        android_app_private_dir.len = strlen(TEST_APP_PRIVATE_DIR);
+
+        android_data_dir.path = TEST_DATA_DIR;
+        android_data_dir.len = strlen(TEST_DATA_DIR);
+
+        android_asec_dir.path = TEST_ASEC_DIR;
+        android_asec_dir.len = strlen(TEST_ASEC_DIR);
+
+        android_system_dirs.count = 2;
+
+        android_system_dirs.dirs = (dir_rec_t*) calloc(android_system_dirs.count, sizeof(dir_rec_t));
+        android_system_dirs.dirs[0].path = TEST_SYSTEM_DIR1;
+        android_system_dirs.dirs[0].len = strlen(TEST_SYSTEM_DIR1);
+
+        android_system_dirs.dirs[1].path = TEST_SYSTEM_DIR2;
+        android_system_dirs.dirs[1].len = strlen(TEST_SYSTEM_DIR2);
+    }
+
+    virtual void TearDown() {
+        free(android_system_dirs.dirs);
+    }
+};
+
+TEST_F(UtilsTest, IsValidApkPath_BadPrefix) {
+    // Bad prefixes directories
+    const char *badprefix1 = "/etc/passwd";
+    EXPECT_EQ(-1, validate_apk_path(badprefix1))
+            << badprefix1 << " should be allowed as a valid path";
+
+    const char *badprefix2 = "../.." TEST_APP_DIR "../../../blah";
+    EXPECT_EQ(-1, validate_apk_path(badprefix2))
+            << badprefix2 << " should be allowed as a valid path";
+
+    const char *badprefix3 = "init.rc";
+    EXPECT_EQ(-1, validate_apk_path(badprefix3))
+            << badprefix3 << " should be allowed as a valid path";
+
+    const char *badprefix4 = "/init.rc";
+    EXPECT_EQ(-1, validate_apk_path(badprefix4))
+            << badprefix4 << " should be allowed as a valid path";
+}
+
+TEST_F(UtilsTest, IsValidApkPath_Internal) {
+    // Internal directories
+    const char *internal1 = TEST_APP_DIR "example.apk";
+    EXPECT_EQ(0, validate_apk_path(internal1))
+            << internal1 << " should be allowed as a valid path";
+
+    const char *badint1 = TEST_APP_DIR "../example.apk";
+    EXPECT_EQ(-1, validate_apk_path(badint1))
+            << badint1 << " should be rejected as a invalid path";
+
+    const char *badint2 = TEST_APP_DIR "/../example.apk";
+    EXPECT_EQ(-1, validate_apk_path(badint2))
+            << badint2 << " should be rejected as a invalid path";
+
+    const char *badint3 = TEST_APP_DIR "example.com/pkg.apk";
+    EXPECT_EQ(-1, validate_apk_path(badint3))
+            << badint3 << " should be rejected as a invalid path";
+}
+
+TEST_F(UtilsTest, IsValidApkPath_Private) {
+    // Internal directories
+    const char *private1 = TEST_APP_PRIVATE_DIR "example.apk";
+    EXPECT_EQ(0, validate_apk_path(private1))
+            << private1 << " should be allowed as a valid path";
+
+    const char *badpriv1 = TEST_APP_PRIVATE_DIR "../example.apk";
+    EXPECT_EQ(-1, validate_apk_path(badpriv1))
+            << badpriv1 << " should be rejected as a invalid path";
+
+    const char *badpriv2 = TEST_APP_PRIVATE_DIR "/../example.apk";
+    EXPECT_EQ(-1, validate_apk_path(badpriv2))
+            << badpriv2 << " should be rejected as a invalid path";
+
+    const char *badpriv3 = TEST_APP_PRIVATE_DIR "example.com/pkg.apk";
+    EXPECT_EQ(-1, validate_apk_path(badpriv3))
+            << badpriv3 << " should be rejected as a invalid path";
+}
+
+
+TEST_F(UtilsTest, IsValidApkPath_AsecGood1) {
+    const char *asec1 = TEST_ASEC_DIR "example.apk";
+    EXPECT_EQ(0, validate_apk_path(asec1))
+            << asec1 << " should be allowed as a valid path";
+}
+
+TEST_F(UtilsTest, IsValidApkPath_AsecGood2) {
+    const char *asec2 = TEST_ASEC_DIR "com.example.asec/pkg.apk";
+    EXPECT_EQ(0, validate_apk_path(asec2))
+            << asec2 << " should be allowed as a valid path";
+}
+
+TEST_F(UtilsTest, IsValidApkPath_EscapeFail) {
+    const char *badasec1 = TEST_ASEC_DIR "../example.apk";
+    EXPECT_EQ(-1, validate_apk_path(badasec1))
+            << badasec1 << " should be rejected as a invalid path";
+}
+
+TEST_F(UtilsTest, IsValidApkPath_DoubleSlashFail) {
+    const char *badasec2 = TEST_ASEC_DIR "com.example.asec//pkg.apk";
+    EXPECT_EQ(-1, validate_apk_path(badasec2))
+            << badasec2 << " should be rejected as a invalid path";
+}
+
+TEST_F(UtilsTest, IsValidApkPath_SubdirEscapeFail) {
+    const char *badasec3 = TEST_ASEC_DIR "com.example.asec/../../../pkg.apk";
+    EXPECT_EQ(-1, validate_apk_path(badasec3))
+            << badasec3  << " should be rejected as a invalid path";
+}
+
+TEST_F(UtilsTest, IsValidApkPath_SlashEscapeFail) {
+    const char *badasec4 = TEST_ASEC_DIR "/../example.apk";
+    EXPECT_EQ(-1, validate_apk_path(badasec4))
+            << badasec4 << " should be rejected as a invalid path";
+}
+
+TEST_F(UtilsTest, IsValidApkPath_CrazyDirFail) {
+    const char *badasec5 = TEST_ASEC_DIR ".//../..";
+    EXPECT_EQ(-1, validate_apk_path(badasec5))
+            << badasec5 << " should be rejected as a invalid path";
+}
+
+TEST_F(UtilsTest, IsValidApkPath_SubdirEscapeSingleFail) {
+    const char *badasec6 = TEST_ASEC_DIR "com.example.asec/../pkg.apk";
+    EXPECT_EQ(-1, validate_apk_path(badasec6))
+            << badasec6 << " should be rejected as a invalid path";
+}
+
+TEST_F(UtilsTest, IsValidApkPath_TwoSubdirFail) {
+    const char *badasec7 = TEST_ASEC_DIR "com.example.asec/subdir1/pkg.apk";
+    EXPECT_EQ(-1, validate_apk_path(badasec7))
+            << badasec7 << " should be rejected as a invalid path";
+}
+
+TEST_F(UtilsTest, CheckSystemApp_Dir1) {
+    const char *sysapp1 = TEST_SYSTEM_DIR1 "Voice.apk";
+    EXPECT_EQ(0, validate_system_app_path(sysapp1))
+            << sysapp1 << " should be allowed as a system path";
+}
+
+TEST_F(UtilsTest, CheckSystemApp_Dir2) {
+    const char *sysapp2 = TEST_SYSTEM_DIR2 "com.example.myapp.apk";
+    EXPECT_EQ(0, validate_system_app_path(sysapp2))
+            << sysapp2 << " should be allowed as a system path";
+}
+
+TEST_F(UtilsTest, CheckSystemApp_EscapeFail) {
+    const char *badapp1 = TEST_SYSTEM_DIR1 "../com.example.apk";
+    EXPECT_EQ(-1, validate_system_app_path(badapp1))
+            << badapp1 << " should be rejected not a system path";
+}
+
+TEST_F(UtilsTest, CheckSystemApp_DoubleEscapeFail) {
+    const char *badapp2 = TEST_SYSTEM_DIR2 "/../../com.example.apk";
+    EXPECT_EQ(-1, validate_system_app_path(badapp2))
+            << badapp2 << " should be rejected not a system path";
+}
+
+TEST_F(UtilsTest, CheckSystemApp_BadPathEscapeFail) {
+    const char *badapp3 = TEST_APP_DIR "/../../com.example.apk";
+    EXPECT_EQ(-1, validate_system_app_path(badapp3))
+            << badapp3 << " should be rejected not a system path";
+}
+
+TEST_F(UtilsTest, GetPathFromString_NullPathFail) {
+    dir_rec_t test1;
+    EXPECT_EQ(-1, get_path_from_string(&test1, NULL))
+            << "Should not allow NULL as a path.";
+}
+
+TEST_F(UtilsTest, GetPathFromString_EmptyPathFail) {
+    dir_rec_t test1;
+    EXPECT_EQ(-1, get_path_from_string(&test1, ""))
+            << "Should not allow empty paths.";
+}
+
+TEST_F(UtilsTest, GetPathFromString_RelativePathFail) {
+    dir_rec_t test1;
+    EXPECT_EQ(-1, get_path_from_string(&test1, "mnt/asec"))
+            << "Should not allow relative paths.";
+}
+
+TEST_F(UtilsTest, GetPathFromString_NonCanonical) {
+    dir_rec_t test1;
+
+    EXPECT_EQ(0, get_path_from_string(&test1, "/mnt/asec"))
+            << "Should be able to canonicalize directory /mnt/asec";
+    EXPECT_STREQ("/mnt/asec/", test1.path)
+            << "/mnt/asec should be canonicalized to /mnt/asec/";
+    EXPECT_EQ(10, (ssize_t) test1.len)
+            << "path len should be equal to the length of /mnt/asec/ (10)";
+    free(test1.path);
+}
+
+TEST_F(UtilsTest, GetPathFromString_CanonicalPath) {
+    dir_rec_t test3;
+    EXPECT_EQ(0, get_path_from_string(&test3, "/data/app/"))
+            << "Should be able to canonicalize directory /data/app/";
+    EXPECT_STREQ("/data/app/", test3.path)
+            << "/data/app/ should be canonicalized to /data/app/";
+    EXPECT_EQ(10, (ssize_t) test3.len)
+            << "path len should be equal to the length of /data/app/ (10)";
+    free(test3.path);
+}
+
+TEST_F(UtilsTest, CreatePkgPath_LongPkgNameSuccess) {
+    char path[PKG_PATH_MAX];
+
+    // Create long packagename of "aaaaa..."
+    size_t pkgnameSize = PKG_NAME_MAX;
+    char pkgname[pkgnameSize + 1];
+    memset(pkgname, 'a', pkgnameSize);
+    pkgname[pkgnameSize] = '\0';
+
+    EXPECT_EQ(0, create_pkg_path(path, pkgname, "", 0))
+            << "Should successfully be able to create package name.";
+
+    const char *prefix = TEST_DATA_DIR PRIMARY_USER_PREFIX;
+    size_t offset = strlen(prefix);
+    EXPECT_STREQ(pkgname, path + offset)
+             << "Package path should be a really long string of a's";
+}
+
+TEST_F(UtilsTest, CreatePkgPath_LongPkgNameFail) {
+    char path[PKG_PATH_MAX];
+
+    // Create long packagename of "aaaaa..."
+    size_t pkgnameSize = PKG_NAME_MAX + 1;
+    char pkgname[pkgnameSize + 1];
+    memset(pkgname, 'a', pkgnameSize);
+    pkgname[pkgnameSize] = '\0';
+
+    EXPECT_EQ(-1, create_pkg_path(path, pkgname, "", 0))
+            << "Should return error because package name is too long.";
+}
+
+TEST_F(UtilsTest, CreatePkgPath_LongPostfixFail) {
+    char path[PKG_PATH_MAX];
+
+    // Create long packagename of "aaaaa..."
+    size_t postfixSize = PKG_PATH_MAX;
+    char postfix[postfixSize + 1];
+    memset(postfix, 'a', postfixSize);
+    postfix[postfixSize] = '\0';
+
+    EXPECT_EQ(-1, create_pkg_path(path, "com.example.package", postfix, 0))
+            << "Should return error because postfix is too long.";
+}
+
+TEST_F(UtilsTest, CreatePkgPath_PrimaryUser) {
+    char path[PKG_PATH_MAX];
+
+    EXPECT_EQ(0, create_pkg_path(path, "com.example.package", "", 0))
+            << "Should return error because postfix is too long.";
+
+    EXPECT_STREQ(TEST_DATA_DIR PRIMARY_USER_PREFIX "com.example.package", path)
+            << "Package path should be in /data/data/";
+}
+
+TEST_F(UtilsTest, CreatePkgPath_SecondaryUser) {
+    char path[PKG_PATH_MAX];
+
+    EXPECT_EQ(0, create_pkg_path(path, "com.example.package", "", 1))
+            << "Should successfully create package path.";
+
+    EXPECT_STREQ(TEST_DATA_DIR SECONDARY_USER_PREFIX "1/com.example.package", path)
+            << "Package path should be in /data/user/";
+}
+
+TEST_F(UtilsTest, CreatePkgPathInDir_ProtectedDir) {
+    char path[PKG_PATH_MAX];
+
+    dir_rec_t dir;
+    dir.path = "/data/app-private/";
+    dir.len = strlen(dir.path);
+
+    EXPECT_EQ(0, create_pkg_path_in_dir(path, &dir, "com.example.package", ".apk"))
+            << "Should successfully create package path.";
+
+    EXPECT_STREQ("/data/app-private/com.example.package.apk", path)
+            << "Package path should be in /data/app-private/";
+}
+
+TEST_F(UtilsTest, CopyAndAppend_Normal) {
+    //int copy_and_append(dir_rec_t* dst, dir_rec_t* src, char* suffix)
+    dir_rec_t dst;
+    dir_rec_t src;
+
+    src.path = "/data/";
+    src.len = strlen(src.path);
+
+    EXPECT_EQ(0, copy_and_append(&dst, &src, "app/"))
+            << "Should return error because postfix is too long.";
+
+    EXPECT_STREQ("/data/app/", dst.path)
+            << "Appended path should be correct";
+
+    EXPECT_EQ(10, (ssize_t) dst.len)
+            << "Appended path should be length of '/data/app/' (10)";
+}
+
+TEST_F(UtilsTest, AppendAndIncrement_Normal) {
+    size_t dst_size = 10;
+    char dst[dst_size];
+    char *dstp = dst;
+    const char* src = "FOO";
+
+    EXPECT_EQ(0, append_and_increment(&dstp, src, &dst_size))
+            << "String should append successfully";
+
+    EXPECT_STREQ("FOO", dst)
+            << "String should append correctly";
+
+    EXPECT_EQ(0, append_and_increment(&dstp, src, &dst_size))
+            << "String should append successfully again";
+
+    EXPECT_STREQ("FOOFOO", dst)
+            << "String should append correctly again";
+}
+
+TEST_F(UtilsTest, AppendAndIncrement_TooBig) {
+    size_t dst_size = 5;
+    char dst[dst_size];
+    char *dstp = dst;
+    const char* src = "FOO";
+
+    EXPECT_EQ(0, append_and_increment(&dstp, src, &dst_size))
+            << "String should append successfully";
+
+    EXPECT_STREQ("FOO", dst)
+            << "String should append correctly";
+
+    EXPECT_EQ(-1, append_and_increment(&dstp, src, &dst_size))
+            << "String should fail because it's too large to fit";
+}
+
+}
diff --git a/cmds/installd/utils.c b/cmds/installd/utils.c
index a5e4b5a..f37a6fb 100644
--- a/cmds/installd/utils.c
+++ b/cmds/installd/utils.c
@@ -16,24 +16,93 @@
 
 #include "installd.h"
 
-int create_pkg_path(char path[PKG_PATH_MAX],
-                    const char *prefix,
-                    const char *pkgname,
-                    const char *postfix)
+int create_pkg_path_in_dir(char path[PKG_PATH_MAX],
+                                const dir_rec_t* dir,
+                                const char* pkgname,
+                                const char* postfix)
 {
-    int len;
-    const char *x;
+     const size_t postfix_len = strlen(postfix);
 
-    len = strlen(pkgname);
-    if (len > PKG_NAME_MAX) {
-        return -1;
+     const size_t pkgname_len = strlen(pkgname);
+     if (pkgname_len > PKG_NAME_MAX) {
+         return -1;
+     }
+
+     if (is_valid_package_name(pkgname) < 0) {
+         return -1;
+     }
+
+     if ((pkgname_len + dir->len + postfix_len) >= PKG_PATH_MAX) {
+         return -1;
+     }
+
+     char *dst = path;
+     size_t dst_size = PKG_PATH_MAX;
+
+     if (append_and_increment(&dst, dir->path, &dst_size) < 0
+             || append_and_increment(&dst, pkgname, &dst_size) < 0
+             || append_and_increment(&dst, postfix, &dst_size) < 0) {
+         LOGE("Error building APK path");
+         return -1;
+     }
+
+     return 0;
+}
+
+/**
+ * Create the package path name for a given package name with a postfix for
+ * a certain persona. Returns 0 on success, and -1 on failure.
+ */
+int create_pkg_path(char path[PKG_PATH_MAX],
+                    const char *pkgname,
+                    const char *postfix,
+                    uid_t persona)
+{
+    size_t uid_len;
+    char* persona_prefix;
+    if (persona == 0) {
+        persona_prefix = PRIMARY_USER_PREFIX;
+        uid_len = 0;
+    } else {
+        persona_prefix = SECONDARY_USER_PREFIX;
+        uid_len = snprintf(NULL, 0, "%d", persona);
     }
-    if ((len + strlen(prefix) + strlen(postfix)) >= PKG_PATH_MAX) {
+
+    const size_t prefix_len = android_data_dir.len + strlen(persona_prefix) + uid_len + 1 /*slash*/;
+    char prefix[prefix_len + 1];
+
+    char *dst = prefix;
+    size_t dst_size = sizeof(prefix);
+
+    if (append_and_increment(&dst, android_data_dir.path, &dst_size) < 0
+            || append_and_increment(&dst, persona_prefix, &dst_size) < 0) {
+        LOGE("Error building prefix for APK path");
         return -1;
     }
 
-    x = pkgname;
+    if (persona != 0) {
+        int ret = snprintf(dst, dst_size, "%d/", persona);
+        if (ret < 0 || (size_t) ret != uid_len + 1) {
+            LOGW("Error appending UID to APK path");
+            return -1;
+        }
+    }
+
+    dir_rec_t dir;
+    dir.path = prefix;
+    dir.len = prefix_len;
+
+    return create_pkg_path_in_dir(path, &dir, pkgname, postfix);
+}
+
+/**
+ * Checks whether the package name is valid. Returns -1 on error and
+ * 0 on success.
+ */
+int is_valid_package_name(const char* pkgname) {
+    const char *x = pkgname;
     int alpha = -1;
+
     while (*x) {
         if (isalnum(*x) || (*x == '_')) {
                 /* alphanumeric or underscore are fine */
@@ -47,13 +116,15 @@
             /* Suffix -X is fine to let versioning of packages.
                But whatever follows should be alphanumeric.*/
             alpha = 1;
-        }else {
+        } else {
                 /* anything not A-Z, a-z, 0-9, _, or . is invalid */
             LOGE("invalid package name '%s'\n", pkgname);
             return -1;
         }
+
         x++;
     }
+
     if (alpha == 1) {
         // Skip current character
         x++;
@@ -66,7 +137,6 @@
         }
     }
 
-    sprintf(path, "%s%s%s", prefix, pkgname, postfix);
     return 0;
 }
 
@@ -171,3 +241,170 @@
     closedir(d);
     return res;
 }
+
+/**
+ * Checks whether a path points to a system app (.apk file). Returns 0
+ * if it is a system app or -1 if it is not.
+ */
+int validate_system_app_path(const char* path) {
+    size_t i;
+
+    for (i = 0; i < android_system_dirs.count; i++) {
+        const size_t dir_len = android_system_dirs.dirs[i].len;
+        if (!strncmp(path, android_system_dirs.dirs[i].path, dir_len)) {
+            if (path[dir_len] == '.' || strchr(path + dir_len, '/') != NULL) {
+                LOGE("invalid system apk path '%s' (trickery)\n", path);
+                return -1;
+            }
+            return 0;
+        }
+    }
+
+    return -1;
+}
+
+/**
+ * Get the contents of a environment variable that contains a path. Caller
+ * owns the string that is inserted into the directory record. Returns
+ * 0 on success and -1 on error.
+ */
+int get_path_from_env(dir_rec_t* rec, const char* var) {
+    const char* path = getenv(var);
+    int ret = get_path_from_string(rec, path);
+    if (ret < 0) {
+        LOGW("Problem finding value for environment variable %s\n", var);
+    }
+    return ret;
+}
+
+/**
+ * Puts the string into the record as a directory. Appends '/' to the end
+ * of all paths. Caller owns the string that is inserted into the directory
+ * record. A null value will result in an error.
+ *
+ * Returns 0 on success and -1 on error.
+ */
+int get_path_from_string(dir_rec_t* rec, const char* path) {
+    if (path == NULL) {
+        return -1;
+    } else {
+        const size_t path_len = strlen(path);
+        if (path_len <= 0) {
+            return -1;
+        }
+
+        // Make sure path is absolute.
+        if (path[0] != '/') {
+            return -1;
+        }
+
+        if (path[path_len - 1] == '/') {
+            // Path ends with a forward slash. Make our own copy.
+
+            rec->path = strdup(path);
+            if (rec->path == NULL) {
+                return -1;
+            }
+
+            rec->len = path_len;
+        } else {
+            // Path does not end with a slash. Generate a new string.
+            char *dst;
+
+            // Add space for slash and terminating null.
+            size_t dst_size = path_len + 2;
+
+            rec->path = malloc(dst_size);
+            if (rec->path == NULL) {
+                return -1;
+            }
+
+            dst = rec->path;
+
+            if (append_and_increment(&dst, path, &dst_size) < 0
+                    || append_and_increment(&dst, "/", &dst_size)) {
+                LOGE("Error canonicalizing path");
+                return -1;
+            }
+
+            rec->len = dst - rec->path;
+        }
+    }
+    return 0;
+}
+
+int copy_and_append(dir_rec_t* dst, const dir_rec_t* src, const char* suffix) {
+    dst->len = src->len + strlen(suffix);
+    const size_t dstSize = dst->len + 1;
+    dst->path = (char*) malloc(dstSize);
+
+    if (dst->path == NULL
+            || snprintf(dst->path, dstSize, "%s%s", src->path, suffix)
+                    != (ssize_t) dst->len) {
+        LOGE("Could not allocate memory to hold appended path; aborting\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+/**
+ * Check whether path points to a valid path for an APK file. An ASEC
+ * directory is allowed to have one level of subdirectory names. Returns -1
+ * when an invalid path is encountered and 0 when a valid path is encountered.
+ */
+int validate_apk_path(const char *path)
+{
+    int allowsubdir = 0;
+    char *subdir = NULL;
+    size_t dir_len;
+    size_t path_len;
+
+    if (!strncmp(path, android_app_dir.path, android_app_dir.len)) {
+        dir_len = android_app_dir.len;
+    } else if (!strncmp(path, android_app_private_dir.path, android_app_private_dir.len)) {
+        dir_len = android_app_private_dir.len;
+    } else if (!strncmp(path, android_asec_dir.path, android_asec_dir.len)) {
+        dir_len = android_asec_dir.len;
+        allowsubdir = 1;
+    } else {
+        LOGE("invalid apk path '%s' (bad prefix)\n", path);
+        return -1;
+    }
+
+    path_len = strlen(path);
+
+    /*
+     * Only allow the path to have a subdirectory if it's been marked as being allowed.
+     */
+    if ((subdir = strchr(path + dir_len, '/')) != NULL) {
+        ++subdir;
+        if (!allowsubdir
+                || (path_len > (size_t) (subdir - path) && (strchr(subdir, '/') != NULL))) {
+            LOGE("invalid apk path '%s' (subdir?)\n", path);
+            return -1;
+        }
+    }
+
+    /*
+     *  Directories can't have a period directly after the directory markers
+     *  to prevent ".."
+     */
+    if (path[dir_len] == '.'
+            || (subdir != NULL && ((*subdir == '.') || (strchr(subdir, '/') != NULL)))) {
+        LOGE("invalid apk path '%s' (trickery)\n", path);
+        return -1;
+    }
+
+    return 0;
+}
+
+int append_and_increment(char** dst, const char* src, size_t* dst_size) {
+    ssize_t ret = strlcpy(*dst, src, *dst_size);
+    if (ret < 0 || (size_t) ret >= *dst_size) {
+        return -1;
+    }
+    *dst += ret;
+    *dst_size -= ret;
+    return 0;
+}
diff --git a/core/java/android/bluetooth/BluetoothHeadset.java b/core/java/android/bluetooth/BluetoothHeadset.java
index fa55520..8a9bef0 100644
--- a/core/java/android/bluetooth/BluetoothHeadset.java
+++ b/core/java/android/bluetooth/BluetoothHeadset.java
@@ -603,7 +603,7 @@
      */
     public boolean setAudioState(BluetoothDevice device, int state) {
         if (DBG) log("setAudioState");
-        if (mService != null && isEnabled()) {
+        if (mService != null && !isDisabled()) {
             try {
                 return mService.setAudioState(device, state);
             } catch (RemoteException e) {Log.e(TAG, e.toString());}
@@ -622,7 +622,7 @@
      */
     public int getAudioState(BluetoothDevice device) {
         if (DBG) log("getAudioState");
-        if (mService != null && isEnabled()) {
+        if (mService != null && !isDisabled()) {
             try {
                 return mService.getAudioState(device);
             } catch (RemoteException e) {Log.e(TAG, e.toString());}
@@ -705,6 +705,11 @@
        return false;
     }
 
+    private boolean isDisabled() {
+       if (mAdapter.getState() == BluetoothAdapter.STATE_OFF) return true;
+       return false;
+    }
+
     private boolean isValidDevice(BluetoothDevice device) {
        if (device == null) return false;
 
diff --git a/core/java/android/bluetooth/BluetoothTetheringDataTracker.java b/core/java/android/bluetooth/BluetoothTetheringDataTracker.java
index c08f14f..a7b0037 100644
--- a/core/java/android/bluetooth/BluetoothTetheringDataTracker.java
+++ b/core/java/android/bluetooth/BluetoothTetheringDataTracker.java
@@ -300,4 +300,8 @@
         msg = mCsHandler.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo);
         msg.sendToTarget();
     }
+
+    public void setDependencyMet(boolean met) {
+        // not supported on this network
+    }
 }
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 7bdd1b9..afc2722 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -1908,6 +1908,21 @@
             "android.intent.action.HDMI_AUDIO_PLUG";
 
     /**
+     * <p>Broadcast Action: The user has switched on advanced settings in the settings app:</p>
+     * <ul>
+     *   <li><em>state</em> - A boolean value indicating whether the settings is on or off.</li>
+     * </ul>
+     *
+     * <p class="note">This is a protected intent that can only be sent
+     * by the system.
+     *
+     * @hide
+     */
+    //@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+    public static final String ACTION_ADVANCED_SETTINGS_CHANGED
+            = "android.intent.action.ADVANCED_SETTINGS";
+
+    /**
      * Broadcast Action: An outgoing call is about to be placed.
      *
      * <p>The Intent will have the following extra value:
diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java
index 46f611f..64c437d 100644
--- a/core/java/android/content/pm/ActivityInfo.java
+++ b/core/java/android/content/pm/ActivityInfo.java
@@ -334,6 +334,12 @@
     public static final int CONFIG_UI_MODE = 0x0200;
     /**
      * Bit in {@link #configChanges} that indicates that the activity
+     * can itself handle the screen size. Set from the
+     * {@link android.R.attr#configChanges} attribute.
+     */
+    public static final int CONFIG_SCREEN_SIZE = 0x0400;
+    /**
+     * Bit in {@link #configChanges} that indicates that the activity
      * can itself handle changes to the font scaling factor.  Set from the
      * {@link android.R.attr#configChanges} attribute.  This is
      * not a core resource configutation, but a higher-level value, so its
@@ -341,6 +347,37 @@
      */
     public static final int CONFIG_FONT_SCALE = 0x40000000;
     
+    /** @hide
+     * Unfortunately the constants for config changes in native code are
+     * different from ActivityInfo. :(  Here are the values we should use for the
+     * native side given the bit we have assigned in ActivityInfo.
+     */
+    public static int[] CONFIG_NATIVE_BITS = new int[] {
+        0x0001, // MNC
+        0x0002, // MCC
+        0x0004, // LOCALE
+        0x0008, // TOUCH SCREEN
+        0x0010, // KEYBOARD
+        0x0020, // KEYBOARD HIDDEN
+        0x0040, // NAVIGATION
+        0x0080, // ORIENTATION
+        0x0800, // SCREEN LAYOUT
+        0x1000, // UI MODE
+        0x0200, // SCREEN SIZE
+    };
+    /** @hide
+     * Convert Java change bits to native.
+     */
+    public static int activityInfoConfigToNative(int input) {
+        int output = 0;
+        for (int i=0; i<CONFIG_NATIVE_BITS.length; i++) {
+            if ((input&(1<<i)) != 0) {
+                output |= CONFIG_NATIVE_BITS[i];
+            }
+        }
+        return output;
+    }
+
     /**
      * Bit mask of kinds of configuration changes that this activity
      * can handle itself (without being restarted by the system).
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 7ebfda4..8dfdaa8 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -396,7 +396,7 @@
             int cookie = assmgr.addAssetPath(mArchiveSourcePath);
             if (cookie != 0) {
                 res = new Resources(assmgr, metrics, null);
-                assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                         Build.VERSION.RESOURCES_SDK_INT);
                 parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
                 assetError = false;
@@ -596,7 +596,7 @@
         AssetManager assmgr = null;
         try {
             assmgr = new AssetManager();
-            assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+            assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     Build.VERSION.RESOURCES_SDK_INT);
             int cookie = assmgr.addAssetPath(packageFilePath);
             parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
@@ -1931,6 +1931,10 @@
             a.info.configChanges = sa.getInt(
                     com.android.internal.R.styleable.AndroidManifestActivity_configChanges,
                     0);
+            if (owner.applicationInfo.targetSdkVersion
+                        < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+                a.info.configChanges |= ActivityInfo.CONFIG_SCREEN_SIZE;
+            }
             a.info.softInputMode = sa.getInt(
                     com.android.internal.R.styleable.AndroidManifestActivity_windowSoftInputMode,
                     0);
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java
index e279f64..afa68c3 100644
--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -652,7 +652,8 @@
     public native final void setConfiguration(int mcc, int mnc, String locale,
             int orientation, int touchscreen, int density, int keyboard,
             int keyboardHidden, int navigation, int screenWidth, int screenHeight,
-            int screenLayout, int uiMode, int majorVersion);
+            int screenWidthDp, int screenHeightDp, int screenLayout, int uiMode,
+            int majorVersion);
 
     /**
      * Retrieve the resource identifier for the given resource name.
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java
index 72fa07c..28ba4e7 100644
--- a/core/java/android/content/res/Configuration.java
+++ b/core/java/android/content/res/Configuration.java
@@ -241,6 +241,20 @@
      */
     public int uiMode;
 
+    public static final int SCREEN_WIDTH_DP_UNDEFINED = 0;
+
+    /**
+     * The current width of the available screen space, in dp units.
+     */
+    public int screenWidthDp;
+
+    public static final int SCREEN_HEIGHT_DP_UNDEFINED = 0;
+
+    /**
+     * The current height of the available screen space, in dp units.
+     */
+    public int screenHeightDp;
+
     /**
      * @hide Internal book-keeping.
      */
@@ -278,6 +292,8 @@
         orientation = o.orientation;
         screenLayout = o.screenLayout;
         uiMode = o.uiMode;
+        screenWidthDp = o.screenWidthDp;
+        screenHeightDp = o.screenHeightDp;
         seq = o.seq;
     }
     
@@ -316,6 +332,10 @@
         sb.append(java.lang.Integer.toHexString(screenLayout));
         sb.append(" uiMode=0x");
         sb.append(java.lang.Integer.toHexString(uiMode));
+        sb.append(" wdp=");
+        sb.append(screenWidthDp);
+        sb.append(" hdp=");
+        sb.append(screenHeightDp);
         if (seq != 0) {
             sb.append(" seq=");
             sb.append(seq);
@@ -341,6 +361,8 @@
         orientation = ORIENTATION_UNDEFINED;
         screenLayout = SCREENLAYOUT_SIZE_UNDEFINED;
         uiMode = UI_MODE_TYPE_UNDEFINED;
+        screenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
+        screenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
         seq = 0;
     }
 
@@ -434,6 +456,16 @@
                         | (delta.uiMode&UI_MODE_NIGHT_MASK);
             }
         }
+        if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED
+                && screenWidthDp != delta.screenWidthDp) {
+            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
+            screenWidthDp = delta.screenWidthDp;
+        }
+        if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED
+                && screenHeightDp != delta.screenHeightDp) {
+            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
+            screenHeightDp = delta.screenHeightDp;
+        }
         
         if (delta.seq != 0) {
             seq = delta.seq;
@@ -463,9 +495,11 @@
      * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION
      * PackageManager.ActivityInfo.CONFIG_NAVIGATION},
      * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION
-     * PackageManager.ActivityInfo.CONFIG_ORIENTATION}, or
+     * PackageManager.ActivityInfo.CONFIG_ORIENTATION},
      * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT
-     * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}.
+     * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}, or
+     * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE
+     * PackageManager.ActivityInfo.CONFIG_SCREEN_SIZE}.
      */
     public int diff(Configuration delta) {
         int changed = 0;
@@ -518,6 +552,14 @@
                 && uiMode != delta.uiMode) {
             changed |= ActivityInfo.CONFIG_UI_MODE;
         }
+        if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED
+                && screenWidthDp != delta.screenWidthDp) {
+            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
+        }
+        if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED
+                && screenHeightDp != delta.screenHeightDp) {
+            changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
+        }
         
         return changed;
     }
@@ -599,6 +641,8 @@
         dest.writeInt(orientation);
         dest.writeInt(screenLayout);
         dest.writeInt(uiMode);
+        dest.writeInt(screenWidthDp);
+        dest.writeInt(screenHeightDp);
         dest.writeInt(seq);
     }
 
@@ -620,6 +664,8 @@
         orientation = source.readInt();
         screenLayout = source.readInt();
         uiMode = source.readInt();
+        screenWidthDp = source.readInt();
+        screenHeightDp = source.readInt();
         seq = source.readInt();
     }
     
@@ -680,6 +726,10 @@
         n = this.screenLayout - that.screenLayout;
         if (n != 0) return n;
         n = this.uiMode - that.uiMode;
+        if (n != 0) return n;
+        n = this.screenWidthDp - that.screenWidthDp;
+        if (n != 0) return n;
+        n = this.screenHeightDp - that.screenHeightDp;
         //if (n != 0) return n;
         return n;
     }
@@ -704,6 +754,7 @@
                 + this.touchscreen
                 + this.keyboard + this.keyboardHidden + this.hardKeyboardHidden
                 + this.navigation + this.navigationHidden
-                + this.orientation + this.screenLayout + this.uiMode;
+                + this.orientation + this.screenLayout + this.uiMode
+                + this.screenWidthDp + this.screenHeightDp;
     }
 }
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index 81eb09c..2e6ae70 100755
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -21,6 +21,7 @@
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
+import android.content.pm.ActivityInfo;
 import android.graphics.Movie;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.ColorDrawable;
@@ -1404,6 +1405,7 @@
             int configChanges = 0xfffffff;
             if (config != null) {
                 configChanges = mConfiguration.updateFrom(config);
+                configChanges = ActivityInfo.activityInfoConfigToNative(configChanges);
             }
             if (mConfiguration.locale == null) {
                 mConfiguration.locale = Locale.getDefault();
@@ -1443,6 +1445,7 @@
                     mConfiguration.touchscreen,
                     (int)(mMetrics.density*160), mConfiguration.keyboard,
                     keyboardHidden, mConfiguration.navigation, width, height,
+                    mConfiguration.screenWidthDp, mConfiguration.screenHeightDp,
                     mConfiguration.screenLayout, mConfiguration.uiMode,
                     Build.VERSION.RESOURCES_SDK_INT);
 
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 26f375d..b541ec3 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -690,4 +690,16 @@
             return null;
         }
     }
+
+    /**
+     * @param networkType The network who's dependence has changed
+     * @param met Boolean - true if network use is ok, false if not
+     * {@hide}
+     */
+    public void setDataDependency(int networkType, boolean met) {
+        try {
+            mService.setDataDependency(networkType, met);
+        } catch (RemoteException e) {
+        }
+    }
 }
diff --git a/core/java/android/net/DummyDataStateTracker.java b/core/java/android/net/DummyDataStateTracker.java
index d0c77cf..e39725a 100644
--- a/core/java/android/net/DummyDataStateTracker.java
+++ b/core/java/android/net/DummyDataStateTracker.java
@@ -191,6 +191,10 @@
         return new LinkCapabilities(mLinkCapabilities);
     }
 
+    public void setDependencyMet(boolean met) {
+        // not supported on this network
+    }
+
     static private void log(String s) {
         Slog.d(TAG, s);
     }
diff --git a/core/java/android/net/EthernetDataTracker.java b/core/java/android/net/EthernetDataTracker.java
index df5fdd0..55850c9 100644
--- a/core/java/android/net/EthernetDataTracker.java
+++ b/core/java/android/net/EthernetDataTracker.java
@@ -330,4 +330,8 @@
     public String getTcpBufferSizesPropName() {
         return "net.tcp.buffersize.wifi";
     }
+
+    public void setDependencyMet(boolean met) {
+        // not supported on this network
+    }
 }
diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl
index 70ab4f1..8be492c 100644
--- a/core/java/android/net/IConnectivityManager.aidl
+++ b/core/java/android/net/IConnectivityManager.aidl
@@ -92,4 +92,6 @@
     void setGlobalProxy(in ProxyProperties p);
 
     ProxyProperties getProxy();
+
+    void setDataDependency(int networkType, boolean met);
 }
diff --git a/core/java/android/net/LinkAddress.java b/core/java/android/net/LinkAddress.java
index 9c36b12..f6a114c 100644
--- a/core/java/android/net/LinkAddress.java
+++ b/core/java/android/net/LinkAddress.java
@@ -78,6 +78,14 @@
             this.prefixLength == linkAddress.prefixLength;
     }
 
+    @Override
+    /*
+     * generate hashcode based on significant fields
+     */
+    public int hashCode() {
+        return ((null == address) ? 0 : address.hashCode()) + prefixLength;
+    }
+
     /**
      * Returns the InetAddress for this address.
      */
diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java
index 81d62a0..e88292f 100644
--- a/core/java/android/net/LinkProperties.java
+++ b/core/java/android/net/LinkProperties.java
@@ -19,11 +19,9 @@
 import android.net.ProxyProperties;
 import android.os.Parcelable;
 import android.os.Parcel;
-import android.util.Log;
+import android.text.TextUtils;
 
 import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -141,7 +139,7 @@
         String ifaceName = (mIfaceName == null ? "" : "InterfaceName: " + mIfaceName + " ");
 
         String linkAddresses = "LinkAddresses: [";
-        for (LinkAddress addr : mLinkAddresses) linkAddresses += addr.toString();
+        for (LinkAddress addr : mLinkAddresses) linkAddresses += addr.toString() + ",";
         linkAddresses += "] ";
 
         String dns = "DnsAddresses: [";
@@ -156,6 +154,67 @@
         return ifaceName + linkAddresses + gateways + dns + proxy;
     }
 
+
+    @Override
+    /**
+     * Compares this {@code LinkProperties} instance against the target
+     * LinkProperties in {@code obj}. Two LinkPropertieses are equal if
+     * all their fields are equal in values.
+     *
+     * For collection fields, such as mDnses, containsAll() is used to check
+     * if two collections contains the same elements, independent of order.
+     * There are two thoughts regarding containsAll()
+     * 1. Duplicated elements. eg, (A, B, B) and (A, A, B) are equal.
+     * 2. Worst case performance is O(n^2).
+     *
+     * @param obj the object to be tested for equality.
+     * @return {@code true} if both objects are equal, {@code false} otherwise.
+     */
+    public boolean equals(Object obj) {
+        if (this == obj) return true;
+
+        if (!(obj instanceof LinkProperties)) return false;
+
+        boolean sameAddresses;
+        boolean sameDnses;
+        boolean sameGateways;
+
+        LinkProperties target = (LinkProperties) obj;
+
+        Collection<InetAddress> targetAddresses = target.getAddresses();
+        Collection<InetAddress> sourceAddresses = getAddresses();
+        sameAddresses = (sourceAddresses.size() == targetAddresses.size()) ?
+                sourceAddresses.containsAll(targetAddresses) : false;
+
+        Collection<InetAddress> targetDnses = target.getDnses();
+        sameDnses = (mDnses.size() == targetDnses.size()) ?
+                mDnses.containsAll(targetDnses) : false;
+
+        Collection<InetAddress> targetGateways = target.getGateways();
+        sameGateways = (mGateways.size() == targetGateways.size()) ?
+                mGateways.containsAll(targetGateways) : false;
+
+        return
+            sameAddresses && sameDnses && sameGateways
+            && TextUtils.equals(getInterfaceName(), target.getInterfaceName())
+            && (getHttpProxy() == null ? target.getHttpProxy() == null :
+                getHttpProxy().equals(target.getHttpProxy()));
+    }
+
+    @Override
+    /**
+     * generate hashcode based on significant fields
+     * Equal objects must produce the same hash code, while unequal objects
+     * may have the same hash codes.
+     */
+    public int hashCode() {
+        return ((null == mIfaceName) ? 0 : mIfaceName.hashCode()
+                + mLinkAddresses.size() * 31
+                + mDnses.size() * 37
+                + mGateways.size() * 41
+                + ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode()));
+    }
+
     /**
      * Implement the Parcelable interface.
      * @hide
diff --git a/core/java/android/net/MobileDataStateTracker.java b/core/java/android/net/MobileDataStateTracker.java
index 5b4da66..bb6ee0f 100644
--- a/core/java/android/net/MobileDataStateTracker.java
+++ b/core/java/android/net/MobileDataStateTracker.java
@@ -20,6 +20,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.os.Bundle;
 import android.os.HandlerThread;
 import android.os.Looper;
 import android.os.Messenger;
@@ -493,6 +494,25 @@
         }
     }
 
+    /**
+     * carrier dependency is met/unmet
+     * @param met
+     */
+    public void setDependencyMet(boolean met) {
+        Bundle bundle = Bundle.forPair(DataConnectionTracker.APN_TYPE_KEY, mApnType);
+        try {
+            log("setDependencyMet: E met=" + met);
+            Message msg = Message.obtain();
+            msg.what = DataConnectionTracker.CMD_SET_DEPENDENCY_MET;
+            msg.arg1 = (met ? DataConnectionTracker.ENABLED : DataConnectionTracker.DISABLED);
+            msg.setData(bundle);
+            mDataConnectionTrackerAc.sendMessage(msg);
+            log("setDependencyMet: X met=" + met);
+        } catch (NullPointerException e) {
+            log("setDependencyMet: X mAc was null" + e);
+        }
+    }
+
     @Override
     public String toString() {
         StringBuffer sb = new StringBuffer("Mobile data state: ");
diff --git a/core/java/android/net/NetworkConfig.java b/core/java/android/net/NetworkConfig.java
new file mode 100644
index 0000000..4adb76b
--- /dev/null
+++ b/core/java/android/net/NetworkConfig.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+import android.util.Log;
+
+/**
+ * Describes the buildtime configuration of a network.
+ * Holds settings read from resources.
+ * @hide
+ */
+public class NetworkConfig {
+    /**
+     * Human readable string
+     */
+    public String name;
+
+    /**
+     * Type from ConnectivityManager
+     */
+    public int type;
+
+    /**
+     * the radio number from radio attributes config
+     */
+    public int radio;
+
+    /**
+     * higher number == higher priority when turning off connections
+     */
+    public int priority;
+
+    /**
+     * indicates the boot time dependencyMet setting
+     */
+    public boolean dependencyMet;
+
+    /**
+     * input string from config.xml resource.  Uses the form:
+     * [Connection name],[ConnectivityManager connection type],
+     * [associated radio-type],[priority],[dependencyMet]
+     */
+    public NetworkConfig(String init) {
+        String fragments[] = init.split(",");
+        name = fragments[0].trim().toLowerCase();
+        type = Integer.parseInt(fragments[1]);
+        radio = Integer.parseInt(fragments[2]);
+        priority = Integer.parseInt(fragments[3]);
+        if (fragments.length > 4) {
+            dependencyMet = Boolean.parseBoolean(fragments[4]);
+        } else {
+            dependencyMet = true;
+        }
+    }
+
+    /**
+     * Indicates if this network is supposed to be default-routable
+     */
+    public boolean isDefault() {
+        return (type == radio);
+    }
+}
diff --git a/core/java/android/net/NetworkStateTracker.java b/core/java/android/net/NetworkStateTracker.java
index eb97d77..f53063d 100644
--- a/core/java/android/net/NetworkStateTracker.java
+++ b/core/java/android/net/NetworkStateTracker.java
@@ -176,4 +176,9 @@
      * Indicate tear down requested from connectivity
      */
     public void setTeardownRequested(boolean isRequested);
+
+    /**
+     * An external dependency has been met/unmet
+     */
+    public void setDependencyMet(boolean met);
 }
diff --git a/core/java/android/net/ProxyProperties.java b/core/java/android/net/ProxyProperties.java
index cbe4445..44dbec1 100644
--- a/core/java/android/net/ProxyProperties.java
+++ b/core/java/android/net/ProxyProperties.java
@@ -163,6 +163,16 @@
         return 0;
     }
 
+    @Override
+    /*
+     * generate hashcode based on significant fields
+     */
+    public int hashCode() {
+        return ((null == mHost) ? 0 : mHost.hashCode())
+        + ((null == mExclusionList) ? 0 : mExclusionList.hashCode())
+        + mPort;
+    }
+
     /**
      * Implement the Parcelable interface.
      * @hide
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index 3bb0821..24d5369 100644
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -230,6 +230,11 @@
          * Newest version of Android, version 3.1.
          */
         public static final int HONEYCOMB_MR1 = 12;
+
+        /**
+         * Current version under development.
+         */
+        public static final int ICE_CREAM_SANDWICH = CUR_DEVELOPMENT;
     }
     
     /** The type of build, like "user" or "eng". */
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java
index 4f88612..22b4c76 100644
--- a/core/java/android/provider/ContactsContract.java
+++ b/core/java/android/provider/ContactsContract.java
@@ -144,6 +144,27 @@
     public static final String LIMIT_PARAM_KEY = "limit";
 
     /**
+     * A query parameter specifing a primary account. This parameter should be used with
+     * {@link #PRIMARY_ACCOUNT_TYPE}. The contacts provider handling a query may rely on
+     * this information to optimize its query results.
+     *
+     * For example, in an email composition screen, its implementation can specify an account when
+     * obtaining possible recipients, letting the provider know which account is selected during
+     * the composition. The provider may use the "primary account" information to optimize
+     * the search result.
+     * @hide
+     */
+    public static final String PRIMARY_ACCOUNT_NAME = "name_for_primary_account";
+
+    /**
+     * A query parameter specifing a primary account. This parameter should be used with
+     * {@link #PRIMARY_ACCOUNT_NAME}. See the doc in {@link #PRIMARY_ACCOUNT_NAME}.
+     * @hide
+     */
+    public static final String PRIMARY_ACCOUNT_TYPE = "type_for_primary_account";
+
+
+    /**
      * @hide
      */
     public static final class Preferences {
diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java
index bb8d874..02fd6e4 100644
--- a/core/java/android/provider/MediaStore.java
+++ b/core/java/android/provider/MediaStore.java
@@ -346,6 +346,13 @@
          */
         public interface FileColumns extends MediaColumns {
             /**
+             * The MTP storage ID of the file
+             * <P>Type: INTEGER</P>
+             * @hide
+             */
+            public static final String STORAGE_ID = "storage_id";
+
+            /**
              * The MTP format code of the file
              * <P>Type: INTEGER</P>
              * @hide
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 6deb5a0..8a19456 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -1103,6 +1103,18 @@
         public static final int END_BUTTON_BEHAVIOR_DEFAULT = END_BUTTON_BEHAVIOR_SLEEP;
 
         /**
+         * Is advanced settings mode turned on. 0 == no, 1 == yes
+         * @hide
+         */
+        public static final String ADVANCED_SETTINGS = "advanced_settings";
+
+        /**
+         * ADVANCED_SETTINGS default value.
+         * @hide
+         */
+        public static final int ADVANCED_SETTINGS_DEFAULT = 0;
+
+        /**
          * Whether Airplane Mode is on.
          */
         public static final String AIRPLANE_MODE_ON = "airplane_mode_on";
@@ -3303,12 +3315,20 @@
         public static final String WIFI_IDLE_MS = "wifi_idle_ms";
 
         /**
-         * The interval in milliseconds to issue scans when the driver is
-         * started. This is necessary to allow wifi to connect to an
-         * access point when the driver is suspended.
+         * The interval in milliseconds to issue wake up scans when wifi needs
+         * to connect. This is necessary to connect to an access point when
+         * device is on the move and the screen is off.
          * @hide
          */
-        public static final String WIFI_SCAN_INTERVAL_MS = "wifi_scan_interval_ms";
+        public static final String WIFI_FRAMEWORK_SCAN_INTERVAL_MS =
+                "wifi_framework_scan_interval_ms";
+
+        /**
+         * The interval in milliseconds to scan as used by the wifi supplicant
+         * @hide
+         */
+        public static final String WIFI_SUPPLICANT_SCAN_INTERVAL_MS =
+                "wifi_supplicant_scan_interval_ms";
 
         /**
          * The interval in milliseconds at which to check packet counts on the
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java
index 132c346..ca2212c 100644
--- a/core/java/android/server/BluetoothA2dpService.java
+++ b/core/java/android/server/BluetoothA2dpService.java
@@ -83,19 +83,6 @@
                     onBluetoothDisable();
                     break;
                 }
-            } else if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
-                int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
-                                                   BluetoothDevice.ERROR);
-                switch(bondState) {
-                case BluetoothDevice.BOND_BONDED:
-                    if (getPriority(device) == BluetoothA2dp.PRIORITY_UNDEFINED) {
-                        setPriority(device, BluetoothA2dp.PRIORITY_ON);
-                    }
-                    break;
-                case BluetoothDevice.BOND_NONE:
-                    setPriority(device, BluetoothA2dp.PRIORITY_UNDEFINED);
-                    break;
-                }
             } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
                 synchronized (this) {
                     if (mAudioDevices.containsKey(device)) {
@@ -158,7 +145,6 @@
         mAdapter = BluetoothAdapter.getDefaultAdapter();
 
         mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
-        mIntentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
         mIntentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
         mIntentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
         mIntentFilter.addAction(AudioManager.VOLUME_CHANGED_ACTION);
diff --git a/core/java/android/server/BluetoothAdapterProperties.java b/core/java/android/server/BluetoothAdapterProperties.java
index ae8104b..9723f60 100644
--- a/core/java/android/server/BluetoothAdapterProperties.java
+++ b/core/java/android/server/BluetoothAdapterProperties.java
@@ -76,14 +76,13 @@
         for (int i = 0; i < properties.length; i++) {
             String name = properties[i];
             String newValue = null;
-            int len;
             if (name == null) {
                 Log.e(TAG, "Error:Adapter Property at index " + i + " is null");
                 continue;
             }
             if (name.equals("Devices") || name.equals("UUIDs")) {
                 StringBuilder str = new StringBuilder();
-                len = Integer.valueOf(properties[++i]);
+                int len = Integer.valueOf(properties[++i]);
                 for (int j = 0; j < len; j++) {
                     str.append(properties[++i]);
                     str.append(",");
diff --git a/core/java/android/server/BluetoothBondState.java b/core/java/android/server/BluetoothBondState.java
index 2304a70..a36cd24 100644
--- a/core/java/android/server/BluetoothBondState.java
+++ b/core/java/android/server/BluetoothBondState.java
@@ -18,6 +18,9 @@
 
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
+import android.bluetooth.BluetoothA2dp;
+import android.bluetooth.BluetoothHeadset;
 import android.content.Context;
 import android.content.Intent;
 import android.util.Log;
@@ -68,6 +71,8 @@
     private final Context mContext;
     private final BluetoothService mService;
     private final BluetoothInputProfileHandler mBluetoothInputProfileHandler;
+    private BluetoothA2dp mA2dpProxy;
+    private BluetoothHeadset mHeadsetProxy;
 
     BluetoothBondState(Context context, BluetoothService service) {
         mContext = context;
@@ -126,14 +131,15 @@
 
         if (state == BluetoothDevice.BOND_BONDED) {
             mService.addProfileState(address);
+        } else if (state == BluetoothDevice.BOND_BONDING) {
+            if (mA2dpProxy == null || mHeadsetProxy == null) {
+                getProfileProxy();
+            }
         } else if (state == BluetoothDevice.BOND_NONE) {
             mService.removeProfileState(address);
         }
 
-        // HID is handled by BluetoothService, other profiles
-        // will be handled by their respective services.
-        mBluetoothInputProfileHandler.setInitialInputDevicePriority(
-            mService.getRemoteDevice(address), state);
+        setProfilePriorities(address, state);
 
         if (DBG) {
             Log.d(TAG, address + " bond state " + oldState + " -> " + state
@@ -261,6 +267,52 @@
         mPinAttempt.put(address, new Integer(newAttempt));
     }
 
+    private void getProfileProxy() {
+        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+
+        if (mA2dpProxy == null) {
+            bluetoothAdapter.getProfileProxy(mContext, mProfileServiceListener,
+                                             BluetoothProfile.A2DP);
+        }
+
+        if (mHeadsetProxy == null) {
+            bluetoothAdapter.getProfileProxy(mContext, mProfileServiceListener,
+                                             BluetoothProfile.HEADSET);
+        }
+    }
+
+    private void closeProfileProxy() {
+        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+
+        if (mA2dpProxy != null) {
+            bluetoothAdapter.closeProfileProxy(BluetoothProfile.A2DP, mA2dpProxy);
+        }
+
+        if (mHeadsetProxy != null) {
+            bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mHeadsetProxy);
+        }
+    }
+
+    private BluetoothProfile.ServiceListener mProfileServiceListener =
+        new BluetoothProfile.ServiceListener() {
+
+        public void onServiceConnected(int profile, BluetoothProfile proxy) {
+            if (profile == BluetoothProfile.A2DP) {
+                mA2dpProxy = (BluetoothA2dp) proxy;
+            } else if (profile == BluetoothProfile.HEADSET) {
+                mHeadsetProxy = (BluetoothHeadset) proxy;
+            }
+        }
+
+        public void onServiceDisconnected(int profile) {
+            if (profile == BluetoothProfile.A2DP) {
+                mA2dpProxy = null;
+            } else if (profile == BluetoothProfile.HEADSET) {
+                mHeadsetProxy = null;
+            }
+        }
+    };
+
     private void copyAutoPairingData() {
         FileInputStream in = null;
         FileOutputStream out = null;
@@ -365,4 +417,30 @@
             }
         }
     }
+
+    // Set service priority of Hid, A2DP and Headset profiles depending on
+    // the bond state change
+    private void setProfilePriorities(String address, int state) {
+        BluetoothDevice remoteDevice = mService.getRemoteDevice(address);
+        // HID is handled by BluetoothService
+        mBluetoothInputProfileHandler.setInitialInputDevicePriority(remoteDevice, state);
+
+        // Set service priority of A2DP and Headset
+        // We used to do the priority change in the 2 services after the broadcast
+        //   intent reach them. But that left a small time gap that could reject
+        //   incoming connection due to undefined priorities.
+        if (state == BluetoothDevice.BOND_BONDED) {
+            if (mA2dpProxy.getPriority(remoteDevice) == BluetoothProfile.PRIORITY_UNDEFINED) {
+                mA2dpProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_ON);
+            }
+
+            if (mHeadsetProxy.getPriority(remoteDevice) == BluetoothProfile.PRIORITY_UNDEFINED) {
+                mHeadsetProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_ON);
+            }
+        } else if (state == BluetoothDevice.BOND_NONE) {
+            mA2dpProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_UNDEFINED);
+            mHeadsetProxy.setPriority(remoteDevice, BluetoothProfile.PRIORITY_UNDEFINED);
+        }
+    }
+
 }
diff --git a/core/java/android/speech/RecognitionListener.java b/core/java/android/speech/RecognitionListener.java
index 5eb71d7..bdb3ba9 100644
--- a/core/java/android/speech/RecognitionListener.java
+++ b/core/java/android/speech/RecognitionListener.java
@@ -70,7 +70,8 @@
      * 
      * @param results the recognition results. To retrieve the results in {@code
      *        ArrayList&lt;String&gt;} format use {@link Bundle#getStringArrayList(String)} with
-     *        {@link SpeechRecognizer#RESULTS_RECOGNITION} as a parameter
+     *        {@link SpeechRecognizer#RESULTS_RECOGNITION} as a parameter. A float array of
+     *        confidence values might also be given in {@link SpeechRecognizer#CONFIDENCE_SCORES}.
      */
     void onResults(Bundle results);
 
diff --git a/core/java/android/speech/RecognizerIntent.java b/core/java/android/speech/RecognizerIntent.java
index 02c324c..fd709f2 100644
--- a/core/java/android/speech/RecognizerIntent.java
+++ b/core/java/android/speech/RecognizerIntent.java
@@ -46,7 +46,7 @@
     }
 
     /**
-     * Starts an activity that will prompt the user for speech and sends it through a
+     * Starts an activity that will prompt the user for speech and send it through a
      * speech recognizer.  The results will be returned via activity results (in
      * {@link Activity#onActivityResult}, if you start the intent using
      * {@link Activity#startActivityForResult(Intent, int)}), or forwarded via a PendingIntent
@@ -81,8 +81,8 @@
     public static final String ACTION_RECOGNIZE_SPEECH = "android.speech.action.RECOGNIZE_SPEECH";
 
     /**
-     * Starts an activity that will prompt the user for speech, sends it through a
-     * speech recognizer, and invokes and either displays a web search result or triggers
+     * Starts an activity that will prompt the user for speech, send it through a
+     * speech recognizer, and either display a web search result or trigger
      * another type of action based on the user's speech.
      *
      * <p>If you want to avoid triggering any type of action besides web search, you can use
@@ -100,11 +100,13 @@
      *   <li>{@link #EXTRA_MAX_RESULTS}
      *   <li>{@link #EXTRA_PARTIAL_RESULTS}
      *   <li>{@link #EXTRA_WEB_SEARCH_ONLY}
+     *   <li>{@link #EXTRA_ORIGIN}
      * </ul>
      * 
      * <p> Result extras (returned in the result, not to be specified in the request):
      * <ul>
      *   <li>{@link #EXTRA_RESULTS}
+     *   <li>{@link #EXTRA_CONFIDENCE_SCORES} (optional)
      * </ul>
      * 
      * <p>NOTE: There may not be any applications installed to handle this action, so you should
@@ -181,6 +183,13 @@
      * {@link java.util.Locale#getDefault()}.
      */
     public static final String EXTRA_LANGUAGE = "android.speech.extra.LANGUAGE";
+    
+    /**
+     * Optional value which can be used to indicate the referer url of a page in which
+     * speech was requested. For example, a web browser may choose to provide this for
+     * uses of speech on a given page.
+     */
+    public static final String EXTRA_ORIGIN = "android.speech.extra.ORIGIN";
 
     /** 
      * Optional limit on the maximum number of results to return. If omitted the recognizer
@@ -232,13 +241,31 @@
 
     /**
      * An ArrayList&lt;String&gt; of the recognition results when performing
-     * {@link #ACTION_RECOGNIZE_SPEECH}. Returned in the results; not to be specified in the
-     * recognition request. Only present when {@link Activity#RESULT_OK} is returned in
-     * an activity result. In a PendingIntent, the lack of this extra indicates failure.
+     * {@link #ACTION_RECOGNIZE_SPEECH}. Generally this list should be ordered in
+     * descending order of speech recognizer confidence. (See {@link #EXTRA_CONFIDENCE_SCORES}).
+     * Returned in the results; not to be specified in the recognition request. Only present
+     * when {@link Activity#RESULT_OK} is returned in an activity result. In a PendingIntent,
+     * the lack of this extra indicates failure.
      */
     public static final String EXTRA_RESULTS = "android.speech.extra.RESULTS";
     
     /**
+     * A float array of confidence scores of the recognition results when performing
+     * {@link #ACTION_RECOGNIZE_SPEECH}. The array should be the same size as the ArrayList
+     * returned in {@link #EXTRA_RESULTS}, and should contain values ranging from 0.0 to 1.0,
+     * or -1 to represent an unavailable confidence score.
+     * <p>
+     * Confidence values close to 1.0 indicate high confidence (the speech recognizer is
+     * confident that the recognition result is correct), while values close to 0.0 indicate
+     * low confidence.
+     * <p>
+     * Returned in the results; not to be specified in the recognition request. This extra is
+     * optional and might not be provided. Only present when {@link Activity#RESULT_OK} is
+     * returned in an activity result.
+     */
+    public static final String EXTRA_CONFIDENCE_SCORES = "android.speech.extra.CONFIDENCE_SCORES";
+    
+    /**
      * Returns the broadcast intent to fire with
      * {@link Context#sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, int, String, Bundle)}
      * to receive details from the package that implements voice search.
diff --git a/core/java/android/speech/SpeechRecognizer.java b/core/java/android/speech/SpeechRecognizer.java
index cd73ba8..8fee41d 100644
--- a/core/java/android/speech/SpeechRecognizer.java
+++ b/core/java/android/speech/SpeechRecognizer.java
@@ -50,12 +50,26 @@
     private static final String TAG = "SpeechRecognizer";
 
     /**
-     * Used to retrieve an {@code ArrayList<String>} from the {@link Bundle} passed to the
+     * Key used to retrieve an {@code ArrayList<String>} from the {@link Bundle} passed to the
      * {@link RecognitionListener#onResults(Bundle)} and
      * {@link RecognitionListener#onPartialResults(Bundle)} methods. These strings are the possible
      * recognition results, where the first element is the most likely candidate.
      */
     public static final String RESULTS_RECOGNITION = "results_recognition";
+    
+    /**
+     * Key used to retrieve a float array from the {@link Bundle} passed to the
+     * {@link RecognitionListener#onResults(Bundle)} and
+     * {@link RecognitionListener#onPartialResults(Bundle)} methods. The array should be
+     * the same size as the ArrayList provided in {@link #RESULTS_RECOGNITION}, and should contain
+     * values ranging from 0.0 to 1.0, or -1 to represent an unavailable confidence score.
+     * <p>
+     * Confidence values close to 1.0 indicate high confidence (the speech recognizer is confident
+     * that the recognition result is correct), while values close to 0.0 indicate low confidence.
+     * <p>
+     * This value is optional and might not be provided.
+     */
+    public static final String CONFIDENCE_SCORES = "confidence_scores";
 
     /** Network operation timed out. */
     public static final int ERROR_NETWORK_TIMEOUT = 1;
diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java
index 28541fe..66f37f2 100644
--- a/core/java/android/view/HardwareRenderer.java
+++ b/core/java/android/view/HardwareRenderer.java
@@ -645,8 +645,21 @@
                     }
     
                     attachInfo.mIgnoreDirtyState = false;
-    
+
+                    final long swapBuffersStartTime;
+                    if (ViewDebug.DEBUG_LATENCY) {
+                        swapBuffersStartTime = System.nanoTime();
+                    }
+
                     sEgl.eglSwapBuffers(sEglDisplay, mEglSurface);
+
+                    if (ViewDebug.DEBUG_LATENCY) {
+                        long now = System.nanoTime();
+                        Log.d(LOG_TAG, "Latency: Spent "
+                                + ((now - swapBuffersStartTime) * 0.000001f)
+                                + "ms waiting for eglSwapBuffers()");
+                    }
+
                     checkEglErrors();
                 }
             }
diff --git a/core/java/android/view/InputEvent.java b/core/java/android/view/InputEvent.java
index 87e7ea7..01ddcc9 100755
--- a/core/java/android/view/InputEvent.java
+++ b/core/java/android/view/InputEvent.java
@@ -106,6 +106,13 @@
      */
     public abstract void setTainted(boolean tainted);
 
+    /**
+     * Returns the time (in ns) when this specific event was generated.
+     * The value is in nanosecond precision but it may not have nanosecond accuracy.
+     * @hide
+     */
+    public abstract long getEventTimeNano();
+
     public int describeContents() {
         return 0;
     }
diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java
index 4320160..13d8809 100755
--- a/core/java/android/view/KeyEvent.java
+++ b/core/java/android/view/KeyEvent.java
@@ -1807,12 +1807,33 @@
      * @see #META_CAPS_LOCK_ON
      * @see #META_NUM_LOCK_ON
      * @see #META_SCROLL_LOCK_ON
+     * @see #getModifiers
      */
     public final int getMetaState() {
         return mMetaState;
     }
 
     /**
+     * Returns the state of the modifier keys.
+     * <p>
+     * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK},
+     * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are
+     * not considered modifier keys.  Consequently, this function specifically masks out
+     * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}.
+     * </p><p>
+     * The value returned consists of the meta state (from {@link #getMetaState})
+     * normalized using {@link #normalizeMetaState(int)} and then masked with
+     * {@link #getModifierMetaStateMask} so that only valid modifier bits are retained.
+     * </p>
+     *
+     * @return An integer in which each bit set to 1 represents a pressed modifier key.
+     * @see #getMetaState
+     */
+    public final int getModifiers() {
+        return normalizeMetaState(mMetaState) & META_MODIFIER_MASK;
+    }
+
+    /**
      * Returns the flags for this key event.
      *
      * @see #FLAG_WOKE_HERE
@@ -2319,6 +2340,12 @@
         return mEventTime;
     }
 
+    /** @hide */
+    @Override
+    public final long getEventTimeNano() {
+        return mEventTime * 1000000L;
+    }
+
     /**
      * Renamed to {@link #getDeviceId}.
      * 
diff --git a/core/java/android/view/ViewDebug.java b/core/java/android/view/ViewDebug.java
index c19a107..89736d6 100644
--- a/core/java/android/view/ViewDebug.java
+++ b/core/java/android/view/ViewDebug.java
@@ -141,6 +141,22 @@
     public static final boolean DEBUG_DRAG = false;
 
     /**
+     * Enables logging of factors that affect the latency and responsiveness of an application.
+     *
+     * Logs the relative difference between the time an event was created and the time it
+     * was delivered.
+     *
+     * Logs the time spent waiting for Surface.lockCanvas() or eglSwapBuffers().
+     * This is time that the event loop spends blocked and unresponsive.  Ideally, drawing
+     * and animations should be perfectly synchronized with VSYNC so that swap buffers
+     * is instantaneous.
+     *
+     * Logs the time spent in ViewRoot.performTraversals() or ViewRoot.draw().
+     * @hide
+     */
+    public static final boolean DEBUG_LATENCY = false;
+
+    /**
      * <p>Enables or disables views consistency check. Even when this property is enabled,
      * view consistency checks happen only if {@link android.util.Config#DEBUG} is set
      * to true. The value of this property can be configured externally in one of the
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index 2f9d501..a899b46 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -186,6 +186,8 @@
     final Rect mVisRect; // used to retrieve visible rect of focused view.
 
     boolean mTraversalScheduled;
+    long mLastTraversalFinishedTimeNanos;
+    long mLastDrawDurationNanos;
     boolean mWillDrawSoon;
     boolean mLayoutRequested;
     boolean mFirst;
@@ -671,6 +673,14 @@
     public void scheduleTraversals() {
         if (!mTraversalScheduled) {
             mTraversalScheduled = true;
+
+            if (ViewDebug.DEBUG_LATENCY && mLastTraversalFinishedTimeNanos != 0) {
+                final long now = System.nanoTime();
+                Log.d(TAG, "Latency: Scheduled traversal, it has been "
+                        + ((now - mLastTraversalFinishedTimeNanos) * 0.000001f)
+                        + "ms since the last traversal finished.");
+            }
+
             sendEmptyMessage(DO_TRAVERSAL);
         }
     }
@@ -1389,8 +1399,18 @@
 
         if (!cancelDraw && !newSurface) {
             mFullRedrawNeeded = false;
+
+            final long drawStartTime;
+            if (ViewDebug.DEBUG_LATENCY) {
+                drawStartTime = System.nanoTime();
+            }
+
             draw(fullRedrawNeeded);
 
+            if (ViewDebug.DEBUG_LATENCY) {
+                mLastDrawDurationNanos = System.nanoTime() - drawStartTime;
+            }
+
             if ((relayoutResult&WindowManagerImpl.RELAYOUT_FIRST_TIME) != 0
                     || mReportNextDraw) {
                 if (LOCAL_LOGV) {
@@ -1601,8 +1621,20 @@
                 int right = dirty.right;
                 int bottom = dirty.bottom;
 
+                final long lockCanvasStartTime;
+                if (ViewDebug.DEBUG_LATENCY) {
+                    lockCanvasStartTime = System.nanoTime();
+                }
+
                 canvas = surface.lockCanvas(dirty);
 
+                if (ViewDebug.DEBUG_LATENCY) {
+                    long now = System.nanoTime();
+                    Log.d(TAG, "Latency: Spent "
+                            + ((now - lockCanvasStartTime) * 0.000001f)
+                            + "ms waiting for surface.lockCanvas()");
+                }
+
                 if (left != dirty.left || top != dirty.top || right != dirty.right ||
                         bottom != dirty.bottom) {
                     mAttachInfo.mIgnoreDirtyState = true;
@@ -2011,8 +2043,24 @@
                 Debug.startMethodTracing("ViewRoot");
             }
 
+            final long traversalStartTime;
+            if (ViewDebug.DEBUG_LATENCY) {
+                traversalStartTime = System.nanoTime();
+                mLastDrawDurationNanos = 0;
+            }
+
             performTraversals();
 
+            if (ViewDebug.DEBUG_LATENCY) {
+                long now = System.nanoTime();
+                Log.d(TAG, "Latency: Spent "
+                        + ((now - traversalStartTime) * 0.000001f)
+                        + "ms in performTraversals(), with "
+                        + (mLastDrawDurationNanos * 0.000001f)
+                        + "ms of that time in draw()");
+                mLastTraversalFinishedTimeNanos = now;
+            }
+
             if (mProfile) {
                 Debug.stopMethodTracing();
                 mProfile = false;
@@ -2180,25 +2228,68 @@
         }
     }
     
-    private void startInputEvent(InputQueue.FinishedCallback finishedCallback) {
+    private void startInputEvent(InputEvent event, InputQueue.FinishedCallback finishedCallback) {
         if (mFinishedCallback != null) {
             Slog.w(TAG, "Received a new input event from the input queue but there is "
                     + "already an unfinished input event in progress.");
         }
 
+        if (ViewDebug.DEBUG_LATENCY) {
+            mInputEventReceiveTimeNanos = System.nanoTime();
+            mInputEventDeliverTimeNanos = 0;
+            mInputEventDeliverPostImeTimeNanos = 0;
+        }
+
         mFinishedCallback = finishedCallback;
     }
 
-    private void finishInputEvent(boolean handled) {
+    private void finishInputEvent(InputEvent event, boolean handled) {
         if (LOCAL_LOGV) Log.v(TAG, "Telling window manager input event is finished");
 
-        if (mFinishedCallback != null) {
-            mFinishedCallback.finished(handled);
-            mFinishedCallback = null;
-        } else {
+        if (mFinishedCallback == null) {
             Slog.w(TAG, "Attempted to tell the input queue that the current input event "
                     + "is finished but there is no input event actually in progress.");
+            return;
         }
+
+        if (ViewDebug.DEBUG_LATENCY) {
+            final long now = System.nanoTime();
+            final long eventTime = event.getEventTimeNano();
+            final StringBuilder msg = new StringBuilder();
+            msg.append("Latency: Spent ");
+            msg.append((now - mInputEventReceiveTimeNanos) * 0.000001f);
+            msg.append("ms processing ");
+            if (event instanceof KeyEvent) {
+                final KeyEvent  keyEvent = (KeyEvent)event;
+                msg.append("key event, action=");
+                msg.append(KeyEvent.actionToString(keyEvent.getAction()));
+            } else {
+                final MotionEvent motionEvent = (MotionEvent)event;
+                msg.append("motion event, action=");
+                msg.append(MotionEvent.actionToString(motionEvent.getAction()));
+                msg.append(", historySize=");
+                msg.append(motionEvent.getHistorySize());
+            }
+            msg.append(", handled=");
+            msg.append(handled);
+            msg.append(", received at +");
+            msg.append((mInputEventReceiveTimeNanos - eventTime) * 0.000001f);
+            if (mInputEventDeliverTimeNanos != 0) {
+                msg.append("ms, delivered at +");
+                msg.append((mInputEventDeliverTimeNanos - eventTime) * 0.000001f);
+            }
+            if (mInputEventDeliverPostImeTimeNanos != 0) {
+                msg.append("ms, delivered post IME at +");
+                msg.append((mInputEventDeliverPostImeTimeNanos - eventTime) * 0.000001f);
+            }
+            msg.append("ms, finished at +");
+            msg.append((now - eventTime) * 0.000001f);
+            msg.append("ms.");
+            Log.d(TAG, msg.toString());
+        }
+
+        mFinishedCallback.finished(handled);
+        mFinishedCallback = null;
     }
     
     /**
@@ -2323,6 +2414,10 @@
     }
 
     private void deliverPointerEvent(MotionEvent event, boolean sendDone) {
+        if (ViewDebug.DEBUG_LATENCY) {
+            mInputEventDeliverTimeNanos = System.nanoTime();
+        }
+
         if (mInputEventConsistencyVerifier != null) {
             if (event.isTouchEvent()) {
                 mInputEventConsistencyVerifier.onTouchEvent(event, 0);
@@ -2425,7 +2520,7 @@
     private void finishMotionEvent(MotionEvent event, boolean sendDone, boolean handled) {
         event.recycle();
         if (sendDone) {
-            finishInputEvent(handled);
+            finishInputEvent(event, handled);
         }
         if (LOCAL_LOGV || WATCH_POINTER) {
             if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
@@ -2435,6 +2530,10 @@
     }
 
     private void deliverTrackballEvent(MotionEvent event, boolean sendDone) {
+        if (ViewDebug.DEBUG_LATENCY) {
+            mInputEventDeliverTimeNanos = System.nanoTime();
+        }
+
         if (DEBUG_TRACKBALL) Log.v(TAG, "Motion event:" + event);
 
         if (mInputEventConsistencyVerifier != null) {
@@ -2569,6 +2668,10 @@
     }
 
     private void deliverGenericMotionEvent(MotionEvent event, boolean sendDone) {
+        if (ViewDebug.DEBUG_LATENCY) {
+            mInputEventDeliverTimeNanos = System.nanoTime();
+        }
+
         if (mInputEventConsistencyVerifier != null) {
             mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0);
         }
@@ -2808,6 +2911,10 @@
     }
 
     private void deliverKeyEvent(KeyEvent event, boolean sendDone) {
+        if (ViewDebug.DEBUG_LATENCY) {
+            mInputEventDeliverTimeNanos = System.nanoTime();
+        }
+
         if (mInputEventConsistencyVerifier != null) {
             mInputEventConsistencyVerifier.onKeyEvent(event, 0);
         }
@@ -2858,6 +2965,10 @@
     }
 
     private void deliverKeyEventPostIme(KeyEvent event, boolean sendDone) {
+        if (ViewDebug.DEBUG_LATENCY) {
+            mInputEventDeliverPostImeTimeNanos = System.nanoTime();
+        }
+
         // If the view went away, then the event will not be handled.
         if (mView == null || !mAdded) {
             finishKeyEvent(event, sendDone, false);
@@ -2971,7 +3082,7 @@
 
     private void finishKeyEvent(KeyEvent event, boolean sendDone, boolean handled) {
         if (sendDone) {
-            finishInputEvent(handled);
+            finishInputEvent(event, handled);
         }
     }
 
@@ -3262,16 +3373,19 @@
         sendMessage(msg);
     }
     
+    private long mInputEventReceiveTimeNanos;
+    private long mInputEventDeliverTimeNanos;
+    private long mInputEventDeliverPostImeTimeNanos;
     private InputQueue.FinishedCallback mFinishedCallback;
     
     private final InputHandler mInputHandler = new InputHandler() {
         public void handleKey(KeyEvent event, InputQueue.FinishedCallback finishedCallback) {
-            startInputEvent(finishedCallback);
+            startInputEvent(event, finishedCallback);
             dispatchKey(event, true);
         }
 
         public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
-            startInputEvent(finishedCallback);
+            startInputEvent(event, finishedCallback);
             dispatchMotion(event, true);
         }
     };
diff --git a/core/java/android/webkit/HTML5VideoFullScreen.java b/core/java/android/webkit/HTML5VideoFullScreen.java
index 3d15968..0918683 100644
--- a/core/java/android/webkit/HTML5VideoFullScreen.java
+++ b/core/java/android/webkit/HTML5VideoFullScreen.java
@@ -114,13 +114,6 @@
         return mVideoSurfaceView;
     }
 
-    @Override
-    public void start() {
-        if (getAutostart()) {
-            super.start();
-        }
-    }
-
     HTML5VideoFullScreen(Context context, int videoLayerId, int position,
             boolean autoStart) {
         mVideoSurfaceView = new VideoSurfaceView(context);
diff --git a/core/java/android/webkit/HTML5VideoViewProxy.java b/core/java/android/webkit/HTML5VideoViewProxy.java
index 14157c2..060c0bb 100644
--- a/core/java/android/webkit/HTML5VideoViewProxy.java
+++ b/core/java/android/webkit/HTML5VideoViewProxy.java
@@ -232,8 +232,9 @@
         }
 
         public static void onPrepared() {
-            // The VideoView will decide whether to really kick off to play.
-            mHTML5VideoView.start();
+            if (!mHTML5VideoView.isFullScreenMode() || mHTML5VideoView.getAutostart()) {
+                mHTML5VideoView.start();
+            }
             if (mBaseLayer != 0) {
                 setBaseLayer(mBaseLayer);
             }
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index e7f8796..f55608c 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -2382,6 +2382,8 @@
      */
     public void setTitleBarGravity(int gravity) {
         mTitleGravity = gravity;
+        // force refresh
+        invalidate();
     }
 
     /**
@@ -5569,6 +5571,7 @@
                         ted.mNativeLayer = nativeScrollableLayer(
                                 contentX, contentY, ted.mNativeLayerRect, null);
                         ted.mSequence = mTouchEventQueue.nextTouchSequence();
+                        mTouchEventQueue.preQueueTouchEventData(ted);
                         mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
                         if (mDeferTouchProcess) {
                             // still needs to set them for compute deltaX/Y
@@ -5618,6 +5621,7 @@
                     ted.mNativeLayer = mScrollingLayer;
                     ted.mNativeLayerRect.set(mScrollingLayerRect);
                     ted.mSequence = mTouchEventQueue.nextTouchSequence();
+                    mTouchEventQueue.preQueueTouchEventData(ted);
                     mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
                     mLastSentTouchTime = eventTime;
                     if (mDeferTouchProcess) {
@@ -5802,6 +5806,7 @@
                     ted.mNativeLayer = mScrollingLayer;
                     ted.mNativeLayerRect.set(mScrollingLayerRect);
                     ted.mSequence = mTouchEventQueue.nextTouchSequence();
+                    mTouchEventQueue.preQueueTouchEventData(ted);
                     mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
                 }
                 mLastTouchUpTime = eventTime;
@@ -5827,6 +5832,7 @@
                                     contentX, contentY,
                                     ted.mNativeLayerRect, null);
                             ted.mSequence = mTouchEventQueue.nextTouchSequence();
+                            mTouchEventQueue.preQueueTouchEventData(ted);
                             mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
                         } else if (mPreventDefault != PREVENT_DEFAULT_YES){
                             mZoomManager.handleDoubleTap(mLastTouchX, mLastTouchY);
@@ -5973,6 +5979,7 @@
         ted.mReprocess = true;
         ted.mMotionEvent = MotionEvent.obtain(ev);
         ted.mSequence = sequence;
+        mTouchEventQueue.preQueueTouchEventData(ted);
         mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
         cancelLongPress();
         mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
@@ -7190,9 +7197,17 @@
         private long mNextTouchSequence = Long.MIN_VALUE + 1;
         private long mLastHandledTouchSequence = Long.MIN_VALUE;
         private long mIgnoreUntilSequence = Long.MIN_VALUE + 1;
+
+        // Events waiting to be processed.
         private QueuedTouch mTouchEventQueue;
+
+        // Known events that are waiting on a response before being enqueued.
+        private QueuedTouch mPreQueue;
+
+        // Pool of QueuedTouch objects saved for later use.
         private QueuedTouch mQueuedTouchRecycleBin;
         private int mQueuedTouchRecycleCount;
+
         private long mLastEventTime = Long.MAX_VALUE;
         private static final int MAX_RECYCLED_QUEUED_TOUCH = 15;
 
@@ -7214,6 +7229,57 @@
          */
         public void ignoreCurrentlyMissingEvents() {
             mIgnoreUntilSequence = mNextTouchSequence;
+
+            // Run any events we have available and complete, pre-queued or otherwise.
+            runQueuedAndPreQueuedEvents();
+        }
+
+        private void runQueuedAndPreQueuedEvents() {
+            QueuedTouch qd = mPreQueue;
+            boolean fromPreQueue = true;
+            while (qd != null && qd.mSequence == mLastHandledTouchSequence + 1) {
+                handleQueuedTouch(qd);
+                QueuedTouch recycleMe = qd;
+                if (fromPreQueue) {
+                    mPreQueue = qd.mNext;
+                } else {
+                    mTouchEventQueue = qd.mNext;
+                }
+                recycleQueuedTouch(recycleMe);
+                mLastHandledTouchSequence++;
+
+                long nextPre = mPreQueue != null ? mPreQueue.mSequence : Long.MAX_VALUE;
+                long nextQueued = mTouchEventQueue != null ?
+                        mTouchEventQueue.mSequence : Long.MAX_VALUE;
+                fromPreQueue = nextPre < nextQueued;
+                qd = fromPreQueue ? mPreQueue : mTouchEventQueue;
+            }
+        }
+
+        /**
+         * Add a TouchEventData to the pre-queue.
+         *
+         * An event in the pre-queue is an event that we know about that
+         * has been sent to webkit, but that we haven't received back and
+         * enqueued into the normal touch queue yet. If webkit ever times
+         * out and we need to ignore currently missing events, we'll run
+         * events from the pre-queue to patch the holes.
+         *
+         * @param ted TouchEventData to pre-queue
+         */
+        public void preQueueTouchEventData(TouchEventData ted) {
+            QueuedTouch newTouch = obtainQueuedTouch().set(ted);
+            if (mPreQueue == null) {
+                mPreQueue = newTouch;
+            } else {
+                QueuedTouch insertionPoint = mPreQueue;
+                while (insertionPoint.mNext != null &&
+                        insertionPoint.mNext.mSequence < newTouch.mSequence) {
+                    insertionPoint = insertionPoint.mNext;
+                }
+                newTouch.mNext = insertionPoint.mNext;
+                insertionPoint.mNext = newTouch;
+            }
         }
 
         private void recycleQueuedTouch(QueuedTouch qd) {
@@ -7237,6 +7303,11 @@
                 mTouchEventQueue = mTouchEventQueue.mNext;
                 recycleQueuedTouch(recycleMe);
             }
+            while (mPreQueue != null) {
+                QueuedTouch recycleMe = mPreQueue;
+                mPreQueue = mPreQueue.mNext;
+                recycleQueuedTouch(recycleMe);
+            }
         }
 
         /**
@@ -7259,6 +7330,28 @@
          * @return true if the event was processed before returning, false if it was just enqueued.
          */
         public boolean enqueueTouchEvent(TouchEventData ted) {
+            // Remove from the pre-queue if present
+            QueuedTouch preQueue = mPreQueue;
+            if (preQueue != null) {
+                // On exiting this block, preQueue is set to the pre-queued QueuedTouch object
+                // if it was present in the pre-queue, and removed from the pre-queue itself.
+                if (preQueue.mSequence == ted.mSequence) {
+                    mPreQueue = preQueue.mNext;
+                } else {
+                    QueuedTouch prev = preQueue;
+                    preQueue = null;
+                    while (prev.mNext != null) {
+                        if (prev.mNext.mSequence == ted.mSequence) {
+                            preQueue = prev.mNext;
+                            prev.mNext = preQueue.mNext;
+                            break;
+                        } else {
+                            prev = prev.mNext;
+                        }
+                    }
+                }
+            }
+
             if (ted.mSequence < mLastHandledTouchSequence) {
                 // Stale event and we already moved on; drop it. (Should not be common.)
                 Log.w(LOGTAG, "Stale touch event " + MotionEvent.actionToString(ted.mAction) +
@@ -7270,23 +7363,24 @@
                 return false;
             }
 
+            // dropStaleGestures above might have fast-forwarded us to
+            // an event we have already.
+            runNextQueuedEvents();
+
             if (mLastHandledTouchSequence + 1 == ted.mSequence) {
+                if (preQueue != null) {
+                    recycleQueuedTouch(preQueue);
+                    preQueue = null;
+                }
                 handleQueuedTouchEventData(ted);
 
                 mLastHandledTouchSequence++;
 
                 // Do we have any more? Run them if so.
-                QueuedTouch qd = mTouchEventQueue;
-                while (qd != null && qd.mSequence == mLastHandledTouchSequence + 1) {
-                    handleQueuedTouch(qd);
-                    QueuedTouch recycleMe = qd;
-                    qd = qd.mNext;
-                    recycleQueuedTouch(recycleMe);
-                    mLastHandledTouchSequence++;
-                }
-                mTouchEventQueue = qd;
+                runNextQueuedEvents();
             } else {
-                QueuedTouch qd = obtainQueuedTouch().set(ted);
+                // Reuse the pre-queued object if we had it.
+                QueuedTouch qd = preQueue != null ? preQueue : obtainQueuedTouch().set(ted);
                 mTouchEventQueue = mTouchEventQueue == null ? qd : mTouchEventQueue.add(qd);
             }
             return true;
@@ -7308,27 +7402,35 @@
                 return;
             }
 
+            // dropStaleGestures above might have fast-forwarded us to
+            // an event we have already.
+            runNextQueuedEvents();
+
             if (mLastHandledTouchSequence + 1 == sequence) {
                 handleQueuedMotionEvent(ev);
 
                 mLastHandledTouchSequence++;
 
                 // Do we have any more? Run them if so.
-                QueuedTouch qd = mTouchEventQueue;
-                while (qd != null && qd.mSequence == mLastHandledTouchSequence + 1) {
-                    handleQueuedTouch(qd);
-                    QueuedTouch recycleMe = qd;
-                    qd = qd.mNext;
-                    recycleQueuedTouch(recycleMe);
-                    mLastHandledTouchSequence++;
-                }
-                mTouchEventQueue = qd;
+                runNextQueuedEvents();
             } else {
                 QueuedTouch qd = obtainQueuedTouch().set(ev, sequence);
                 mTouchEventQueue = mTouchEventQueue == null ? qd : mTouchEventQueue.add(qd);
             }
         }
 
+        private void runNextQueuedEvents() {
+            QueuedTouch qd = mTouchEventQueue;
+            while (qd != null && qd.mSequence == mLastHandledTouchSequence + 1) {
+                handleQueuedTouch(qd);
+                QueuedTouch recycleMe = qd;
+                qd = qd.mNext;
+                recycleQueuedTouch(recycleMe);
+                mLastHandledTouchSequence++;
+            }
+            mTouchEventQueue = qd;
+        }
+
         private boolean dropStaleGestures(MotionEvent ev, long sequence) {
             if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && !mConfirmMove) {
                 // This is to make sure that we don't attempt to process a tap
@@ -7348,13 +7450,16 @@
             }
 
             // If we have a new down event and it's been a while since the last event
-            // we saw, just reset and keep going.
+            // we saw, catch up as best we can and keep going.
             if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN) {
                 long eventTime = ev.getEventTime();
                 long lastHandledEventTime = mLastEventTime;
                 if (eventTime > lastHandledEventTime + QUEUED_GESTURE_TIMEOUT) {
                     Log.w(LOGTAG, "Got ACTION_DOWN but still waiting on stale event. " +
-                            "Ignoring previous queued events.");
+                            "Catching up.");
+                    runQueuedAndPreQueuedEvents();
+
+                    // Drop leftovers that we truly don't have.
                     QueuedTouch qd = mTouchEventQueue;
                     while (qd != null && qd.mSequence < sequence) {
                         QueuedTouch recycleMe = qd;
@@ -7377,6 +7482,17 @@
                 mLastHandledTouchSequence = mIgnoreUntilSequence - 1;
             }
 
+            if (mPreQueue != null) {
+                // Drop stale prequeued events
+                QueuedTouch qd = mPreQueue;
+                while (qd != null && qd.mSequence < mIgnoreUntilSequence) {
+                    QueuedTouch recycleMe = qd;
+                    qd = qd.mNext;
+                    recycleQueuedTouch(recycleMe);
+                }
+                mPreQueue = qd;
+            }
+
             return sequence <= mLastHandledTouchSequence;
         }
 
@@ -7626,6 +7742,7 @@
                                 ted.mPoints[0].x, ted.mPoints[0].y,
                                 ted.mNativeLayerRect, null);
                         ted.mSequence = mTouchEventQueue.nextTouchSequence();
+                        mTouchEventQueue.preQueueTouchEventData(ted);
                         mWebViewCore.sendMessage(EventHub.TOUCH_EVENT, ted);
                     } else if (mPreventDefault != PREVENT_DEFAULT_YES) {
                         mTouchMode = TOUCH_DONE_MODE;
diff --git a/core/java/android/widget/AdapterViewAnimator.java b/core/java/android/widget/AdapterViewAnimator.java
index ca1effb..c773527 100644
--- a/core/java/android/widget/AdapterViewAnimator.java
+++ b/core/java/android/widget/AdapterViewAnimator.java
@@ -79,7 +79,7 @@
     /**
      * Map of the children of the {@link AdapterViewAnimator}.
      */
-    HashMap<Integer, ViewAndIndex> mViewsMap = new HashMap<Integer, ViewAndIndex>();
+    HashMap<Integer, ViewAndMetaData> mViewsMap = new HashMap<Integer, ViewAndMetaData>();
 
     /**
      * List of views pending removal from the {@link AdapterViewAnimator}
@@ -204,13 +204,18 @@
         mPreviousViews = new ArrayList<Integer>();
     }
 
-    class ViewAndIndex {
-        ViewAndIndex(View v, int i) {
-            view = v;
-            index = i;
-        }
+    class ViewAndMetaData {
         View view;
-        int index;
+        int relativeIndex;
+        int adapterPosition;
+        long itemId;
+
+        ViewAndMetaData(View view, int relativeIndex, int adapterPosition, long itemId) {
+            this.view = view;
+            this.relativeIndex = relativeIndex;
+            this.adapterPosition = adapterPosition;
+            this.itemId = itemId;
+        }
     }
 
     /**
@@ -376,6 +381,15 @@
         }
     }
 
+    private ViewAndMetaData getMetaDataForChild(View child) {
+        for (ViewAndMetaData vm: mViewsMap.values()) {
+            if (vm.view == child) {
+                return vm;
+            }
+        }
+        return null;
+     }
+
     LayoutParams createOrReuseLayoutParams(View v) {
         final ViewGroup.LayoutParams currentLp = v.getLayoutParams();
         if (currentLp instanceof ViewGroup.LayoutParams) {
@@ -478,7 +492,7 @@
 
             if (remove) {
                 View previousView = mViewsMap.get(index).view;
-                int oldRelativeIndex = mViewsMap.get(index).index;
+                int oldRelativeIndex = mViewsMap.get(index).relativeIndex;
 
                 mPreviousViews.add(index);
                 transformViewForTransition(oldRelativeIndex, -1, previousView, animate);
@@ -494,7 +508,7 @@
                 int index = modulo(i, getWindowSize());
                 int oldRelativeIndex;
                 if (mViewsMap.containsKey(index)) {
-                    oldRelativeIndex = mViewsMap.get(index).index;
+                    oldRelativeIndex = mViewsMap.get(index).relativeIndex;
                 } else {
                     oldRelativeIndex = -1;
                 }
@@ -507,14 +521,16 @@
 
                 if (inOldRange) {
                     View view = mViewsMap.get(index).view;
-                    mViewsMap.get(index).index = newRelativeIndex;
+                    mViewsMap.get(index).relativeIndex = newRelativeIndex;
                     applyTransformForChildAtIndex(view, newRelativeIndex);
                     transformViewForTransition(oldRelativeIndex, newRelativeIndex, view, animate);
 
                 // Otherwise this view is new to the window
                 } else {
                     // Get the new view from the adapter, add it and apply any transform / animation
-                    View newView = mAdapter.getView(modulo(i, adapterCount), null, this);
+                    final int adapterPosition = modulo(i, adapterCount);
+                    View newView = mAdapter.getView(adapterPosition, null, this);
+                    long itemId = mAdapter.getItemId(adapterPosition);
 
                     // We wrap the new view in a FrameLayout so as to respect the contract
                     // with the adapter, that is, that we don't modify this view directly
@@ -524,7 +540,8 @@
                     if (newView != null) {
                        fl.addView(newView);
                     }
-                    mViewsMap.put(index, new ViewAndIndex(fl, newRelativeIndex));
+                    mViewsMap.put(index, new ViewAndMetaData(fl, newRelativeIndex,
+                            adapterPosition, itemId));
                     addChild(fl);
                     applyTransformForChildAtIndex(fl, newRelativeIndex);
                     transformViewForTransition(-1, newRelativeIndex, fl, animate);
@@ -601,6 +618,7 @@
             case MotionEvent.ACTION_UP: {
                 if (mTouchMode == TOUCH_MODE_DOWN_IN_CURRENT_VIEW) {
                     final View v = getCurrentView();
+                    final ViewAndMetaData viewData = getMetaDataForChild(v);
                     if (v != null) {
                         if (isTransformedTouchPointInView(ev.getX(), ev.getY(), v, null)) {
                             final Handler handler = getHandler();
@@ -613,7 +631,12 @@
                                     hideTapFeedback(v);
                                     post(new Runnable() {
                                         public void run() {
-                                            performItemClick(v, 0, 0);
+                                            if (viewData != null) {
+                                                performItemClick(v, viewData.adapterPosition,
+                                                        viewData.itemId);
+                                            } else {
+                                                performItemClick(v, 0, 0);
+                                            }
                                         }
                                     });
                                 }
diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java
index ec4ef4b..71c91e1 100644
--- a/core/java/android/widget/StackView.java
+++ b/core/java/android/widget/StackView.java
@@ -427,8 +427,8 @@
         // Here we need to make sure that the z-order of the children is correct
         for (int i = mCurrentWindowEnd; i >= mCurrentWindowStart; i--) {
             int index = modulo(i, getWindowSize());
-            ViewAndIndex vi = mViewsMap.get(index);
-            if (vi != null) {
+            ViewAndMetaData vm = mViewsMap.get(index);
+            if (vm != null) {
                 View v = mViewsMap.get(index).view;
                 if (v != null) v.bringToFront();
             }
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 86dfb9b..dc10624 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -43,7 +43,6 @@
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
-import android.os.IBinder;
 import android.os.Message;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -88,6 +87,7 @@
 import android.text.style.UpdateAppearance;
 import android.text.util.Linkify;
 import android.util.AttributeSet;
+import android.util.DisplayMetrics;
 import android.util.FloatMath;
 import android.util.Log;
 import android.util.TypedValue;
@@ -311,6 +311,10 @@
     private int mTextEditPasteWindowLayout, mTextEditSidePasteWindowLayout;
     private int mTextEditNoPasteWindowLayout, mTextEditSideNoPasteWindowLayout;
 
+    private int mTextEditSuggestionsBottomWindowLayout, mTextEditSuggestionsTopWindowLayout;
+    private int mTextEditSuggestionItemLayout;
+    private SuggestionsPopupWindow mSuggestionsPopupWindow;
+
     private int mCursorDrawableRes;
     private final Drawable[] mCursorDrawable = new Drawable[2];
     private int mCursorCount; // Actual current number of used mCursorDrawable: 0, 1 or 2
@@ -779,6 +783,18 @@
                 mTextEditSideNoPasteWindowLayout = a.getResourceId(attr, 0);
                 break;
 
+            case com.android.internal.R.styleable.TextView_textEditSuggestionsBottomWindowLayout:
+                mTextEditSuggestionsBottomWindowLayout = a.getResourceId(attr, 0);
+                break;
+
+            case com.android.internal.R.styleable.TextView_textEditSuggestionsTopWindowLayout:
+                mTextEditSuggestionsTopWindowLayout = a.getResourceId(attr, 0);
+                break;
+
+            case com.android.internal.R.styleable.TextView_textEditSuggestionItemLayout:
+                mTextEditSuggestionItemLayout = a.getResourceId(attr, 0);
+                break;
+
             case com.android.internal.R.styleable.TextView_textIsSelectable:
                 mTextIsSelectable = a.getBoolean(attr, false);
                 break;
@@ -7343,6 +7359,7 @@
                     startSelectionActionMode();
                 } else {
                     stopSelectionActionMode();
+                    hideSuggestions();
                     if (hasInsertionController() && !selectAllGotFocus && mText.length() > 0) {
                         getInsertionController().show();
                     }
@@ -7776,7 +7793,7 @@
                 // Cases where the text ends with a '.' and we select from the end of the line
                 // (right after the dot), or when we select from the space character in "aaa, bbb".
                 continue;
-            }              
+            }
             if (type == Character.SURROGATE) { // Two Character codepoint
                 end = start - 1; // Recheck as a pair when scanning forward
                 continue;
@@ -8221,6 +8238,201 @@
         return ((minOffset >= selectionStart) && (maxOffset < selectionEnd));
     }
 
+    private class SuggestionsPopupWindow implements OnClickListener {
+        private static final int MAX_NUMBER_SUGGESTIONS = 5;
+        private static final long NO_SUGGESTIONS = -1L;
+        private final PopupWindow mContainer;
+        private final ViewGroup[] mSuggestionViews = new ViewGroup[2];
+        private final int[] mSuggestionViewLayouts = new int[] {
+                mTextEditSuggestionsBottomWindowLayout, mTextEditSuggestionsTopWindowLayout};
+
+        public SuggestionsPopupWindow() {
+            mContainer = new PopupWindow(TextView.this.mContext, null,
+                    com.android.internal.R.attr.textSuggestionsWindowStyle);
+            mContainer.setSplitTouchEnabled(true);
+            mContainer.setClippingEnabled(false);
+            mContainer.setWindowLayoutType(WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL);
+
+            mContainer.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
+            mContainer.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
+        }
+
+        private ViewGroup getViewGroup(boolean under) {
+            final int viewIndex = under ? 0 : 1;
+            ViewGroup viewGroup = mSuggestionViews[viewIndex];
+
+            if (viewGroup == null) {
+                final int layout = mSuggestionViewLayouts[viewIndex];
+                LayoutInflater inflater = (LayoutInflater) TextView.this.mContext.
+                        getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+                if (inflater == null) {
+                    throw new IllegalArgumentException(
+                            "Unable to create TextEdit suggestion window inflater");
+                }
+
+                View view = inflater.inflate(layout, null);
+
+                if (! (view instanceof ViewGroup)) {
+                    throw new IllegalArgumentException(
+                            "Inflated TextEdit suggestion window is not a ViewGroup: " + view);
+                }
+
+                viewGroup = (ViewGroup) view;
+
+                // Inflate the suggestion items once and for all.
+                for (int i = 0; i < MAX_NUMBER_SUGGESTIONS; i++) {
+                    View childView = inflater.inflate(mTextEditSuggestionItemLayout, viewGroup,
+                            false);
+
+                    if (! (childView instanceof TextView)) {
+                        throw new IllegalArgumentException(
+                               "Inflated TextEdit suggestion item is not a TextView: " + childView);
+                    }
+
+                    viewGroup.addView(childView);
+                    childView.setOnClickListener(this);
+                }
+
+                mSuggestionViews[viewIndex] = viewGroup;
+            }
+
+            return viewGroup;
+        }
+
+        public void show() {
+            if (!(mText instanceof Editable)) return;
+
+            final int pos = TextView.this.getSelectionStart();
+            Spannable spannable = (Spannable)TextView.this.mText;
+            CorrectionSpan[] correctionSpans = spannable.getSpans(pos, pos, CorrectionSpan.class);
+            final int nbSpans = correctionSpans.length;
+
+            ViewGroup viewGroup = getViewGroup(true);
+            mContainer.setContentView(viewGroup);
+
+            int totalNbSuggestions = 0;
+            for (int spanIndex = 0; spanIndex < nbSpans; spanIndex++) {
+                CorrectionSpan correctionSpan = correctionSpans[spanIndex];
+                final int spanStart = spannable.getSpanStart(correctionSpan);
+                final int spanEnd = spannable.getSpanEnd(correctionSpan);
+                final Long spanRange = packRangeInLong(spanStart, spanEnd);
+
+                String[] suggestions = correctionSpan.getSuggestions();
+                int nbSuggestions = suggestions.length;
+                for (int suggestionIndex = 0; suggestionIndex < nbSuggestions; suggestionIndex++) {
+                    TextView textView = (TextView) viewGroup.getChildAt(totalNbSuggestions);
+                    textView.setText(suggestions[suggestionIndex]);
+                    textView.setTag(spanRange);
+
+                    totalNbSuggestions++;
+                    if (totalNbSuggestions == MAX_NUMBER_SUGGESTIONS) {
+                        spanIndex = nbSpans;
+                        break;
+                    }
+                }
+            }
+
+            if (totalNbSuggestions == 0) {
+                // TODO Replace by final text, use a dedicated layout, add a fade out timer...
+                TextView textView = (TextView) viewGroup.getChildAt(0);
+                textView.setText("No suggestions available");
+                textView.setTag(NO_SUGGESTIONS);
+                totalNbSuggestions++;
+            }
+
+            for (int i = 0; i < MAX_NUMBER_SUGGESTIONS; i++) {
+                viewGroup.getChildAt(i).setVisibility(i < totalNbSuggestions ? VISIBLE : GONE);
+            }
+
+            final int size = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
+            viewGroup.measure(size, size);
+
+            positionAtCursor();
+        }
+
+        public void hide() {
+            mContainer.dismiss();
+        }
+
+        @Override
+        public void onClick(View view) {
+            if (view instanceof TextView) {
+                TextView textView = (TextView) view;
+                Long range = ((Long) view.getTag());
+                if (range != NO_SUGGESTIONS) {
+                    final int spanStart = extractRangeStartFromLong(range);
+                    final int spanEnd = extractRangeEndFromLong(range);
+                    ((Editable) mText).replace(spanStart, spanEnd, textView.getText());
+                }
+            }
+            hide();
+        }
+
+        void positionAtCursor() {
+            View contentView = mContainer.getContentView();
+            int width = contentView.getMeasuredWidth();
+            int height = contentView.getMeasuredHeight();
+            final int offset = TextView.this.getSelectionStart();
+            final int line = mLayout.getLineForOffset(offset);
+            final int lineBottom = mLayout.getLineBottom(line);
+            float primaryHorizontal = mLayout.getPrimaryHorizontal(offset);
+
+            final Rect bounds = sCursorControllerTempRect;
+            bounds.left = (int) (primaryHorizontal - width / 2.0f);
+            bounds.top = lineBottom;
+
+            bounds.right = bounds.left + width;
+            bounds.bottom = bounds.top + height;
+
+            convertFromViewportToContentCoordinates(bounds);
+
+            final int[] coords = mTempCoords;
+            TextView.this.getLocationInWindow(coords);
+            coords[0] += bounds.left;
+            coords[1] += bounds.top;
+
+            final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
+            final int screenHeight = displayMetrics.heightPixels;
+
+            // Vertical clipping
+            if (coords[1] + height > screenHeight) {
+                // Try to position above current line instead
+                // TODO use top layout instead, reverse suggestion order,
+                // try full screen vertical down if it still does not fit. TBD with designers.
+
+                // Update dimensions from new view
+                contentView = mContainer.getContentView();
+                width = contentView.getMeasuredWidth();
+                height = contentView.getMeasuredHeight();
+
+                final int lineTop = mLayout.getLineTop(line);
+                final int lineHeight = lineBottom - lineTop;
+                coords[1] -= height + lineHeight;
+            }
+
+            // Horizontal clipping
+            coords[0] = Math.max(0, coords[0]);
+            coords[0] = Math.min(displayMetrics.widthPixels - width, coords[0]);
+
+            mContainer.showAtLocation(TextView.this, Gravity.NO_GRAVITY, coords[0], coords[1]);
+        }
+    }
+
+    void showSuggestions() {
+        if (mSuggestionsPopupWindow == null) {
+            mSuggestionsPopupWindow = new SuggestionsPopupWindow();
+        }
+        hideControllers();
+        mSuggestionsPopupWindow.show();
+    }
+
+    void hideSuggestions() {
+        if (mSuggestionsPopupWindow != null) {
+            mSuggestionsPopupWindow.hide();
+        }
+    }
+
     /**
      * If provided, this ActionMode.Callback will be used to create the ActionMode when text
      * selection is initiated in this View.
@@ -8429,16 +8641,14 @@
         }
     }
 
-    private class PastePopupMenu implements OnClickListener {
+    private class PastePopupWindow implements OnClickListener {
         private final PopupWindow mContainer;
-        private int mPositionX;
-        private int mPositionY;
         private final View[] mPasteViews = new View[4];
         private final int[] mPasteViewLayouts = new int[] { 
                 mTextEditPasteWindowLayout,  mTextEditNoPasteWindowLayout, 
                 mTextEditSidePasteWindowLayout, mTextEditSideNoPasteWindowLayout };
         
-        public PastePopupMenu() {
+        public PastePopupWindow() {
             mContainer = new PopupWindow(TextView.this.mContext, null,
                     com.android.internal.R.attr.textSelectHandleWindowStyle);
             mContainer.setSplitTouchEnabled(true);
@@ -8521,14 +8731,10 @@
 
             convertFromViewportToContentCoordinates(bounds);
 
-            mPositionX = bounds.left;
-            mPositionY = bounds.top;
-
-
             final int[] coords = mTempCoords;
             TextView.this.getLocationInWindow(coords);
-            coords[0] += mPositionX;
-            coords[1] += mPositionY;
+            coords[0] += bounds.left;
+            coords[1] += bounds.top;
 
             final int screenWidth = mContext.getResources().getDisplayMetrics().widthPixels;
             if (coords[1] < 0) {
@@ -8873,7 +9079,7 @@
         void hideAssociatedPopupWindow() {
             // No associated popup window by default
         }
-        
+
         public void onDetached() {
             // Should be overriden to clean possible Runnable
         }
@@ -8883,10 +9089,10 @@
         private static final int DELAY_BEFORE_FADE_OUT = 4000;
         private static final int RECENT_CUT_COPY_DURATION = 15 * 1000; // seconds
 
-        // Used to detect taps on the insertion handle, which will affect the PastePopupMenu
+        // Used to detect taps on the insertion handle, which will affect the PastePopupWindow
         private long mTouchTimer;
         private float mDownPositionX, mDownPositionY;
-        private PastePopupMenu mPastePopupWindow;
+        private PastePopupWindow mPastePopupWindow;
         private Runnable mHider;
         private Runnable mPastePopupShower;
 
@@ -9026,7 +9232,7 @@
         void showAssociatedPopupWindow() {
             if (mPastePopupWindow == null) {
                 // Lazy initialisation: create when actually shown only.
-                mPastePopupWindow = new PastePopupMenu();
+                mPastePopupWindow = new PastePopupWindow();
             }
             mPastePopupWindow.show();
         }
@@ -9237,6 +9443,7 @@
             mEndHandle.show();
 
             hideInsertionPointCursorController();
+            hideSuggestions();
         }
 
         public void hide() {
@@ -9264,7 +9471,7 @@
                             final int deltaY = y - mPreviousTapPositionY;
                             final int distanceSquared = deltaX * deltaX + deltaY * deltaY;
                             if (distanceSquared < mSquaredTouchSlopDistance) {
-                                startSelectionActionMode();
+                                showSuggestions();
                                 mDiscardNextActionUp = true;
                             }
                         }
@@ -9354,6 +9561,7 @@
     private void hideControllers() {
         hideInsertionPointCursorController();
         stopSelectionActionMode();
+        hideSuggestions();
     }
 
     /**
diff --git a/core/jni/android/graphics/Movie.cpp b/core/jni/android/graphics/Movie.cpp
index de18f9f..b319a74 100644
--- a/core/jni/android/graphics/Movie.cpp
+++ b/core/jni/android/graphics/Movie.cpp
@@ -137,7 +137,6 @@
 
 #define RETURN_ERR_IF_NULL(value)   do { if (!(value)) { assert(0); return -1; } } while (false)
 
-int register_android_graphics_Movie(JNIEnv* env);
 int register_android_graphics_Movie(JNIEnv* env)
 {
     gMovie_class = env->FindClass(kClassPathName);
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index 27be871..fbb9cea 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -407,7 +407,7 @@
         HB_ShaperItem shaperItem;
         HB_FontRec font;
         FontData fontData;
-        RunAdvanceDescription::shapeWithHarfbuzz(&shaperItem, &font, &fontData, paint, text,
+        TextLayoutCacheValue::shapeWithHarfbuzz(&shaperItem, &font, &fontData, paint, text,
                 start, count, contextCount, flags);
 
         int glyphCount = shaperItem.num_glyphs;
diff --git a/core/jni/android/graphics/TextLayout.cpp b/core/jni/android/graphics/TextLayout.cpp
index 434f63b..2578ea1 100644
--- a/core/jni/android/graphics/TextLayout.cpp
+++ b/core/jni/android/graphics/TextLayout.cpp
@@ -264,7 +264,7 @@
             dirFlags, resultAdvances, &resultTotalAdvance);
 #else
     // Compute advances and return them
-    RunAdvanceDescription::computeAdvances(paint, chars, start, count, contextCount, dirFlags,
+    TextLayoutCacheValue::computeAdvances(paint, chars, start, count, contextCount, dirFlags,
             resultAdvances, &resultTotalAdvance);
 #endif
 }
@@ -273,7 +273,7 @@
                                     jint count, jint contextCount, jint dirFlags,
                                     jfloat* resultAdvances, jfloat& resultTotalAdvance) {
     // Compute advances and return them
-    RunAdvanceDescription::computeAdvancesWithHarfbuzz(paint, chars, start, count, contextCount, dirFlags,
+    TextLayoutCacheValue::computeAdvancesWithHarfbuzz(paint, chars, start, count, contextCount, dirFlags,
             resultAdvances, &resultTotalAdvance);
 }
 
@@ -281,7 +281,7 @@
                                     jint count, jint contextCount, jint dirFlags,
                                     jfloat* resultAdvances, jfloat& resultTotalAdvance) {
     // Compute advances and return them
-    RunAdvanceDescription::computeAdvancesWithICU(paint, chars, start, count, contextCount, dirFlags,
+    TextLayoutCacheValue::computeAdvancesWithICU(paint, chars, start, count, contextCount, dirFlags,
             resultAdvances, &resultTotalAdvance);
 }
 
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp
index a7265be..10e2e41 100644
--- a/core/jni/android/graphics/TextLayoutCache.cpp
+++ b/core/jni/android/graphics/TextLayoutCache.cpp
@@ -19,14 +19,14 @@
 namespace android {
 
 TextLayoutCache::TextLayoutCache():
-        mCache(GenerationCache<TextLayoutCacheKey, RunAdvanceDescription*>::kUnlimitedCapacity),
+        mCache(GenerationCache<TextLayoutCacheKey, TextLayoutCacheValue*>::kUnlimitedCapacity),
         mSize(0), mMaxSize(MB(DEFAULT_TEXT_LAYOUT_CACHE_SIZE_IN_MB)),
         mCacheHitCount(0), mNanosecondsSaved(0) {
     init();
 }
 
 TextLayoutCache::TextLayoutCache(uint32_t max):
-        mCache(GenerationCache<TextLayoutCacheKey, RunAdvanceDescription*>::kUnlimitedCapacity),
+        mCache(GenerationCache<TextLayoutCacheKey, TextLayoutCacheValue*>::kUnlimitedCapacity),
         mSize(0), mMaxSize(max),
         mCacheHitCount(0), mNanosecondsSaved(0) {
     init();
@@ -88,12 +88,12 @@
 /**
  *  Callbacks
  */
-void TextLayoutCache::operator()(TextLayoutCacheKey& text, RunAdvanceDescription*& desc) {
+void TextLayoutCache::operator()(TextLayoutCacheKey& text, TextLayoutCacheValue*& desc) {
     if (desc) {
         size_t totalSizeToDelete = text.getSize() + desc->getSize();
         mSize -= totalSizeToDelete;
         if (mDebugEnabled) {
-            LOGD("RunAdvance description deleted, size = %d", totalSizeToDelete);
+            LOGD("Cache value deleted, size = %d", totalSizeToDelete);
         }
         delete desc;
     }
@@ -120,21 +120,21 @@
         startTime = systemTime(SYSTEM_TIME_MONOTONIC);
     }
 
-    TextLayoutCacheKey entry(paint, text, start, count, contextCount, dirFlags);
+    TextLayoutCacheKey key(paint, text, start, count, contextCount, dirFlags);
 
     // Get entry for cache if possible
-    RunAdvanceDescription* desc = mCache.get(entry);
+    TextLayoutCacheValue* value = mCache.get(key);
 
     // Value not found for the entry, we need to add a new value in the cache
-    if (!desc) {
-        desc = new RunAdvanceDescription();
+    if (!value) {
+        value = new TextLayoutCacheValue();
 
         // Compute advances and store them
-        desc->computeAdvances(paint, text, start, count, contextCount, dirFlags);
-        desc->copyResult(outAdvances, outTotalAdvance);
+        value->computeAdvances(paint, text, start, count, contextCount, dirFlags);
+        value->copyResult(outAdvances, outTotalAdvance);
 
         // Don't bother to add in the cache if the entry is too big
-        size_t size = entry.getSize() + desc->getSize();
+        size_t size = key.getSize() + value->getSize();
         if (size <= mMaxSize) {
             // Cleanup to make some room if needed
             if (mSize + size > mMaxSize) {
@@ -152,18 +152,18 @@
             mSize += size;
 
             // Copy the text when we insert the new entry
-            entry.internalTextCopy();
-            mCache.put(entry, desc);
+            key.internalTextCopy();
+            mCache.put(key, value);
 
             if (mDebugEnabled) {
                 // Update timing information for statistics.
-                desc->setElapsedTime(systemTime(SYSTEM_TIME_MONOTONIC) - startTime);
+                value->setElapsedTime(systemTime(SYSTEM_TIME_MONOTONIC) - startTime);
 
                 LOGD("CACHE MISS: Added entry for text='%s' with start=%d, count=%d, "
                         "contextCount=%d, entry size %d bytes, remaining space %d bytes"
                         " - Compute time in nanos: %d",
                         String8(text, contextCount).string(), start, count, contextCount,
-                        size, mMaxSize - mSize, desc->getElapsedTime());
+                        size, mMaxSize - mSize, value->getElapsedTime());
             }
         } else {
             if (mDebugEnabled) {
@@ -172,27 +172,27 @@
                         "entry size %d bytes, remaining space %d bytes"
                         " - Compute time in nanos: %d",
                         String8(text, contextCount).string(), start, count, contextCount,
-                        size, mMaxSize - mSize, desc->getElapsedTime());
+                        size, mMaxSize - mSize, value->getElapsedTime());
             }
-            delete desc;
+            delete value;
         }
     } else {
         // This is a cache hit, just copy the pre-computed results
-        desc->copyResult(outAdvances, outTotalAdvance);
+        value->copyResult(outAdvances, outTotalAdvance);
         if (mDebugEnabled) {
             nsecs_t elapsedTimeThruCacheGet = systemTime(SYSTEM_TIME_MONOTONIC) - startTime;
-            mNanosecondsSaved += (desc->getElapsedTime() - elapsedTimeThruCacheGet);
+            mNanosecondsSaved += (value->getElapsedTime() - elapsedTimeThruCacheGet);
             ++mCacheHitCount;
 
-            if (desc->getElapsedTime() > 0) {
-                float deltaPercent = 100 * ((desc->getElapsedTime() - elapsedTimeThruCacheGet)
-                        / ((float)desc->getElapsedTime()));
+            if (value->getElapsedTime() > 0) {
+                float deltaPercent = 100 * ((value->getElapsedTime() - elapsedTimeThruCacheGet)
+                        / ((float)value->getElapsedTime()));
                 LOGD("CACHE HIT #%d for text='%s' with start=%d, count=%d, contextCount=%d "
                         "- Compute time in nanos: %d - "
                         "Cache get time in nanos: %lld - Gain in percent: %2.2f",
                         mCacheHitCount, String8(text, contextCount).string(), start, count,
                         contextCount,
-                        desc->getElapsedTime(), elapsedTimeThruCacheGet, deltaPercent);
+                        value->getElapsedTime(), elapsedTimeThruCacheGet, deltaPercent);
             }
             if (mCacheHitCount % DEFAULT_DUMP_STATS_CACHE_HIT_INTERVAL == 0) {
                 dumpCacheStats();
@@ -215,4 +215,309 @@
     LOGD("------------------------------------------------");
 }
 
+/**
+ * TextLayoutCacheKey
+ */
+TextLayoutCacheKey::TextLayoutCacheKey() : text(NULL), start(0), count(0), contextCount(0),
+        dirFlags(0), typeface(NULL), textSize(0), textSkewX(0), textScaleX(0), flags(0),
+        hinting(SkPaint::kNo_Hinting)  {
+}
+
+TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint,
+        const UChar* text, size_t start, size_t count,
+        size_t contextCount, int dirFlags) :
+            text(text), start(start), count(count), contextCount(contextCount),
+            dirFlags(dirFlags) {
+    typeface = paint->getTypeface();
+    textSize = paint->getTextSize();
+    textSkewX = paint->getTextSkewX();
+    textScaleX = paint->getTextScaleX();
+    flags = paint->getFlags();
+    hinting = paint->getHinting();
+}
+
+bool TextLayoutCacheKey::operator<(const TextLayoutCacheKey& rhs) const {
+    LTE_INT(count) {
+        LTE_INT(contextCount) {
+            LTE_INT(start) {
+                LTE_INT(typeface) {
+                    LTE_FLOAT(textSize) {
+                        LTE_FLOAT(textSkewX) {
+                            LTE_FLOAT(textScaleX) {
+                                LTE_INT(flags) {
+                                    LTE_INT(hinting) {
+                                        LTE_INT(dirFlags) {
+                                            return strncmp16(text, rhs.text, contextCount) < 0;
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+    return false;
+}
+
+void TextLayoutCacheKey::internalTextCopy() {
+    textCopy.setTo(text, contextCount);
+    text = textCopy.string();
+}
+
+size_t TextLayoutCacheKey::getSize() {
+    return sizeof(TextLayoutCacheKey) + sizeof(UChar) * contextCount;
+}
+
+/**
+ * TextLayoutCacheValue
+ */
+TextLayoutCacheValue::TextLayoutCacheValue() {
+    advances = NULL;
+    totalAdvance = 0;
+}
+
+TextLayoutCacheValue::~TextLayoutCacheValue() {
+    delete[] advances;
+}
+
+void TextLayoutCacheValue::setElapsedTime(uint32_t time) {
+    elapsedTime = time;
+}
+
+uint32_t TextLayoutCacheValue::getElapsedTime() {
+    return elapsedTime;
+}
+
+void TextLayoutCacheValue::computeAdvances(SkPaint* paint, const UChar* chars, size_t start,
+        size_t count, size_t contextCount, int dirFlags) {
+    advances = new float[count];
+    this->count = count;
+
+#if RTL_USE_HARFBUZZ
+    computeAdvancesWithHarfbuzz(paint, chars, start, count, contextCount, dirFlags,
+            advances, &totalAdvance);
+#else
+    computeAdvancesWithICU(paint, chars, start, count, contextCount, dirFlags,
+            advances, &totalAdvance);
+#endif
+#if DEBUG_ADVANCES
+    LOGD("Advances - count=%d - countextCount=%d - totalAdvance=%f - "
+            "adv[0]=%f adv[1]=%f adv[2]=%f adv[3]=%f", count, contextCount, totalAdvance,
+            advances[0], advances[1], advances[2], advances[3]);
+#endif
+}
+
+void TextLayoutCacheValue::copyResult(jfloat* outAdvances, jfloat* outTotalAdvance) {
+    memcpy(outAdvances, advances, count * sizeof(jfloat));
+    *outTotalAdvance = totalAdvance;
+}
+
+size_t TextLayoutCacheValue::getSize() {
+    return sizeof(TextLayoutCacheValue) + sizeof(jfloat) * count;
+}
+
+void TextLayoutCacheValue::setupShaperItem(HB_ShaperItem* shaperItem, HB_FontRec* font,
+        FontData* fontData, SkPaint* paint, const UChar* chars, size_t start, size_t count,
+        size_t contextCount, int dirFlags) {
+    bool isRTL = dirFlags & 0x1;
+
+    font->klass = &harfbuzzSkiaClass;
+    font->userData = 0;
+    // The values which harfbuzzSkiaClass returns are already scaled to
+    // pixel units, so we just set all these to one to disable further
+    // scaling.
+    font->x_ppem = 1;
+    font->y_ppem = 1;
+    font->x_scale = 1;
+    font->y_scale = 1;
+
+    memset(shaperItem, 0, sizeof(*shaperItem));
+    shaperItem->font = font;
+    shaperItem->face = HB_NewFace(shaperItem->font, harfbuzzSkiaGetTable);
+
+    shaperItem->kerning_applied = false;
+
+    // We cannot know, ahead of time, how many glyphs a given script run
+    // will produce. We take a guess that script runs will not produce more
+    // than twice as many glyphs as there are code points plus a bit of
+    // padding and fallback if we find that we are wrong.
+    createGlyphArrays(shaperItem, (contextCount + 2) * 2);
+
+    // Free memory for clusters if needed and recreate the clusters array
+    if (shaperItem->log_clusters) {
+        delete shaperItem->log_clusters;
+    }
+    shaperItem->log_clusters = new unsigned short[contextCount];
+
+    shaperItem->item.pos = start;
+    shaperItem->item.length = count;
+    shaperItem->item.bidiLevel = isRTL;
+    shaperItem->item.script = isRTL ? HB_Script_Arabic : HB_Script_Common;
+
+    shaperItem->string = chars;
+    shaperItem->stringLength = contextCount;
+
+    fontData->typeFace = paint->getTypeface();
+    fontData->textSize = paint->getTextSize();
+    fontData->textSkewX = paint->getTextSkewX();
+    fontData->textScaleX = paint->getTextScaleX();
+    fontData->flags = paint->getFlags();
+    fontData->hinting = paint->getHinting();
+
+    shaperItem->font->userData = fontData;
+}
+
+void TextLayoutCacheValue::shapeWithHarfbuzz(HB_ShaperItem* shaperItem, HB_FontRec* font,
+        FontData* fontData, SkPaint* paint, const UChar* chars, size_t start, size_t count,
+        size_t contextCount, int dirFlags) {
+    // Setup Harfbuzz Shaper
+    setupShaperItem(shaperItem, font, fontData, paint, chars, start, count,
+            contextCount, dirFlags);
+
+    // Shape
+    resetGlyphArrays(shaperItem);
+    while (!HB_ShapeItem(shaperItem)) {
+        // We overflowed our arrays. Resize and retry.
+        // HB_ShapeItem fills in shaperItem.num_glyphs with the needed size.
+        deleteGlyphArrays(shaperItem);
+        createGlyphArrays(shaperItem, shaperItem->num_glyphs << 1);
+        resetGlyphArrays(shaperItem);
+    }
+}
+
+void TextLayoutCacheValue::computeAdvancesWithHarfbuzz(SkPaint* paint, const UChar* chars,
+        size_t start, size_t count, size_t contextCount, int dirFlags,
+        jfloat* outAdvances, jfloat* outTotalAdvance) {
+
+    bool isRTL = dirFlags & 0x1;
+
+    HB_ShaperItem shaperItem;
+    HB_FontRec font;
+    FontData fontData;
+    shapeWithHarfbuzz(&shaperItem, &font, &fontData, paint, chars, start, count,
+            contextCount, dirFlags);
+
+#if DEBUG_ADVANCES
+    LOGD("HARFBUZZ -- num_glypth=%d - kerning_applied=%d", shaperItem.num_glyphs,
+            shaperItem.kerning_applied);
+    LOGD("         -- string= '%s'", String8(chars, contextCount).string());
+    LOGD("         -- isDevKernText=%d", paint->isDevKernText());
+#endif
+
+    jfloat totalAdvance = 0;
+
+    for (size_t i = 0; i < count; i++) {
+        totalAdvance += outAdvances[i] = HBFixedToFloat(shaperItem.advances[i]);
+
+#if DEBUG_ADVANCES
+        LOGD("hb-adv = %d - rebased = %f - total = %f", shaperItem.advances[i], outAdvances[i],
+                totalAdvance);
+#endif
+    }
+
+    deleteGlyphArrays(&shaperItem);
+    HB_FreeFace(shaperItem.face);
+
+    *outTotalAdvance = totalAdvance;
+}
+
+void TextLayoutCacheValue::computeAdvancesWithICU(SkPaint* paint, const UChar* chars,
+        size_t start, size_t count, size_t contextCount, int dirFlags,
+        jfloat* outAdvances, jfloat* outTotalAdvance) {
+
+    SkAutoSTMalloc<CHAR_BUFFER_SIZE, jchar> tempBuffer(contextCount);
+    jchar* buffer = tempBuffer.get();
+
+    SkScalar* scalarArray = (SkScalar*)outAdvances;
+
+    // this is where we'd call harfbuzz
+    // for now we just use ushape.c
+    size_t widths;
+    const jchar* text;
+    if (dirFlags & 0x1) { // rtl, call arabic shaping in case
+        UErrorCode status = U_ZERO_ERROR;
+        // Use fixed length since we need to keep start and count valid
+        u_shapeArabic(chars, contextCount, buffer, contextCount,
+                U_SHAPE_LENGTH_FIXED_SPACES_NEAR |
+                U_SHAPE_TEXT_DIRECTION_LOGICAL | U_SHAPE_LETTERS_SHAPE |
+                U_SHAPE_X_LAMALEF_SUB_ALTERNATE, &status);
+        // we shouldn't fail unless there's an out of memory condition,
+        // in which case we're hosed anyway
+        for (int i = start, e = i + count; i < e; ++i) {
+            if (buffer[i] == UNICODE_NOT_A_CHAR) {
+                buffer[i] = UNICODE_ZWSP; // zero-width-space for skia
+            }
+        }
+        text = buffer + start;
+        widths = paint->getTextWidths(text, count << 1, scalarArray);
+    } else {
+        text = chars + start;
+        widths = paint->getTextWidths(text, count << 1, scalarArray);
+    }
+
+    jfloat totalAdvance = 0;
+    if (widths < count) {
+#if DEBUG_ADVANCES
+    LOGD("ICU -- count=%d", widths);
+#endif
+        // Skia operates on code points, not code units, so surrogate pairs return only
+        // one value. Expand the result so we have one value per UTF-16 code unit.
+
+        // Note, skia's getTextWidth gets confused if it encounters a surrogate pair,
+        // leaving the remaining widths zero.  Not nice.
+        for (size_t i = 0, p = 0; i < widths; ++i) {
+            totalAdvance += outAdvances[p++] = SkScalarToFloat(scalarArray[i]);
+            if (p < count &&
+                    text[p] >= UNICODE_FIRST_LOW_SURROGATE &&
+                    text[p] < UNICODE_FIRST_PRIVATE_USE &&
+                    text[p-1] >= UNICODE_FIRST_HIGH_SURROGATE &&
+                    text[p-1] < UNICODE_FIRST_LOW_SURROGATE) {
+                outAdvances[p++] = 0;
+            }
+#if DEBUG_ADVANCES
+            LOGD("icu-adv = %f - total = %f", outAdvances[i], totalAdvance);
+#endif
+        }
+    } else {
+#if DEBUG_ADVANCES
+    LOGD("ICU -- count=%d", count);
+#endif
+        for (size_t i = 0; i < count; i++) {
+            totalAdvance += outAdvances[i] = SkScalarToFloat(scalarArray[i]);
+#if DEBUG_ADVANCES
+            LOGD("icu-adv = %f - total = %f", outAdvances[i], totalAdvance);
+#endif
+        }
+    }
+    *outTotalAdvance = totalAdvance;
+}
+
+void TextLayoutCacheValue::deleteGlyphArrays(HB_ShaperItem* shaperItem) {
+    delete[] shaperItem->glyphs;
+    delete[] shaperItem->attributes;
+    delete[] shaperItem->advances;
+    delete[] shaperItem->offsets;
+}
+
+void TextLayoutCacheValue::createGlyphArrays(HB_ShaperItem* shaperItem, int size) {
+    shaperItem->glyphs = new HB_Glyph[size];
+    shaperItem->attributes = new HB_GlyphAttributes[size];
+    shaperItem->advances = new HB_Fixed[size];
+    shaperItem->offsets = new HB_FixedPoint[size];
+    shaperItem->num_glyphs = size;
+}
+
+void TextLayoutCacheValue::resetGlyphArrays(HB_ShaperItem* shaperItem) {
+    int size = shaperItem->num_glyphs;
+    // All the types here don't have pointers. It is safe to reset to
+    // zero unless Harfbuzz breaks the compatibility in the future.
+    memset(shaperItem->glyphs, 0, size * sizeof(shaperItem->glyphs[0]));
+    memset(shaperItem->attributes, 0, size * sizeof(shaperItem->attributes[0]));
+    memset(shaperItem->advances, 0, size * sizeof(shaperItem->advances[0]));
+    memset(shaperItem->offsets, 0, size * sizeof(shaperItem->offsets[0]));
+}
+
+
 } // namespace android
diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h
index bced40c..cd5a58d 100644
--- a/core/jni/android/graphics/TextLayoutCache.h
+++ b/core/jni/android/graphics/TextLayoutCache.h
@@ -64,62 +64,24 @@
  */
 class TextLayoutCacheKey {
 public:
-    TextLayoutCacheKey() : text(NULL), start(0), count(0), contextCount(0),
-            dirFlags(0), typeface(NULL), textSize(0), textSkewX(0), textScaleX(0), flags(0),
-            hinting(SkPaint::kNo_Hinting)  {
-    }
+    TextLayoutCacheKey();
 
     TextLayoutCacheKey(const SkPaint* paint,
             const UChar* text, size_t start, size_t count,
-            size_t contextCount, int dirFlags) :
-                text(text), start(start), count(count), contextCount(contextCount),
-                dirFlags(dirFlags) {
-        typeface = paint->getTypeface();
-        textSize = paint->getTextSize();
-        textSkewX = paint->getTextSkewX();
-        textScaleX = paint->getTextScaleX();
-        flags = paint->getFlags();
-        hinting = paint->getHinting();
-    }
+            size_t contextCount, int dirFlags);
 
-    bool operator<(const TextLayoutCacheKey& rhs) const {
-        LTE_INT(count) {
-            LTE_INT(contextCount) {
-                LTE_INT(start) {
-                    LTE_INT(typeface) {
-                        LTE_FLOAT(textSize) {
-                            LTE_FLOAT(textSkewX) {
-                                LTE_FLOAT(textScaleX) {
-                                    LTE_INT(flags) {
-                                        LTE_INT(hinting) {
-                                            LTE_INT(dirFlags) {
-                                                return strncmp16(text, rhs.text, contextCount) < 0;
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return false;
-    }
+    bool operator<(const TextLayoutCacheKey& rhs) const;
 
-    // We need to copy the text when we insert the key into the cache itself.
-    // We don't need to copy the text when we are only comparing keys.
-    void internalTextCopy() {
-        textCopy.setTo(text, contextCount);
-        text = textCopy.string();
-    }
+    /**
+     * We need to copy the text when we insert the key into the cache itself.
+     * We don't need to copy the text when we are only comparing keys.
+     */
+    void internalTextCopy();
 
     /**
      * Get the size of the Cache key.
      */
-    size_t getSize() {
-        return sizeof(TextLayoutCacheKey) + sizeof(UChar) * contextCount;
-    }
+    size_t getSize();
 
 private:
     const UChar* text;
@@ -137,232 +99,41 @@
 }; // TextLayoutCacheKey
 
 /*
- * RunAdvanceDescription is the Cache entry
+ * TextLayoutCacheValue is the Cache value
  */
-class RunAdvanceDescription {
+class TextLayoutCacheValue {
 public:
-    RunAdvanceDescription() {
-        advances = NULL;
-        totalAdvance = 0;
-    }
+    TextLayoutCacheValue();
+    ~TextLayoutCacheValue();
 
-    ~RunAdvanceDescription() {
-        delete[] advances;
-    }
-
-    void setElapsedTime(uint32_t time) {
-        elapsedTime = time;
-    }
-
-    uint32_t getElapsedTime() {
-        return elapsedTime;
-    }
+    void setElapsedTime(uint32_t time);
+    uint32_t getElapsedTime();
 
     void computeAdvances(SkPaint* paint, const UChar* chars, size_t start, size_t count,
-            size_t contextCount, int dirFlags) {
-        advances = new float[count];
-        this->count = count;
+            size_t contextCount, int dirFlags);
 
-#if RTL_USE_HARFBUZZ
-        computeAdvancesWithHarfbuzz(paint, chars, start, count, contextCount, dirFlags,
-                advances, &totalAdvance);
-#else
-        computeAdvancesWithICU(paint, chars, start, count, contextCount, dirFlags,
-                advances, &totalAdvance);
-#endif
-#if DEBUG_ADVANCES
-        LOGD("Advances - count=%d - countextCount=%d - totalAdvance=%f - "
-                "adv[0]=%f adv[1]=%f adv[2]=%f adv[3]=%f", count, contextCount, totalAdvance,
-                advances[0], advances[1], advances[2], advances[3]);
-#endif
-    }
-
-    void copyResult(jfloat* outAdvances, jfloat* outTotalAdvance) {
-        memcpy(outAdvances, advances, count * sizeof(jfloat));
-        *outTotalAdvance = totalAdvance;
-    }
+    void copyResult(jfloat* outAdvances, jfloat* outTotalAdvance);
 
     /**
      * Get the size of the Cache entry
      */
-    size_t getSize() {
-        return sizeof(RunAdvanceDescription) + sizeof(jfloat) * count;
-    }
+    size_t getSize();
 
     static void setupShaperItem(HB_ShaperItem* shaperItem, HB_FontRec* font, FontData* fontData,
             SkPaint* paint, const UChar* chars, size_t start, size_t count, size_t contextCount,
-            int dirFlags) {
-        bool isRTL = dirFlags & 0x1;
-
-        font->klass = &harfbuzzSkiaClass;
-        font->userData = 0;
-        // The values which harfbuzzSkiaClass returns are already scaled to
-        // pixel units, so we just set all these to one to disable further
-        // scaling.
-        font->x_ppem = 1;
-        font->y_ppem = 1;
-        font->x_scale = 1;
-        font->y_scale = 1;
-
-        memset(shaperItem, 0, sizeof(*shaperItem));
-        shaperItem->font = font;
-        shaperItem->face = HB_NewFace(shaperItem->font, harfbuzzSkiaGetTable);
-
-        shaperItem->kerning_applied = false;
-
-        // We cannot know, ahead of time, how many glyphs a given script run
-        // will produce. We take a guess that script runs will not produce more
-        // than twice as many glyphs as there are code points plus a bit of
-        // padding and fallback if we find that we are wrong.
-        createGlyphArrays(shaperItem, (contextCount + 2) * 2);
-
-        // Free memory for clusters if needed and recreate the clusters array
-        if (shaperItem->log_clusters) {
-            delete shaperItem->log_clusters;
-        }
-        shaperItem->log_clusters = new unsigned short[contextCount];
-
-        shaperItem->item.pos = start;
-        shaperItem->item.length = count;
-        shaperItem->item.bidiLevel = isRTL;
-        shaperItem->item.script = isRTL ? HB_Script_Arabic : HB_Script_Common;
-
-        shaperItem->string = chars;
-        shaperItem->stringLength = contextCount;
-
-        fontData->typeFace = paint->getTypeface();
-        fontData->textSize = paint->getTextSize();
-        fontData->textSkewX = paint->getTextSkewX();
-        fontData->textScaleX = paint->getTextScaleX();
-        fontData->flags = paint->getFlags();
-        fontData->hinting = paint->getHinting();
-
-        shaperItem->font->userData = fontData;
-    }
+            int dirFlags);
 
     static void shapeWithHarfbuzz(HB_ShaperItem* shaperItem, HB_FontRec* font, FontData* fontData,
             SkPaint* paint, const UChar* chars, size_t start, size_t count, size_t contextCount,
-            int dirFlags) {
-        // Setup Harfbuzz Shaper
-        setupShaperItem(shaperItem, font, fontData, paint, chars, start, count,
-                contextCount, dirFlags);
-
-        // Shape
-        resetGlyphArrays(shaperItem);
-        while (!HB_ShapeItem(shaperItem)) {
-            // We overflowed our arrays. Resize and retry.
-            // HB_ShapeItem fills in shaperItem.num_glyphs with the needed size.
-            deleteGlyphArrays(shaperItem);
-            createGlyphArrays(shaperItem, shaperItem->num_glyphs << 1);
-            resetGlyphArrays(shaperItem);
-        }
-    }
+            int dirFlags);
 
     static void computeAdvancesWithHarfbuzz(SkPaint* paint, const UChar* chars, size_t start,
             size_t count, size_t contextCount, int dirFlags,
-            jfloat* outAdvances, jfloat* outTotalAdvance) {
-
-        bool isRTL = dirFlags & 0x1;
-
-        HB_ShaperItem shaperItem;
-        HB_FontRec font;
-        FontData fontData;
-        shapeWithHarfbuzz(&shaperItem, &font, &fontData, paint, chars, start, count,
-                contextCount, dirFlags);
-
-#if DEBUG_ADVANCES
-        LOGD("HARFBUZZ -- num_glypth=%d - kerning_applied=%d", shaperItem.num_glyphs, shaperItem.kerning_applied);
-        LOGD("         -- string= '%s'", String8(chars, contextCount).string());
-        LOGD("         -- isDevKernText=%d", paint->isDevKernText());
-#endif
-
-        jfloat totalAdvance = 0;
-
-        for (size_t i = 0; i < count; i++) {
-            totalAdvance += outAdvances[i] = HBFixedToFloat(shaperItem.advances[i]);
-
-#if DEBUG_ADVANCES
-            LOGD("hb-adv = %d - rebased = %f - total = %f", shaperItem.advances[i], outAdvances[i],
-                    totalAdvance);
-#endif
-        }
-
-        deleteGlyphArrays(&shaperItem);
-        HB_FreeFace(shaperItem.face);
-
-        *outTotalAdvance = totalAdvance;
-    }
+            jfloat* outAdvances, jfloat* outTotalAdvance);
 
     static void computeAdvancesWithICU(SkPaint* paint, const UChar* chars, size_t start,
             size_t count, size_t contextCount, int dirFlags,
-            jfloat* outAdvances, jfloat* outTotalAdvance) {
-
-        SkAutoSTMalloc<CHAR_BUFFER_SIZE, jchar> tempBuffer(contextCount);
-        jchar* buffer = tempBuffer.get();
-
-        SkScalar* scalarArray = (SkScalar*)outAdvances;
-
-        // this is where we'd call harfbuzz
-        // for now we just use ushape.c
-        size_t widths;
-        const jchar* text;
-        if (dirFlags & 0x1) { // rtl, call arabic shaping in case
-            UErrorCode status = U_ZERO_ERROR;
-            // Use fixed length since we need to keep start and count valid
-            u_shapeArabic(chars, contextCount, buffer, contextCount,
-                    U_SHAPE_LENGTH_FIXED_SPACES_NEAR |
-                    U_SHAPE_TEXT_DIRECTION_LOGICAL | U_SHAPE_LETTERS_SHAPE |
-                    U_SHAPE_X_LAMALEF_SUB_ALTERNATE, &status);
-            // we shouldn't fail unless there's an out of memory condition,
-            // in which case we're hosed anyway
-            for (int i = start, e = i + count; i < e; ++i) {
-                if (buffer[i] == UNICODE_NOT_A_CHAR) {
-                    buffer[i] = UNICODE_ZWSP; // zero-width-space for skia
-                }
-            }
-            text = buffer + start;
-            widths = paint->getTextWidths(text, count << 1, scalarArray);
-        } else {
-            text = chars + start;
-            widths = paint->getTextWidths(text, count << 1, scalarArray);
-        }
-
-        jfloat totalAdvance = 0;
-        if (widths < count) {
-#if DEBUG_ADVANCES
-        LOGD("ICU -- count=%d", widths);
-#endif
-            // Skia operates on code points, not code units, so surrogate pairs return only
-            // one value. Expand the result so we have one value per UTF-16 code unit.
-
-            // Note, skia's getTextWidth gets confused if it encounters a surrogate pair,
-            // leaving the remaining widths zero.  Not nice.
-            for (size_t i = 0, p = 0; i < widths; ++i) {
-                totalAdvance += outAdvances[p++] = SkScalarToFloat(scalarArray[i]);
-                if (p < count &&
-                        text[p] >= UNICODE_FIRST_LOW_SURROGATE &&
-                        text[p] < UNICODE_FIRST_PRIVATE_USE &&
-                        text[p-1] >= UNICODE_FIRST_HIGH_SURROGATE &&
-                        text[p-1] < UNICODE_FIRST_LOW_SURROGATE) {
-                    outAdvances[p++] = 0;
-                }
-#if DEBUG_ADVANCES
-                LOGD("icu-adv = %f - total = %f", outAdvances[i], totalAdvance);
-#endif
-            }
-        } else {
-#if DEBUG_ADVANCES
-        LOGD("ICU -- count=%d", count);
-#endif
-            for (size_t i = 0; i < count; i++) {
-                totalAdvance += outAdvances[i] = SkScalarToFloat(scalarArray[i]);
-#if DEBUG_ADVANCES
-                LOGD("icu-adv = %f - total = %f", outAdvances[i], totalAdvance);
-#endif
-            }
-        }
-        *outTotalAdvance = totalAdvance;
-    }
+            jfloat* outAdvances, jfloat* outTotalAdvance);
 
 private:
     jfloat* advances;
@@ -371,35 +142,14 @@
 
     uint32_t elapsedTime;
 
-    static void deleteGlyphArrays(HB_ShaperItem* shaperItem) {
-        delete[] shaperItem->glyphs;
-        delete[] shaperItem->attributes;
-        delete[] shaperItem->advances;
-        delete[] shaperItem->offsets;
-    }
+    static void deleteGlyphArrays(HB_ShaperItem* shaperItem);
+    static void createGlyphArrays(HB_ShaperItem* shaperItem, int size);
+    static void resetGlyphArrays(HB_ShaperItem* shaperItem);
 
-    static void createGlyphArrays(HB_ShaperItem* shaperItem, int size) {
-        shaperItem->glyphs = new HB_Glyph[size];
-        shaperItem->attributes = new HB_GlyphAttributes[size];
-        shaperItem->advances = new HB_Fixed[size];
-        shaperItem->offsets = new HB_FixedPoint[size];
-        shaperItem->num_glyphs = size;
-    }
-
-    static void resetGlyphArrays(HB_ShaperItem* shaperItem) {
-        int size = shaperItem->num_glyphs;
-        // All the types here don't have pointers. It is safe to reset to
-        // zero unless Harfbuzz breaks the compatibility in the future.
-        memset(shaperItem->glyphs, 0, size * sizeof(shaperItem->glyphs[0]));
-        memset(shaperItem->attributes, 0, size * sizeof(shaperItem->attributes[0]));
-        memset(shaperItem->advances, 0, size * sizeof(shaperItem->advances[0]));
-        memset(shaperItem->offsets, 0, size * sizeof(shaperItem->offsets[0]));
-    }
-
-}; // RunAdvanceDescription
+}; // TextLayoutCacheValue
 
 
-class TextLayoutCache: public OnEntryRemoved<TextLayoutCacheKey, RunAdvanceDescription*>
+class TextLayoutCache: public OnEntryRemoved<TextLayoutCacheKey, TextLayoutCacheValue*>
 {
 public:
     TextLayoutCache();
@@ -415,7 +165,7 @@
      * Used as a callback when an entry is removed from the cache.
      * Do not invoke directly.
      */
-    void operator()(TextLayoutCacheKey& text, RunAdvanceDescription*& desc);
+    void operator()(TextLayoutCacheKey& text, TextLayoutCacheValue*& desc);
 
     /**
      * Get cache entries
@@ -448,7 +198,7 @@
     Mutex mLock;
     bool mInitialized;
 
-    GenerationCache<TextLayoutCacheKey, RunAdvanceDescription*> mCache;
+    GenerationCache<TextLayoutCacheKey, TextLayoutCacheValue*> mCache;
 
     uint32_t mSize;
     uint32_t mMaxSize;
diff --git a/core/jni/android_bluetooth_BluetoothAudioGateway.cpp b/core/jni/android_bluetooth_BluetoothAudioGateway.cpp
index acf858a..cb742a3 100755
--- a/core/jni/android_bluetooth_BluetoothAudioGateway.cpp
+++ b/core/jni/android_bluetooth_BluetoothAudioGateway.cpp
@@ -484,21 +484,21 @@
         lm = RFCOMM_LM_AUTH | RFCOMM_LM_ENCRYPT;
     }
 
-	if (lm && setsockopt(sk, SOL_RFCOMM, RFCOMM_LM, &lm, sizeof(lm)) < 0) {
-		LOGE("Can't set RFCOMM link mode");
-		close(sk);
-		return -1;
-	}
+    if (lm && setsockopt(sk, SOL_RFCOMM, RFCOMM_LM, &lm, sizeof(lm)) < 0) {
+        LOGE("Can't set RFCOMM link mode");
+        close(sk);
+        return -1;
+    }
 
     laddr.rc_family = AF_BLUETOOTH;
-    bacpy(&laddr.rc_bdaddr, BDADDR_ANY);
+    memcpy(&laddr.rc_bdaddr, BDADDR_ANY, sizeof(bdaddr_t));
     laddr.rc_channel = channel;
 
-	if (bind(sk, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) {
-		LOGE("Can't bind RFCOMM socket");
-		close(sk);
-		return -1;
-	}
+    if (bind(sk, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) {
+        LOGE("Can't bind RFCOMM socket");
+        close(sk);
+        return -1;
+    }
 
     listen(sk, 10);
     return sk;
diff --git a/core/jni/android_bluetooth_common.cpp b/core/jni/android_bluetooth_common.cpp
index aae0f21..6ae3e35 100644
--- a/core/jni/android_bluetooth_common.cpp
+++ b/core/jni/android_bluetooth_common.cpp
@@ -43,6 +43,7 @@
     {"Icon", DBUS_TYPE_STRING},
     {"Class", DBUS_TYPE_UINT32},
     {"UUIDs", DBUS_TYPE_ARRAY},
+    {"Services", DBUS_TYPE_ARRAY},
     {"Paired", DBUS_TYPE_BOOLEAN},
     {"Connected", DBUS_TYPE_BOOLEAN},
     {"Trusted", DBUS_TYPE_BOOLEAN},
@@ -52,7 +53,8 @@
     {"Adapter", DBUS_TYPE_OBJECT_PATH},
     {"LegacyPairing", DBUS_TYPE_BOOLEAN},
     {"RSSI", DBUS_TYPE_INT16},
-    {"TX", DBUS_TYPE_UINT32}
+    {"TX", DBUS_TYPE_UINT32},
+    {"Broadcaster", DBUS_TYPE_BOOLEAN}
 };
 
 static Properties adapter_properties[] = {
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp
index b6619ab..1b6b24f 100644
--- a/core/jni/android_media_AudioRecord.cpp
+++ b/core/jni/android_media_AudioRecord.cpp
@@ -41,7 +41,6 @@
 
 struct fields_t {
     // these fields provide access from C++ to the...
-    jclass    audioRecordClass;      //... AudioRecord class
     jmethodID postNativeEventInJava; //... event post callback method
     int       PCM16;                 //...  format constants
     int       PCM8;                  //...  format constants
@@ -520,22 +519,20 @@
 // ----------------------------------------------------------------------------
 int register_android_media_AudioRecord(JNIEnv *env)
 {
-    javaAudioRecordFields.audioRecordClass = NULL;
     javaAudioRecordFields.postNativeEventInJava = NULL;
     javaAudioRecordFields.nativeRecorderInJavaObj = NULL;
     javaAudioRecordFields.nativeCallbackCookie = NULL;
     
 
     // Get the AudioRecord class
-    javaAudioRecordFields.audioRecordClass = env->FindClass(kClassPathName);
-    if (javaAudioRecordFields.audioRecordClass == NULL) {
+    jclass audioRecordClass = env->FindClass(kClassPathName);
+    if (audioRecordClass == NULL) {
         LOGE("Can't find %s", kClassPathName);
         return -1;
     }
-    
     // Get the postEvent method
     javaAudioRecordFields.postNativeEventInJava = env->GetStaticMethodID(
-            javaAudioRecordFields.audioRecordClass,
+            audioRecordClass,
             JAVA_POSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;IIILjava/lang/Object;)V");
     if (javaAudioRecordFields.postNativeEventInJava == NULL) {
         LOGE("Can't find AudioRecord.%s", JAVA_POSTEVENT_CALLBACK_NAME);
@@ -545,7 +542,7 @@
     // Get the variables
     //    mNativeRecorderInJavaObj
     javaAudioRecordFields.nativeRecorderInJavaObj = 
-        env->GetFieldID(javaAudioRecordFields.audioRecordClass,
+        env->GetFieldID(audioRecordClass,
                         JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "I");
     if (javaAudioRecordFields.nativeRecorderInJavaObj == NULL) {
         LOGE("Can't find AudioRecord.%s", JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME);
@@ -553,7 +550,7 @@
     }
     //     mNativeCallbackCookie
     javaAudioRecordFields.nativeCallbackCookie = env->GetFieldID(
-            javaAudioRecordFields.audioRecordClass,
+            audioRecordClass,
             JAVA_NATIVECALLBACKINFO_FIELD_NAME, "I");
     if (javaAudioRecordFields.nativeCallbackCookie == NULL) {
         LOGE("Can't find AudioRecord.%s", JAVA_NATIVECALLBACKINFO_FIELD_NAME);
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 5f3fed2..5016bf9 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -34,6 +34,8 @@
 
 using namespace android;
 
+static const char* const kClassPathName = "android/media/AudioSystem";
+
 enum AudioError {
     kAudioStatusOk = 0,
     kAudioStatusError = 1,
@@ -96,14 +98,15 @@
     return env->NewStringUTF(AudioSystem::getParameters(0, c_keys8).string());
 }
 
-void android_media_AudioSystem_error_callback(status_t err)
+static void
+android_media_AudioSystem_error_callback(status_t err)
 {
     JNIEnv *env = AndroidRuntime::getJNIEnv();
     if (env == NULL) {
         return;
     }
 
-    jclass clazz = env->FindClass("android/media/AudioSystem");
+    jclass clazz = env->FindClass(kClassPathName);
 
     int error;
 
@@ -218,12 +221,10 @@
     {"getDevicesForStream", "(I)I",     (void *)android_media_AudioSystem_getDevicesForStream},
 };
 
-const char* const kClassPathName = "android/media/AudioSystem";
-
 int register_android_media_AudioSystem(JNIEnv *env)
 {
     AudioSystem::setErrorCallback(android_media_AudioSystem_error_callback);
     
     return AndroidRuntime::registerNativeMethods(env,
-                "android/media/AudioSystem", gMethods, NELEM(gMethods));
+                kClassPathName, gMethods, NELEM(gMethods));
 }
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index 44d2a52..587a16c 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -43,7 +43,6 @@
 
 struct fields_t {
     // these fields provide access from C++ to the...
-    jclass    audioTrackClass;       //... AudioTrack class
     jmethodID postNativeEventInJava; //... event post callback method
     int       PCM16;                 //...  format constants
     int       PCM8;                  //...  format constants
@@ -915,20 +914,19 @@
 // ----------------------------------------------------------------------------
 int register_android_media_AudioTrack(JNIEnv *env)
 {
-    javaAudioTrackFields.audioTrackClass = NULL;
     javaAudioTrackFields.nativeTrackInJavaObj = NULL;
     javaAudioTrackFields.postNativeEventInJava = NULL;
 
     // Get the AudioTrack class
-    javaAudioTrackFields.audioTrackClass = env->FindClass(kClassPathName);
-    if (javaAudioTrackFields.audioTrackClass == NULL) {
+    jclass audioTrackClass = env->FindClass(kClassPathName);
+    if (audioTrackClass == NULL) {
         LOGE("Can't find %s", kClassPathName);
         return -1;
     }
 
     // Get the postEvent method
     javaAudioTrackFields.postNativeEventInJava = env->GetStaticMethodID(
-            javaAudioTrackFields.audioTrackClass,
+            audioTrackClass,
             JAVA_POSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;IIILjava/lang/Object;)V");
     if (javaAudioTrackFields.postNativeEventInJava == NULL) {
         LOGE("Can't find AudioTrack.%s", JAVA_POSTEVENT_CALLBACK_NAME);
@@ -938,7 +936,7 @@
     // Get the variables fields
     //      nativeTrackInJavaObj
     javaAudioTrackFields.nativeTrackInJavaObj = env->GetFieldID(
-            javaAudioTrackFields.audioTrackClass,
+            audioTrackClass,
             JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "I");
     if (javaAudioTrackFields.nativeTrackInJavaObj == NULL) {
         LOGE("Can't find AudioTrack.%s", JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME);
@@ -946,7 +944,7 @@
     }
     //      jniData;
     javaAudioTrackFields.jniData = env->GetFieldID(
-            javaAudioTrackFields.audioTrackClass,
+            audioTrackClass,
             JAVA_JNIDATA_FIELD_NAME, "I");
     if (javaAudioTrackFields.jniData == NULL) {
         LOGE("Can't find AudioTrack.%s", JAVA_JNIDATA_FIELD_NAME);
@@ -954,10 +952,10 @@
     }
 
     // Get the memory mode constants
-    if ( !android_media_getIntConstantFromClass(env, javaAudioTrackFields.audioTrackClass,
+    if ( !android_media_getIntConstantFromClass(env, audioTrackClass,
                kClassPathName, 
                JAVA_CONST_MODE_STATIC_NAME, &(javaAudioTrackFields.MODE_STATIC))
-         || !android_media_getIntConstantFromClass(env, javaAudioTrackFields.audioTrackClass,
+         || !android_media_getIntConstantFromClass(env, audioTrackClass,
                kClassPathName, 
                JAVA_CONST_MODE_STREAM_NAME, &(javaAudioTrackFields.MODE_STREAM)) ) {
         // error log performed in android_media_getIntConstantFromClass() 
diff --git a/core/jni/android_net_NetUtils.cpp b/core/jni/android_net_NetUtils.cpp
index 3adf770..db132ec 100644
--- a/core/jni/android_net_NetUtils.cpp
+++ b/core/jni/android_net_NetUtils.cpp
@@ -55,7 +55,6 @@
  * to look them up every time.
  */
 static struct fieldIds {
-    jclass dhcpInfoInternalClass;
     jmethodID constructorId;
     jfieldID ipaddress;
     jfieldID gateway;
@@ -163,7 +162,7 @@
     result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength,
                                         dns1, dns2, server, &lease);
     env->ReleaseStringUTFChars(ifname, nameStr);
-    if (result == 0 && dhcpInfoInternalFieldIds.dhcpInfoInternalClass != NULL) {
+    if (result == 0) {
         env->SetObjectField(info, dhcpInfoInternalFieldIds.ipaddress, env->NewStringUTF(ipaddr));
         env->SetObjectField(info, dhcpInfoInternalFieldIds.gateway, env->NewStringUTF(gateway));
         env->SetIntField(info, dhcpInfoInternalFieldIds.prefixLength, prefixLength);
@@ -229,17 +228,16 @@
     jclass netutils = env->FindClass(NETUTILS_PKG_NAME);
     LOG_FATAL_IF(netutils == NULL, "Unable to find class " NETUTILS_PKG_NAME);
 
-    dhcpInfoInternalFieldIds.dhcpInfoInternalClass = env->FindClass("android/net/DhcpInfoInternal");
-    if (dhcpInfoInternalFieldIds.dhcpInfoInternalClass != NULL) {
-        dhcpInfoInternalFieldIds.constructorId = env->GetMethodID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "<init>", "()V");
-        dhcpInfoInternalFieldIds.ipaddress = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "ipAddress", "Ljava/lang/String;");
-        dhcpInfoInternalFieldIds.gateway = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "gateway", "Ljava/lang/String;");
-        dhcpInfoInternalFieldIds.prefixLength = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "prefixLength", "I");
-        dhcpInfoInternalFieldIds.dns1 = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "dns1", "Ljava/lang/String;");
-        dhcpInfoInternalFieldIds.dns2 = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "dns2", "Ljava/lang/String;");
-        dhcpInfoInternalFieldIds.serverAddress = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "serverAddress", "Ljava/lang/String;");
-        dhcpInfoInternalFieldIds.leaseDuration = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "leaseDuration", "I");
-    }
+    jclass dhcpInfoInternalClass = env->FindClass("android/net/DhcpInfoInternal");
+    LOG_FATAL_IF(dhcpInfoInternalClass == NULL, "Unable to find class android/net/DhcpInfoInternal");
+    dhcpInfoInternalFieldIds.constructorId = env->GetMethodID(dhcpInfoInternalClass, "<init>", "()V");
+    dhcpInfoInternalFieldIds.ipaddress = env->GetFieldID(dhcpInfoInternalClass, "ipAddress", "Ljava/lang/String;");
+    dhcpInfoInternalFieldIds.gateway = env->GetFieldID(dhcpInfoInternalClass, "gateway", "Ljava/lang/String;");
+    dhcpInfoInternalFieldIds.prefixLength = env->GetFieldID(dhcpInfoInternalClass, "prefixLength", "I");
+    dhcpInfoInternalFieldIds.dns1 = env->GetFieldID(dhcpInfoInternalClass, "dns1", "Ljava/lang/String;");
+    dhcpInfoInternalFieldIds.dns2 = env->GetFieldID(dhcpInfoInternalClass, "dns2", "Ljava/lang/String;");
+    dhcpInfoInternalFieldIds.serverAddress = env->GetFieldID(dhcpInfoInternalClass, "serverAddress", "Ljava/lang/String;");
+    dhcpInfoInternalFieldIds.leaseDuration = env->GetFieldID(dhcpInfoInternalClass, "leaseDuration", "I");
 
     return AndroidRuntime::registerNativeMethods(env,
             NETUTILS_PKG_NAME, gNetworkUtilMethods, NELEM(gNetworkUtilMethods));
diff --git a/core/jni/android_net_wifi_Wifi.cpp b/core/jni/android_net_wifi_Wifi.cpp
index 667ba75..494dc27 100644
--- a/core/jni/android_net_wifi_Wifi.cpp
+++ b/core/jni/android_net_wifi_Wifi.cpp
@@ -556,7 +556,7 @@
     return doBooleanCommand(cmdstr, "OK");
 }
 
-static void android_net_wifi_enableBackgroundScan(JNIEnv* env, jobject clazz, jboolean enable)
+static void android_net_wifi_enableBackgroundScanCommand(JNIEnv* env, jobject clazz, jboolean enable)
 {
     //Note: BGSCAN-START and BGSCAN-STOP are documented in core/res/res/values/config.xml
     //and will need an update if the names are changed
@@ -568,6 +568,16 @@
     }
 }
 
+static void android_net_wifi_setScanIntervalCommand(JNIEnv* env, jobject clazz, jint scanInterval)
+{
+    char cmdstr[BUF_SIZE];
+
+    int numWritten = snprintf(cmdstr, sizeof(cmdstr), "SCAN_INTERVAL %d", scanInterval);
+
+    if(numWritten < (int)sizeof(cmdstr)) doBooleanCommand(cmdstr, "OK");
+}
+
+
 // ----------------------------------------------------------------------------
 
 /*
@@ -635,7 +645,8 @@
         (void*) android_net_wifi_setSuspendOptimizationsCommand},
     { "setCountryCodeCommand", "(Ljava/lang/String;)Z",
         (void*) android_net_wifi_setCountryCodeCommand},
-    { "enableBackgroundScan", "(Z)V", (void*) android_net_wifi_enableBackgroundScan},
+    { "enableBackgroundScanCommand", "(Z)V", (void*) android_net_wifi_enableBackgroundScanCommand},
+    { "setScanIntervalCommand", "(I)V", (void*) android_net_wifi_setScanIntervalCommand},
 };
 
 int register_android_net_wifi_WifiManager(JNIEnv* env)
diff --git a/core/jni/android_server_BluetoothEventLoop.cpp b/core/jni/android_server_BluetoothEventLoop.cpp
index afaade8..dced1a5 100644
--- a/core/jni/android_server_BluetoothEventLoop.cpp
+++ b/core/jni/android_server_BluetoothEventLoop.cpp
@@ -373,7 +373,6 @@
     }
     dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &agent_path,
                              DBUS_TYPE_STRING, &capabilities,
-                             DBUS_TYPE_BOOLEAN, &oob,
                              DBUS_TYPE_INVALID);
 
     dbus_error_init(&err);
diff --git a/core/jni/android_server_BluetoothService.cpp b/core/jni/android_server_BluetoothService.cpp
index 158e475..5c6958a 100644
--- a/core/jni/android_server_BluetoothService.cpp
+++ b/core/jni/android_server_BluetoothService.cpp
@@ -695,9 +695,7 @@
            str_array =  parse_remote_device_properties(env, &iter);
         dbus_message_unref(reply);
 
-        env->PopLocalFrame(NULL);
-
-        return str_array;
+        return (jobjectArray) env->PopLocalFrame(str_array);
     }
 #endif
     return NULL;
@@ -731,8 +729,7 @@
             str_array = parse_adapter_properties(env, &iter);
         dbus_message_unref(reply);
 
-        env->PopLocalFrame(NULL);
-        return str_array;
+        return (jobjectArray) env->PopLocalFrame(str_array);
     }
 #endif
     return NULL;
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index fdb7fda..65b5990 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -532,6 +532,7 @@
                                                           jint keyboard, jint keyboardHidden,
                                                           jint navigation,
                                                           jint screenWidth, jint screenHeight,
+                                                          jint screenWidthDp, jint screenHeightDp,
                                                           jint screenLayout, jint uiMode,
                                                           jint sdkVersion)
 {
@@ -555,6 +556,8 @@
     config.navigation = (uint8_t)navigation;
     config.screenWidth = (uint16_t)screenWidth;
     config.screenHeight = (uint16_t)screenHeight;
+    config.screenWidthDp = (uint16_t)screenWidthDp;
+    config.screenHeightDp = (uint16_t)screenHeightDp;
     config.screenLayout = (uint8_t)screenLayout;
     config.uiMode = (uint8_t)uiMode;
     config.sdkVersion = (uint16_t)sdkVersion;
@@ -1693,7 +1696,7 @@
         (void*) android_content_AssetManager_setLocale },
     { "getLocales",      "()[Ljava/lang/String;",
         (void*) android_content_AssetManager_getLocales },
-    { "setConfiguration", "(IILjava/lang/String;IIIIIIIIIII)V",
+    { "setConfiguration", "(IILjava/lang/String;IIIIIIIIIIIII)V",
         (void*) android_content_AssetManager_setConfiguration },
     { "getResourceIdentifier","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I",
         (void*) android_content_AssetManager_getResourceIdentifier },
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp
index 9a727a7..f31bba9 100644
--- a/core/jni/android_view_GLES20Canvas.cpp
+++ b/core/jni/android_view_GLES20Canvas.cpp
@@ -736,9 +736,9 @@
 
 int register_android_app_ActivityThread(JNIEnv* env)
 {
-    jclass gFileDescriptorClass = env->FindClass("java/io/FileDescriptor");
+    jclass fileDescriptorClass = env->FindClass("java/io/FileDescriptor");
     LOG_FATAL_IF(clazz == NULL, "Unable to find class java.io.FileDescriptor");
-    gFileDescriptorField = env->GetFieldID(gFileDescriptorClass, "descriptor", "I");
+    gFileDescriptorField = env->GetFieldID(fileDescriptorClass, "descriptor", "I");
     LOG_FATAL_IF(gFileDescriptorField == NULL,
                  "Unable to find descriptor field in java.io.FileDescriptor");
 
diff --git a/core/res/res/drawable-mdpi/text_edit_suggestions_bottom_window.9.png b/core/res/res/drawable-mdpi/text_edit_suggestions_bottom_window.9.png
new file mode 100644
index 0000000..88be6e1
--- /dev/null
+++ b/core/res/res/drawable-mdpi/text_edit_suggestions_bottom_window.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/text_edit_suggestions_top_window.9.png b/core/res/res/drawable-mdpi/text_edit_suggestions_top_window.9.png
new file mode 100644
index 0000000..41886eb
--- /dev/null
+++ b/core/res/res/drawable-mdpi/text_edit_suggestions_top_window.9.png
Binary files differ
diff --git a/core/res/res/layout/text_edit_suggestion_item.xml b/core/res/res/layout/text_edit_suggestion_item.xml
new file mode 100644
index 0000000..a54cad2
--- /dev/null
+++ b/core/res/res/layout/text_edit_suggestion_item.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:paddingLeft="16dip"
+          android:paddingRight="16dip"
+          android:paddingTop="8dip"
+          android:paddingBottom="8dip"
+          android:layout_gravity="center"
+          android:textAppearance="?android:attr/textAppearanceMedium"
+          android:textColor="@android:color/black" />
+
diff --git a/core/res/res/layout/text_edit_suggestions_bottom_window.xml b/core/res/res/layout/text_edit_suggestions_bottom_window.xml
new file mode 100644
index 0000000..588bfbd
--- /dev/null
+++ b/core/res/res/layout/text_edit_suggestions_bottom_window.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:background="@android:drawable/text_edit_suggestions_bottom_window">
+
+</LinearLayout>
diff --git a/core/res/res/layout/text_edit_suggestions_top_window.xml b/core/res/res/layout/text_edit_suggestions_top_window.xml
new file mode 100644
index 0000000..67faa37
--- /dev/null
+++ b/core/res/res/layout/text_edit_suggestions_top_window.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:background="@android:drawable/text_edit_suggestions_top_window">
+
+</LinearLayout>
diff --git a/core/res/res/values-fr/strings.xml b/core/res/res/values-fr/strings.xml
index 7e7b24e..b38ae93 100644
--- a/core/res/res/values-fr/strings.xml
+++ b/core/res/res/values-fr/strings.xml
@@ -465,7 +465,7 @@
     <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6594393334785738252">"Autorise une application à écrire sur la mémoire USB."</string>
     <string name="permdesc_sdcardWrite" product="default" msgid="6643963204976471878">"Autorise une application à écrire sur la carte SD."</string>
     <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"modif./suppr. contenu mémoire interne"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8232008512478316233">"Permet à une application de modifier le contenu de la mémoire de stockage interne du support."</string>
+    <string name="permdesc_mediaStorageWrite" product="default" msgid="8232008512478316233">"Permet à une application de modifier le contenu de la mémoire de stockage interne."</string>
     <string name="permlab_cache_filesystem" msgid="5656487264819669824">"accéder au système de fichiers en cache"</string>
     <string name="permdesc_cache_filesystem" msgid="1624734528435659906">"Permet à une application de lire et d\'écrire dans le système de fichiers en cache."</string>
     <string name="permlab_use_sip" msgid="5986952362795870502">"effectuer/recevoir des appels Internet"</string>
diff --git a/core/res/res/values-hr/strings.xml b/core/res/res/values-hr/strings.xml
index 25e66b4..d8c64f0 100644
--- a/core/res/res/values-hr/strings.xml
+++ b/core/res/res/values-hr/strings.xml
@@ -987,7 +987,7 @@
     <item quantity="other" msgid="4641872797067609177">"<xliff:g id="INDEX">%d</xliff:g> od <xliff:g id="TOTAL">%d</xliff:g>"</item>
   </plurals>
     <string name="action_mode_done" msgid="7217581640461922289">"Gotovo"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="535863554318797377">"Isključivanje memorije USB..."</string>
+    <string name="progress_unmounting" product="nosdcard" msgid="535863554318797377">"Isključivanje USB memorije..."</string>
     <string name="progress_unmounting" product="default" msgid="5556813978958789471">"Isključivanje SD kartice..."</string>
     <string name="progress_erasing" product="nosdcard" msgid="4183664626203056915">"Brisanje memorije USB..."</string>
     <string name="progress_erasing" product="default" msgid="2115214724367534095">"Brisanje SD kartice..."</string>
diff --git a/core/res/res/values-pl/strings.xml b/core/res/res/values-pl/strings.xml
index de44e72..043faaf 100644
--- a/core/res/res/values-pl/strings.xml
+++ b/core/res/res/values-pl/strings.xml
@@ -251,8 +251,8 @@
     <string name="permdesc_injectEvents" product="default" msgid="3946098050410874715">"Pozwala aplikacjom na dostarczanie własnych zdarzeń wprowadzania danych (naciśnięcie klawisza itp.) do innych aplikacji. Szkodliwe aplikacje mogą to wykorzystać do przejęcia kontroli nad telefonem."</string>
     <string name="permlab_readInputState" msgid="469428900041249234">"zapamiętywanie wpisywanych znaków oraz wykonywanych czynności"</string>
     <string name="permdesc_readInputState" msgid="5132879321450325445">"Pozwala aplikacjom na śledzenie naciskanych klawiszy, nawet podczas pracy z innym programem (na przykład podczas wpisywania hasła). Nigdy nie powinno być potrzebne normalnym aplikacjom."</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"tworzenie powiązania z metodą wejściową"</string>
-    <string name="permdesc_bindInputMethod" msgid="3734838321027317228">"Pozwala na tworzenie powiązania z interfejsem najwyższego poziomu metody wejściowej. To uprawnienie nie powinno być nigdy wymagane przez zwykłe aplikacje."</string>
+    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"powiązanie ze sposobem wprowadzania tekstu"</string>
+    <string name="permdesc_bindInputMethod" msgid="3734838321027317228">"Pozwala na powiązanie wybranego sposobu wprowadzania tekstu z interfejsem najwyższego poziomu. To uprawnienie nie powinno być nigdy wymagane przez zwykłe aplikacje."</string>
     <string name="permlab_bindWallpaper" msgid="8716400279937856462">"powiązanie z tapetą"</string>
     <string name="permdesc_bindWallpaper" msgid="5287754520361915347">"Umożliwia posiadaczowi powiązać interfejs najwyższego poziomu dla tapety. Nie powinno być nigdy potrzebne w przypadku zwykłych aplikacji."</string>
     <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"powiązanie z usługą widżetów"</string>
@@ -797,7 +797,7 @@
     <string name="copyUrl" msgid="2538211579596067402">"Kopiuj adres URL"</string>
     <string name="selectTextMode" msgid="6738556348861347240">"Zaznacz tekst"</string>
     <string name="textSelectionCABTitle" msgid="5236850394370820357">"Zaznaczanie tekstu"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"Metoda wprowadzania"</string>
+    <string name="inputMethod" msgid="1653630062304567879">"Sposób wprowadzania tekstu"</string>
     <string name="editTextMenuTitle" msgid="4909135564941815494">"Działania na tekście"</string>
     <string name="low_internal_storage_view_title" msgid="1399732408701697546">"Mało miejsca"</string>
     <string name="low_internal_storage_view_text" product="tablet" msgid="4231085657068852042">"Pamięć tabletu wkrótce zostanie zapełniona."</string>
@@ -903,7 +903,7 @@
     <string name="extmedia_format_button_format" msgid="4131064560127478695">"Formatuj"</string>
     <string name="adb_active_notification_title" msgid="6729044778949189918">"Podłączono moduł debugowania USB"</string>
     <string name="adb_active_notification_message" msgid="8470296818270110396">"Wybierz, aby wyłączyć debugowanie USB."</string>
-    <string name="select_input_method" msgid="6865512749462072765">"Wybierz metodę wprowadzania"</string>
+    <string name="select_input_method" msgid="6865512749462072765">"Wybierz sposób wprowadzania tekstu"</string>
     <string name="configure_input_methods" msgid="6324843080254191535">"Konfiguruj metody wprowadzania"</string>
     <string name="fast_scroll_alphabet" msgid="5433275485499039199">" AĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŹŻ"</string>
     <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
@@ -956,7 +956,7 @@
     <string name="deny" msgid="2081879885755434506">"Odmów"</string>
     <string name="permission_request_notification_title" msgid="5390555465778213840">"Żądane pozwolenie"</string>
     <string name="permission_request_notification_with_subtitle" msgid="4325409589686688000">"Prośba o pozwolenie"\n"dotyczące konta <xliff:g id="ACCOUNT">%s</xliff:g>"</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"Metoda wprowadzania"</string>
+    <string name="input_method_binding_label" msgid="1283557179944992649">"Sposób wprowadzania tekstu"</string>
     <string name="sync_binding_label" msgid="3687969138375092423">"Synchronizacja"</string>
     <string name="accessibility_binding_label" msgid="4148120742096474641">"Ułatwienia dostępu"</string>
     <string name="wallpaper_binding_label" msgid="1240087844304687662">"Tapeta"</string>
diff --git a/core/res/res/values-ru/strings.xml b/core/res/res/values-ru/strings.xml
index 10a2898..8e8f87f 100644
--- a/core/res/res/values-ru/strings.xml
+++ b/core/res/res/values-ru/strings.xml
@@ -416,7 +416,7 @@
     <string name="permdesc_authenticateAccounts" msgid="4006839406474208874">"Разрешает приложению использовать возможности аутентификации диспетчера аккаунта, в том числе создавать аккаунты, получать и устанавливать пароли для них."</string>
     <string name="permlab_manageAccounts" msgid="4440380488312204365">"управление списком аккаунтов"</string>
     <string name="permdesc_manageAccounts" msgid="8804114016661104517">"Разрешает приложению добавлять и удалять аккаунты и стирать их пароли."</string>
-    <string name="permlab_useCredentials" msgid="6401886092818819856">"использование регистрационных данных аккаунта для аутентификации"</string>
+    <string name="permlab_useCredentials" msgid="6401886092818819856">"использование учетных данных аккаунта для аутентификации"</string>
     <string name="permdesc_useCredentials" msgid="7416570544619546974">"Разрешает приложению запрашивать маркеры аутентификации."</string>
     <string name="permlab_accessNetworkState" msgid="6865575199464405769">"просматривать состояние сети"</string>
     <string name="permdesc_accessNetworkState" msgid="558721128707712766">"Позволяет приложению просматривать состояние всех сетей."</string>
@@ -460,11 +460,11 @@
     <string name="permdesc_readDictionary" msgid="1082972603576360690">"Позволяет приложению считывать любые слова, имена и фразы личного пользования, которые могут храниться в пользовательском словаре."</string>
     <string name="permlab_writeDictionary" msgid="6703109511836343341">"записывать в словарь пользователя"</string>
     <string name="permdesc_writeDictionary" msgid="2241256206524082880">"Позволяет приложению записывать новые слова в словарь пользователя."</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="85430876310764752">"изменять и удалять содержимое USB-накопителя"</string>
+    <string name="permlab_sdcardWrite" product="nosdcard" msgid="85430876310764752">"изм./удал. содерж. накопителя"</string>
     <string name="permlab_sdcardWrite" product="default" msgid="8079403759001777291">"изменять/удалять содержимое SD-карты"</string>
     <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6594393334785738252">"Разрешает приложению запись на USB-накопитель."</string>
     <string name="permdesc_sdcardWrite" product="default" msgid="6643963204976471878">"Разрешает приложению запись на SD-карту"</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"изменение/удаление данных из внутреннего хранилища мультимедиа"</string>
+    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"изм./удал. данных мультимедиа"</string>
     <string name="permdesc_mediaStorageWrite" product="default" msgid="8232008512478316233">"Приложение сможет изменять содержание внутреннего хранилища мультимедиа."</string>
     <string name="permlab_cache_filesystem" msgid="5656487264819669824">"получать доступ к кэшу файловой системы"</string>
     <string name="permdesc_cache_filesystem" msgid="1624734528435659906">"Разрешает программам доступ для записи и чтения к кэшу файловой системы."</string>
@@ -825,7 +825,7 @@
     <string name="anr_application_process" msgid="4185842666452210193">"Приложение <xliff:g id="APPLICATION">%1$s</xliff:g> (в процессе <xliff:g id="PROCESS">%2$s</xliff:g>) не отвечает."</string>
     <string name="anr_process" msgid="1246866008169975783">"Процесс <xliff:g id="PROCESS">%1$s</xliff:g> не отвечает."</string>
     <string name="force_close" msgid="3653416315450806396">"Закрыть"</string>
-    <string name="report" msgid="4060218260984795706">"Отчет"</string>
+    <string name="report" msgid="4060218260984795706">"Отзыв"</string>
     <string name="wait" msgid="7147118217226317732">"Подождать"</string>
     <string name="launch_warning_title" msgid="8323761616052121936">"Приложение перенаправлено"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"Приложение <xliff:g id="APP_NAME">%1$s</xliff:g> выполняется."</string>
@@ -919,7 +919,7 @@
     <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"Поврежденная карта SD"</string>
     <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="529021299294450667">"USB-накопитель поврежден. Попробуйте отформатировать его."</string>
     <string name="ext_media_unmountable_notification_message" product="default" msgid="6902531775948238989">"SD-карта повреждена. Попробуйте отформатировать ее."</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"USB-накопитель неожиданно отключен"</string>
+    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"Накопитель неожиданно отключен"</string>
     <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"Карта SD неожиданно извлечена"</string>
     <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"Перед извлечением USB-накопителя отключите его во избежание потери данных."</string>
     <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"Перед извлечением карты SD отключите ее во избежание потери данных."</string>
diff --git a/core/res/res/values-tr/strings.xml b/core/res/res/values-tr/strings.xml
index 58b681e..ad4eee7 100644
--- a/core/res/res/values-tr/strings.xml
+++ b/core/res/res/values-tr/strings.xml
@@ -896,7 +896,7 @@
     <string name="dlg_confirm_kill_storage_users_text" msgid="3202838234780505886">"USB depolama birimini açarsanız, kullanmakta olduğunuz bazı uygulamalar durur ve USB depolama birimi kapatılıncaya kadar kullanılamayabilir."</string>
     <string name="dlg_error_title" msgid="8048999973837339174">"USB işlemi başarısız oldu"</string>
     <string name="dlg_ok" msgid="7376953167039865701">"Tamam"</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="7980995592595097841">"USB dep br biçimlndr"</string>
+    <string name="extmedia_format_title" product="nosdcard" msgid="7980995592595097841">"USB\'yi biçimlendir"</string>
     <string name="extmedia_format_title" product="default" msgid="8663247929551095854">"SD kartı biçimlendir"</string>
     <string name="extmedia_format_message" product="nosdcard" msgid="8296908079722897772">"USB depolama birimi biçimlendirilsin mi? Depolama biriminde saklanan tüm dosyalar silinir. İşlem geri alınamaz!"</string>
     <string name="extmedia_format_message" product="default" msgid="3621369962433523619">"SD kartı biçimlendirmek istediğinizden emin misiniz? Kartınızdaki tüm veriler yok olacak."</string>
diff --git a/core/res/res/values-zh-rTW/strings.xml b/core/res/res/values-zh-rTW/strings.xml
index 141ed01..f87c2f6 100644
--- a/core/res/res/values-zh-rTW/strings.xml
+++ b/core/res/res/values-zh-rTW/strings.xml
@@ -426,8 +426,8 @@
     <string name="permdesc_writeApnSettings" msgid="7443433457842966680">"允許應用程式修改 APN 設定,例如:Proxy 及 APN 的連接埠。"</string>
     <string name="permlab_changeNetworkState" msgid="958884291454327309">"變更網路連線"</string>
     <string name="permdesc_changeNetworkState" msgid="4199958910396387075">"允許應用程式變更網路連線狀態。"</string>
-    <string name="permlab_changeTetherState" msgid="2702121155761140799">"變更數據連線"</string>
-    <string name="permdesc_changeTetherState" msgid="8905815579146349568">"允許應用程式變更數據網路連線狀態。"</string>
+    <string name="permlab_changeTetherState" msgid="2702121155761140799">"變更網路共用設定"</string>
+    <string name="permdesc_changeTetherState" msgid="8905815579146349568">"允許應用程式變更已共用網路的連線狀態。"</string>
     <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"變更背景資料使用設定"</string>
     <string name="permdesc_changeBackgroundDataSetting" msgid="1001482853266638864">"允許應用程式變更背景資料使用設定。"</string>
     <string name="permlab_accessWifiState" msgid="8100926650211034400">"檢視 Wi-Fi 狀態"</string>
@@ -971,7 +971,7 @@
     <string name="submit" msgid="1602335572089911941">"提交"</string>
     <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"已啟用車用模式"</string>
     <string name="car_mode_disable_notification_message" msgid="668663626721675614">"選取結束車用模式。"</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"數據連線或無線基地台已啟用"</string>
+    <string name="tethered_notification_title" msgid="3146694234398202601">"網路共用或無線基地台已啟用"</string>
     <string name="tethered_notification_message" msgid="3067108323903048927">"輕觸以設定"</string>
     <string name="back_button_label" msgid="2300470004503343439">"返回"</string>
     <string name="next_button_label" msgid="1080555104677992408">"繼續"</string>
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index b7849bb..819ce58 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -525,6 +525,9 @@
         <!-- Reference to a style that will be used for the window containing a text
              selection anchor. -->
         <attr name="textSelectHandleWindowStyle" format="reference" />
+        <!-- Reference to a style that will be used for the window containing a list of possible
+             text suggestions in an EditText. -->
+        <attr name="textSuggestionsWindowStyle" format="reference" />
         <!-- Default ListPopupWindow style. -->
         <attr name="listPopupWindowStyle" format="reference" />
         <!-- Default PopupMenu style. -->
@@ -675,6 +678,15 @@
         <!-- Variation of textEditSidePasteWindowLayout displayed when the clipboard is empty. -->
         <attr name="textEditSideNoPasteWindowLayout" format="reference" />
 
+        <!-- Layout of a the view that is used to create the text suggestions popup window in an
+             EditText. This window will be displayed below the text line. -->
+        <attr name="textEditSuggestionsBottomWindowLayout" format="reference" />
+        <!-- Same as textEditSuggestionsBottomWindowLayout, but used when the popup is displayed
+             above the current line of text instead of below. -->
+        <attr name="textEditSuggestionsTopWindowLayout" format="reference" />
+        <!-- Layout of the TextView item that will populate the suggestion popup window. -->
+        <attr name="textEditSuggestionItemLayout" format="reference" />
+
         <!-- Theme to use for dialogs spawned from this theme. -->
         <attr name="dialogTheme" format="reference" />
         <!-- Window decor layout to use in dialog mode with icons -->
@@ -2819,6 +2831,16 @@
         <!-- Variation of textEditSidePasteWindowLayout displayed when the clipboard is empty. -->
         <attr name="textEditSideNoPasteWindowLayout" />
 
+        <!-- Layout of a the view that is used to create the text suggestions popup window in an
+             EditText. This window will be displayed below the text line. -->
+        <attr name="textEditSuggestionsBottomWindowLayout" />
+        <!-- Same as textEditSuggestionsBottomWindowLayout, but used when the popup is displayed
+             above the current line of text instead of below. -->
+        <attr name="textEditSuggestionsTopWindowLayout" />
+        <!-- Layout of the TextView item that will populate the suggestion popup window. -->
+        <attr name="textEditSuggestionItemLayout" />
+
+
         <!-- Reference to a drawable that will be drawn under the insertion cursor. -->
         <attr name="textCursorDrawable" />
 
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index e8f30ad..80beaa5 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -590,6 +590,11 @@
         <!-- The global user interface mode has changed.  For example,
              going in or out of car mode, night mode changing, etc. -->
         <flag name="uiMode" value="0x0200" />
+        <!-- The physical screen size has changed.  If applications don't
+             target at least {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}
+             then the activity will always handle this itself (the change
+             will not result in a restart). -->
+        <flag name="screenSize" value="0x0400" />
         <!-- The font scaling factor has changed, that is the user has
              selected a new global font size. -->
         <flag name="fontScale" value="0x40000000" />
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 56bc1d3..fc4272d8 100755
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -114,6 +114,23 @@
          removable. -->
     <bool name="config_externalStorageRemovable" product="default">true</bool>
 
+    <!-- List of mount points for external storage devices.
+         The first item on the list should be the primary external storage and should match the
+         value returned by Environment.getExternalStorageDirectory (/mnt/sdcard).
+         MTP storage IDs will be generated based on the position of the mountpoint in this list:
+            0x00010001 - ID for primary external storage (/mnt/sdcard)
+            0x00020001 - ID for first secondary external storage
+            0x00030001 - ID for second secondary external storage
+         etc. -->
+    <string-array translatable="false" name="config_externalStoragePaths">
+        <item>"/mnt/sdcard"</item>
+    </string-array>
+
+    <!-- User visible descriptions of the volumes in the config_externalStoragePaths array. -->
+    <string-array translatable="true" name="config_externalStorageDescriptions">
+        <item>"SD card"</item>
+    </string-array>
+
     <!-- Number of megabytes of space to leave unallocated by MTP.
          MTP will subtract this value from the free space it reports back
          to the host via GetStorageInfo, and will not allow new files to
@@ -132,6 +149,7 @@
          based on the hardware -->
     <!-- An Array of "[Connection name],[ConnectivityManager connection type],
          [associated radio-type],[priority]  -->
+    <!-- an optional 5th element can be added indicating boot-time dependency-met value.  Defaults to true -->
     <string-array translatable="false" name="networkAttributes">
         <item>"wifi,1,1,1"</item>
         <item>"mobile,0,0,0"</item>
@@ -209,6 +227,15 @@
          The driver commands needed to support the feature are BGSCAN-START and BGSCAN-STOP -->
     <bool translatable="false" name="config_wifi_background_scan_support">false</bool>
 
+    <!-- Integer indicating wpa_supplicant scan interval in milliseconds -->
+    <integer translatable="false" name="config_wifi_supplicant_scan_interval">15000</integer>
+
+    <!-- Integer indicating the framework scan interval in milliseconds. This is used in the scenario
+         where the chipset does not support background scanning (config_wifi_background_scan_suport
+         is false) to set up a periodic wake up scan so that the device can connect to a new access
+         point on the move. A value of 0 means no periodic scans will be used in the framework. -->
+    <integer translatable="false" name="config_wifi_framework_scan_interval">300000</integer>
+
     <!-- Flag indicating whether the keyguard should be bypassed when
          the slider is open.  This can be set or unset depending how easily
          the slider can be opened (for example, in a pocket or purse). -->
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 4109ae1..d5c374d 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1659,4 +1659,9 @@
 
   <public type="style" name="Theme.Holo.Light.NoActionBar" />
 
+  <public type="attr" name="textSuggestionsWindowStyle" />
+  <public type="attr" name="textEditSuggestionsBottomWindowLayout" />
+  <public type="attr" name="textEditSuggestionsTopWindowLayout" />
+  <public type="attr" name="textEditSuggestionItemLayout" />
+
 </resources>
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index f6a3979..bf4c6d7 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -426,6 +426,9 @@
         <item name="android:textEditNoPasteWindowLayout">?android:attr/textEditNoPasteWindowLayout</item>
         <item name="android:textEditSidePasteWindowLayout">?android:attr/textEditSidePasteWindowLayout</item>
         <item name="android:textEditSideNoPasteWindowLayout">?android:attr/textEditSideNoPasteWindowLayout</item>
+        <item name="android:textEditSuggestionsBottomWindowLayout">?android:attr/textEditSuggestionsBottomWindowLayout</item>
+        <item name="android:textEditSuggestionsTopWindowLayout">?android:attr/textEditSuggestionsTopWindowLayout</item>
+        <item name="android:textEditSuggestionItemLayout">?android:attr/textEditSuggestionItemLayout</item>
         <item name="android:textCursorDrawable">?android:attr/textCursorDrawable</item>
     </style>
     
@@ -1047,6 +1050,17 @@
         <item name="windowExitAnimation">@android:anim/fade_out</item>
     </style>
 
+    <!-- Style for the popup window that contains text suggestions. -->
+    <style name="Widget.TextSuggestions">
+        <item name="android:popupAnimationStyle">@android:style/Animation.TextSuggestions</item>
+    </style>
+
+    <!-- Animation effects when showing/hiding the text suggestions popup window. -->
+    <style name="Animation.TextSuggestions">
+        <item name="windowEnterAnimation">@android:anim/fade_in</item>
+        <item name="windowExitAnimation">@android:anim/fade_out</item>
+    </style>
+
     <style name="Widget.ActionBar">
         <item name="android:background">@android:drawable/action_bar_background</item>
         <item name="android:displayOptions">useLogo|showHome|showTitle</item>
@@ -1465,6 +1479,9 @@
     <style name="Widget.Holo.TextSelectHandle" parent="Widget.TextSelectHandle">
     </style>
 
+    <style name="Widget.Holo.TextSuggestions" parent="Widget.TextSuggestions">
+    </style>
+
     <style name="Widget.Holo.AbsListView" parent="Widget.AbsListView">
     </style>
 
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index fdeb229..b1e4f0f 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -180,6 +180,10 @@
         <item name="textEditNoPasteWindowLayout">@android:layout/text_edit_no_paste_window</item>
         <item name="textEditSidePasteWindowLayout">@android:layout/text_edit_side_paste_window</item>
         <item name="textEditSideNoPasteWindowLayout">@android:layout/text_edit_side_no_paste_window</item>
+        <item name="textSuggestionsWindowStyle">@android:style/Widget.TextSuggestions</item>
+        <item name="textEditSuggestionsBottomWindowLayout">@android:layout/text_edit_suggestions_bottom_window</item>
+        <item name="textEditSuggestionsTopWindowLayout">@android:layout/text_edit_suggestions_top_window</item>
+        <item name="textEditSuggestionItemLayout">@android:layout/text_edit_suggestion_item</item>
         <item name="textCursorDrawable">@null</item>
 
         <!-- Widget styles -->
@@ -917,6 +921,7 @@
         <item name="textSelectHandleRight">@android:drawable/text_select_handle_right</item>
         <item name="textSelectHandle">@android:drawable/text_select_handle_middle</item>
         <item name="textSelectHandleWindowStyle">@android:style/Widget.Holo.TextSelectHandle</item>
+        <item name="textSuggestionsWindowStyle">@android:style/Widget.Holo.TextSuggestions</item>
         <item name="textCursorDrawable">@android:drawable/text_cursor_holo_dark</item>
 
         <!-- Widget styles -->
@@ -1201,6 +1206,7 @@
         <item name="textSelectHandleRight">@android:drawable/text_select_handle_right</item>
         <item name="textSelectHandle">@android:drawable/text_select_handle_middle</item>
         <item name="textSelectHandleWindowStyle">@android:style/Widget.Holo.TextSelectHandle</item>
+        <item name="textSuggestionsWindowStyle">@android:style/Widget.Holo.TextSuggestions</item>
         <item name="textCursorDrawable">@android:drawable/text_cursor_holo_light</item>
 
         <!-- Widget styles -->
diff --git a/core/tests/coretests/src/android/net/LinkPropertiesTest.java b/core/tests/coretests/src/android/net/LinkPropertiesTest.java
new file mode 100644
index 0000000..50666b4
--- /dev/null
+++ b/core/tests/coretests/src/android/net/LinkPropertiesTest.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net;
+
+import android.net.LinkProperties;
+import android.test.suitebuilder.annotation.SmallTest;
+import junit.framework.TestCase;
+
+import java.net.InetAddress;
+
+public class LinkPropertiesTest extends TestCase {
+    private static String ADDRV4 = "75.208.6.1";
+    private static String ADDRV6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
+    private static String DNS1 = "75.208.7.1";
+    private static String DNS2 = "69.78.7.1";
+    private static String GATEWAY1 = "75.208.8.1";
+    private static String GATEWAY2 = "69.78.8.1";
+    private static String NAME = "qmi0";
+
+    @SmallTest
+    public void testEqualsNull() {
+        LinkProperties source = new LinkProperties();
+        LinkProperties target = new LinkProperties();
+
+        assertFalse(source == target);
+        assertTrue(source.equals(target));
+        assertTrue(source.hashCode() == target.hashCode());
+    }
+
+    @SmallTest
+    public void testEqualsSameOrder() {
+        try {
+            LinkProperties source = new LinkProperties();
+            source.setInterfaceName(NAME);
+            // set 2 link addresses
+            source.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV4), 32));
+            source.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV6), 128));
+            // set 2 dnses
+            source.addDns(NetworkUtils.numericToInetAddress(DNS1));
+            source.addDns(NetworkUtils.numericToInetAddress(DNS2));
+            // set 2 gateways
+            source.addGateway(NetworkUtils.numericToInetAddress(GATEWAY1));
+            source.addGateway(NetworkUtils.numericToInetAddress(GATEWAY2));
+
+            LinkProperties target = new LinkProperties();
+
+            // All fields are same
+            target.setInterfaceName(NAME);
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV4), 32));
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV6), 128));
+            target.addDns(NetworkUtils.numericToInetAddress(DNS1));
+            target.addDns(NetworkUtils.numericToInetAddress(DNS2));
+            target.addGateway(NetworkUtils.numericToInetAddress(GATEWAY1));
+            target.addGateway(NetworkUtils.numericToInetAddress(GATEWAY2));
+
+            assertTrue(source.equals(target));
+            assertTrue(source.hashCode() == target.hashCode());
+
+            target.clear();
+            // change Interface Name
+            target.setInterfaceName("qmi1");
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV4), 32));
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV6), 128));
+            target.addDns(NetworkUtils.numericToInetAddress(DNS1));
+            target.addDns(NetworkUtils.numericToInetAddress(DNS2));
+            target.addGateway(NetworkUtils.numericToInetAddress(GATEWAY1));
+            target.addGateway(NetworkUtils.numericToInetAddress(GATEWAY2));
+            assertFalse(source.equals(target));
+
+            target.clear();
+            target.setInterfaceName(NAME);
+            // change link addresses
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress("75.208.6.2"), 32));
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV6), 128));
+            target.addDns(NetworkUtils.numericToInetAddress(DNS1));
+            target.addDns(NetworkUtils.numericToInetAddress(DNS2));
+            target.addGateway(NetworkUtils.numericToInetAddress(GATEWAY1));
+            target.addGateway(NetworkUtils.numericToInetAddress(GATEWAY2));
+            assertFalse(source.equals(target));
+
+            target.clear();
+            target.setInterfaceName(NAME);
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV4), 32));
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV6), 128));
+            // change dnses
+            target.addDns(NetworkUtils.numericToInetAddress("75.208.7.2"));
+            target.addDns(NetworkUtils.numericToInetAddress(DNS2));
+            target.addGateway(NetworkUtils.numericToInetAddress(GATEWAY1));
+            target.addGateway(NetworkUtils.numericToInetAddress(GATEWAY2));
+            assertFalse(source.equals(target));
+
+            target.clear();
+            target.setInterfaceName(NAME);
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV4), 32));
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV6), 128));
+            target.addDns(NetworkUtils.numericToInetAddress(DNS1));
+            target.addDns(NetworkUtils.numericToInetAddress(DNS2));
+            // change gateway
+            target.addGateway(NetworkUtils.numericToInetAddress("75.208.8.2"));
+            target.addGateway(NetworkUtils.numericToInetAddress(GATEWAY2));
+            assertFalse(source.equals(target));
+
+        } catch (Exception e) {
+            throw new RuntimeException(e.toString());
+            //fail();
+        }
+    }
+
+    @SmallTest
+    public void testEqualsDifferentOrder() {
+        try {
+            LinkProperties source = new LinkProperties();
+            source.setInterfaceName(NAME);
+            // set 2 link addresses
+            source.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV4), 32));
+            source.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV6), 128));
+            // set 2 dnses
+            source.addDns(NetworkUtils.numericToInetAddress(DNS1));
+            source.addDns(NetworkUtils.numericToInetAddress(DNS2));
+            // set 2 gateways
+            source.addGateway(NetworkUtils.numericToInetAddress(GATEWAY1));
+            source.addGateway(NetworkUtils.numericToInetAddress(GATEWAY2));
+
+            LinkProperties target = new LinkProperties();
+            // Exchange order
+            target.setInterfaceName(NAME);
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV6), 128));
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV4), 32));
+            target.addDns(NetworkUtils.numericToInetAddress(DNS2));
+            target.addDns(NetworkUtils.numericToInetAddress(DNS1));
+            target.addGateway(NetworkUtils.numericToInetAddress(GATEWAY2));
+            target.addGateway(NetworkUtils.numericToInetAddress(GATEWAY1));
+
+            assertTrue(source.equals(target));
+            assertTrue(source.hashCode() == target.hashCode());
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+    @SmallTest
+    public void testEqualsDuplicated() {
+        try {
+            LinkProperties source = new LinkProperties();
+            // set 3 link addresses, eg, [A, A, B]
+            source.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV4), 32));
+            source.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV4), 32));
+            source.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV6), 128));
+
+            LinkProperties target = new LinkProperties();
+            // set 3 link addresses, eg, [A, B, B]
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV4), 32));
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV6), 128));
+            target.addLinkAddress(new LinkAddress(
+                    NetworkUtils.numericToInetAddress(ADDRV6), 128));
+
+            assertTrue(source.equals(target));
+            assertTrue(source.hashCode() == target.hashCode());
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
+}
diff --git a/data/keyboards/Generic.kcm b/data/keyboards/Generic.kcm
index ef0a4e6..b5f6897 100644
--- a/data/keyboards/Generic.kcm
+++ b/data/keyboards/Generic.kcm
@@ -300,8 +300,7 @@
 key TAB {
     label:                              '\t'
     base:                               '\t'
-    ctrl:                               none
-    alt, meta:                          fallback APP_SWITCH
+    ctrl, alt, meta:                    none
 }
 
 key COMMA {
diff --git a/docs/html/guide/appendix/media-formats.jd b/docs/html/guide/appendix/media-formats.jd
index 7f77b5f..e128a1c 100644
--- a/docs/html/guide/appendix/media-formats.jd
+++ b/docs/html/guide/appendix/media-formats.jd
@@ -50,6 +50,8 @@
 
 <p class="note"><strong>Note:</strong> Media codecs that are not guaranteed to be available on all Android platform versions are accordingly noted in parentheses&mdash;for example &quot;(Android 3.0+)&quot;.</p>
 
+<p class="table-caption" id="formats-table"><strong>Table 1.</strong> Core media format and codec support.</p>
+
 <table>
 <tbody>
 
@@ -218,81 +220,61 @@
 
 <h2 id="recommendations">Video Encoding Recommendations</h2>
 
-<p>Below are examples of video encoding profiles and parameters that the Android media framework supports for playback.</p>
+<p>Table 2, below, lists examples of video encoding profiles and parameters that the Android media framework supports for playback. In addition to these encoding parameter recommendations, a device's available video recording profiles can be used as a proxy for media playback capabilities. These profiles can be inspected using the {@link android.media.CamcorderProfile CamcorderProfile} class, which is available since API level 8.</p>
+
+<p class="table-caption" id="encoding-recommendations-table"><strong>Table 2.</strong> Examples of supported video encoding parameters.</p>
+
+<table>
+  <thead>
+  <tr>
+    <th>&nbsp;</th>
+    <th style="background-color:#f3f3f3;font-weight:normal">Lower quality</th>
+    <th style="background-color:#f3f3f3;font-weight:normal">Higher quality</th>
+  </tr>
+  </thead>
+  <tbody>
+  <tr>
+    <th>Video codec</th>
+    <td>H.264 Baseline Profile</th>
+    <td>H.264 Baseline Profile</th>
+  </tr>
+  <tr>
+    <th>Video resolution</th>
+    <td>176 x 144 px</th>
+    <td>480 x 360 px</th>
+  </tr>
+  <tr>
+    <th>Video frame rate</th>
+    <td>12 fps</th>
+    <td>30 fps</th>
+  </tr>
+  <tr>
+    <th>Video bitrate</th>
+    <td>56 Kbps</th>
+    <td>500 Kbps</th>
+  </tr>
+  <tr>
+    <th>Audio codec</th>
+    <td>AAC-LC</th>
+    <td>AAC-LC</th>
+  </tr>
+  <tr>
+    <th>Audio channels</th>
+    <td>1 (mono)</th>
+    <td>2 (stereo)</th>
+  </tr>
+  <tr>
+    <th>Audio bitrate</th>
+    <td>24 Kbps</th>
+    <td>128 Kbps</th>
+  </tr>
+  </tbody>
+</table>
+
+<p style="margin-top: 2em">For video content that is streamed over HTTP or RTSP, there are additional requirements:</p>
 
 <ul>
-  <li><strong>Lower quality video</strong><br>
-
-    <table style="margin-top: 4px">
-    <tbody>
-    <tr>
-      <th>Video codec</th>
-      <td>H.264 Baseline Profile</th>
-    </tr>
-    <tr>
-      <th>Video resolution</th>
-      <td>176 x 144 px</th>
-    </tr>
-    <tr>
-      <th>Video frame rate</th>
-      <td>12 fps</th>
-    </tr>
-    <tr>
-      <th>Video bitrate</th>
-      <td>56 Kbps</th>
-    </tr>
-    <tr>
-      <th>Audio codec</th>
-      <td>AAC-LC</th>
-    </tr>
-    <tr>
-      <th>Audio channels</th>
-      <td>1 (mono)</th>
-    </tr>
-    <tr>
-      <th>Audio bitrate</th>
-      <td>24 Kbps</th>
-    </tr>
-    </tbody>
-    </table>
-  </li>
-
-  <li><strong>Higher quality video</strong><br>
-
-    <table style="margin-top: 4px">
-    <tbody>
-    <tr>
-      <th>Video codec</th>
-      <td>H.264 Baseline Profile</th>
-    </tr>
-    <tr>
-      <th>Video resolution</th>
-      <td>480 x 360 px</th>
-    </tr>
-    <tr>
-      <th>Video frame rate</th>
-      <td>30 fps</th>
-    </tr>
-    <tr>
-      <th>Video bitrate</th>
-      <td>500 Kbps</th>
-    </tr>
-    <tr>
-      <th>Audio codec</th>
-      <td>AAC-LC</th>
-    </tr>
-    <tr>
-      <th>Audio channels</th>
-      <td>2 (stereo)</th>
-    </tr>
-    <tr>
-      <th>Audio bitrate</th>
-      <td>128 Kbps</th>
-    </tr>
-    </tbody>
-    </table>
-
-  </li>
+  <li>For 3GPP and MPEG-4 containers, the <code>moov</code> atom must precede any <code>mdat</code> atoms.</li>
+  <li>For 3GPP, MPEG-4, and WebM containers, audio and video samples corresponding to the same time offset may be no more than 500 KB apart.
+      To minimize this audio/video drift, consider interleaving audio and video in smaller chunk sizes.</li>
 </ul>
-
-<p>In addition to the encoding parameters above, a device's available video recording profiles can be used as a proxy for media playback capabilities. These profiles can be inspected using the {@link android.media.CamcorderProfile CamcorderProfile} class, which is available since API level 8.</p>
diff --git a/docs/html/guide/market/billing/billing_admin.jd b/docs/html/guide/market/billing/billing_admin.jd
index 38099ee..723113d 100755
--- a/docs/html/guide/market/billing/billing_admin.jd
+++ b/docs/html/guide/market/billing/billing_admin.jd
@@ -15,118 +15,214 @@
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
 </div>
 </div>
 
-<p>In-app billing frees you from processing financial transactions, but you still need to perform a few administrative tasks, including setting up and maintaining your product list on the publisher site, registering test accounts, and handling refunds when necessary.</p>
+<p>In-app billing frees you from processing financial transactions, but you still need to perform a
+few administrative tasks, including setting up and maintaining your product list on the publisher
+site, registering test accounts, and handling refunds when necessary.</p>
 
-<p>You must have an Android Market publisher account to register test accounts. And you must have a Google Checkout Merchant account to create a product list and issue refunds to your users. If you already have a publisher account on Android Market, you can use your existing account. You do not need to register for a new account to support in-app billing. If you do not have a publisher account, you can register as an Android Market developer and set up a publisher account at the Android Market <a href="http://market.android.com/publish">publisher site</a>. If you do not have a Google Checkout Merchant account, you can register for one at the <a href="http://checkout.google.com">Google Checkout site</a>.</p>
+<p>You must have an Android Market publisher account to register test accounts. And you must have a
+Google Checkout Merchant account to create a product list and issue refunds to your users. If you
+already have a publisher account on Android Market, you can use your existing account. You do not
+need to register for a new account to support in-app billing. If you do not have a publisher
+account, you can register as an Android Market developer and set up a publisher account at the
+Android Market <a href="http://market.android.com/publish">publisher site</a>. If you do not have a
+Google Checkout Merchant account, you can register for one at the <a
+href="http://checkout.google.com">Google Checkout site</a>.</p>
 
 <h2 id="billing-list-setup">Creating a Product List</h2>
 
-<p>The Android Market publisher site provides a product list for each of your published applications. You can sell an item using Android Market's in-app billing feature only if the item is listed on an application's product list. Each application has its own product list; you cannot sell items that are listed in another application's product list.</p>
+<p>The Android Market publisher site provides a product list for each of your published
+applications. You can sell an item using Android Market's in-app billing feature only if the item is
+listed on an application's product list. Each application has its own product list; you cannot sell
+items that are listed in another application's product list.</p>
 
-<p>You can access an application's product list by clicking the <strong>In-App Products</strong> link that appears under each of the applications that are listed for your publisher account (see figure 1). The <strong>In-App Products</strong> link appears only if you have a Google Checkout Merchant account and an application's manifest includes the <code>com.android.vending.BILLING</code> permission.</p>
+<p>You can access an application's product list by clicking the <strong>In-App Products</strong>
+link that appears under each of the applications that are listed for your publisher account (see
+figure 1). The <strong>In-App Products</strong> link appears only if you have a Google Checkout
+Merchant account and an application's manifest includes the <code>com.android.vending.BILLING</code>
+permission.</p>
 
 <img src="{@docRoot}images/billing_product_list_entry.png" height="548" id="figure1" />
 <p class="img-caption">
-  <strong>Figure 1.</strong> You can access an application's product list by clicking the <strong>In-App Products</strong> link.
+  <strong>Figure 1.</strong> You can access an application's product list by clicking the
+  <strong>In-App Products</strong> link.
 </p>
 
-<p>A product list contains information about the items you are selling, such as a product id, product description, and price (see figure 2). The product list stores only metadata about the items you are selling in your application. It does not store any digital content. You are responsible for storing and delivering the digital content that you sell in your applications.</p>
+<p>A product list contains information about the items you are selling, such as a product id,
+product description, and price (see figure 2). The product list stores only metadata about the items
+you are selling in your application. It does not store any digital content. You are responsible for
+storing and delivering the digital content that you sell in your applications.</p>
 
 <img src="{@docRoot}images/billing_product_list.png" height="560" id="figure2" />
 <p class="img-caption">
   <strong>Figure 2.</strong> An application's product list.
 </p>
 
-<p>You can create a product list for a published application or a draft application that's been uploaded and saved to the Android Market site. However, you must have a Google Checkout Merchant account and the application's manifest must include the <code>com.android.vending.BILLING</code> permission. If an application's manifest does not include this permission, you will be able to edit existing items in the product list but you will not be able to add new items to the list. For more information, see <a href="#billing-permission">Modifying your application's AndroidManifest.xml file</a>.</p>
+<p>You can create a product list for a published application or a draft application that's been
+uploaded and saved to the Android Market site. However, you must have a Google Checkout Merchant
+account and the application's manifest must include the <code>com.android.vending.BILLING</code>
+permission. If an application's manifest does not include this permission, you will be able to edit
+existing items in the product list but you will not be able to add new items to the list. For more
+information, see <a href="#billing-permission">Modifying your application's AndroidManifest.xml
+file</a>.</p>
 
 <p>To create a product list for an application, follow these steps:</p>
 
 <ol>
   <li><a href="http://market.android.com/publish">Log in</a> to your publisher account.</li>
-  <li>In the <strong>All Android Market listings</strong> panel, under the application name, click <strong>In-app Products</strong>.</li>
+  <li>In the <strong>All Android Market listings</strong> panel, under the application name, click
+  <strong>In-app Products</strong>.</li>
   <li>On the In-app Products List page, click <strong>Add in-app product</strong>.</li>
-  <li>On the Create New In-app Product page (see figure 3), provide details about the item you are selling and then click <strong>Save</strong>.</li>
+  <li>On the Create New In-app Product page (see figure 3), provide details about the item you are
+  selling and then click <strong>Save</strong>.</li>
 </ol>
 
 <img src="{@docRoot}images/billing_list_form.png" height="840" id="figure3" />
 <p class="img-caption">
-  f<strong>Figure 3.</strong> The Create New In-app Product page lets you add items to an application's product list.
+  f<strong>Figure 3.</strong> The Create New In-app Product page lets you add items to an
+  application's product list.
 </p>
 
 <p>You must enter the following information for each item in a product list:</p>
 <ul>
   <li><strong>In-app Product ID</strong>
-    <p>Product IDs are unique across an application's namespace. A product ID must start with a lowercase letter or a number, and must be composed using only lowercase letters (a-z), numbers (0-9), underlines (_), and dots (.). The product ID "android.test" is reserved, as are all product IDs that start with "android.test."</p>
-    <p>In addition, you cannot modify an item's product ID after it is created, and you cannot reuse a product ID, even if you delete the item previously using the product ID.</p>
+    <p>Product IDs are unique across an application's namespace. A product ID must start with a
+    lowercase letter or a number, and must be composed using only lowercase letters (a-z), numbers
+    (0-9), underlines (_), and dots (.). The product ID "android.test" is reserved, as are all
+    product IDs that start with "android.test."</p>
+    <p>In addition, you cannot modify an item's product ID after it is created, and you cannot reuse
+    a product ID, even if you delete the item previously using the product ID.</p>
   </li>
   <li><strong>Purchase type</strong>
-    <p>The purchase type can be "managed per user account" or "unmanaged." You can specify an item's purchase type only through the publisher site and you can never change an item's purchase type once you specify it. For more information, see <a href="#billing_purchase_type">Choosing a purchase type</a> later in this document.</p>
+    <p>The purchase type can be "managed per user account" or "unmanaged." You can specify an item's
+    purchase type only through the publisher site and you can never change an item's purchase type
+    once you specify it. For more information, see <a href="#billing_purchase_type">Choosing a
+    purchase type</a> later in this document.</p>
   </li>
   <li><strong>Publishing State</strong>
-    <p>An item's publishing state can be "published" or "unpublished." However, to be visible to a user during checkout, an item's publishing state must be set to "published" and the item's application must be published on Android Market.</p>
-    <p class="note"><strong>Note:</strong> This is not true for test accounts. An item is visible to a test account if the application is not published and the item is published. See <a href="{@docRoot}guide/market/billing/billing_testing.html#billing-testing-real">Testing In-app Billing</a> for more information.</p>
+    <p>An item's publishing state can be "published" or "unpublished." However, to be visible to a
+    user during checkout, an item's publishing state must be set to "published" and the item's
+    application must be published on Android Market.</p>
+    <p class="note"><strong>Note:</strong> This is not true for test accounts. An item is visible to
+    a test account if the application is not published and the item is published. See <a
+    href="{@docRoot}guide/market/billing/billing_testing.html#billing-testing-real">Testing In-app
+    Billing</a> for more information.</p>
   </li>
   <li><strong>Language</strong>
     <p>A product list inherits its language from the parent application.</p>
   </li>
   <li><strong>Title</strong>
-    <p>The title is a short descriptor for the item. For example, "Sleeping potion." Titles must be unique across an application's namespace. Every item must have a title. The title is visible to users during checkout. For optimum appearance, titles should be no longer than 25 characters; however, titles can be up to 55 characters in length.</p>
+    <p>The title is a short descriptor for the item. For example, "Sleeping potion." Titles must be
+    unique across an application's namespace. Every item must have a title. The title is visible to
+    users during checkout. For optimum appearance, titles should be no longer than 25 characters;
+    however, titles can be up to 55 characters in length.</p>
   </li>
   <li><strong>Description</strong>
-    <p>The description is a long descriptor for the item. For example, "Instantly puts creatures to sleep. Does not work on angry elves." Every item must have a description. The description is visible to users during checkout. Descriptions can be up to 80 characters in length.</p>
+    <p>The description is a long descriptor for the item. For example, "Instantly puts creatures to
+    sleep. Does not work on angry elves." Every item must have a description. The description is
+    visible to users during checkout. Descriptions can be up to 80 characters in length.</p>
   </li>
   <li><strong>Price</strong>
     <p>Every item must have a price greater than zero; you cannot set a price of "0" (free).</p>
   </li>
 </ul>
 
-<p>For more information about product IDs and product lists, see <a href="http://market.android.com/support/bin/answer.py?answer=1072599">Creating In-App Product IDs</a>. For more information about pricing, see <a href="http://market.android.com/support/bin/answer.py?answer=1153485">In-App Billing Pricing</a>.</p>
+<p>For more information about product IDs and product lists, see <a
+href="http://market.android.com/support/bin/answer.py?answer=1072599">Creating In-App Product
+IDs</a>. For more information about pricing, see <a
+href="http://market.android.com/support/bin/answer.py?answer=1153485">In-App Billing
+Pricing</a>.</p>
 
-<p class="note"><strong>Note</strong>: Be sure to plan your product ID namespace. You cannot reuse or modify product IDs after you save them.</p>
+<p class="note"><strong>Note</strong>: Be sure to plan your product ID namespace. You cannot reuse
+or modify product IDs after you save them.</p>
 
 <h3 id="billing-purchase-type">Choosing a Purchase Type</h3>
 
-<p>An item's purchase type controls how Android Market manages the purchase of the item. There are two purchase types: "managed per user account" and "unmanaged."</p>
+<p>An item's purchase type controls how Android Market manages the purchase of the item. There are
+two purchase types: "managed per user account" and "unmanaged."</p>
 
-<p>Items that are managed per user account can be purchased only once per user account. When an item is managed per user account, Android Market permanently stores the transaction information for each item on a per-user basis. This enables you to query Android Market with the <code>RESTORE_TRANSACTIONS</code> request and restore the state of the items a specific user has purchased.</p>
+<p>Items that are managed per user account can be purchased only once per user account. When an item
+is managed per user account, Android Market permanently stores the transaction information for each
+item on a per-user basis. This enables you to query Android Market with the
+<code>RESTORE_TRANSACTIONS</code> request and restore the state of the items a specific user has
+purchased.</p>
 
-<p>If a user attempts to purchase a managed item that has already been purchased, Android Market displays an "Item already purchased" error. This occurs during checkout, when Android Market displays the price and description information on the checkout page. When the user dismisses the error message, the checkout page disappears and the user returns to your user interface. As a best practice, your application should prevent the user from seeing this error. The sample application demonstrates how you can do this by keeping track of items that are managed and already purchased and not allowing users to select those items from the list. Your application should do something similar&mdash;either graying out the item or hiding it so that it cannot be selected.</p>
+<p>If a user attempts to purchase a managed item that has already been purchased, Android Market
+displays an "Item already purchased" error. This occurs during checkout, when Android Market
+displays the price and description information on the checkout page. When the user dismisses the
+error message, the checkout page disappears and the user returns to your user interface. As a best
+practice, your application should prevent the user from seeing this error. The sample application
+demonstrates how you can do this by keeping track of items that are managed and already purchased
+and not allowing users to select those items from the list. Your application should do something
+similar&mdash;either graying out the item or hiding it so that it cannot be selected.</p>
 
-<p>The "manage by user account" purchase type is useful if you are selling items such as game levels or application features. These items are not transient and usually need to be restored whenever a user reinstalls your application, wipes the data on their device, or installs your application on a new device.</p>
+<p>The "manage by user account" purchase type is useful if you are selling items such as game levels
+or application features. These items are not transient and usually need to be restored whenever a
+user reinstalls your application, wipes the data on their device, or installs your application on a
+new device.</p>
 
-<p>Items that are unmanaged do not have their transaction information stored on Android Market, which means you cannot query Android Market to retrieve transaction information for items whose purchase type is listed as unmanaged. You are responsible for managing the transaction information of unmanaged items. Also, unmanaged items can be purchased multiple times as far as Android Market is concerned, so it's also up to you to control how many times an unmanaged item can be purchased.</p>
+<p>Items that are unmanaged do not have their transaction information stored on Android Market,
+which means you cannot query Android Market to retrieve transaction information for items whose
+purchase type is listed as unmanaged. You are responsible for managing the transaction information
+of unmanaged items. Also, unmanaged items can be purchased multiple times as far as Android Market
+is concerned, so it's also up to you to control how many times an unmanaged item can be
+purchased.</p>
 
-<p>The "unmanaged" purchase type is useful if you are selling consumable items, such as fuel or magic spells. These items are consumed within your application and are usually purchased multiple times.</p>
+<p>The "unmanaged" purchase type is useful if you are selling consumable items, such as fuel or
+magic spells. These items are consumed within your application and are usually purchased multiple
+times.</p>
 
 <h2 id="billing-refunds">Handling Refunds</h2>
 
-<p>In-app billing does not allow users to send a refund request to Android Market. Refunds for in-app purchases must be directed to you (the application developer). You can then process the refund through your Google Checkout Merchant account. When you do this, Android Market receives a refund notification from Google Checkout, and Android Market sends a refund message to your application. For more information, see <a href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling IN_APP_NOTIFY messages</a> and <a href="http://www.google.com/support/androidmarket/bin/answer.py?answer=1153485">In-app Billing Pricing</a>.</p>
+<p>In-app billing does not allow users to send a refund request to Android Market. Refunds for
+in-app purchases must be directed to you (the application developer). You can then process the
+refund through your Google Checkout Merchant account. When you do this, Android Market receives a
+refund notification from Google Checkout, and Android Market sends a refund message to your
+application. For more information, see <a
+href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling
+IN_APP_NOTIFY messages</a> and <a
+href="http://www.google.com/support/androidmarket/bin/answer.py?answer=1153485">In-app Billing
+Pricing</a>.</p>
 
 <h2 id="billing-testing-setup">Setting Up Test Accounts</h2>
 
-<p>The Android Market publisher site lets you set up one or more test accounts. A test account is a regular Google account that you register on the publisher site as a test account. Test accounts are authorized to make in-app purchases from applications that you have uploaded to the Android Market site but have not yet published.</p>
+<p>The Android Market publisher site lets you set up one or more test accounts. A test account is a
+regular Google account that you register on the publisher site as a test account. Test accounts are
+authorized to make in-app purchases from applications that you have uploaded to the Android Market
+site but have not yet published.</p>
 
-<p>You can use any Google account as a test account. Test accounts are useful if you want to let multiple people test in-app billing on applications without giving them access to your publisher account's sign-in credentials. If you want to own and control the test accounts, you can create the accounts yourself and distribute the credentials to your developers or testers.</p>
+<p>You can use any Google account as a test account. Test accounts are useful if you want to let
+multiple people test in-app billing on applications without giving them access to your publisher
+account's sign-in credentials. If you want to own and control the test accounts, you can create the
+accounts yourself and distribute the credentials to your developers or testers.</p>
 
 <p>Test accounts have three limitations:</p>
 
 <ul>
-  <li>Test account users can make purchase requests only within applications that are already uploaded to your publisher account (although the application doesn't need to be published).</li>
-  <li>Test accounts can only be used to purchase items that are listed (and published) in an application's product list.</li>
-  <li>Test account users do not have access to your publisher account and cannot upload applications to your publisher account.</li>
+  <li>Test account users can make purchase requests only within applications that are already
+  uploaded to your publisher account (although the application doesn't need to be published).</li>
+  <li>Test accounts can only be used to purchase items that are listed (and published) in an
+  application's product list.</li>
+  <li>Test account users do not have access to your publisher account and cannot upload applications
+  to your publisher account.</li>
 </ul>
 
 <p>To add test accounts to your publisher account, follow these steps:</p>
@@ -134,21 +230,27 @@
 <ol>
   <li><a href="http://market.android.com/publish">Log in</a> to your publisher account.</li>
   <li>On the upper left part of the page, under your name, click <strong>Edit profile</strong>.</li>
-  <li>On the Edit Profile page, scroll down to the Licensing &amp; In-app Billing panel (see figure 4).</li>
-  <li>In Test Accounts, add the email addresses for the test accounts you want to register, separating each account with a comma.</li>
+  <li>On the Edit Profile page, scroll down to the Licensing &amp; In-app Billing panel (see figure
+  4).</li>
+  <li>In Test Accounts, add the email addresses for the test accounts you want to register,
+  separating each account with a comma.</li>
   <li>Click <strong>Save</strong> to save your profile changes.</li>
 </ol>
 
 <img src="{@docRoot}images/billing_public_key.png" height="510" id="figure4" />
 <p class="img-caption">
-  <strong>Figure 4.</strong> The Licensing and In-app Billing panel of your account's Edit Profile page lets you register test accounts.
+  <strong>Figure 4.</strong> The Licensing and In-app Billing panel of your account's Edit Profile
+  page lets you register test accounts.
 </p>
 
 <h2 id="billing-support">Where to Get Support</h2>
 
-<p>If you have questions or encounter problems while implementing in-app billing, contact the support resources listed in the following table (see table 2). By directing your queries to the correct forum, you can get the support you need more quickly.</p>
+<p>If you have questions or encounter problems while implementing in-app billing, contact the
+support resources listed in the following table (see table 2). By directing your queries to the
+correct forum, you can get the support you need more quickly.</p>
 
-<p class="table-caption" id="support-table"><strong>Table 2.</strong> Developer support resources for Android Market in-app billing.</p>
+<p class="table-caption" id="support-table"><strong>Table 2.</strong> Developer support resources
+for Android Market in-app billing.</p>
 
 <table>
 
@@ -159,12 +261,15 @@
 </tr>
 <tr>
 <td rowspan="2">Development and testing issues</td>
-<td>Google Groups: <a href="http://groups.google.com/group/android-developers">android-developers</a> </td>
-<td rowspan="2">In-app billing integration questions, user experience ideas, handling of responses, obfuscating code, IPC, test environment setup.</td>
+<td>Google Groups: <a
+href="http://groups.google.com/group/android-developers">android-developers</a> </td>
+<td rowspan="2">In-app billing integration questions, user experience ideas, handling of responses,
+obfuscating code, IPC, test environment setup.</td>
 </tr>
 <tr>
 <td>Stack Overflow: <a
-href="http://stackoverflow.com/questions/tagged/android">http://stackoverflow.com/questions/tagged/android</a></td>
+href="http://stackoverflow.com/questions/tagged/android">http://stackoverflow.com/questions/tagged/
+android</a></td>
 </tr>
 <tr>
 <td>Market billing issue tracker</td>
@@ -174,7 +279,9 @@
 </tr>
 </table>
 
-<p>For general information about how to post to the groups listed above, see <a href="{@docRoot}resources/community-groups.html">Developer Forums</a> document in the Resources tab.</p>
+<p>For general information about how to post to the groups listed above, see <a
+href="{@docRoot}resources/community-groups.html">Developer Forums</a> document in the Resources
+tab.</p>
 
 
 
diff --git a/docs/html/guide/market/billing/billing_best_practices.jd b/docs/html/guide/market/billing/billing_best_practices.jd
index 6f9f64c..d9776af 100755
--- a/docs/html/guide/market/billing/billing_best_practices.jd
+++ b/docs/html/guide/market/billing/billing_best_practices.jd
@@ -11,62 +11,101 @@
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
 </div>
 </div>
 
-<p>As you design your in-app billing implementation, be sure to follow the security and design guidelines that are discussed in this document. These guidelines are recommended best practices for anyone who is using Android Market's in-app billing service.</p>
+<p>As you design your in-app billing implementation, be sure to follow the security and design
+guidelines that are discussed in this document. These guidelines are recommended best practices for
+anyone who is using Android Market's in-app billing service.</p>
 
 <h2>Security Best Practices</h2>
 
 <h4>Perform signature verification tasks on a server</h4>
-<p>If practical, you should perform signature verification on a remote server and not on a device. Implementing the verification process on a server makes it difficult for attackers to break the verification process by reverse engineering your .apk file. If you do offload security processing to a remote server, be sure that the device-server handshake is secure.</p>
+<p>If practical, you should perform signature verification on a remote server and not on a device.
+Implementing the verification process on a server makes it difficult for attackers to break the
+verification process by reverse engineering your .apk file. If you do offload security processing to
+a remote server, be sure that the device-server handshake is secure.</p>
 
 <h4>Protect your unlocked content</h4>
-<p>To prevent malicious users from redistributing your unlocked content, do not bundle it in your .apk file. Instead, do one of the following:</p>
+<p>To prevent malicious users from redistributing your unlocked content, do not bundle it in your
+.apk file. Instead, do one of the following:</p>
   <ul>
-    <li>Use a real-time service to deliver your content, such as a content feed. Delivering content through a real-time service allows you to keep your content fresh.</li>
+    <li>Use a real-time service to deliver your content, such as a content feed. Delivering content
+    through a real-time service allows you to keep your content fresh.</li>
     <li>Use a remote server to deliver your content.</li>
   </ul>
-<p>When you deliver content from a remote server or a real-time service, you can store the unlocked content in device memory or store it on the device's SD card. If you store content on an SD card, be sure to encrypt the content and use a device-specific encryption key.</p>
+<p>When you deliver content from a remote server or a real-time service, you can store the unlocked
+content in device memory or store it on the device's SD card. If you store content on an SD card, be
+sure to encrypt the content and use a device-specific encryption key.</p>
 
 <h4>Obfuscate your code</h4>
-<p>You should obfuscate your in-app billing code so it is difficult for an attacker to reverse engineer security protocols and other application components. At a minimum, we recommend that you run an  obfuscation tool like <a href="http://developer.android.com/guide/developing/tools/proguard.html">Proguard</a> on your code.</p>
-<p>In addition to running an obfuscation program, we recommend that you use the following techniques to obfuscate your in-app billing code.</p>
+<p>You should obfuscate your in-app billing code so it is difficult for an attacker to reverse
+engineer security protocols and other application components. At a minimum, we recommend that you
+run an  obfuscation tool like <a
+href="http://developer.android.com/guide/developing/tools/proguard.html">Proguard</a> on your
+code.</p>
+<p>In addition to running an obfuscation program, we recommend that you use the following techniques
+to obfuscate your in-app billing code.</p>
 <ul>
   <li>Inline methods into other methods.</li>
   <li>Construct strings on the fly instead of defining them as constants.</li>
   <li>Use Java reflection to call methods.</li>
 </ul>
-<p>Using these techniques can help reduce the attack surface of your application and help minimize attacks that can compromise your in-app billing implementation.</p>
+<p>Using these techniques can help reduce the attack surface of your application and help minimize
+attacks that can compromise your in-app billing implementation.</p>
 <div class="note">
-  <p><strong>Note:</strong> If you use Proguard to obfuscate your code, you must add the following line to your Proguard configuration file:</p>
+  <p><strong>Note:</strong> If you use Proguard to obfuscate your code, you must add the following
+  line to your Proguard configuration file:</p>
   <p><code>-keep class com.android.vending.billing.**</code></p>
 </div>
   
 <h4>Modify all sample application code</h4>
-<p>The in-app billing sample application is publicly distributed and can be downloaded by anyone, which means it is relatively easy for an attacker to reverse engineer your application if you use the sample code exactly as it is published. The sample application is intended to be used only as an example. If you use any part of the sample application, you must modify it before you publish it or release it as part of a production application.</p>
-<p>In particular, attackers look for known entry points and exit points in an application, so it is important that you modify these parts of your code that are identical to the sample application.</p>
+<p>The in-app billing sample application is publicly distributed and can be downloaded by anyone,
+which means it is relatively easy for an attacker to reverse engineer your application if you use
+the sample code exactly as it is published. The sample application is intended to be used only as an
+example. If you use any part of the sample application, you must modify it before you publish it or
+release it as part of a production application.</p>
+<p>In particular, attackers look for known entry points and exit points in an application, so it is
+important that you modify these parts of your code that are identical to the sample application.</p>
 
 <h4>Use secure random nonces</h4>
-<p>Nonces must not be predictable or reused. Always use a cryptographically secure random number generator (like {@link java.security.SecureRandom}) when you generate nonces. This can help reduce replay attacks.</p>
-<p>Also, if you are performing nonce verification on a server, make sure that you generate the nonces on the server.</p>
+<p>Nonces must not be predictable or reused. Always use a cryptographically secure random number
+generator (like {@link java.security.SecureRandom}) when you generate nonces. This can help reduce
+replay attacks.</p>
+<p>Also, if you are performing nonce verification on a server, make sure that you generate the
+nonces on the server.</p>
 
 <h4>Take action against trademark and copyright infringement</h4>
-<p>If you see your content being redistributed on Android Market, act quickly and decisively. File a <a href="http://market.android.com/support/bin/answer.py?hl=en&amp;answer=141511">trademark notice of infringement</a> or a <a href="http://www.google.com/android_dmca.html">copyright notice of infringement</a>.</p>
+<p>If you see your content being redistributed on Android Market, act quickly and decisively. File a
+<a href="http://market.android.com/support/bin/answer.py?hl=en&amp;answer=141511">trademark notice
+of infringement</a> or a <a href="http://www.google.com/android_dmca.html">copyright notice of
+infringement</a>.</p>
 
 <h4>Implement a revocability scheme for unlocked content</h4>
-<p>If you are using a remote server to deliver or manage content, have your application verify the purchase state of the unlocked content whenever a user accesses the content. This allows you to revoke use when necessary and minimize piracy.</p>
+<p>If you are using a remote server to deliver or manage content, have your application verify the
+purchase state of the unlocked content whenever a user accesses the content. This allows you to
+revoke use when necessary and minimize piracy.</p>
 
 <h4>Protect your Android Market public key</h4>
-<p>To keep your public key safe from malicious users and hackers, do not embed it in any code as a literal string. Instead, construct the string at runtime from pieces or use bit manipulation (for example, XOR with some other string) to hide the actual key. The key itself is not secret information, but you do not want to make it easy for a hacker or malicious user to replace the public key with another key.</p>
+<p>To keep your public key safe from malicious users and hackers, do not embed it in any code as a
+literal string. Instead, construct the string at runtime from pieces or use bit manipulation (for
+example, XOR with some other string) to hide the actual key. The key itself is not secret
+information, but you do not want to make it easy for a hacker or malicious user to replace the
+public key with another key.</p>
 
diff --git a/docs/html/guide/market/billing/billing_integrate.jd b/docs/html/guide/market/billing/billing_integrate.jd
index 7532337..f57ebe3 100755
--- a/docs/html/guide/market/billing/billing_integrate.jd
+++ b/docs/html/guide/market/billing/billing_integrate.jd
@@ -21,33 +21,50 @@
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
 </div>
 </div>
 
-<p>Android Market In-app Billing provides a straightforward, simple interface for sending in-app billing requests and managing in-app billing transactions using Android Market. This document helps you implement in-app billing by stepping through the primary implementation tasks, using the in-app billing sample application as an example.</p>
+<p>Android Market In-app Billing provides a straightforward, simple interface for sending in-app
+billing requests and managing in-app billing transactions using Android Market. This document helps
+you implement in-app billing by stepping through the primary implementation tasks, using the in-app
+billing sample application as an example.</p>
 
-<p>Before you implement in-app billing in your own application, be sure that you read <a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a> and <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>. These documents provide background information that will make it easier for you to implement in-app billing.</p>
+<p>Before you implement in-app billing in your own application, be sure that you read <a
+href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a> and <a
+href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>. These
+documents provide background information that will make it easier for you to implement in-app
+billing.</p>
 
 <p>To implement in-app billing in your application, you need to do the following:</p>
 <ol>
   <li><a href="#billing-download">Download the in-app billing sample application</a>.</li>
   <li><a href="#billing-add-aidl">Add the IMarketBillingService.aidl file</a> to your project.</li>
   <li><a href="#billing-permission">Update your AndroidManifest.xml file</a>.</li>
-  <li><a href="#billing-service">Create a Service</a> and bind it to the <code>MarketBillingService</code> so your application can send billing requests and receive billing responses from the Android Market application.</li>
-  <li><a href="#billing-broadcast-receiver">Create a BroadcastReceiver</a> to handle broadcast intents from the Android Market application.</li>
-  <li><a href="#billing-signatures">Create a security processing component</a> to verify the integrity of the transaction messages that are sent by Android Market .</li>
+  <li><a href="#billing-service">Create a Service</a> and bind it to the
+  <code>MarketBillingService</code> so your application can send billing requests and receive
+  billing responses from the Android Market application.</li>
+  <li><a href="#billing-broadcast-receiver">Create a BroadcastReceiver</a> to handle broadcast
+  intents from the Android Market application.</li>
+  <li><a href="#billing-signatures">Create a security processing component</a> to verify the
+  integrity of the transaction messages that are sent by Android Market .</li>
   <li><a href="#billing-implement">Modify your application code</a> to support in-app billing.</li>
 </ol>
 
 <h2 id="billing-download">Downloading the Sample Application</h2>
 
-<p>The in-app billing sample application shows you how to perform several tasks that are common to all Android Market in-app billing implementations, including:</p>
+<p>The in-app billing sample application shows you how to perform several tasks that are common to
+all Android Market in-app billing implementations, including:</p>
 
 <ul>
   <li>Sending in-app billing requests to the Android Market application.</li>
@@ -57,10 +74,14 @@
   <li>Creating a user interface that lets users select items for purchase.</li>
 </ul>
 
-<p>The sample application includes an application file (<code>Dungeons.java</code>), the AIDL file for the <code>MarketBillingService</code> (<code>IMarketBillingService.aidl</code>), and several classes that demonstrate in-app billing messaging. It also includes a class that demonstrates basic security tasks, such as signature verification.</p>
+<p>The sample application includes an application file (<code>Dungeons.java</code>), the AIDL file
+for the <code>MarketBillingService</code> (<code>IMarketBillingService.aidl</code>), and several
+classes that demonstrate in-app billing messaging. It also includes a class that demonstrates basic
+security tasks, such as signature verification.</p>
 
 <p>Table 1 lists the source files that are included with the sample application.</p>
-<p class="table-caption" id="source-files-table"><strong>Table 1.</strong> In-app billing sample application source files.</p>
+<p class="table-caption" id="source-files-table"><strong>Table 1.</strong> In-app billing sample
+application source files.</p>
 
 <table>
 <tr>
@@ -70,12 +91,14 @@
 
 <tr>
 <td>IMarketBillingService.aidl</td>
-<td>Android Interface Definition Library (AIDL) file that defines the IPC interface to Android Market's in-app billing service (<code>MarketBillingService</code>).</td>
+<td>Android Interface Definition Library (AIDL) file that defines the IPC interface to Android
+Market's in-app billing service (<code>MarketBillingService</code>).</td>
 </tr>
 
 <tr>
 <td>Dungeons.java</td>
-<td>Sample application file that provides a UI for making purchases and displaying purchase history.</td>
+<td>Sample application file that provides a UI for making purchases and displaying purchase
+history.</td>
 </tr>
 
 <tr>
@@ -85,16 +108,20 @@
 
 <tr>
   <td>BillingReceiver.java</td>
-  <td>A {@link android.content.BroadcastReceiver} that receives asynchronous response messages (broadcast intents) from Android Market. Forwards all messages to the <code>BillingService</code>.</td>
+  <td>A {@link android.content.BroadcastReceiver} that receives asynchronous response messages
+  (broadcast intents) from Android Market. Forwards all messages to the
+  <code>BillingService</code>.</td>
 </tr>
 <tr>
   <td>BillingService.java</td>
-  <td>A {@link android.app.Service} that sends messages to Android Market on behalf of the application by connecting (binding) to the <code>MarketBillingService</code>.</td>
+  <td>A {@link android.app.Service} that sends messages to Android Market on behalf of the
+  application by connecting (binding) to the <code>MarketBillingService</code>.</td>
 </tr>
 
 <tr>
   <td>ResponseHandler.java</td>
-  <td>A {@link android.os.Handler} that contains methods for updating the purchases database and the UI.</td>
+  <td>A {@link android.os.Handler} that contains methods for updating the purchases database and the
+  UI.</td>
 </tr>
 
 <tr>
@@ -109,29 +136,38 @@
 
 <tr>
 <td>Consts.java</td>
-<td>Defines various Android Market constants and sample application constants. All constants that are defined by Android Market must be defined the same way in your application.</td>
+<td>Defines various Android Market constants and sample application constants. All constants that
+are defined by Android Market must be defined the same way in your application.</td>
 </tr>
 
 <tr>
 <td>Base64.java and Base64DecoderException.java</td>
-<td>Provides conversion services from binary to Base64 encoding. The <code>Security</code> class relies on these utility classes.</td>
+<td>Provides conversion services from binary to Base64 encoding. The <code>Security</code> class
+relies on these utility classes.</td>
 </tr>
 
 </table>
 
-<p>The in-app billing sample application is available as a downloadable component of the Android SDK. To download the sample application component, launch the Android SDK and AVD Manager and then select the "Google Market Billing package" component (see figure 1), and click <strong>Install Selected</strong> to begin the download.</p>
+<p>The in-app billing sample application is available as a downloadable component of the Android
+SDK. To download the sample application component, launch the Android SDK and AVD Manager and then
+select the "Google Market Billing package" component (see figure 1), and click <strong>Install
+Selected</strong> to begin the download.</p>
 
 
 <img src="{@docRoot}images/billing_package.png" height="325" id="figure1" />
 <p class="img-caption">
-  <strong>Figure 1.</strong> The Google Market Billing package contains the sample application and the AIDL file.
+  <strong>Figure 1.</strong> The Google Market Billing package contains the sample application and
+  the AIDL file.
 </p>
 
-<p>When the download is complete, the Android SDK and AVD Manager saves the component into the following directory:</p>
+<p>When the download is complete, the Android SDK and AVD Manager saves the component into the
+following directory:</p>
 
 <p><code>&lt;sdk&gt;/google-market_billing/</code></p>
 
-<p>If you want to see an end-to-end demonstration of in-app billing before you integrate in-app billing into your own application, you can build and run the sample application. Building and running the sample application involves three tasks:<p>
+<p>If you want to see an end-to-end demonstration of in-app billing before you integrate in-app
+billing into your own application, you can build and run the sample application. Building and
+running the sample application involves three tasks:<p>
 
 <ul>
   <li>Configuring and building the sample application.</li>
@@ -139,19 +175,28 @@
   <li>Setting up test accounts and running the sample application.</li>
 </ul>
 
-<p class="note"><strong>Note:</strong> Building and running the sample application is necessary only if you want to see a demonstration of in-app billing. If you do not want to run the sample application, you can skip to the next section, <a href="#billing-add-aidl">Adding the AIDL file to your project</a>.</p>
+<p class="note"><strong>Note:</strong> Building and running the sample application is necessary only
+if you want to see a demonstration of in-app billing. If you do not want to run the sample
+application, you can skip to the next section, <a href="#billing-add-aidl">Adding the AIDL file to
+your project</a>.</p>
 
 <h3>Configuring and building the sample application</h3>
 
-<p>Before you can run the sample application, you need to configure it and build it by doing the following:</p>
+<p>Before you can run the sample application, you need to configure it and build it by doing the
+following:</p>
 
 <ol>
   <li><strong>Add your Android Market public key to the sample application code.</strong>
-    <p>This enables the application to verify the signature of the transaction information that is returned from Android Market. To add your public key to the sample application code, do the following:</p>
+    <p>This enables the application to verify the signature of the transaction information that is
+    returned from Android Market. To add your public key to the sample application code, do the
+    following:</p>
     <ol>
-      <li>Log in to your Android Market <a href="http://market.android.com/publish">publisher account</a>.</li>
-      <li>On the upper left part of the page, under your name, click <strong>Edit Profile</strong>.</li>
-      <li>On the Edit Profile page, scroll down to the <strong>Licensing &amp; In-app Billing</strong> panel.</li>
+      <li>Log in to your Android Market <a href="http://market.android.com/publish">publisher
+      account</a>.</li>
+      <li>On the upper left part of the page, under your name, click <strong>Edit
+      Profile</strong>.</li>
+      <li>On the Edit Profile page, scroll down to the <strong>Licensing &amp; In-app
+      Billing</strong> panel.</li>
       <li>Copy your public key.</li>
       <li>Open <code>src/com/example/dungeons/Security.java</code> in the editor of your choice.
         <p>You can find this file in the sample application's project folder.</p>
@@ -163,61 +208,112 @@
     </ol>
   </li>
   <li><strong>Change the package name of the sample application.</strong>
-    <p>The current package name is <code>com.example.dungeons</code>. Android Market does not let you upload applications with package names that contain <code>com.example</code>, so you must change the package name to something else.</p>
+    <p>The current package name is <code>com.example.dungeons</code>. Android Market does not let
+    you upload applications with package names that contain <code>com.example</code>, so you must
+    change the package name to something else.</p>
   </li>
   <li><strong>Build the sample application in release mode and sign it.</strong>
-    <p>To learn how to build and sign applications, see <a href="{@docRoot}guide/developing/building/index.html">Building and Running</a>.</p>
+    <p>To learn how to build and sign applications, see <a
+    href="{@docRoot}guide/developing/building/index.html">Building and Running</a>.</p>
   </li>
 </ol>
 
 <h3>Uploading the sample application</h3>
 
-<p>After you build a release version of the sample application and sign it, you need to upload it as a draft to the Android Market publisher site. You also need to create a product list for the in-app items that are available for purchase in the sample application. The following instructions show you how to do this.</p>
+<p>After you build a release version of the sample application and sign it, you need to upload it as
+a draft to the Android Market publisher site. You also need to create a product list for the in-app
+items that are available for purchase in the sample application. The following instructions show you
+how to do this.</p>
 <ol>
   <li><strong>Upload the release version of the sample application to Android Market.</strong>
-    <p>Do not publish the sample application; leave it as an unpublished draft application. The sample application is for demonstration purposes only and should not be made publicly available on Android Market. To learn how to upload an application to Android Market, see <a href="http://market.android.com/support/bin/answer.py?answer=113469">Uploading applications</a>.</p>
+    <p>Do not publish the sample application; leave it as an unpublished draft application. The
+    sample application is for demonstration purposes only and should not be made publicly available
+    on Android Market. To learn how to upload an application to Android Market, see <a
+    href="http://market.android.com/support/bin/answer.py?answer=113469">Uploading
+    applications</a>.</p>
   </li>
   <li><strong>Create a product list for the sample application.</strong>
-    <p>The sample application lets you purchase two items: a two-handed sword (<code>sword_001</code>) and a potion (<code>potion_001</code>). We recommend that you set up your product list so that <code>sword_001</code> has a purchase type of "Managed per user account" and <code>potion_001</code> has a purchase type of "Unmanaged" so you can see how these two purchase types behave. To learn how to set up a product list, see <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-list-setup">Creating a Product List</a>.</p>
-    <p class="note"><strong>Note:</strong> You must publish the items in your product list (<code>sword_001</code> and <code>potion_001</code>) even though you are not publishing the sample application. Also, you must have a Google Checkout Merchant account to add items to the sample application's product list.</p>
+    <p>The sample application lets you purchase two items: a two-handed sword
+    (<code>sword_001</code>) and a potion (<code>potion_001</code>). We recommend that you set up
+    your product list so that <code>sword_001</code> has a purchase type of "Managed per user
+    account" and <code>potion_001</code> has a purchase type of "Unmanaged" so you can see how these
+    two purchase types behave. To learn how to set up a product list, see <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-list-setup">Creating a Product
+    List</a>.</p>
+    <p class="note"><strong>Note:</strong> You must publish the items in your product
+    list (<code>sword_001</code> and <code>potion_001</code>) even though you are not publishing the
+    sample application. Also, you must have a Google Checkout Merchant account to add items to the
+    sample application's product list.</p>
   </li>
 </ol>
 
 <h3>Running the sample application</h3>
 
-<p>You cannot run the sample application in the emulator. You must install the sample application onto a device to run it. To run the sample application, do the following:</p>
+<p>You cannot run the sample application in the emulator. You must install the sample application
+onto a device to run it. To run the sample application, do the following:</p>
 
 <ol>
-  <li><strong>Make sure you have at least one test account registered under your Android Market publisher account.</strong>
-    <p>You cannot purchase items from yourself (Google Checkout prohibits this), so you need to create at least one test account that you can use to purchase items in the sample application. To learn how to set up a test account, see <a href="{@docRoot}guide/market/billing/billing_testing.html#billing-testing-setup">Setting up Test Accounts</a>.</p>
+  <li><strong>Make sure you have at least one test account registered under your Android Market
+  publisher account.</strong>
+    <p>You cannot purchase items from yourself (Google Checkout prohibits this), so you need to
+    create at least one test account that you can use to purchase items in the sample application.
+    To learn how to set up a test account, see <a
+    href="{@docRoot}guide/market/billing/billing_testing.html#billing-testing-setup">Setting up Test
+    Accounts</a>.</p>
   </li>
-  <li><strong>Verify that your device is running a supported version of the Android Market application or the MyApps application.</strong>
-    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the version of the Android Market application, see <a href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android Market</a>.</p>
+  <li><strong>Verify that your device is running a supported version of the Android Market
+  application or the MyApps application.</strong>
+    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of
+    the MyApps application. If your device is running any other version of Android, in-app billing
+    requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the
+    version of the Android Market application, see <a
+    href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android
+    Market</a>.</p>
   </li>
   <li><strong>Install the application onto your device.</strong>
-    <p>Even though you uploaded the application to Android Market, the application is not published, so you cannot download it from Android Market to a device. Instead, you must install the application onto your device. To learn how to install an application onto a device, see <a href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a device</a>.</p>
+    <p>Even though you uploaded the application to Android Market, the application is not published,
+    so you cannot download it from Android Market to a device. Instead, you must install the
+    application onto your device. To learn how to install an application onto a device, see <a
+    href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a
+    device</a>.</p>
  </li>
  <li><strong>Make one of your test accounts the primary account on your device.</strong>
-    <p>The primary account on your device must be one of the <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a> that you registered on the Android Market site. If the primary account on your device is not a test account, you must do a factory reset of the device and then sign in with one of your test accounts. To perform a factory reset, do the following:</p>
+    <p>The primary account on your device must be one of the <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a>
+    that you registered on the Android Market site. If the primary account on your device is not a
+    test account, you must do a factory reset of the device and then sign in with one of your test
+    accounts. To perform a factory reset, do the following:</p>
     <ol>
       <li>Open Settings on your device.</li>
       <li>Touch <strong>Privacy</strong>.</li>
       <li>Touch <strong>Factory data reset</strong>.</li>
       <li>Touch <strong>Reset phone</strong>.</li>
-      <li>After the phone resets, be sure to sign in with one of your test accounts during the device setup process.</li>
+      <li>After the phone resets, be sure to sign in with one of your test accounts during the
+      device setup process.</li>
     </ol>
   </li>
   <li><strong>Run the application and purchase the sword or the potion.</strong>
-    <p>When you use a test account to purchase items, the test account is billed through Google Checkout and your Google Checkout Merchant account receives a payout for the purchase. Therefore, you may want to refund purchases that are made with test accounts, otherwise the purchases will show up as actual payouts to your merchant account.</p>
+    <p>When you use a test account to purchase items, the test account is billed through Google
+    Checkout and your Google Checkout Merchant account receives a payout for the purchase.
+    Therefore, you may want to refund purchases that are made with test accounts, otherwise the
+    purchases will show up as actual payouts to your merchant account.</p>
 </ol>
 
 <p class="note"><strong>Note</strong>: Debug log messages are turned off by default in the sample application. You can turn them on by setting the variable <code>DEBUG</code> to <code>true</code> in the <code>Consts.java</code> file.</p>
 
 <h2 id="billing-add-aidl">Adding the AIDL file to your project</h2>
 
-<p>The sample application contains an Android Interface Definition Language (AIDL) file,  which defines the interface to Android Market's in-app billing service (<code>MarketBillingService</code>). When you add this file to your project, the Android build environment creates an interface file (<code>IMarketBillingService.java</code>). You can then use this interface to make billing requests by invoking IPC method calls.</p>
+<p>The sample application contains an Android Interface Definition Language (AIDL) file,  which
+defines the interface to Android Market's in-app billing service
+(<code>MarketBillingService</code>). When you add this file to your project, the Android build
+environment creates an interface file (<code>IMarketBillingService.java</code>). You can then use
+this interface to make billing requests by invoking IPC method calls.</p>
 
-<p>If you are using the ADT plug-in with Eclipse, you can just add this file to your <code>/src</code> directory. Eclipse will automatically generate the interface file when you build your project (which should happen immediately). If you are not using the ADT plug-in, you can put the AIDL file into your project and use the Ant tool to build your project so that the <code>IMarketBillingService.java</code> file gets generated.</p>
+<p>If you are using the ADT plug-in with Eclipse, you can just add this file to your
+<code>/src</code> directory. Eclipse will automatically generate the interface file when you build
+your project (which should happen immediately). If you are not using the ADT plug-in, you can put
+the AIDL file into your project and use the Ant tool to build your project so that the
+<code>IMarketBillingService.java</code> file gets generated.</p>
 
 <p>To add the <code>IMarketBillingService.aidl</code> file to your project, do the following:</p>
 
@@ -225,19 +321,39 @@
   <li>Create the following directory in your application's <code>/src</code> directory:
     <p><code>com/android/vending/billing/</code></p>
   </li>
-  <li>Copy the <code>IMarketBillingService.aidl</code> file into the <code>sample/src/com/android/vending/billing/</code> directory.</li>
+  <li>Copy the <code>IMarketBillingService.aidl</code> file into the
+  <code>sample/src/com/android/vending/billing/</code> directory.</li>
   <li>Build your application.</li>
 </ol>
 
-<p>You should now find a generated interface file named <code>IMarketBillingService.java</code> in the <code>gen</code> folder of your project.</p>
+<p>You should now find a generated interface file named <code>IMarketBillingService.java</code> in
+the <code>gen</code> folder of your project.</p>
 
 <h2 id="billing-permission">Updating Your Application's Manifest</h2>
 
-<p>In-app billing relies on the Android Market application, which handles all communication between your application and the Android Market server. To use the Android Market application, your application must request the proper permission. You can do this by adding the <code>com.android.vending.BILLING</code> permission to your AndroidManifest.xml file. If your application does not declare the in-app billing permission, but attempts to send billing requests, Android Market will refuse the requests and respond with a <code>RESULT_DEVELOPER_ERROR</code> response code.</p>
+<p>In-app billing relies on the Android Market application, which handles all communication between
+your application and the Android Market server. To use the Android Market application, your
+application must request the proper permission. You can do this by adding the
+<code>com.android.vending.BILLING</code> permission to your AndroidManifest.xml file. If your
+application does not declare the in-app billing permission, but attempts to send billing requests,
+Android Market will refuse the requests and respond with a <code>RESULT_DEVELOPER_ERROR</code>
+response code.</p>
 
-<p>In addition to the billing permission, you need to declare the {@link android.content.BroadcastReceiver} that you will use to receive asynchronous response messages (broadcast intents) from Android Market, and you need to declare the {@link android.app.Service} that you will use to bind with the <code>IMarketBillingService</code> and send messages to Android Market. You must also declare <a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">intent filters</a> for the {@link android.content.BroadcastReceiver} so that the Android system knows how to handle the broadcast intents that are sent from the Android Market application.</p>
+<p>In addition to the billing permission, you need to declare the {@link
+android.content.BroadcastReceiver} that you will use to receive asynchronous response messages
+(broadcast intents) from Android Market, and you need to declare the {@link android.app.Service}
+that you will use to bind with the <code>IMarketBillingService</code> and send messages to Android
+Market. You must also declare <a
+href="{@docRoot}guide/topics/manifest/intent-filter-element.html">intent filters</a> for the {@link
+android.content.BroadcastReceiver} so that the Android system knows how to handle the broadcast
+intents that are sent from the Android Market application.</p>
 
-<p>For example, here is how the in-app billing sample application declares the billing permission, the {@link android.content.BroadcastReceiver}, the {@link android.app.Service}, and the intent filters. In the sample application, <code>BillingReceiver</code> is the {@link android.content.BroadcastReceiver} that handles broadcast intents from the Android Market application and <code>BillingService</code> is the {@link android.app.Service} that sends requests to the Android Market application.</p>
+<p>For example, here is how the in-app billing sample application declares the billing permission,
+the {@link android.content.BroadcastReceiver}, the {@link android.app.Service}, and the intent
+filters. In the sample application, <code>BillingReceiver</code> is the {@link
+android.content.BroadcastReceiver} that handles broadcast intents from the Android Market
+application and <code>BillingService</code> is the {@link android.app.Service} that sends requests
+to the Android Market application.</p>
 
 <pre>
 &lt;?xml version="1.0" encoding="utf-8"?&gt;
@@ -272,11 +388,13 @@
 
 <h2 id="billing-service">Creating a Local Service</h2>
 
-<p>Your application must have a local {@link android.app.Service} to facilitate messaging between your application and Android Market. At a minimum, this service must do the following:</p>
+<p>Your application must have a local {@link android.app.Service} to facilitate messaging between
+your application and Android Market. At a minimum, this service must do the following:</p>
 
 <ul>
   <li>Bind to the <code>MarketBillingService</code>.
-  <li>Send billing requests (as IPC method calls) to the Android Market application. The five types of billing requests include:
+  <li>Send billing requests (as IPC method calls) to the Android Market application. The five types
+  of billing requests include:
     <ul>
       <li><code>CHECK_BILLING_SUPPORTED</code> requests</li>
       <li><code>REQUEST_PURCHASE</code> requests</li>
@@ -290,12 +408,17 @@
 
 <h3>Binding to the MarketBillingService</h3>
 
-<p>Binding to the <code>MarketBillingService</code> is relatively easy if you've already added the <code>IMarketBillingService.aidl</code> file to your project. The following code sample shows how to use the {@link android.content.Context#bindService bindService()} method to bind a service to the <code>MarketBillingService</code>. You could put this code in your service's {@link android.app.Activity#onCreate onCreate()} method.</p>
+<p>Binding to the <code>MarketBillingService</code> is relatively easy if you've already added the
+<code>IMarketBillingService.aidl</code> file to your project. The following code sample shows how to
+use the {@link android.content.Context#bindService bindService()} method to bind a service to the
+<code>MarketBillingService</code>. You could put this code in your service's {@link
+android.app.Activity#onCreate onCreate()} method.</p>
 
 <pre>
 try {
   boolean bindResult = mContext.bindService(
-    new Intent("com.android.vending.billing.MarketBillingService.BIND"), this, Context.BIND_AUTO_CREATE);
+    new Intent("com.android.vending.billing.MarketBillingService.BIND"), this,
+    Context.BIND_AUTO_CREATE);
   if (bindResult) {
     Log.i(TAG, "Service bind successful.");
   } else {
@@ -306,7 +429,10 @@
 }
 </pre>
 
-<p>After you bind to the service, you need to create a reference to the <code>IMarketBillingService</code> interface so you can make billing requests via IPC method calls. The following code shows you how to do this using the {@link android.content.ServiceConnection#onServiceConnected onServiceConnected()} callback method.</p>
+<p>After you bind to the service, you need to create a reference to the
+<code>IMarketBillingService</code> interface so you can make billing requests via IPC method calls.
+The following code shows you how to do this using the {@link
+android.content.ServiceConnection#onServiceConnected onServiceConnected()} callback method.</p>
 
 <pre>
 /**
@@ -318,24 +444,51 @@
   }
 </pre>
 
-<p>You can now use the <code>mService</code> reference to invoke the <code>sendBillingRequest()</code> method.</p>
+<p>You can now use the <code>mService</code> reference to invoke the
+<code>sendBillingRequest()</code> method.</p>
 
-<p>For a complete implementation of a service that binds to the <code>MarketBillingService</code>, see the <code>BillingService</code> class in the sample application.</p>
+<p>For a complete implementation of a service that binds to the <code>MarketBillingService</code>,
+see the <code>BillingService</code> class in the sample application.</p>
 
 <h3>Sending billing requests to the MarketBillingService</h3>
 
-<p>Now that your {@link android.app.Service} has a reference to the <code>IMarketBillingService</code> interface, you can use that reference to send billing requests (via IPC method calls) to the <code>MarketBillingService</code>. The <code>MarketBillingService</code> IPC interface exposes a single public method (<code>sendBillingRequest()</code>), which takes a single {@link android.os.Bundle} parameter. The Bundle that you deliver with this method specifies the type of request you want to perform, using various key-value pairs. For instance, one key indicates the type of request you are making, another indicates the item being purchased, and another identifies your application. The <code>sendBillingRequest()</code> method immediately returns a Bundle containing an initial response code. However, this is not the complete purchase response; the complete response is delivered with an asynchronous broadcast intent. For more information about the various Bundle keys that are supported by the <code>MarketBillingService</code>, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-interface">In-app Billing Service Interface</a>.</p>
+<p>Now that your {@link android.app.Service} has a reference to the
+<code>IMarketBillingService</code> interface, you can use that reference to send billing requests
+(via IPC method calls) to the <code>MarketBillingService</code>. The
+<code>MarketBillingService</code> IPC interface exposes a single public method
+(<code>sendBillingRequest()</code>), which takes a single {@link android.os.Bundle} parameter. The
+Bundle that you deliver with this method specifies the type of request you want to perform, using
+various key-value pairs. For instance, one key indicates the type of request you are making, another
+indicates the item being purchased, and another identifies your application. The
+<code>sendBillingRequest()</code> method immediately returns a Bundle containing an initial response
+code. However, this is not the complete purchase response; the complete response is delivered with
+an asynchronous broadcast intent. For more information about the various Bundle keys that are
+supported by the <code>MarketBillingService</code>, see <a
+href="{@docRoot}guide/market/billing/billing_reference.html#billing-interface">In-app Billing
+Service Interface</a>.</p>
 
-<p>You can use the <code>sendBillingRequest()</code> method to send five types of billing requests. The five request types are specified using the <code>BILLING_REQUEST</code> Bundle key. This Bundle key can have the following five values:</p>
+<p>You can use the <code>sendBillingRequest()</code> method to send five types of billing requests.
+The five request types are specified using the <code>BILLING_REQUEST</code> Bundle key. This Bundle
+key can have the following five values:</p>
 
 <ul>
-  <li><code>CHECK_BILLING_SUPPORTED</code>&mdash;verifies that the Android Market application supports in-app billing.</li>
-  <li><code>REQUEST_PURCHASE</code>&mdash;sends a purchase request for an in-app item.</li>  <li><code>GET_PURCHASE_INFORMATION</code>&mdash;retrieves transaction information for a purchase or refund.</li>
-  <li><code>CONFIRM_NOTIFICATIONS</code>&mdash;acknowledges that you received the transaction information for a purchase or refund.</li>
-  <li><code>RESTORE_TRANSACTIONS</code>&mdash;retrieves a user's transaction history for <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">managed purchases</a>.</li>
+  <li><code>CHECK_BILLING_SUPPORTED</code>&mdash;verifies that the Android Market application
+  supports in-app billing.</li>
+  <li><code>REQUEST_PURCHASE</code>&mdash;sends a purchase request for an in-app item.</li> 
+  <li><code>GET_PURCHASE_INFORMATION</code>&mdash;retrieves transaction information for a purchase
+  or refund.</li>
+  <li><code>CONFIRM_NOTIFICATIONS</code>&mdash;acknowledges that you received the transaction
+  information for a purchase or refund.</li>
+  <li><code>RESTORE_TRANSACTIONS</code>&mdash;retrieves a user's transaction history for <a
+  href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">managed
+  purchases</a>.</li>
 </ul>
 
-<p>To make any of these billing requests, you first need to build an initial {@link android.os.Bundle} that contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The following code sample shows you how to create a helper method named <code>makeRequestBundle()</code> that does this.</p>
+<p>To make any of these billing requests, you first need to build an initial {@link
+android.os.Bundle} that contains the three keys that are required for all requests:
+<code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The following
+code sample shows you how to create a helper method named <code>makeRequestBundle()</code> that does
+this.</p>
 
 <pre>
 protected Bundle makeRequestBundle(String method) {
@@ -346,13 +499,18 @@
   return request;
 </pre>
 
-<p>To use this helper method, you pass in a <code>String</code> that corresponds to one of the five types of billing requests. The method returns a Bundle that has the three required keys defined. The following sections show you how to use this helper method when you send a billing request.<p>
+<p>To use this helper method, you pass in a <code>String</code> that corresponds to one of the five
+types of billing requests. The method returns a Bundle that has the three required keys defined. The
+following sections show you how to use this helper method when you send a billing request.<p>
 
-<p class="caution"><strong>Important</strong>: You must make all in-app billing requests from your application's main thread.</p>
+<p class="caution"><strong>Important</strong>: You must make all in-app billing requests from your
+application's main thread.</p>
 
 <h4>Verifying that in-app billing is supported (CHECK_BILLING_SUPPPORTED)</h4>
 
-<p>The following code sample shows how to verify whether the Android Market application supports in-app billing. In the sample, <code>mService</code> is an instance of the <code>MarketBillingService</code> interface.</p>
+<p>The following code sample shows how to verify whether the Android Market application supports
+in-app billing. In the sample, <code>mService</code> is an instance of the
+<code>MarketBillingService</code> interface.</p>
 
 <pre>
 /**
@@ -363,19 +521,37 @@
   // Do something with this response.
 }
 </pre>
-<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The request returns a synchronous {@link android.os.Bundle} response, which contains only a single key: <code>RESPONSE_CODE</code>. The <code>RESPONSE_CODE</code> key can have the following values:</p>
+<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the
+three keys that are required for all requests: <code>BILLING_REQUEST</code>,
+<code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The request returns a synchronous {@link
+android.os.Bundle} response, which contains only a single key: <code>RESPONSE_CODE</code>. The
+<code>RESPONSE_CODE</code> key can have the following values:</p>
 <ul>
   <li><code>RESULT_OK</code>&mdash;in-app billing is supported.</li>
-  <li><code>RESULT_BILLING_UNAVAILABLE</code>&mdash;in-app billing is not available because the API version you specified is not recognized or the user is not eligible to make in-app purchases (for example, the user resides in a country that prohibits in-app purchases).</li>
-  <li><code>RESULT_ERROR</code>&mdash;there was an error connecting with the Android Market application.</li>
-  <li><code>RESULT_DEVELOPER_ERROR</code>&mdash;the application is trying to make an in-app billing request but the application has not declared the <code>com.android.vending.BILLING</code> permission in its manifest. Can also indicate that an application is not properly signed, or that you sent a malformed request.</li>
+  <li><code>RESULT_BILLING_UNAVAILABLE</code>&mdash;in-app billing is not available because the API
+  version you specified is not recognized or the user is not eligible to make in-app purchases (for
+  example, the user resides in a country that prohibits in-app purchases).</li>
+  <li><code>RESULT_ERROR</code>&mdash;there was an error connecting with the Android Market
+  application.</li>
+  <li><code>RESULT_DEVELOPER_ERROR</code>&mdash;the application is trying to make an in-app billing
+  request but the application has not declared the <code>com.android.vending.BILLING</code>
+  permission in its manifest. Can also indicate that an application is not properly signed, or that
+  you sent a malformed request.</li>
 </ul>
 
-<p>The <code>CHECK_BILLING_SUPPORTED</code> request does not trigger any asynchronous responses (broadcast intents).</p>
+<p>The <code>CHECK_BILLING_SUPPORTED</code> request does not trigger any asynchronous responses
+(broadcast intents).</p>
 
-<p>We recommend that you invoke the <code>CHECK_BILLING_SUPPORTED</code> request within a <code>RemoteException</code> block. When your code throws a <code>RemoteException</code> it indicates that the remote method call failed, which means that the Android Market application is out of date and needs to be updated. In this case, you can provide users with an error message that contains a link to the <a href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android Market</a> Help topic.</p>
+<p>We recommend that you invoke the <code>CHECK_BILLING_SUPPORTED</code> request within a
+<code>RemoteException</code> block. When your code throws a <code>RemoteException</code> it
+indicates that the remote method call failed, which means that the Android Market application is out
+of date and needs to be updated. In this case, you can provide users with an error message that
+contains a link to the <a
+href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android Market</a>
+Help topic.</p>
 
-<p>The sample application demonstrates how you can handle this error condition (see <code>DIALOG_CANNOT_CONNECT_ID</code> in <code>Dungeons.java</code>).</p>
+<p>The sample application demonstrates how you can handle this error condition (see
+<code>DIALOG_CANNOT_CONNECT_ID</code> in <code>Dungeons.java</code>).</p>
 
 <h4>Making a purchase request (REQUEST_PURCHASE)</h4>
 
@@ -383,13 +559,19 @@
 
 <ul>
   <li>Send the <code>REQUEST_PURCHASE</code> request.</li>
-  <li>Launch the {@link android.app.PendingIntent} that is returned from the Android Market application.</li>
+  <li>Launch the {@link android.app.PendingIntent} that is returned from the Android Market
+  application.</li>
   <li>Handle the broadcast intents that are sent by the Android Market application.</li>
 </ul>
 
 <h5>Making the request</h5>
 
-<p>You must specify four keys in the request {@link android.os.Bundle}. The following code sample shows how to set these keys and make a purchase request for a single in-app item. In the sample, <code>mProductId</code> is the Android Market product ID of an in-app item (which is listed in the application's <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-list-setup">product list</a>), and <code>mService</code> is an instance of the <code>MarketBillingService</code> interface.</p>
+<p>You must specify four keys in the request {@link android.os.Bundle}. The following code sample
+shows how to set these keys and make a purchase request for a single in-app item. In the sample,
+<code>mProductId</code> is the Android Market product ID of an in-app item (which is listed in the
+application's <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-list-setup">product
+list</a>), and <code>mService</code> is an instance of the <code>MarketBillingService</code>
+interface.</p>
 
 <pre>
 /**
@@ -404,13 +586,26 @@
   // Do something with this response.
   }
 </pre>
-<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The <code>ITEM_ID</code> key is then added to the Bundle prior to invoking the <code>sendBillingRequest()</code> method.</p>
+<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the
+three keys that are required for all requests: <code>BILLING_REQUEST</code>,
+<code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The <code>ITEM_ID</code> key is then added
+to the Bundle prior to invoking the <code>sendBillingRequest()</code> method.</p>
 
-<p>The request returns a synchronous {@link android.os.Bundle} response, which contains three keys: <code>RESPONSE_CODE</code>, <code>PURCHASE_INTENT</code>, and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique request identifier for the request. The <code>PURCHASE_INTENT</code> key provides you with a {@link android.app.PendingIntent}, which you can use to launch the checkout UI.</p>
+<p>The request returns a synchronous {@link android.os.Bundle} response, which contains three keys:
+<code>RESPONSE_CODE</code>, <code>PURCHASE_INTENT</code>, and <code>REQUEST_ID</code>. The
+<code>RESPONSE_CODE</code> key provides you with the status of the request and the
+<code>REQUEST_ID</code> key provides you with a unique request identifier for the request. The
+<code>PURCHASE_INTENT</code> key provides you with a {@link android.app.PendingIntent}, which you
+can use to launch the checkout UI.</p>
 
 <h5>Launching the pending intent</h5>
 
-<p>How you use the pending intent depends on which version of Android a device is running. On Android 1.6, you must use the pending intent to launch the checkout UI in its own separate task instead of your application's activity stack. On Android 2.0 and higher, you can use the pending intent to launch the checkout UI on your application's activity stack. The following code shows you how to do this. You can find this code in the <code>PurchaseObserver.java</code> file in the sample application.</p>
+<p>How you use the pending intent depends on which version of Android a device is running. On
+Android 1.6, you must use the pending intent to launch the checkout UI in its own separate task
+instead of your application's activity stack. On Android 2.0 and higher, you can use the pending
+intent to launch the checkout UI on your application's activity stack. The following code shows you
+how to do this. You can find this code in the <code>PurchaseObserver.java</code> file in the sample
+application.</p>
 
 <pre>
 void startBuyPageActivity(PendingIntent pendingIntent, Intent intent) {
@@ -443,19 +638,37 @@
 }
 </pre>
 
-<p class="caution"><strong>Important:</strong> You must launch the pending intent from an activity context and not an application context. Also, you cannot use the <code>singleTop</code> <a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">launch mode</a> to launch the pending intent. If you do either of these, the Android system will not attach the pending intent to your application process. Instead, it will bring Android Market to the foreground, disrupting your application.</p>
+<p class="caution"><strong>Important:</strong> You must launch the pending intent from an activity
+context and not an application context. Also, you cannot use the <code>singleTop</code> <a
+href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">launch mode</a> to launch the
+pending intent. If you do either of these, the Android system will not attach the pending intent to
+your application process. Instead, it will bring Android Market to the foreground, disrupting your
+application.</p>
 
 <h5>Handling broadcast intents</h5>
 
-<p>A <code>REQUEST_PURCHASE</code> request also triggers two asynchronous responses (broadcast intents). First, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent, which provides error information about the request. Next, if the request was successful, the Android Market application sends an <code>IN_APP_NOTIFY</code> broadcast intent. This message contains a notification ID, which you can use to retrieve the transaction details for the <code>REQUEST_PURCHASE</code> request.</p>
+<p>A <code>REQUEST_PURCHASE</code> request also triggers two asynchronous responses (broadcast
+intents). First, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent,
+which provides error information about the request. Next, if the request was successful, the Android
+Market application sends an <code>IN_APP_NOTIFY</code> broadcast intent. This message contains a
+notification ID, which you can use to retrieve the transaction details for the
+<code>REQUEST_PURCHASE</code> request.</p>
 
-<p>Keep in mind, the Android Market application also sends an <code>IN_APP_NOTIFY</code> for refunds. For more information, see <a href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling IN_APP_NOTIFY messages</a>.</p>
+<p>Keep in mind, the Android Market application also sends an <code>IN_APP_NOTIFY</code> for
+refunds. For more information, see <a
+href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling
+IN_APP_NOTIFY messages</a>.</p>
 
 <h4>Retrieving transaction information for a purchase or refund (GET_PURCHASE_INFORMATION)</h4>
 
-<p>You retrieve transaction information in response to an <code>IN_APP_NOTIFY</code> broadcast intent. The <code>IN_APP_NOTIFY</code> message contains a notification ID, which you can use to retrieve transaction information.</p>
+<p>You retrieve transaction information in response to an <code>IN_APP_NOTIFY</code> broadcast
+intent. The <code>IN_APP_NOTIFY</code> message contains a notification ID, which you can use to
+retrieve transaction information.</p>
 
-<p>To retrieve transaction information for a purchase or refund you must specify five keys in the request {@link android.os.Bundle}. The following code sample shows how to set these keys and make the request. In the sample, <code>mService</code> is an instance of the <code>MarketBillingService</code> interface.</p>
+<p>To retrieve transaction information for a purchase or refund you must specify five keys in the
+request {@link android.os.Bundle}. The following code sample shows how to set these keys and make
+the request. In the sample, <code>mService</code> is an instance of the
+<code>MarketBillingService</code> interface.</p>
 
 <pre>
 /**
@@ -468,15 +681,36 @@
   // Do something with this response.
 }
 </pre>
-<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional keys are then added to the bundle prior to invoking the <code>sendBillingRequest()</code> method. The <code>REQUEST_NONCE</code> key contains a cryptographically secure nonce (number used once) that you must generate. The Android Market application returns this nonce with the <code>PURCHASE_STATE_CHANGED</code> broadcast intent so you can verify the integrity of the transaction information. The <code>NOTIFY_IDS</code> key contains an array of notification IDs, which you received in the <code>IN_APP_NOTIFY</code> broadcast intent.</p>
+<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the
+three keys that are required for all requests: <code>BILLING_REQUEST</code>,
+<code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional keys are then added to the
+bundle prior to invoking the <code>sendBillingRequest()</code> method. The
+<code>REQUEST_NONCE</code> key contains a cryptographically secure nonce (number used once) that you
+must generate. The Android Market application returns this nonce with the
+<code>PURCHASE_STATE_CHANGED</code> broadcast intent so you can verify the integrity of the
+transaction information. The <code>NOTIFY_IDS</code> key contains an array of notification IDs,
+which you received in the <code>IN_APP_NOTIFY</code> broadcast intent.</p>
 
-<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys: <code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique request identifier for the request.</p>
+<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys:
+<code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides
+you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique
+request identifier for the request.</p>
 
-<p>A <code>GET_PURCHASE_INFORMATION</code> request also triggers two asynchronous responses (broadcast intents). First, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent, which provides status and error information about the request. Next, if the request was successful, the Android Market application sends a <code>PURCHASE_STATE_CHANGED</code> broadcast intent. This message contains detailed transaction information. The transaction information is contained in a signed JSON string (unencrypted). The message includes the signature so you can verify the integrity of the signed string.</p>
+<p>A <code>GET_PURCHASE_INFORMATION</code> request also triggers two asynchronous responses
+(broadcast intents). First, the Android Market application sends a <code>RESPONSE_CODE</code>
+broadcast intent, which provides status and error information about the request. Next, if the
+request was successful, the Android Market application sends a <code>PURCHASE_STATE_CHANGED</code>
+broadcast intent. This message contains detailed transaction information. The transaction
+information is contained in a signed JSON string (unencrypted). The message includes the signature
+so you can verify the integrity of the signed string.</p>
 
 <h4>Acknowledging transaction information (CONFIRM_NOTIFICATIONS)</h4>
 
-<p>To acknowledge that you received transaction information you send a <code>CONFIRM_NOTIFICATIONS</code> request. You must specify four keys in the request {@link android.os.Bundle}. The following code sample shows how to set these keys and make the request. In the sample, <code>mService</code> is an instance of the <code>MarketBillingService</code> interface.</p>
+<p>To acknowledge that you received transaction information you send a
+<code>CONFIRM_NOTIFICATIONS</code> request. You must specify four keys in the request {@link
+android.os.Bundle}. The following code sample shows how to set these keys and make the request. In
+the sample, <code>mService</code> is an instance of the <code>MarketBillingService</code>
+interface.</p>
 
 <pre>
 /**
@@ -488,17 +722,35 @@
   // Do something with this response.
 }
 </pre>
-<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional <code>NOTIFY_IDS</code> key is then added to the bundle prior to invoking the <code>sendBillingRequest()</code> method. The <code>NOTIFY_IDS</code> key contains an array of notification IDs, which you received in an <code>IN_APP_NOTIFY</code> broadcast intent and also used in a <code>GET_PURCHASE_INFORMATION</code> request.</p>
+<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the
+three keys that are required for all requests: <code>BILLING_REQUEST</code>,
+<code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional <code>NOTIFY_IDS</code> key
+is then added to the bundle prior to invoking the <code>sendBillingRequest()</code> method. The
+<code>NOTIFY_IDS</code> key contains an array of notification IDs, which you received in an
+<code>IN_APP_NOTIFY</code> broadcast intent and also used in a <code>GET_PURCHASE_INFORMATION</code>
+request.</p>
 
-<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys: <code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique request identifier for the request.</p>
+<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys:
+<code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides
+you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique
+request identifier for the request.</p>
 
-<p>A <code>CONFIRM_NOTIFICATIONS</code> request triggers a single asynchronous response&mdash;a <code>RESPONSE_CODE</code> broadcast intent. This broadcast intent provides status and error information about the request.</p>
+<p>A <code>CONFIRM_NOTIFICATIONS</code> request triggers a single asynchronous response&mdash;a
+<code>RESPONSE_CODE</code> broadcast intent. This broadcast intent provides status and error
+information about the request.</p>
 
-<p class="note"><strong>Note:</strong> As a best practice, you should not send a <code>CONFIRM_NOTIFICATIONS</code> request for a purchased item until you have delivered the item to the user. This way, if your application crashes or something else prevents your application from delivering the product, your application will still receive an <code>IN_APP_NOTIFY</code> broadcast intent from Android Market indicating that you need to deliver the product.</p>
+<p class="note"><strong>Note:</strong> As a best practice, you should not send a
+<code>CONFIRM_NOTIFICATIONS</code> request for a purchased item until you have delivered the item to
+the user. This way, if your application crashes or something else prevents your application from
+delivering the product, your application will still receive an <code>IN_APP_NOTIFY</code> broadcast
+intent from Android Market indicating that you need to deliver the product.</p>
 
 <h4>Restoring transaction information (RESTORE_TRANSACTIONS)</h4>
 
-<p>To restore a user's transaction information, you send a <code>RESTORE_TRANSACTIONS</code> request. You must specify four keys in the request {@link android.os.Bundle}. The following code sample shows how to set these keys and make the request. In the sample, <code>mService</code> is an instance of the <code>MarketBillingService</code> interface.</p>
+<p>To restore a user's transaction information, you send a <code>RESTORE_TRANSACTIONS</code>
+request. You must specify four keys in the request {@link android.os.Bundle}. The following code
+sample shows how to set these keys and make the request. In the sample, <code>mService</code> is an
+instance of the <code>MarketBillingService</code> interface.</p>
 
 <pre>
 /**
@@ -510,36 +762,73 @@
   // Do something with this response.
 }
 </pre>
-<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the three keys that are required for all requests: <code>BILLING_REQUEST</code>, <code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional <code>REQUEST_NONCE</code> key is then added to the bundle prior to invoking the <code>sendBillingRequest()</code> method. The <code>REQUEST_NONCE</code> key contains a cryptographically secure nonce (number used once) that you must generate. The Android Market application returns this nonce with the transactions information contained in the <code>PURCHASE_STATE_CHANGED</code> broadcast intent so you can verify the integrity of the transaction information.</p>
+<p>The <code>makeRequestBundle()</code> method constructs an initial Bundle, which contains the
+three keys that are required for all requests: <code>BILLING_REQUEST</code>,
+<code>API_VERSION</code>, and <code>PACKAGE_NAME</code>. The additional <code>REQUEST_NONCE</code>
+key is then added to the bundle prior to invoking the <code>sendBillingRequest()</code> method. The
+<code>REQUEST_NONCE</code> key contains a cryptographically secure nonce (number used once) that you
+must generate. The Android Market application returns this nonce with the transactions information
+contained in the <code>PURCHASE_STATE_CHANGED</code> broadcast intent so you can verify the
+integrity of the transaction information.</p>
 
-<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys: <code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique request identifier for the request.</p>
+<p>The request returns a synchronous {@link android.os.Bundle} response, which contains two keys:
+<code>RESPONSE_CODE</code> and <code>REQUEST_ID</code>. The <code>RESPONSE_CODE</code> key provides
+you with the status of the request and the <code>REQUEST_ID</code> key provides you with a unique
+request identifier for the request.</p>
 
-<p>A <code>RESTORE_TRANSACTIONS</code> request also triggers two asynchronous responses (broadcast intents). First, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent, which provides status and error information about the request. Next, if the request was successful, the Android Market application sends a <code>PURCHASE_STATE_CHANGED</code> broadcast intent. This message contains the detailed transaction information. The transaction information is contained in a signed JSON string (unencrypted). The message includes the signature so you can verify the integrity of the signed string.</p>
-
+<p>A <code>RESTORE_TRANSACTIONS</code> request also triggers two asynchronous responses (broadcast
+intents). First, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent,
+which provides status and error information about the request. Next, if the request was successful,
+the Android Market application sends a <code>PURCHASE_STATE_CHANGED</code> broadcast intent. This
+message contains the detailed transaction information. The transaction information is contained in a
+signed JSON string (unencrypted). The message includes the signature so you can verify the integrity
+of the signed string.</p>
 
 <h3>Other service tasks</h3>
 
-<p>You may also want your {@link android.app.Service} to receive intent messages from your {@link android.content.BroadcastReceiver}. You can use these intent messages to convey the information that was sent asynchronously from the Android Market application to your {@link android.content.BroadcastReceiver}. To see an example of how you can send and receive these intent messages, see the <code>BillingReceiver.java</code> and <code>BillingService.java</code> files in the sample application. You can use these samples as a basis for your own implementation. However, if you use any of the code from the sample application, be sure you follow the guidelines in <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
+<p>You may also want your {@link android.app.Service} to receive intent messages from your {@link
+android.content.BroadcastReceiver}. You can use these intent messages to convey the information that
+was sent asynchronously from the Android Market application to your {@link
+android.content.BroadcastReceiver}. To see an example of how you can send and receive these intent
+messages, see the <code>BillingReceiver.java</code> and <code>BillingService.java</code> files in
+the sample application. You can use these samples as a basis for your own implementation. However,
+if you use any of the code from the sample application, be sure you follow the guidelines in <a
+href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
 
 <h2 id="billing-broadcast-receiver">Creating a BroadcastReceiver</h2>
 
-<p>The Android Market application uses broadcast intents to send asynchronous billing responses to your application. To receive these intent messages, you need to create a {@link android.content.BroadcastReceiver} that can handle the following intents:</p>
+<p>The Android Market application uses broadcast intents to send asynchronous billing responses to
+your application. To receive these intent messages, you need to create a {@link
+android.content.BroadcastReceiver} that can handle the following intents:</p>
 
 <ul>
   <li>com.android.vending.billing.RESPONSE_CODE
-  <p>This broadcast intent contains an Android Market response code, and is sent after you make an in-app billing request. For more information about the response codes that are sent with this response, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-codes">Android Market Response Codes for In-app Billing</a>.</p>
+  <p>This broadcast intent contains an Android Market response code, and is sent after you make an
+  in-app billing request. For more information about the response codes that are sent with this
+  response, see <a
+  href="{@docRoot}guide/market/billing/billing_reference.html#billing-codes">Android Market Response
+  Codes for In-app Billing</a>.</p>
   </li>
   <li>com.android.vending.billing.IN_APP_NOTIFY
-  <p>This response indicates that a purchase has changed state, which means a purchase succeeded, was canceled, or was refunded. For more information about notification messages, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing Broadcast Intents</a></p>
+  <p>This response indicates that a purchase has changed state, which means a purchase succeeded,
+  was canceled, or was refunded. For more information about notification messages, see <a
+  href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing
+  Broadcast Intents</a></p>
   </li>
   <li>com.android.vending.billing.PURCHASE_STATE_CHANGED
-  <p>This broadcast intent contains detailed information about one or more transactions. For more information about purchase state messages, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing Broadcast Intents</a></p>
+  <p>This broadcast intent contains detailed information about one or more transactions. For more
+  information about purchase state messages, see <a
+  href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing
+  Broadcast Intents</a></p>
   </li>
 </ul>
 
-<p>Each of these broadcast intents provide intent extras, which your {@link android.content.BroadcastReceiver} must handle. The intent extras are listed in the following table (see table 1).</p>
+<p>Each of these broadcast intents provide intent extras, which your {@link
+android.content.BroadcastReceiver} must handle. The intent extras are listed in the following table
+(see table 1).</p>
 
-<p class="table-caption"><strong>Table 1.</strong> Description of broadcast intent extras that are sent in response to billing requests.</p>
+<p class="table-caption"><strong>Table 1.</strong> Description of broadcast intent extras that are
+sent in response to billing requests.</p>
 
 <table>
 
@@ -551,7 +840,8 @@
 <tr>
   <td><code>com.android.vending.billing.RESPONSE_CODE</code></td>
   <td><code>request_id</code></td>
-  <td>A <code>long</code> representing a request ID. A request ID identifies a specific billing request and is returned by Android Market at the time a request is made.</td>
+  <td>A <code>long</code> representing a request ID. A request ID identifies a specific billing
+  request and is returned by Android Market at the time a request is made.</td>
 </tr>
 <tr>
   <td><code>com.android.vending.billing.RESPONSE_CODE</code></td>
@@ -561,12 +851,17 @@
 <tr>
   <td><code>com.android.vending.billing.IN_APP_NOTIFY</code></td>
   <td><code>notification_id</code></td>
-  <td>A <code>String</code> representing the notification ID for a given purchase state change. Android Market notifies you when there is a purchase state change and the notification includes a unique notification ID. To get the details of the purchase state change, you send the notification ID with the <code>GET_PURCHASE_INFORMATION</code> request.</td>
+  <td>A <code>String</code> representing the notification ID for a given purchase state change.
+  Android Market notifies you when there is a purchase state change and the notification includes a
+  unique notification ID. To get the details of the purchase state change, you send the notification
+  ID with the <code>GET_PURCHASE_INFORMATION</code> request.</td>
 </tr>
 <tr>
   <td><code>com.android.vending.billing.PURCHASE_STATE_CHANGED</code></td>
   <td><code>inapp_signed_data</code></td>
-  <td>A <code>String</code> representing the signed JSON string. The JSON string contains information about the billing transaction, such as order number, amount, and the item that was purchased or refunded.</td>
+  <td>A <code>String</code> representing the signed JSON string. The JSON string contains
+  information about the billing transaction, such as order number, amount, and the item that was
+  purchased or refunded.</td>
 </tr>
 <tr>
   <td><code>com.android.vending.billing.PURCHASE_STATE_CHANGED</code></td>
@@ -575,7 +870,9 @@
 </tr>
 </table>
 
-<p>The following code sample shows how to handle these broadcast intents and intent extras within a {@link android.content.BroadcastReceiver}. The BroadcastReceiver in this case is named <code>BillingReceiver</code>, just as it is in the sample application.</p>
+<p>The following code sample shows how to handle these broadcast intents and intent extras within a
+{@link android.content.BroadcastReceiver}. The BroadcastReceiver in this case is named
+<code>BillingReceiver</code>, just as it is in the sample application.</p>
 
 <pre>
 public class BillingReceiver extends BroadcastReceiver {
@@ -623,13 +920,28 @@
 }
 </pre>
 
-<p>In addition to receiving broadcast intents from the Android Market application, your {@link android.content.BroadcastReceiver} must handle the information it received in the broadcast intents. Usually, your {@link android.content.BroadcastReceiver} does this by sending the information to a local service (discussed in the next section). The <code>BillingReceiver.java</code> file in the sample application shows you how to do this. You can use this sample as a basis for your own {@link android.content.BroadcastReceiver}. However, if you use any of the code from the sample application, be sure you follow the guidelines that are discussed in <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design </a>.</p>
+<p>In addition to receiving broadcast intents from the Android Market application, your {@link
+android.content.BroadcastReceiver} must handle the information it received in the broadcast intents.
+Usually, your {@link android.content.BroadcastReceiver} does this by sending the information to a
+local service (discussed in the next section). The <code>BillingReceiver.java</code> file in the
+sample application shows you how to do this. You can use this sample as a basis for your own {@link
+android.content.BroadcastReceiver}. However, if you use any of the code from the sample application,
+be sure you follow the guidelines that are discussed in <a
+href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design </a>.</p>
 
 <h2 id="billing-signatures">Verifying Signatures and Nonces</h2>
 
-<p>Android Market's in-app billing service uses two mechanisms to help verify the integrity of the transaction information you receive from Android Market: nonces and signatures. A nonce (number used once) is a cryptographically secure number that your application generates and sends with every <code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code> request. The nonce is returned with the <code>PURCHASE_STATE_CHANGED</code> broadcast intent, enabling you to verify that any given <code>PURCHASE_STATE_CHANGED</code> response corresponds to an actual request that you made. Every <code>PURCHASE_STATE_CHANGED</code> broadcast intent also includes a signed JSON string and a signature, which you can use to verify the integrity of the response.</p>
+<p>Android Market's in-app billing service uses two mechanisms to help verify the integrity of the
+transaction information you receive from Android Market: nonces and signatures. A nonce (number used
+once) is a cryptographically secure number that your application generates and sends with every
+<code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code> request. The nonce is
+returned with the <code>PURCHASE_STATE_CHANGED</code> broadcast intent, enabling you to verify that
+any given <code>PURCHASE_STATE_CHANGED</code> response corresponds to an actual request that you
+made. Every <code>PURCHASE_STATE_CHANGED</code> broadcast intent also includes a signed JSON string
+and a signature, which you can use to verify the integrity of the response.</p>
 
-<p>Your application must provide a way to generate, manage, and verify nonces. The following sample code shows some simple methods you can use to do this.</p>
+<p>Your application must provide a way to generate, manage, and verify nonces. The following sample
+code shows some simple methods you can use to do this.</p>
 
 <pre>
   private static final SecureRandom RANDOM = new SecureRandom();
@@ -650,27 +962,42 @@
   }
 </pre>
 
-<p>Your application must also provide a way to verify the signatures that accompany every <code>PURCHASE_STATE_CHANGED</code> broadcast intent. The <code>Security.java</code> file in the sample application shows you how to do this. If you use this file as a basis for your own security implementation, be sure to follow the guidelines in <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a> and obfuscate your code.</p>
+<p>Your application must also provide a way to verify the signatures that accompany every
+<code>PURCHASE_STATE_CHANGED</code> broadcast intent. The <code>Security.java</code> file in the
+sample application shows you how to do this. If you use this file as a basis for your own security
+implementation, be sure to follow the guidelines in <a
+href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a> and
+obfuscate your code.</p>
 
-<p>You will need to use your Android Market public key to perform the signature verification. The following procedure shows you how to retrieve Base64-encoded public key from the Android Market publisher site.</p>
+<p>You will need to use your Android Market public key to perform the signature verification. The
+following procedure shows you how to retrieve Base64-encoded public key from the Android Market
+publisher site.</p>
 
 <ol>
   <li>Log in to your <a href="http://market.android.com/publish">publisher account</a>.</li>
   <li>On the upper left part of the page, under your name, click <strong>Edit profile</strong>.</li>
-  <li>On the Edit Profile page, scroll down to the Licensing &amp; In-app Billing panel (see figure 2).</li>
+  <li>On the Edit Profile page, scroll down to the Licensing &amp; In-app Billing panel (see figure
+  2).</li>
   <li>Copy your public key.</li>
 </ol>
 
-<p class="caution"><strong>Important</strong>: To keep your public key safe from malicious users and hackers, do not embed your public key as an entire literal string. Instead, construct the string at runtime from pieces or use bit manipulation (for example, XOR with some other string) to hide the actual key. The key itself is not secret information, but you do not want to make it easy for a hacker or malicious user to replace the public key with another key.</p>
+<p class="caution"><strong>Important</strong>: To keep your public key safe from malicious users and
+hackers, do not embed your public key as an entire literal string. Instead, construct the string at
+runtime from pieces or use bit manipulation (for example, XOR with some other string) to hide the
+actual key. The key itself is not secret information, but you do not want to make it easy for a
+hacker or malicious user to replace the public key with another key.</p>
 
 <img src="{@docRoot}images/billing_public_key.png" height="510" id="figure2" />
 <p class="img-caption">
-  <strong>Figure 2.</strong> The Licensing and In-app Billing panel of your account's Edit Profile page lets you see your public key.
+  <strong>Figure 2.</strong> The Licensing and In-app Billing panel of your account's Edit Profile
+  page lets you see your public key.
 </p>
 
 <h2 id="billing-implement">Modifying Your Application Code</h2>
 
-<p>After you finish adding in-app billing components to your project, you are ready to modify your application's code. For a typical implementation, like the one that is demonstrated in the sample application, this means you need to write code to do the following: </p>
+<p>After you finish adding in-app billing components to your project, you are ready to modify your
+application's code. For a typical implementation, like the one that is demonstrated in the sample
+application, this means you need to write code to do the following: </p>
 
 <ul>
   <li>Create a storage mechanism for storing users' purchase information.</li>
@@ -681,13 +1008,26 @@
 
 <h3>Creating a storage mechanism for storing purchase information</h3>
 
-<p>You must set up a database or some other mechanism for storing users' purchase information. The sample application provides an example database (PurchaseDatabase.java); however, the example database has been simplified for clarity and does not exhibit the security best practices that we recommend. If you have a remote server, we recommend that you store purchase information on your server instead of in a local database on a device. For more information about security best practices, see <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
+<p>You must set up a database or some other mechanism for storing users' purchase information. The
+sample application provides an example database (PurchaseDatabase.java); however, the example
+database has been simplified for clarity and does not exhibit the security best practices that we
+recommend. If you have a remote server, we recommend that you store purchase information on your
+server instead of in a local database on a device. For more information about security best
+practices, see <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+Design</a>.</p>
 
-<p class="note"><strong>Note</strong>: If you store any purchase information on a device, be sure to encrypt the data and use a device-specific encryption key.</p>
+<p class="note"><strong>Note</strong>: If you store any purchase information on a device, be sure to
+encrypt the data and use a device-specific encryption key.</p>
 
 <h3>Creating a user interface for selecting items</h3>
 
-<p>You must provide users with a means for selecting items that they want to purchase. Android Market provides the checkout user interface (which is where the user provides a form of payment and approves the purchase), but your application must provide a control (widget) that invokes the <code>sendBillingRequest()</code> method when a user selects an item for purchase.</p>
+<p>You must provide users with a means for selecting items that they want to purchase. Android
+Market provides the checkout user interface (which is where the user provides a form of payment and
+approves the purchase), but your application must provide a control (widget) that invokes the
+<code>sendBillingRequest()</code> method when a user selects an item for purchase.</p>
 
-<p>You can render the control and trigger the <code>sendBillingRequest()</code> method any way you want. The sample application uses a spinner widget and a button to present items to a user and trigger a billing request (see <code>Dungeons.java</code>). The user interface also shows a list of recently purchased items.</p>
+<p>You can render the control and trigger the <code>sendBillingRequest()</code> method any way you
+want. The sample application uses a spinner widget and a button to present items to a user and
+trigger a billing request (see <code>Dungeons.java</code>). The user interface also shows a list of
+recently purchased items.</p>
 
diff --git a/docs/html/guide/market/billing/billing_overview.jd b/docs/html/guide/market/billing/billing_overview.jd
index feac5b0..a42b772 100755
--- a/docs/html/guide/market/billing/billing_overview.jd
+++ b/docs/html/guide/market/billing/billing_overview.jd
@@ -20,110 +20,210 @@
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
     <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
 </div>
 </div>
 
-<p>Android Market In-app Billing is an Android Market service that provides checkout processing for in-app purchases. To use the service, your application sends a billing request for a specific in-app product. The service then handles all of the checkout details for the transaction, including requesting and validating the form of payment and processing the financial transaction. When the checkout process is complete, the service sends your application the purchase details, such as the order number, the order date and time, and the price paid. At no point does your application have to handle any financial transactions; that role is provided by Android Market's in-app billing service.</p>
+<p>Android Market In-app Billing is an Android Market service that provides checkout processing for
+in-app purchases. To use the service, your application sends a billing request for a specific in-app
+product. The service then handles all of the checkout details for the transaction, including
+requesting and validating the form of payment and processing the financial transaction. When the
+checkout process is complete, the service sends your application the purchase details, such as the
+order number, the order date and time, and the price paid. At no point does your application have to
+handle any financial transactions; that role is provided by Android Market's in-app billing
+service.</p>
 
 <h2 id="billing-arch">In-app Billing Architecture</h2>
 
-<p>In-app billing uses an asynchronous message loop to convey billing requests and billing responses between your application and the Android Market server. In practice, your application never directly communicates with the Android Market server (see figure 1). Instead, your application sends billing requests to the Android Market application over interprocess communication (IPC) and receives purchase responses from the Android Market application in the form of asynchronous broadcast intents. Your application does not manage any network connections between itself and the Android Market server or use any special APIs from the Android platform.</p>
+<p>In-app billing uses an asynchronous message loop to convey billing requests and billing responses
+between your application and the Android Market server. In practice, your application never directly
+communicates with the Android Market server (see figure 1). Instead, your application sends billing
+requests to the Android Market application over interprocess communication (IPC) and receives
+purchase responses from the Android Market application in the form of asynchronous broadcast
+intents. Your application does not manage any network connections between itself and the Android
+Market server or use any special APIs from the Android platform.</p>
 
-<p>Some in-app billing implementations may also use a private remote server to deliver content or validate transactions, but a remote server is not required to implement in-app billing. A remote server can be useful if you are selling digital content that needs to be delivered to a user's device, such as media files or photos. You might also use a remote server to store users' transaction history or perform various in-app billing security tasks, such as signature verification. Although you can handle all security-related tasks in your application, performing those tasks on a remote server is recommended because it helps make your application less vulnerable to security attacks.</p>
+<p>Some in-app billing implementations may also use a private remote server to deliver content or
+validate transactions, but a remote server is not required to implement in-app billing. A remote
+server can be useful if you are selling digital content that needs to be delivered to a user's
+device, such as media files or photos. You might also use a remote server to store users'
+transaction history or perform various in-app billing security tasks, such as signature
+verification. Although you can handle all security-related tasks in your application, performing
+those tasks on a remote server is recommended because it helps make your application less vulnerable
+to security attacks.</p>
 
 <div class="figure" style="width:440px">
 <img src="{@docRoot}images/billing_arch.png" alt="" height="582" />
 <p class="img-caption">
-  <strong>Figure 1.</strong> Your application sends and receives billing messages through the Android Market application, which handles all communication with the Android Market server.</p>
+  <strong>Figure 1.</strong> Your application sends and receives billing messages through the
+  Android Market application, which handles all communication with the Android Market server.</p>
 </div>
 
 <p>A typical in-app billing implementation relies on three components:</p>
 <ul>
-  <li>A {@link android.app.Service} (named <code>BillingService</code> in the sample application), which processes purchase messages from the application and sends billing requests to Android Market's in-app billing service.</li>
-  <li>A {@link android.content.BroadcastReceiver} (named <code>BillingReceiver</code> in the sample application), which receives all asynchronous billing responses from the Android Market application.</li>
-  <li>A security component (named <code>Security</code> in the sample application), which performs security-related tasks, such as signature verification and nonce generation. For more information about in-app billing security, see <a href="#billing-security">Security controls</a> later in this document.</li>
+  <li>A {@link android.app.Service} (named <code>BillingService</code> in the sample application),
+  which processes purchase messages from the application and sends billing requests to Android
+  Market's in-app billing service.</li>
+  <li>A {@link android.content.BroadcastReceiver} (named <code>BillingReceiver</code> in the sample
+  application), which receives all asynchronous billing responses from the Android Market
+  application.</li>
+  <li>A security component (named <code>Security</code> in the sample application), which performs
+  security-related tasks, such as signature verification and nonce generation. For more information
+  about in-app billing security, see <a href="#billing-security">Security controls</a> later in this
+  document.</li>
 </ul>
 
 <p>You may also want to incorporate two other components to support in-app billing:</p>
 <ul>
-  <li>A response {@link android.os.Handler} (named <code>ResponseHandler</code> in the sample application), which provides application-specific processing of purchase notifications, errors, and other status messages.</li>
-  <li>An observer (named <code>PurchaseObserver</code> in the sample application), which is responsible for sending callbacks to your application so you can update your user interface with purchase information and status.</li>
+  <li>A response {@link android.os.Handler} (named <code>ResponseHandler</code> in the sample
+  application), which provides application-specific processing of purchase notifications, errors,
+  and other status messages.</li>
+  <li>An observer (named <code>PurchaseObserver</code> in the sample application), which is
+  responsible for sending callbacks to your application so you can update your user interface with
+  purchase information and status.</li>
 </ul>
 
-<p>In addition to these components, your application must provide a way to store information about users' purchases and some sort of user interface that lets users select items to purchase. You do not need to provide a checkout user interface. When a user initiates an in-app purchase, the Android Market application presents the checkout user interface to your user. When the user completes the checkout process, your application resumes.</p>
+<p>In addition to these components, your application must provide a way to store information about
+users' purchases and some sort of user interface that lets users select items to purchase. You do
+not need to provide a checkout user interface. When a user initiates an in-app purchase, the Android
+Market application presents the checkout user interface to your user. When the user completes the
+checkout process, your application resumes.</p>
 
 <h2 id="billing-msgs">In-app Billing Messages</h2>
 
-<p>When the user initiates a purchase, your application sends billing messages to Android Market's in-app billing service (named <code>MarketBillingService</code>) using simple IPC method calls. The Android Market application responds to all billing requests synchronously, providing your application with status notifications and other information. The Android Market application also responds to some billing requests asynchronously, providing your application with error messages and detailed transaction information. The following section describes the basic request-response messaging that takes place between your application and the Android Market application.</p>
+<p>When the user initiates a purchase, your application sends billing messages to Android Market's
+in-app billing service (named <code>MarketBillingService</code>) using simple IPC method calls. The
+Android Market application responds to all billing requests synchronously, providing your
+application with status notifications and other information. The Android Market application also
+responds to some billing requests asynchronously, providing your application with error messages and
+detailed transaction information. The following section describes the basic request-response
+messaging that takes place between your application and the Android Market application.</p>
 
 <h3 id="billing-request">In-app billing requests</h3>
 
-<p>Your application sends in-app billing requests by invoking a single IPC method (<code>sendBillingRequest()</code>), which is exposed by the <code>MarketBillingService</code> interface. This interface is defined in an <a href="{@docRoot}guide/developing/tools/aidl.html">Android Interface Definition Language</a> file (<code>IMarketBillingService.aidl</code>). You can <a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">download</a> this AIDL file with the in-app billing sample application.</p>
+<p>Your application sends in-app billing requests by invoking a single IPC method
+(<code>sendBillingRequest()</code>), which is exposed by the <code>MarketBillingService</code>
+interface. This interface is defined in an <a
+href="{@docRoot}guide/developing/tools/aidl.html">Android Interface Definition Language</a> file
+(<code>IMarketBillingService.aidl</code>). You can <a
+href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">download</a> this AIDL
+file with the in-app billing sample application.</p>
 
-<p>The <code>sendBillingRequest()</code> method has a single {@link android.os.Bundle} parameter. The Bundle that you deliver must include several key-value pairs that specify various parameters for the request, such as the type of billing request you are making, the item that is being purchased, and the application that is making the request. For more information about the Bundle keys that are sent with a request, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-interface">In-app Billing Service Interface</a>.
+<p>The <code>sendBillingRequest()</code> method has a single {@link android.os.Bundle} parameter.
+The Bundle that you deliver must include several key-value pairs that specify various parameters for
+the request, such as the type of billing request you are making, the item that is being purchased,
+and the application that is making the request. For more information about the Bundle keys that are
+sent with a request, see <a
+href="{@docRoot}guide/market/billing/billing_reference.html#billing-interface">In-app Billing
+Service Interface</a>.
 
-<p>One of the most important keys that every request Bundle must have is the <code>BILLING_REQUEST</code> key. This key lets you specify the type of billing request you are making. Android Market's in-app billing service supports the following five types of billing requests:</p>
+<p>One of the most important keys that every request Bundle must have is the
+<code>BILLING_REQUEST</code> key. This key lets you specify the type of billing request you are
+making. Android Market's in-app billing service supports the following five types of billing
+requests:</p>
 
 <ul>
   <li><code>CHECK_BILLING_SUPPORTED</code>
-    <p>This request verifies that the Android Market application supports in-app billing. You usually send this request when your application first starts up. This request is useful if you want to enable or disable certain UI features that are relevant only to in-app billing.</p>
+    <p>This request verifies that the Android Market application supports in-app billing. You
+    usually send this request when your application first starts up. This request is useful if you
+    want to enable or disable certain UI features that are relevant only to in-app billing.</p>
   </li>
   <li><code>REQUEST_PURCHASE</code>
-    <p>This request sends a purchase message to the Android Market application and is the foundation of in-app billing. You send this request when a user indicates that he or she wants to purchase an item in your application. Android Market then handles the financial transaction by displaying the checkout user interface.</p>
+    <p>This request sends a purchase message to the Android Market application and is the foundation
+    of in-app billing. You send this request when a user indicates that he or she wants to purchase
+    an item in your application. Android Market then handles the financial transaction by displaying
+    the checkout user interface.</p>
   </li>
   <li><code>GET_PURCHASE_INFORMATION</code>
-    <p>This request retrieves the details of a purchase state change. A purchase changes state when a requested purchase is billed successfully or when a user cancels a transaction during checkout. It can also occur when a previous purchase is refunded. Android Market notifies your application when a purchase changes state, so you only need to send this request when there is transaction information to retrieve.</p>
+    <p>This request retrieves the details of a purchase state change. A purchase changes state when
+    a requested purchase is billed successfully or when a user cancels a transaction during
+    checkout. It can also occur when a previous purchase is refunded. Android Market notifies your
+    application when a purchase changes state, so you only need to send this request when there is
+    transaction information to retrieve.</p>
   </li>
   <li><code>CONFIRM_NOTIFICATIONS</code>
-    <p>This request acknowledges that your application received the details of a purchase state change. Android Market sends purchase state change notifications to your application until you confirm that you received them.</p>
+    <p>This request acknowledges that your application received the details of a purchase state
+    change. Android Market sends purchase state change notifications to your application until you
+    confirm that you received them.</p>
   </li>
   <li><code>RESTORE_TRANSACTIONS</code>
-    <p>This request retrieves a user's transaction status for <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">managed purchases</a>. You should send this request only when you need to retrieve a user's transaction status, which is usually only when your application is reinstalled or installed for the first time on a device.</p>
+    <p>This request retrieves a user's transaction status for <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">managed
+    purchases</a>. You should send this request only when you need to retrieve a user's transaction
+    status, which is usually only when your application is reinstalled or installed for the first
+    time on a device.</p>
   </li>
 </ul>
 
 <h3 id="billing-response">In-app Billing Responses</h3>
 
-<p>The Android Market application responds to in-app billing requests with both synchronous and asynchronous responses. The synchronous response is a {@link android.os.Bundle} with the following three keys:</p>
+<p>The Android Market application responds to in-app billing requests with both synchronous and
+asynchronous responses. The synchronous response is a {@link android.os.Bundle} with the following
+three keys:</p>
 
 <ul>
   <li><code>RESPONSE_CODE</code>
     <p>This key provides status information and error information about a request.</p>
   </li>
   <li><code>PURCHASE_INTENT</code>
-    <p>This key provides a {@link android.app.PendingIntent}, which you use to launch the checkout activity.</p>
+    <p>This key provides a {@link android.app.PendingIntent}, which you use to launch the checkout
+    activity.</p>
   </li>
   <li><code>REQUEST_ID</code>
-    <p>This key provides you with a request identifier, which you can use to match asynchronous responses with requests.</p>
+    <p>This key provides you with a request identifier, which you can use to match asynchronous
+    responses with requests.</p>
   </li>
 </ul>
-<p>Some of these keys are not relevant to every request. For more information, see <a href="#billing-message-sequence">Messaging sequence</a> later in this document.</p>
+<p>Some of these keys are not relevant to every request. For more information, see <a
+href="#billing-message-sequence">Messaging sequence</a> later in this document.</p>
 
-<p>The asynchronous response messages are sent in the form of individual broadcast intents and include the following:</p>
+<p>The asynchronous response messages are sent in the form of individual broadcast intents and
+include the following:</p>
 
 <ul>
     <li><code>com.android.vending.billing.RESPONSE_CODE</code>
-    <p>This response contains an Android Market server response code, and is sent after you make an in-app billing request. A server response code can indicate that a billing request was successfully sent to Android Market or it can indicate that some error occurred during a billing request. This response is <em>not</em> used to report any purchase state changes (such as refund or purchase information). For more information about the response codes that are sent with this response, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-codes">Server Response Codes for In-app Billing</a>.</p>
+    <p>This response contains an Android Market server response code, and is sent after you make an
+    in-app billing request. A server response code can indicate that a billing request was
+    successfully sent to Android Market or it can indicate that some error occurred during a billing
+    request. This response is <em>not</em> used to report any purchase state changes (such as refund
+    or purchase information). For more information about the response codes that are sent with this
+    response, see <a
+    href="{@docRoot}guide/market/billing/billing_reference.html#billing-codes">Server Response Codes
+    for In-app Billing</a>.</p>
   </li>
   <li><code>com.android.vending.billing.IN_APP_NOTIFY</code>
-    <p>This response indicates that a purchase has changed state, which means a purchase succeeded, was canceled, or was refunded. This response contains one or more notification IDs. Each notification ID corresponds to a specific server-side message, and each messages contains information about one or more transactions. After your application receives an <code>IN_APP_NOTIFY</code> broadcast intent, you send a <code>GET_PURCHASE_INFORMATION</code> request with the notification IDs to retrieve message details.</p>
+    <p>This response indicates that a purchase has changed state, which means a purchase succeeded,
+    was canceled, or was refunded. This response contains one or more notification IDs. Each
+    notification ID corresponds to a specific server-side message, and each messages contains
+    information about one or more transactions. After your application receives an
+    <code>IN_APP_NOTIFY</code> broadcast intent, you send a <code>GET_PURCHASE_INFORMATION</code>
+    request with the notification IDs to retrieve message details.</p>
   </li>
   <li><code>com.android.vending.billing.PURCHASE_STATE_CHANGED</code>
-    <p>This response contains detailed information about one or more transactions. The transaction information is contained in a JSON string. The JSON string is signed and the signature is sent to your application along with the JSON string (unencrypted). To help ensure the security of your in-app billing messages, your application can verify the signature of this JSON string.</p>
+    <p>This response contains detailed information about one or more transactions. The transaction
+    information is contained in a JSON string. The JSON string is signed and the signature is sent
+    to your application along with the JSON string (unencrypted). To help ensure the security of
+    your in-app billing messages, your application can verify the signature of this JSON string.</p>
   </li>
 </ul>
 
-<p>The JSON string that is returned with the <code>PURCHASE_STATE_CHANGED</code> intent provides your application with the details of one or more billing transactions. An example of this JSON string is shown below:</p>
+<p>The JSON string that is returned with the <code>PURCHASE_STATE_CHANGED</code> intent provides
+your application with the details of one or more billing transactions. An example of this JSON
+string is shown below:</p>
 <pre class="no-pretty-print" style="color:black">
 { "nonce" : 1836535032137741465,
   "orders" :
@@ -137,34 +237,57 @@
 }
 </pre>
 
-<p>For more information about the fields in this JSON string, see <a href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing Broadcast Intents</a>.</p>
+<p>For more information about the fields in this JSON string, see <a
+href="{@docRoot}guide/market/billing/billing_reference.html#billing-intents">In-app Billing
+Broadcast Intents</a>.</p>
 
 <h3 id="billing-message-sequence">Messaging sequence</h3>
 
-<p>The messaging sequence for a typical purchase request is shown in figure 2. Request types for each <code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents are shown in <em>italic</em>. For clarity, figure 2 does not show the <code>RESPONSE_CODE</code> broadcast intents that are sent for every request.</p>
+<p>The messaging sequence for a typical purchase request is shown in figure 2. Request types for
+each <code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents
+are shown in <em>italic</em>. For clarity, figure 2 does not show the <code>RESPONSE_CODE</code>
+broadcast intents that are sent for every request.</p>
 
 <p>The basic message sequence for an in-app purchase request is as follows:</p>
 
 <ol>
-  <li>Your application sends a purchase request (<code>REQUEST_PURCHASE</code> type), specifying a product ID and other parameters.</li>
-  <li>The Android Market application sends your application a Bundle with the following keys: <code>RESPONSE_CODE</code>, <code>PURCHASE_INTENT</code>, and <code>REQUEST_ID</code>. The <code>PURCHASE_INTENT</code> key provides a {@link android.app.PendingIntent}, which your application uses to start the checkout UI for the given product ID.</li>
+  <li>Your application sends a purchase request (<code>REQUEST_PURCHASE</code> type), specifying a
+  product ID and other parameters.</li>
+  <li>The Android Market application sends your application a Bundle with the following keys:
+  <code>RESPONSE_CODE</code>, <code>PURCHASE_INTENT</code>, and <code>REQUEST_ID</code>. The
+  <code>PURCHASE_INTENT</code> key provides a {@link android.app.PendingIntent}, which your
+  application uses to start the checkout UI for the given product ID.</li>
   <li>Your application launches the pending intent, which launches the checkout UI.</li>
-  <li>When the checkout flow finishes (that is, the user successfully purchases the item or cancels the purchase), Android Market sends your application a notification message (an <code>IN_APP_NOTIFY</code> broadcast intent). The notification message includes a notification ID, which references the transaction.</li>
-  <li>Your application requests the transaction information by sending a <code>GET_PURCHASE_STATE_CHANGED</code> request, specifying the notification ID for the transaction.</li>
-  <li>The Android Market application sends a Bundle with a <code>RESPONSE_CODE</code> key and a  <code>REQUEST_ID</code> key.
-  <li>Android Market sends the transaction information to your application in a <code>PURCHASE_STATE_CHANGED</code> broadcast intent.</li>
-  <li>Your application confirms that you received the transaction information for the given notification ID by sending a confirmation message (<code>CONFIRM_NOTIFICATIONS</code> type), specifying the notification ID for which you received transaction information.</li>
-  <li>The Android Market application sends your application a Bundle with a <code>RESPONSE_CODE</code> key and a <code>REQUEST_ID</code> key.</li>
+  <li>When the checkout flow finishes (that is, the user successfully purchases the item or cancels
+  the purchase), Android Market sends your application a notification message (an
+  <code>IN_APP_NOTIFY</code> broadcast intent). The notification message includes a notification ID,
+  which references the transaction.</li>
+  <li>Your application requests the transaction information by sending a
+  <code>GET_PURCHASE_STATE_CHANGED</code> request, specifying the notification ID for the
+  transaction.</li>
+  <li>The Android Market application sends a Bundle with a <code>RESPONSE_CODE</code> key and a 
+  <code>REQUEST_ID</code> key.
+  <li>Android Market sends the transaction information to your application in a
+  <code>PURCHASE_STATE_CHANGED</code> broadcast intent.</li>
+  <li>Your application confirms that you received the transaction information for the given
+  notification ID by sending a confirmation message (<code>CONFIRM_NOTIFICATIONS</code> type),
+  specifying the notification ID for which you received transaction information.</li>
+  <li>The Android Market application sends your application a Bundle with a
+  <code>RESPONSE_CODE</code> key and a <code>REQUEST_ID</code> key.</li>
 </ol>
 
-<p class="note"><strong>Note:</strong> You must launch the pending intent from an activity context and not an application context.</p>
+<p class="note"><strong>Note:</strong> You must launch the pending intent from an activity context
+and not an application context.</p>
 
 <img src="{@docRoot}images/billing_request_purchase.png" height="231" id="figure2" />
 <p class="img-caption">
   <strong>Figure 2.</strong> Message sequence for a purchase request.
 </p>
 
-<p>The messaging sequence for a restore transaction request is shown in figure 3. Request types for each <code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents are shown in <em>italic</em>. For clarity, figure 3 does not show the <code>RESPONSE_CODE</code> broadcast intents that are sent for every request.</p>
+<p>The messaging sequence for a restore transaction request is shown in figure 3. Request types for
+each <code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents
+are shown in <em>italic</em>. For clarity, figure 3 does not show the <code>RESPONSE_CODE</code>
+broadcast intents that are sent for every request.</p>
 
 <div class="figure" style="width:490px">
 <img src="{@docRoot}images/billing_restore_transactions.png" alt="" height="168" />
@@ -173,11 +296,20 @@
 </p>
 </div>
 
-<p>The request triggers three responses. The first is a {@link android.os.Bundle} with a <code>RESPONSE_CODE</code> key and a <code>REQUEST_ID</code> key. Next, the Android Market application sends a <code>RESPONSE_CODE</code> broadcast intent, which provides status information or error information about the request. As always, the <code>RESPONSE_CODE</code> message references a specific request ID, so you can determine which request a <code>RESPONSE_CODE</code> message pertains to.</p>
+<p>The request triggers three responses. The first is a {@link android.os.Bundle} with a
+<code>RESPONSE_CODE</code> key and a <code>REQUEST_ID</code> key. Next, the Android Market
+application sends a <code>RESPONSE_CODE</code> broadcast intent, which provides status information
+or error information about the request. As always, the <code>RESPONSE_CODE</code> message references
+a specific request ID, so you can determine which request a <code>RESPONSE_CODE</code> message
+pertains to.</p>
 
-<p>The <code>RESTORE_TRANSACTIONS</code> request type also triggers a <code>PURCHASE_STATE_CHANGED</code> broadcast intent, which contains the same type of transaction information that is sent during a purchase request, although you do not need to respond to this intent with a <code>CONFIRM_NOTIFICATIONS</code> message.</p>
+<p>The <code>RESTORE_TRANSACTIONS</code> request type also triggers a
+<code>PURCHASE_STATE_CHANGED</code> broadcast intent, which contains the same type of transaction
+information that is sent during a purchase request, although you do not need to respond to this
+intent with a <code>CONFIRM_NOTIFICATIONS</code> message.</p>
 
-<p>The messaging sequence for checking whether in-app billing is supported is shown in figure 4. The request type for the <code>sendBillingRequest()</code> method is shown in <strong>bold</strong>.</p>
+<p>The messaging sequence for checking whether in-app billing is supported is shown in figure 4. The
+request type for the <code>sendBillingRequest()</code> method is shown in <strong>bold</strong>.</p>
 
 <div class="figure" style="width:454px">
 <img src="{@docRoot}images/billing_check_supported.png" alt="" height="168" />
@@ -186,15 +318,43 @@
 </p>
 </div>
 
-<p>The synchronous response for a <code>CHECK_BILLING_SUPPORTED</code> request provides a Bundle with a server response code.  A <code>RESULT_OK</code> response code indicates that in-app billing is supported; a <code>RESULT_BILLING_UNAVAILABLE</code> response code indicates that in-app billing is unavailable because the API version you specified is unrecognized or the user is not eligible to make in-app purchases (for example, the user resides in a country that does not allow in-app billing). A <code>SERVER_ERROR</code> can also be returned, indicating that there was a problem with the Android Market server.</p>
+<p>The synchronous response for a <code>CHECK_BILLING_SUPPORTED</code> request provides a Bundle
+with a server response code.  A <code>RESULT_OK</code> response code indicates that in-app billing
+is supported; a <code>RESULT_BILLING_UNAVAILABLE</code> response code indicates that in-app billing
+is unavailable because the API version you specified is unrecognized or the user is not eligible to
+make in-app purchases (for example, the user resides in a country that does not allow in-app
+billing). A <code>SERVER_ERROR</code> can also be returned, indicating that there was a problem with
+the Android Market server.</p>
 
 <h3 id="billing-action-notify">Handling IN_APP_NOTIFY messages</h3>
 
-<p>Usually, your application receives an <code>IN_APP_NOTIFY</code> broadcast intent from Android Market in response to a <code>REQUEST_PURCHASE</code> message (see figure 2). The <code>IN_APP_NOTIFY</code> broadcast intent informs your application that the state of a requested purchase has changed. To retrieve the details of that purchase, your application sends a <code>GET_PURCHASE_INFORMATION</code> request. Android Market responds with a <code>PURCHASE_STATE_CHANGED</code> broadcast intent, which contains the details of the purchase state change. Your application then sends a <code>CONFIRM_NOTIFICATIONS</code> message, informing Android Market that you've received the purchase state change information.</p>
+<p>Usually, your application receives an <code>IN_APP_NOTIFY</code> broadcast intent from Android
+Market in response to a <code>REQUEST_PURCHASE</code> message (see figure 2). The
+<code>IN_APP_NOTIFY</code> broadcast intent informs your application that the state of a requested
+purchase has changed. To retrieve the details of that purchase, your application sends a
+<code>GET_PURCHASE_INFORMATION</code> request. Android Market responds with a
+<code>PURCHASE_STATE_CHANGED</code> broadcast intent, which contains the details of the purchase
+state change. Your application then sends a <code>CONFIRM_NOTIFICATIONS</code> message, informing
+Android Market that you've received the purchase state change information.</p>
 
-<p>When Android Market receives a <code>CONFIRM_NOTIFICATIONS</code> message for a given message, it usually stops sending <code>IN_APP_NOTIFY</code> intents for that message. However, there are some cases where Android Market may send repeated <code>IN_APP_NOTIFY</code> intents for a message even though your application has sent a <code>CONFIRM_NOTIFICATIONS</code> message. This can occur if a device loses network connectivity while you are sending the <code>CONFIRM_NOTIFICATIONS</code> message. In this case, Android Market might not receive your <code>CONFIRM_NOTIFICATIONS</code> message and it could send multiple <code>IN_APP_NOTIFY</code> messages until it receives acknowledgement that you received the message. Therefore, your application must be able to recognize that the subsequent <code>IN_APP_NOTIFY</code> messages are for a previously processed transaction. You can do this by checking the <code>orderID</code> that's contained in the JSON string because every transaction has a unique <code>orderId</code>.</p>
+<p>When Android Market receives a <code>CONFIRM_NOTIFICATIONS</code> message for a given message, it
+usually stops sending <code>IN_APP_NOTIFY</code> intents for that message. However, there are some
+cases where Android Market may send repeated <code>IN_APP_NOTIFY</code> intents for a message even
+though your application has sent a <code>CONFIRM_NOTIFICATIONS</code> message. This can occur if a
+device loses network connectivity while you are sending the <code>CONFIRM_NOTIFICATIONS</code>
+message. In this case, Android Market might not receive your <code>CONFIRM_NOTIFICATIONS</code>
+message and it could send multiple <code>IN_APP_NOTIFY</code> messages until it receives
+acknowledgement that you received the message. Therefore, your application must be able to recognize
+that the subsequent <code>IN_APP_NOTIFY</code> messages are for a previously processed transaction.
+You can do this by checking the <code>orderID</code> that's contained in the JSON string because
+every transaction has a unique <code>orderId</code>.</p>
 
-<p>There are two cases where your application may also receive <code>IN_APP_NOTIFY</code> broadcast intents even though your application has not sent a <code>REQUEST_PURCHASE</code> message. Figure 5 shows the messaging sequence for both of these cases. Request types for each <code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents are shown in <em>italic</em>. For clarity, figure 5 does not show the <code>RESPONSE_CODE</code> broadcast intents that are sent for every request.</p>
+<p>There are two cases where your application may also receive <code>IN_APP_NOTIFY</code> broadcast
+intents even though your application has not sent a <code>REQUEST_PURCHASE</code> message. Figure 5
+shows the messaging sequence for both of these cases. Request types for each
+<code>sendBillingRequest()</code> method are shown in <strong>bold</strong>, broadcast intents are
+shown in <em>italic</em>. For clarity, figure 5 does not show the <code>RESPONSE_CODE</code>
+broadcast intents that are sent for every request.</p>
 
 <div class="figure" style="width:481px">
 <img src="{@docRoot}images/billing_refund.png" alt="" height="189" />
@@ -203,32 +363,77 @@
 </p>
 </div>
 
-<p>In the first case, your application can receive an <code>IN_APP_NOTIFY</code> broadcast intent when a user has your application installed on two (or more) devices and the user makes an in-app purchase from one of the devices. In this case, Android Market sends an <code>IN_APP_NOTIFY</code> message to the second device, informing the application that there is a purchase state change. Your application can handle this message the same way it handles the response from an application-initiated <code>REQUEST_PURCHASE</code> message, so that ultimately your application receives a <code>PURCHASE_STATE_CHANGED</code> broadcast intent message that includes information about the item that has been purchased. This applies only to items that have their <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">purchase type</a> set to "managed per user account."</p>
+<p>In the first case, your application can receive an <code>IN_APP_NOTIFY</code> broadcast intent
+when a user has your application installed on two (or more) devices and the user makes an in-app
+purchase from one of the devices. In this case, Android Market sends an <code>IN_APP_NOTIFY</code>
+message to the second device, informing the application that there is a purchase state change. Your
+application can handle this message the same way it handles the response from an
+application-initiated <code>REQUEST_PURCHASE</code> message, so that ultimately your application
+receives a <code>PURCHASE_STATE_CHANGED</code> broadcast intent message that includes information
+about the item that has been purchased. This applies only to items that have their <a
+href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">purchase type</a> set
+to "managed per user account."</p>
 
-<p>In the second case, your application can receive an <code>IN_APP_NOTIFY</code> broadcast intent when Android Market receives a refund notification from Google Checkout. In this case, Android Market sends an <code>IN_APP_NOTIFY</code> message to your application. Your application can handle this message the same way it handles responses from an application-initiated <code>REQUEST_PURCHASE</code> message so that ultimately your application receives a <code>PURCHASE_STATE_CHANGED</code> message that includes information about the item that has been refunded. The refund information is included in the JSON string that accompanies the <code>PURCHASE_STATE_CHANGED</code> broadcast intent. Also, the <code>purchaseState</code> field in the JSON string is set to 2.</p>
+<p>In the second case, your application can receive an <code>IN_APP_NOTIFY</code> broadcast intent
+when Android Market receives a refund notification from Google Checkout. In this case, Android
+Market sends an <code>IN_APP_NOTIFY</code> message to your application. Your application can handle
+this message the same way it handles responses from an application-initiated
+<code>REQUEST_PURCHASE</code> message so that ultimately your application receives a
+<code>PURCHASE_STATE_CHANGED</code> message that includes information about the item that has been
+refunded. The refund information is included in the JSON string that accompanies the
+<code>PURCHASE_STATE_CHANGED</code> broadcast intent. Also, the <code>purchaseState</code> field in
+the JSON string is set to 2.</p>
 
 <h2 id="billing-security">Security Controls</h2>
 
-<p>To help ensure the integrity of the transaction information that is sent to your application, Android Market signs the JSON string that is contained in the <code>PURCHASE_STATE_CHANGED</code> broadcast intent. Android Market uses the private key that is associated with your publisher account to create this signature. The publisher site generates an RSA key pair for each publisher account. You can find the public key portion of this key pair on your account's profile page. It is the same public key that is used with Android Market licensing.</p>
+<p>To help ensure the integrity of the transaction information that is sent to your application,
+Android Market signs the JSON string that is contained in the <code>PURCHASE_STATE_CHANGED</code>
+broadcast intent. Android Market uses the private key that is associated with your publisher account
+to create this signature. The publisher site generates an RSA key pair for each publisher account.
+You can find the public key portion of this key pair on your account's profile page. It is the same
+public key that is used with Android Market licensing.</p>
 
-<p>When Android Market signs a billing response, it includes the signed JSON string (unencrypted) and the signature. When your application receives this signed response you can use the public key portion of your RSA key pair to verify the signature. By performing signature verification you can help detect responses that have been tampered with or that have been spoofed. You can perform this signature verification step in your application; however, if your application connects to a secure remote server then we recommend that you perform the signature verification on that server.</p>
+<p>When Android Market signs a billing response, it includes the signed JSON string (unencrypted)
+and the signature. When your application receives this signed response you can use the public key
+portion of your RSA key pair to verify the signature. By performing signature verification you can
+help detect responses that have been tampered with or that have been spoofed. You can perform this
+signature verification step in your application; however, if your application connects to a secure
+remote server then we recommend that you perform the signature verification on that server.</p>
 
-<p>In-app billing also uses nonces (a random number used once) to help verify the integrity of the purchase information that's returned from Android Market. Your application must generate a nonce and send it with a <code>GET_PURCHASE_INFORMATION</code> request and a <code>RESTORE_TRANSACTIONS</code> request. When Android Market receives the request, it adds the nonce to the JSON string that contains the transaction information. The JSON string is then signed and returned to your application. When your application receives the JSON string, you need to verify the nonce as well as the signature of the JSON string.</p>
+<p>In-app billing also uses nonces (a random number used once) to help verify the integrity of the
+purchase information that's returned from Android Market. Your application must generate a nonce and
+send it with a <code>GET_PURCHASE_INFORMATION</code> request and a <code>RESTORE_TRANSACTIONS</code>
+request. When Android Market receives the request, it adds the nonce to the JSON string that
+contains the transaction information. The JSON string is then signed and returned to your
+application. When your application receives the JSON string, you need to verify the nonce as well as
+the signature of the JSON string.</p>
 
-<p>For more information about best practices for security and design, see <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
+<p>For more information about best practices for security and design, see <a
+href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
 
 <h2 id="billing-limitations">In-app Billing Requirements and Limitations</h2>
 
-<p>Before you get started with in-app billing, be sure to review the following requirements and limitations.</p>
+<p>Before you get started with in-app billing, be sure to review the following requirements and
+limitations.</p>
 
 <ul>
-  <li>In-app billing can be implemented only in applications that you publish through Android Market.</li>
+  <li>In-app billing can be implemented only in applications that you publish through Android
+  Market.</li>
   <li>You must have a Google Checkout Merchant account to use Android Market In-app Billing.</li>
-  <li>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application.</li>
-  <li>An application can use in-app billing only if the device is running Android 1.6 (API level 4) or higher.</li>
-  <li>You can use in-app billing to sell only digital content. You cannot use in-app billing to sell physical goods, personal services, or anything that requires physical delivery.</li>
-  <li>Android Market does not provide any form of content delivery. You are responsible for delivering the digital content that you sell in your applications.</li>
-  <li>You cannot implement in-app billing on a device that never connects to the network. To complete in-app purchase requests, a device must be able to access the Android Market server over the network. </li>
+  <li>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of
+  the MyApps application. If your device is running any other version of Android, in-app billing
+  requires version 2.3.4 (or higher) of the Android Market application.</li>
+  <li>An application can use in-app billing only if the device is running Android 1.6 (API level 4)
+  or higher.</li>
+  <li>You can use in-app billing to sell only digital content. You cannot use in-app billing to sell
+  physical goods, personal services, or anything that requires physical delivery.</li>
+  <li>Android Market does not provide any form of content delivery. You are responsible for
+  delivering the digital content that you sell in your applications.</li>
+  <li>You cannot implement in-app billing on a device that never connects to the network. To
+  complete in-app purchase requests, a device must be able to access the Android Market server over
+  the network. </li>
 </ul>
 
-<p>For more information about in-app billing requirements, see <a href="http://market.android.com/support/bin/answer.py?answer=1153481">In-App Billing Availability and Policies</a>.</p>
+<p>For more information about in-app billing requirements, see <a
+href="http://market.android.com/support/bin/answer.py?answer=1153481">In-App Billing Availability
+and Policies</a>.</p>
diff --git a/docs/html/guide/market/billing/billing_reference.jd b/docs/html/guide/market/billing/billing_reference.jd
index 292823d..5a7ba56 100755
--- a/docs/html/guide/market/billing/billing_reference.jd
+++ b/docs/html/guide/market/billing/billing_reference.jd
@@ -14,15 +14,21 @@
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
   </ol>
 </div>
 </div>
@@ -37,53 +43,82 @@
 
 <h2 id="billing-codes">Android Market Server Response Codes for In-app Billing</h2>
 
-<p>The following table lists all of the server response codes that are sent from Android Market to your application. Android Market sends these response codes asynchronously as <code>response_code</code> extras in the <code>com.android.vending.billing.RESPONSE_CODE</code> broadcast intent. Your application must handle all of these response codes.</p>
+<p>The following table lists all of the server response codes that are sent from Android Market to
+your application. Android Market sends these response codes asynchronously as
+<code>response_code</code> extras in the <code>com.android.vending.billing.RESPONSE_CODE</code>
+broadcast intent. Your application must handle all of these response codes.</p>
 
-<p class="table-caption" id="response-codes-table"><strong>Table 1.</strong> Summary of response codes returned by Android Market.</p>
+<p class="table-caption" id="response-codes-table"><strong>Table 1.</strong> Summary of response
+codes returned by Android Market.</p>
 
 <table>
 
 <tr>
 <th>Response Code</th>
+<th>Value</th>
 <th>Description</th>
 </tr>
 <tr>
   <td><code>RESULT_OK</code></td>
-  <td>Indicates that the request was sent to the server successfully. When this code is returned in response to a <code>CHECK_BILLING_SUPPORTED</code> request, indicates that billing is supported.</td>
+  <td>0</td>
+  <td>Indicates that the request was sent to the server successfully. When this code is returned in
+  response to a <code>CHECK_BILLING_SUPPORTED</code> request, indicates that billing is
+  supported.</td>
 </tr>
 <tr>
   <td><code>RESULT_USER_CANCELED</code></td>
-  <td>Indicates that the user pressed the back button on the checkout page instead of buying the item.</td>
+  <td>1</td>
+  <td>Indicates that the user pressed the back button on the checkout page instead of buying the
+  item.</td>
 </tr>
 <tr>
   <td><code>RESULT_SERVICE_UNAVAILABLE</code></td>
+  <td>2</td>
   <td>Indicates that the network connection is down.</td>
 </tr>
 <tr>
   <td><code>RESULT_BILLING_UNAVAILABLE</code></td>
-  <td>Indicates that in-app billing is not available because the <code>API_VERSION</code> that you specified is not recognized by the Android Market application or the user is ineligible for in-app billing (for example, the user resides in a country that prohibits in-app purchases).</td>
+  <td>3</td>
+  <td>Indicates that in-app billing is not available because the <code>API_VERSION</code> that you
+  specified is not recognized by the Android Market application or the user is ineligible for in-app
+  billing (for example, the user resides in a country that prohibits in-app purchases).</td>
 </tr>
 <tr>
   <td><code>RESULT_ITEM_UNAVAILABLE</code></td>
-  <td>Indicates that Android Market cannot find the requested item in the application's product list. This can happen if the product ID is misspelled in your <code>REQUEST_PURCHASE</code> request or if an item is unpublished in the application's product list.</td>
+  <td>4</td>
+  <td>Indicates that Android Market cannot find the requested item in the application's product
+  list. This can happen if the product ID is misspelled in your <code>REQUEST_PURCHASE</code>
+  request or if an item is unpublished in the application's product list.</td>
+</tr>
+<tr>
+  <td><code>RESULT_DEVELOPER_ERROR</code></td>
+  <td>5</td>
+  <td>Indicates that an application is trying to make an in-app billing request but the application
+  has not declared the com.android.vending.BILLING permission in its manifest. Can also indicate
+  that an application is not properly signed, or that you sent a malformed request, such as a
+  request with missing Bundle keys or a request that uses an unrecognized request type.</td>
 </tr>
 <tr>
   <td><code>RESULT_ERROR</code></td>
-  <td>Indicates an unexpected server error.</td>
-</tr>
-
-<tr>
-  <td><code>RESULT_DEVELOPER_ERROR</code></td>
-  <td>Indicates that an application is trying to make an in-app billing request but the application has not declared the com.android.vending.BILLING permission in its manifest. Can also indicate that an application is not properly signed, or that you sent a malformed request, such as a request with missing Bundle keys or a request that uses an unrecognized request type.</td>
+  <td>6</td>
+  <td>Indicates an unexpected server error. For example, this error is triggered if you try to
+purchase an item from yourself, which is not allowed by Google Checkout.</td>
 </tr>
 </table>
 
 <h2 id="billing-interface">In-app Billing Service Interface</h2>
 
-<p>The following section describes the interface for Android Market's in-app billing service. The interface is defined in the <code>IMarketBillingService.aidl</code> file, which is included with the in-app billing <a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">sample application</a>.</p>
-<p>The interface consists of a single request method <code>sendBillingRequest()</code>. This method takes a single {@link android.os.Bundle} parameter. The Bundle parameter includes several key-value pairs, which are summarized in table 2.</p>
+<p>The following section describes the interface for Android Market's in-app billing service. The
+interface is defined in the <code>IMarketBillingService.aidl</code> file, which is included with the
+in-app billing <a
+href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">sample
+application</a>.</p>
+<p>The interface consists of a single request method <code>sendBillingRequest()</code>. This method
+takes a single {@link android.os.Bundle} parameter. The Bundle parameter includes several key-value
+pairs, which are summarized in table 2.</p>
 
-<p class="table-caption"><strong>Table 2.</strong> Description of Bundle keys passed in a <code>sendBillingRequest()</code> request.</p>
+<p class="table-caption"><strong>Table 2.</strong> Description of Bundle keys passed in a
+<code>sendBillingRequest()</code> request.</p>
 
 <table>
 
@@ -97,16 +132,20 @@
 <tr>
   <td><code>BILLING_REQUEST</code></td>
   <td><code>String</code></td>
-  <td><code>CHECK_BILLING_SUPPORTED</code>, <code>REQUEST_PURCHASE</code>, <code>GET_PURCHASE_INFORMATION</code>, <code>CONFIRM_NOTIFICATIONS</code>, or <code>RESTORE_TRANSACTIONS</code></td>
+  <td><code>CHECK_BILLING_SUPPORTED</code>, <code>REQUEST_PURCHASE</code>,
+  <code>GET_PURCHASE_INFORMATION</code>, <code>CONFIRM_NOTIFICATIONS</code>, or
+  <code>RESTORE_TRANSACTIONS</code></td>
   <td>Yes</td>
-  <td>The type of billing request you are making with the <code>sendBillingRequest()</code> request. The possible values are discussed more below this table.</td>
+  <td>The type of billing request you are making with the <code>sendBillingRequest()</code> request.
+  The possible values are discussed more below this table.</td>
 </tr>
 <tr>
   <td><code>API_VERSION</code></td>
   <td><code>int</code></td>
   <td>1</td>
   <td>Yes</td>
-  <td>The version of Android Market's in-app billing service you are using. The current version is 1.</td>
+  <td>The version of Android Market's in-app billing service you are using. The current version is
+  1.</td>
 </tr>
 <tr>
   <td><code>PACKAGE_NAME</code></td>
@@ -120,28 +159,42 @@
   <td><code>String</code></td>
   <td>Any valid product identifier.</td>
   <td>Required for <code>REQUEST_PURCHASE</code> requests.</td>
-  <td>The product ID of the item you are making a billing request for. Every in-app item that you sell using Android Market's in-app billing service must have a unique product ID, which you specify on the Android Market publisher site.</td>
+  <td>The product ID of the item you are making a billing request for. Every in-app item that you
+  sell using Android Market's in-app billing service must have a unique product ID, which you
+  specify on the Android Market publisher site.</td>
 </tr>
 <tr>
   <td><code>NONCE</code></td>
   <td><code>long</code></td>
   <td>Any valid <code>long</code> value.</td>
-  <td>Required for <code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code> requests.</td>
-  <td>A number used once. Your application must generate and send a nonce with each <code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code> request. The nonce is returned with the <code>PURCHASE_STATE_CHANGED</code> broadcast intent, so you can use this value to verify the integrity of transaction responses form Android Market.</td>
+  <td>Required for <code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code>
+  requests.</td>
+  <td>A number used once. Your application must generate and send a nonce with each
+  <code>GET_PURCHASE_INFORMATION</code> and <code>RESTORE_TRANSACTIONS</code> request. The nonce is
+  returned with the <code>PURCHASE_STATE_CHANGED</code> broadcast intent, so you can use this value
+  to verify the integrity of transaction responses form Android Market.</td>
 </tr>
 <tr>
   <td><code>NOTIFY_IDS</code></td>
   <td>Array of <code>long</code> values</td>
   <td>Any valid array of <code>long</code> values</td>
-  <td>Required for <code>GET_PURCHASE_INFORMATION</code> and <code>CONFIRM_NOTIFICATIONS</code> requests.</td>
-  <td>An array of notification identifiers. A notification ID is sent to your application in an <code>IN_APP_NOTIFY</code> broadcast intent every time a purchase changes state. You use the notification to retrieve the details of the purchase state change.</td>
+  <td>Required for <code>GET_PURCHASE_INFORMATION</code> and <code>CONFIRM_NOTIFICATIONS</code>
+  requests.</td>
+  <td>An array of notification identifiers. A notification ID is sent to your application in an
+  <code>IN_APP_NOTIFY</code> broadcast intent every time a purchase changes state. You use the
+  notification to retrieve the details of the purchase state change.</td>
 </tr>
 <tr>
   <td><code>DEVELOPER_PAYLOAD</code></td>
   <td><code>String</code></td>
   <td>Any valid <code>String</code> less than 256 characters long.</td>
   <td>No</td>
-  <td>A developer-specified string that can be specified when you make a <code>REQUEST_PURCHASE</code> request. This field is returned in the JSON string that contains transaction information for an order. You can use this key to send supplemental information with an order. For example, you can use this key to send index keys with an order, which is useful if you are using a database to store purchase information. We recommend that you do not use this key to send data or content.</td>
+  <td>A developer-specified string that can be specified when you make a
+  <code>REQUEST_PURCHASE</code> request. This field is returned in the JSON string that contains
+  transaction information for an order. You can use this key to send supplemental information with
+  an order. For example, you can use this key to send index keys with an order, which is useful if
+  you are using a database to store purchase information. We recommend that you do not use this key
+  to send data or content.</td>
 </tr>
 </table>
 
@@ -149,39 +202,60 @@
 
 <ul>
   <li><code>CHECK_BILLING_SUPPORTED</code>
-    <p>This request verifies that the Android Market application supports in-app billing. You usually send this request when your application first starts up. This request is useful if you want to enable or disable certain UI features that are relevant only to in-app billing.</p>
+    <p>This request verifies that the Android Market application supports in-app billing. You
+    usually send this request when your application first starts up. This request is useful if you
+    want to enable or disable certain UI features that are relevant only to in-app billing.</p>
   </li>
   <li><code>REQUEST_PURCHASE</code>
-    <p>This request sends a purchase message to the Android Market application and is the foundation of in-app billing. You send this request when a user indicates that he or she wants to purchase an item in your application. Android Market then handles the financial transaction by displaying the checkout user interface.</p>
+    <p>This request sends a purchase message to the Android Market application and is the foundation
+    of in-app billing. You send this request when a user indicates that he or she wants to purchase
+    an item in your application. Android Market then handles the financial transaction by displaying
+    the checkout user interface.</p>
   </li>
   <li><code>GET_PURCHASE_INFORMATION</code>
-    <p>This request retrieves the details of a purchase state change. A purchase state change can occur when a purchase request is billed successfully or when a user cancels a transaction during checkout. It can also occur when a previous purchase is refunded. Android Market notifies your application when a purchase changes state, so you only need to send this request when there is transaction information to retrieve.</p>
+    <p>This request retrieves the details of a purchase state change. A purchase state change can
+    occur when a purchase request is billed successfully or when a user cancels a transaction during
+    checkout. It can also occur when a previous purchase is refunded. Android Market notifies your
+    application when a purchase changes state, so you only need to send this request when there is
+    transaction information to retrieve.</p>
   </li>
   <li><code>CONFIRM_NOTIFICATIONS</code>
-    <p>This request acknowledges that your application received the details of a purchase state change. That is, this message confirms that you sent a <code>GET_PURCHASE_INFORMATION</code> request for a given notification and that you received the purchase information for the notification.</p>
+    <p>This request acknowledges that your application received the details of a purchase state
+    change. That is, this message confirms that you sent a <code>GET_PURCHASE_INFORMATION</code>
+    request for a given notification and that you received the purchase information for the
+    notification.</p>
   </li>
   <li><code>RESTORE_TRANSACTIONS</code>
-    <p>This request retrieves a user's transaction status for managed purchases (see <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">Choosing a Purchase Type</a> for more information). You should send this message only when you need to retrieve a user's transaction status, which is usually only when your application is reinstalled or installed for the first time on a device.</p>
+    <p>This request retrieves a user's transaction status for managed purchases (see <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-purchase-type">Choosing a
+    Purchase Type</a> for more information). You should send this message only when you need to
+    retrieve a user's transaction status, which is usually only when your application is reinstalled
+    or installed for the first time on a device.</p>
   </li>
 </ul>
 
-<p>Every in-app billing request generates a synchronous response. The response is a {@link android.os.Bundle} and can include one or more of the following keys:</p>
+<p>Every in-app billing request generates a synchronous response. The response is a {@link
+android.os.Bundle} and can include one or more of the following keys:</p>
 
 <ul>
   <li><code>RESPONSE_CODE</code>
     <p>This key provides status information and error information about a request.</p>
   </li>
   <li><code>PURCHASE_INTENT</code>
-    <p>This key provides a {@link android.app.PendingIntent}, which you use to launch the checkout activity.</p>
+    <p>This key provides a {@link android.app.PendingIntent}, which you use to launch the checkout
+    activity.</p>
   </li>
   <li><code>REQUEST_ID</code>
-    <p>This key provides you with a request identifier, which you can use to match asynchronous responses with requests.</p>
+    <p>This key provides you with a request identifier, which you can use to match asynchronous
+    responses with requests.</p>
   </li>
 </ul>
 
-<p>Some of these keys are not relevant to certain types of requests. Table 3 shows which keys are returned for each request type.</p>
+<p>Some of these keys are not relevant to certain types of requests. Table 3 shows which keys are
+returned for each request type.</p>
 
-<p class="table-caption"><strong>Table 3.</strong> Description of Bundle keys that are returned with each in-app billing request type.</p>
+<p class="table-caption"><strong>Table 3.</strong> Description of Bundle keys that are returned with
+each in-app billing request type.</p>
 
 <table>
 
@@ -193,7 +267,8 @@
 <tr>
   <td><code>CHECK_BILLING_SUPPORTED</code></td>
   <td><code>RESPONSE_CODE</code></td>
-  <td><code>RESULT_OK</code>, <code>RESULT_BILLING_UNAVAILABLE</code>, <code>RESULT_ERROR</code>, <code>RESULT_DEVELOPER_ERROR</code></td>
+  <td><code>RESULT_OK</code>, <code>RESULT_BILLING_UNAVAILABLE</code>, <code>RESULT_ERROR</code>,
+  <code>RESULT_DEVELOPER_ERROR</code></td>
 </tr>
 <tr>
   <td><code>REQUEST_PURCHASE</code></td>
@@ -219,45 +294,77 @@
 
 <h2 id="billing-intents">In-app Billing Broadcast Intents</h2>
 
-<p>The following section describes the in-app billing broadcast intents that are sent by the Android Market application. These broadcast intents inform your application about in-app billing actions that have occurred. Your application must implement a {@link android.content.BroadcastReceiver} to receive these broadcast intents, such as the <code>BillingReceiver</code> that's shown in the in-app billing <a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">sample application</a>.</p>
+<p>The following section describes the in-app billing broadcast intents that are sent by the Android
+Market application. These broadcast intents inform your application about in-app billing actions
+that have occurred. Your application must implement a {@link android.content.BroadcastReceiver} to
+receive these broadcast intents, such as the <code>BillingReceiver</code> that's shown in the in-app
+billing <a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">sample
+application</a>.</p>
 
 <h4>com.android.vending.billing.RESPONSE_CODE</h4>
 
-<p>This broadcast intent contains an Android Market response code, and is sent after you make an in-app billing request. A server response code can indicate that a billing request was successfully sent to Android Market or it can indicate that some error occurred during a billing request. This intent is not used to report any purchase state changes (such as refund or purchase information). For more information about the response codes that are sent with this response, see <a href="#billing-codes">Android Market Response Codes for In-app Billing</a>. The sample application assigns this broadcast intent to a constant named <code>ACTION_RESPONSE_CODE</code>.</p>
+<p>This broadcast intent contains an Android Market response code, and is sent after you make an
+in-app billing request. A server response code can indicate that a billing request was successfully
+sent to Android Market or it can indicate that some error occurred during a billing request. This
+intent is not used to report any purchase state changes (such as refund or purchase information).
+For more information about the response codes that are sent with this response, see <a
+href="#billing-codes">Android Market Response Codes for In-app Billing</a>. The sample application
+assigns this broadcast intent to a constant named <code>ACTION_RESPONSE_CODE</code>.</p>
 
 <h5>Extras</h5>
 
 <ul type="none">
-  <li><code>request_id</code>&mdash;a <code>long</code> representing a request ID. A request ID identifies a specific billing request and is returned by Android Market at the time a request is made.</li>
-  <li><code>response_code</code>&mdash;an <code>int</code> representing the Android Market server response code.</li>
+  <li><code>request_id</code>&mdash;a <code>long</code> representing a request ID. A request ID
+  identifies a specific billing request and is returned by Android Market at the time a request is
+  made.</li>
+  <li><code>response_code</code>&mdash;an <code>int</code> representing the Android Market server
+  response code.</li>
 </ul>
 
 <h4>com.android.vending.billing.IN_APP_NOTIFY</h4>
 
-<p>This response indicates that a purchase has changed state, which means a purchase succeeded, was canceled, or was refunded. This response contains one or more notification IDs. Each notification ID corresponds to a specific server-side message, and each messages contains information about one or more transactions. After your application receives an <code>IN_APP_NOTIFY</code> broadcast intent, you send a <code>GET_PURCHASE_INFORMATION</code> request with the notification IDs to retrieve the message details. The sample application assigns this broadcast intent to a constant named <code>ACTION_NOTIFY</code>.</p>
+<p>This response indicates that a purchase has changed state, which means a purchase succeeded, was
+canceled, or was refunded. This response contains one or more notification IDs. Each notification ID
+corresponds to a specific server-side message, and each messages contains information about one or
+more transactions. After your application receives an <code>IN_APP_NOTIFY</code> broadcast intent,
+you send a <code>GET_PURCHASE_INFORMATION</code> request with the notification IDs to retrieve the
+message details. The sample application assigns this broadcast intent to a constant named
+<code>ACTION_NOTIFY</code>.</p>
 
 <h5>Extras</h5>
 
 <ul type="none">
-  <li><code>notification_id</code>&mdash;a <code>String</code> representing the notification ID for a given purchase state change. Android Market notifies you when there is a purchase state change and the notification includes a unique notification ID. To get the details of the purchase state change, you send the notification ID with the <code>GET_PURCHASE_INFORMATION</code> request.</li>
+  <li><code>notification_id</code>&mdash;a <code>String</code> representing the notification ID for
+  a given purchase state change. Android Market notifies you when there is a purchase state change
+  and the notification includes a unique notification ID. To get the details of the purchase state
+  change, you send the notification ID with the <code>GET_PURCHASE_INFORMATION</code> request.</li>
 </ul>
 
 <h4>com.android.vending.billing.PURCHASE_STATE_CHANGED</h4>
 
-<p>This broadcast intent contains detailed information about one or more transactions. The transaction information is contained in a JSON string. The JSON string is signed and the signature is sent to your application along with the JSON string (unencrypted). To help ensure the security of your in-app billing messages, your application can verify the signature of this JSON string. The sample application assigns this broadcast intent to a constant named <code>ACTION_PURCHASE_STATE_CHANGED</code>.</p>
+<p>This broadcast intent contains detailed information about one or more transactions. The
+transaction information is contained in a JSON string. The JSON string is signed and the signature
+is sent to your application along with the JSON string (unencrypted). To help ensure the security of
+your in-app billing messages, your application can verify the signature of this JSON string. The
+sample application assigns this broadcast intent to a constant named
+<code>ACTION_PURCHASE_STATE_CHANGED</code>.</p>
 
 <h5>Extras</h5>
 
 <ul type="none">
-  <li><code>inapp_signed_data</code>&mdash;a <code>String</code> representing the signed JSON string.</li>
+  <li><code>inapp_signed_data</code>&mdash;a <code>String</code> representing the signed JSON
+  string.</li>
   <li><code>inapp_signature</code>&mdash;a <code>String</code> representing the signature.</li>
 </ul>
 
-<p class="note"><strong>Note:</strong> Your application should map the broadcast intents and extras to constants that are unique to your application. See the <code>Consts.java</code> file in the sample application to see how this is done.</p>
+<p class="note"><strong>Note:</strong> Your application should map the broadcast intents and extras
+to constants that are unique to your application. See the <code>Consts.java</code> file in the
+sample application to see how this is done.</p>
 
 <p>The fields in the JSON string are described in the following table (see table 4):</p>
 
-<p class="table-caption"><strong>Table 4.</strong> Description of JSON fields that are returned with a <code>PURCHASE_STATE_CHANGED</code> intent.</p>
+<p class="table-caption"><strong>Table 4.</strong> Description of JSON fields that are returned with
+a <code>PURCHASE_STATE_CHANGED</code> intent.</p>
 
 <table>
 
@@ -267,15 +374,22 @@
 </tr>
 <tr>
   <td>nonce</td>
-  <td>A number used once. Your application generates the nonce and sends it with the <code>GET_PURCHASE_INFORMATION</code> request. Android Market sends the nonce back as part of the JSON string so you can verify the integrity of the message.</td>
+  <td>A number used once. Your application generates the nonce and sends it with the
+  <code>GET_PURCHASE_INFORMATION</code> request. Android Market sends the nonce back as part of the
+  JSON string so you can verify the integrity of the message.</td>
 </tr>
 <tr>
   <td>notificationId</td>
-  <td>A unique identifier that is sent with an <code>IN_APP_NOTIFY</code> broadcast intent. Each <code>notificationId</code> corresponds to a specify message that is waiting to be retrieved on the Android Market server. Your application sends back the <code>notificationId</code> with the <code>GET_PURCHASE_INFORMATION</code> message so Android Market can determine which messages you are retrieving.</td>
+  <td>A unique identifier that is sent with an <code>IN_APP_NOTIFY</code> broadcast intent. Each
+  <code>notificationId</code> corresponds to a specify message that is waiting to be retrieved on
+  the Android Market server. Your application sends back the <code>notificationId</code> with the
+  <code>GET_PURCHASE_INFORMATION</code> message so Android Market can determine which messages you
+  are retrieving.</td>
 </tr>
 <tr>
   <td>orderId</td>
-  <td>A unique order identifier for the transaction. This corresponds to the Google Checkout Order ID.</td>
+  <td>A unique order identifier for the transaction. This corresponds to the Google Checkout Order
+  ID.</td>
 </tr>
 <tr>
   <td>packageName</td>
@@ -283,7 +397,8 @@
 </tr>
 <tr>
   <td>productId</td>
-  <td>The item's product identifier. Every item has a product ID, which you must specify in the application's product list on the Android Market publisher site.</td>
+  <td>The item's product identifier. Every item has a product ID, which you must specify in the
+  application's product list on the Android Market publisher site.</td>
 </tr>
 <tr>
   <td>purchaseTime</td>
@@ -292,10 +407,12 @@
 
 <tr>
   <td>purchaseState</td>
-  <td>The purchase state of the order. Possible values are 0 (purchased), 1 (canceled), or 2 (refunded).</td>
+  <td>The purchase state of the order. Possible values are 0 (purchased), 1 (canceled), or 2
+  (refunded).</td>
 </tr>
 <tr>
   <td>developerPayload</td>
-  <td>A developer-specified string that contains supplemental information about an order. You can specify a value for this field when you make a <code>REQUEST_PURCHASE</code> request.</td>
+  <td>A developer-specified string that contains supplemental information about an order. You can
+  specify a value for this field when you make a <code>REQUEST_PURCHASE</code> request.</td>
 </tr>
 </table>
diff --git a/docs/html/guide/market/billing/billing_testing.jd b/docs/html/guide/market/billing/billing_testing.jd
index 742e7ef4d..84d25b2 100755
--- a/docs/html/guide/market/billing/billing_testing.jd
+++ b/docs/html/guide/market/billing/billing_testing.jd
@@ -13,57 +13,104 @@
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>
   <h2>See also</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
 </div>
 </div>
 
-<p>The Android Market publisher site provides several tools that help you test your in-app billing implementation before it is published. You can use these tools to create test accounts and purchase special reserved items that send static billing responses to your application.</p>
+<p>The Android Market publisher site provides several tools that help you test your in-app billing
+implementation before it is published. You can use these tools to create test accounts and purchase
+special reserved items that send static billing responses to your application.</p>
 
-<p>To test in-app billing in an application you must install the application on an Android-powered device. You cannot use the Android emulator to test in-app billing.  The device you use for testing must run a standard version of the Android 1.6 or later platform (API level 4 or higher), and have the most current version of the Android Market application installed. If a device is not running the most current Android Market application, your application won't be able to send in-app billing requests to Android Market. For general information about how to set up a device for use in developing Android applications, see <a
-href="{@docRoot}guide/developing/device.html">Using Hardware Devices</a>.</p>
+<p>To test in-app billing in an application you must install the application on an Android-powered
+device. You cannot use the Android emulator to test in-app billing.  The device you use for testing
+must run a standard version of the Android 1.6 or later platform (API level 4 or higher), and have
+the most current version of the Android Market application installed. If a device is not running the
+most current Android Market application, your application won't be able to send in-app billing
+requests to Android Market. For general information about how to set up a device for use in
+developing Android applications, see <a href="{@docRoot}guide/developing/device.html">Using Hardware
+Devices</a>.</p>
 
 <p>The following section shows you how to set up and use the in-app billing test tools.</p>
 
 <h2 id="billing-testing-static">Testing in-app purchases with static responses</h2>
 
-<p>We recommend that you first test your in-app billing implementation using static responses from Android Market. This enables you to verify that your application is handling the primary Android Market responses correctly and that your application is able to verify signatures correctly.</p>
+<p>We recommend that you first test your in-app billing implementation using static responses from
+Android Market. This enables you to verify that your application is handling the primary Android
+Market responses correctly and that your application is able to verify signatures correctly.</p>
 
-<p>To test your implementation with static responses, you make an in-app billing request using a special item that has a reserved product ID. Each reserved product ID returns a specific static response from Android Market. No money is transferred when you make in-app billing requests with the reserved product IDs. Also, you cannot specify the form of payment when you make a billing request with a reserved product ID. Figure 1 shows the checkout flow for the reserved item that has the product ID android.test.purchased.</p>
+<p>To test your implementation with static responses, you make an in-app billing request using a
+special item that has a reserved product ID. Each reserved product ID returns a specific static
+response from Android Market. No money is transferred when you make in-app billing requests with the
+reserved product IDs. Also, you cannot specify the form of payment when you make a billing request
+with a reserved product ID. Figure 1 shows the checkout flow for the reserved item that has the
+product ID android.test.purchased.</p>
 
 <img src="{@docRoot}images/billing_test_flow.png" height="381" id="figure1" />
 <p class="img-caption">
   <strong>Figure 1.</strong> Checkout flow for the special reserved item android.test.purchased.
 </p>
 
-<p>You do not need to list the reserved products in your application's product list. Android Market already knows about the reserved product IDs. Also, you do not need to upload your application to the publisher site to perform static response tests with the reserved product IDs. You can simply install your application on a device, log into the device, and make billing requests using the reserved product IDs.</p>
+<p>You do not need to list the reserved products in your application's product list. Android Market
+already knows about the reserved product IDs. Also, you do not need to upload your application to
+the publisher site to perform static response tests with the reserved product IDs. You can simply
+install your application on a device, log into the device, and make billing requests using the
+reserved product IDs.</p>
 
 <p>There are four reserved product IDs for testing static in-app billing responses:</p>
 
 <ul>
   <li><strong>android.test.purchased</strong>
-    <p>When you make an in-app billing request with this product ID, Android Market responds as though you successfully purchased an item. The response includes a JSON string, which contains fake purchase information (for example, a fake order ID). In some cases, the JSON string is signed and the response includes the signature so you can test your signature verification implementation using these responses.</p>
+    <p>When you make an in-app billing request with this product ID, Android Market responds as
+    though you successfully purchased an item. The response includes a JSON string, which contains
+    fake purchase information (for example, a fake order ID). In some cases, the JSON string is
+    signed and the response includes the signature so you can test your signature verification
+    implementation using these responses.</p>
   </li>
   <li><strong>android.test.canceled</strong>
-    <p>When you make an in-app billing request with this product ID Android Market responds as though the purchase was canceled. This can occur when an error is encountered in the order process, such as an invalid credit card, or when you cancel a user's order before it is charged.</p>
+    <p>When you make an in-app billing request with this product ID Android Market responds as
+    though the purchase was canceled. This can occur when an error is encountered in the order
+    process, such as an invalid credit card, or when you cancel a user's order before it is
+    charged.</p>
   </li>
   <li><strong>android.test.refunded</strong>
-    <p>When you make an in-app billing request with this product ID, Android Market responds as though the purchase was refunded. Refunds cannot be initiated through Android Market's in-app billing service. Refunds must be initiated by you (the merchant). After you process a refund request through your Google Checkout account, a refund message is sent to your application by Android Market. This occurs only when Android Market gets notification from Google Checkout that a refund has been made. For more information about refunds, see <a href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling IN_APP_NOTIFY messages</a> and <a href="http://www.google.com/support/androidmarket/bin/answer.py?answer=1153485">In-app Billing Pricing</a>.</p>
+    <p>When you make an in-app billing request with this product ID, Android Market responds as
+    though the purchase was refunded. Refunds cannot be initiated through Android Market's in-app
+    billing service. Refunds must be initiated by you (the merchant). After you process a refund
+    request through your Google Checkout account, a refund message is sent to your application by
+    Android Market. This occurs only when Android Market gets notification from Google Checkout that
+    a refund has been made. For more information about refunds, see <a
+    href="{@docRoot}guide/market/billing/billing_overview.html#billing-action-notify">Handling
+    IN_APP_NOTIFY messages</a> and <a
+    href="http://www.google.com/support/androidmarket/bin/answer.py?answer=1153485">In-app Billing
+    Pricing</a>.</p>
   </li>
   <li><strong>android.test.item_unavailable</strong>
-    <p>When you make an in-app billing request with this product ID, Android Market responds as though the item being purchased was not listed in your application's product list.</p>
+    <p>When you make an in-app billing request with this product ID, Android Market responds as
+    though the item being purchased was not listed in your application's product list.</p>
   </li>
 </ul>
 
-<p>In some cases, the reserved items may return signed static responses, which lets you test signature verification in your application. To test signature verification with the special reserved product IDs, you may need to set up <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a> or upload your application as a unpublished draft application. Table 1 shows you the conditions under which static responses are signed.</p>
+<p>In some cases, the reserved items may return signed static responses, which lets you test
+signature verification in your application. To test signature verification with the special reserved
+product IDs, you may need to set up <a
+href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a> or
+upload your application as a unpublished draft application. Table 1 shows you the conditions under
+which static responses are signed.</p>
 
 <p class="table-caption" id="static-responses-table"><strong>Table 1.</strong>
 Conditions under which static responses are signed.</p>
@@ -120,68 +167,118 @@
 
 </table>
 
-<p>To make an in-app billing request with a reserved product ID, you simply construct a normal <code>REQUEST_PURCHASE</code> request, but instead of using a real product ID from your application's product list you use one of the reserved product IDs.</p>
+<p>To make an in-app billing request with a reserved product ID, you simply construct a normal
+<code>REQUEST_PURCHASE</code> request, but instead of using a real product ID from your
+application's product list you use one of the reserved product IDs.</p>
 
 <p>To test your application using the reserved product IDs, follow these steps:</p>
 
 <ol>
   <li><strong>Install your application on an Android-powered device.</strong>
-    <p>You cannot use the emulator to test in-app billing; you must install your application on a device to test in-app billing.</p>
-    <p>To learn how to install an application on a device, see <a href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a device</a>.</p>
+    <p>You cannot use the emulator to test in-app billing; you must install your application on a
+    device to test in-app billing.</p>
+    <p>To learn how to install an application on a device, see <a
+    href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a
+    device</a>.</p>
   </li>
   <li><strong>Sign in to your device with your developer account.</strong>
-    <p>You do not need to use a test account if you are testing only with the reserved product IDs.</p>
+    <p>You do not need to use a test account if you are testing only with the reserved product
+    IDs.</p>
   </li>
-  <li><strong>Verify that your device is running a supported version of the Android Market application or the MyApps application.</strong>
-    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the version of the Android Market application, see <a href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android Market</a>.</p>
+  <li><strong>Verify that your device is running a supported version of the Android Market
+  application or the MyApps application.</strong>
+    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of
+    the MyApps application. If your device is running any other version of Android, in-app billing
+    requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the
+    version of the Android Market application, see <a
+    href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android
+    Market</a>.</p>
   </li>
   <li><strong>Run your application and purchase the reserved product IDs.</strong></li>
 </ol>
 
-<p class="note"><strong>Note</strong>: Making in-app billing requests with the reserved product IDs overrides the usual Android Market production system. When you send an in-app billing request for a reserved product ID, the quality of service will not be comparable to the production environment.</p>
+<p class="note"><strong>Note</strong>: Making in-app billing requests with the reserved product IDs
+overrides the usual Android Market production system. When you send an in-app billing request for a
+reserved product ID, the quality of service will not be comparable to the production
+environment.</p>
 
 <h2 id="billing-testing-real">Testing In-app Purchases Using Your Own Product IDs</h2>
 
-<p>After you finish your static response testing, and you verify that signature verification is working in your application, you can test your in-app billing implementation by making actual in-app purchases. Testing real in-app purchases enables you to test the end-to-end in-app billing experience, including the actual responses from Android Market and the actual checkout flow that users will experience in your application.</p>
+<p>After you finish your static response testing, and you verify that signature verification is
+working in your application, you can test your in-app billing implementation by making actual in-app
+purchases. Testing real in-app purchases enables you to test the end-to-end in-app billing
+experience, including the actual responses from Android Market and the actual checkout flow that
+users will experience in your application.</p>
 
-<p class="note"><strong>Note</strong>: You do not need to publish your application to do end-to-end testing. You only need to upload your draft application to perform end-to-end testing.</p>
+<p class="note"><strong>Note</strong>: You do not need to publish your application to do end-to-end
+testing. You only need to upload your draft application to perform end-to-end testing.</p>
 
-<p>To test your in-app billing implementation with actual in-app purchases, you will need to register at least one test account on the Android Market publisher site. You cannot use your developer account to test the complete in-app purchase process because Google Checkout does not let you buy items from yourself. If you have not set up test accounts before, see <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">Setting up test accounts</a>.</p>
+<p>To test your in-app billing implementation with actual in-app purchases, you will need to
+register at least one test account on the Android Market publisher site. You cannot use your
+developer account to test the complete in-app purchase process because Google Checkout does not let
+you buy items from yourself. If you have not set up test accounts before, see <a
+href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">Setting up test
+accounts</a>.</p>
 
-<p>Also, a test account can purchase an item in your product list only if the item is published. The application does not need to be published, but the item does need to be published.</p>
+<p>Also, a test account can purchase an item in your product list only if the item is published. The
+application does not need to be published, but the item does need to be published.</p>
 
-<p>When you use a test account to purchase items, the test account is billed through Google Checkout and your Google Checkout Merchant account receives a payout for the purchase. Therefore, you may want to refund purchases that are made with test accounts, otherwise the purchases will show up as actual payouts to your merchant account.</p>
+<p>When you use a test account to purchase items, the test account is billed through Google Checkout
+and your Google Checkout Merchant account receives a payout for the purchase. Therefore, you may
+want to refund purchases that are made with test accounts, otherwise the purchases will show up as
+actual payouts to your merchant account.</p>
 
 <p>To test your in-app billing implementation with actual purchases, follow these steps:</p>
 
 <ol>
   <li><strong>Upload your application as a draft application to the publisher site.</strong>
-    <p>You do not need to publish your application to perform end-to-end testing with real product IDs. To learn how to upload an application to Android Market, see <a href="http://market.android.com/support/bin/answer.py?answer=113469">Uploading applications</a>.</p>
+    <p>You do not need to publish your application to perform end-to-end testing with real product
+    IDs. To learn how to upload an application to Android Market, see <a
+    href="http://market.android.com/support/bin/answer.py?answer=113469">Uploading
+    applications</a>.</p>
   </li>
   <li><strong>Add items to the application's product list.</strong>
-    <p>Make sure that you publish the items (the application can remain unpublished). See <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-catalog">Creating a product list</a> to learn how to do this.</p>
+    <p>Make sure that you publish the items (the application can remain unpublished). See <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-catalog">Creating a product
+    list</a> to learn how to do this.</p>
   </li>
   <li><strong>Install your application on an Android-powered device.</strong>
-    <p>You cannot use the emulator to test in-app billing; you must install your application on a device to test in-app billing.</p>
-    <p>To learn how to install an application on a device, see <a href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a device</a>.</p>
+    <p>You cannot use the emulator to test in-app billing; you must install your application on a
+    device to test in-app billing.</p>
+    <p>To learn how to install an application on a device, see <a
+    href="{@docRoot}guide/developing/building/building-cmdline.html#RunningOnDevice">Running on a
+    device</a>.</p>
   </li>
  <li><strong>Make one of your test accounts the primary account on your device.</strong>
-    <p>To perform end-to-end testing of in-app billing, the primary account on your device must be one of the <a href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a> that you registered on the Android Market site. If the primary account on your device is not a test account, you must do a factory reset of the device and then sign in with one of your test accounts. To perform a factory reset, do the following:</p>
+    <p>To perform end-to-end testing of in-app billing, the primary account on your device must be
+    one of the <a
+    href="{@docRoot}guide/market/billing/billing_admin.html#billing-testing-setup">test accounts</a>
+    that you registered on the Android Market site. If the primary account on your device is not a
+    test account, you must do a factory reset of the device and then sign in with one of your test
+    accounts. To perform a factory reset, do the following:</p>
     <ol>
       <li>Open Settings on your device.</li>
       <li>Touch <strong>Privacy</strong>.</li>
       <li>Touch <strong>Factory data reset</strong>.</li>
       <li>Touch <strong>Reset phone</strong>.</li>
-      <li>After the phone resets, be sure to sign in with one of your test accounts during the device setup process.</li>
+      <li>After the phone resets, be sure to sign in with one of your test accounts during the
+      device setup process.</li>
     </ol>
   </li>
-  <li><strong>Verify that your device is running a supported version of the Android Market application or the MyApps application.</strong>
-    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the version of the Android Market application, see <a href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android Market</a>.</p>
+  <li><strong>Verify that your device is running a supported version of the Android Market
+  application or the MyApps application.</strong>
+    <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of
+    the MyApps application. If your device is running any other version of Android, in-app billing
+    requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the
+    version of the Android Market application, see <a
+    href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Android
+    Market</a>.</p>
   </li>
   <li><strong>Make in-app purchases in your application.</strong></li>
 </ol>
 
-<p class="note"><strong>Note:</strong> The only way to change the primary account on a device is to do a factory reset, making sure you log on with your primary account first.</p>
+<p class="note"><strong>Note:</strong> The only way to change the primary account on a device is to
+do a factory reset, making sure you log on with your primary account first.</p>
 
 <p>When you are finished testing your in-app billing implementation, you are ready to
 publish your application on Android Market. You can follow the normal steps for <a
diff --git a/docs/html/guide/market/billing/index.jd b/docs/html/guide/market/billing/index.jd
index fb85fa6..fdfa6fa 100755
--- a/docs/html/guide/market/billing/index.jd
+++ b/docs/html/guide/market/billing/index.jd
@@ -6,52 +6,89 @@
 
   <h2>Topics</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></li>
-    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and
+    Design</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+    Billing</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app
+    Billing</a></li>
   </ol>
   <h2>Reference</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+    Reference</a></li>
   </ol>
   <h2>Downloads</h2>
   <ol>
-    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample Application</a></li>
+    <li><a href="{@docRoot}guide/market/billing/billing_integrate.html#billing-download">Sample
+    Application</a></li>
   </ol>  
 </div>
 </div>
 
-<p>Android Market In-app Billing is an Android Market service that lets you sell digital content in your applications. You can use the service to sell a wide range of content, including downloadable content such as media files or photos, and virtual content such as game levels or potions.</p>
+<p>Android Market In-app Billing is an Android Market service that lets you sell digital content in
+your applications. You can use the service to sell a wide range of content, including downloadable
+content such as media files or photos, and virtual content such as game levels or potions.</p>
 
-<p>When you use Android Market's in-app billing service to sell an item, Android Market handles all checkout details so your application never has to directly process any financial transactions. Android Market uses the same checkout service that is used for application purchases, so your users experience a consistent and familiar purchase flow (see figure 1). Also, the transaction fee for in-app purchases is the same as the transaction fee for application purchases (30%).</p>
+<p>When you use Android Market's in-app billing service to sell an item, Android Market handles all
+checkout details so your application never has to directly process any financial transactions.
+Android Market uses the same checkout service that is used for application purchases, so your users
+experience a consistent and familiar purchase flow (see figure 1). Also, the transaction fee for
+in-app purchases is the same as the transaction fee for application purchases (30%).</p>
 
-<p>Any application that you publish through Android Market can implement in-app billing. No special account or registration is required other than an Android Market publisher account and a Google Checkout Merchant account. Also, because the service uses no dedicated framework APIs, you can add in-app billing to any application that uses a minimum API level of 4 or higher.</p>
+<p>Any application that you publish through Android Market can implement in-app billing. No special
+account or registration is required other than an Android Market publisher account and a Google
+Checkout Merchant account. Also, because the service uses no dedicated framework APIs, you can add
+in-app billing to any application that uses a minimum API level of 4 or higher.</p>
 
-<p>To help you integrate in-app billing into your application, the Android SDK provides a sample application that demonstrates a simple implementation of in-app billing. The sample application contains examples of billing-related classes you can use to implement in-app billing in your application. It also contains examples of the database, user interface, and business logic you might use to implement in-app billing.</p>
+<p>To help you integrate in-app billing into your application, the Android SDK provides a sample
+application that demonstrates a simple implementation of in-app billing. The sample application
+contains examples of billing-related classes you can use to implement in-app billing in your
+application. It also contains examples of the database, user interface, and business logic you might
+use to implement in-app billing.</p>
 
-<p class="caution"><strong>Important</strong>: Although the sample application is a working example of how you can implement in-app billing, we <em>strongly recommend</em> that you modify and obfuscate the sample code before you use it in a production application. For more information, see <a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
+<p class="caution"><strong>Important</strong>: Although the sample application is a working example
+of how you can implement in-app billing, we <em>strongly recommend</em> that you modify and
+obfuscate the sample code before you use it in a production application. For more information, see
+<a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a>.</p>
 
 <img src="{@docRoot}images/billing_checkout_flow.png" height="382" id="figure1" />
 <p class="img-caption">
-  <strong>Figure 1.</strong> Applications initiate in-app billing requests through their own UI (first screen). Android Market responds to the request by providing the checkout user interface (middle screen). When checkout is complete, the application resumes.
+  <strong>Figure 1.</strong> Applications initiate in-app billing requests through their own UI
+  (first screen). Android Market responds to the request by providing the checkout user interface
+  (middle screen). When checkout is complete, the application resumes.
 </p>
 
-<p>To learn more about Android Market's in-app billing service and start integrating it into your applications, read the following documents:</p>
+<p>To learn more about Android Market's in-app billing service and start integrating it into your
+applications, read the following documents:</p>
 
 <dl>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app Billing</a></strong></dt>
-    <dd>Learn how the service works and what a typical in-app billing implementation looks like.</dd>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing In-app Billing</a></strong></dt>
-    <dd>Use this step-by-step guide to start incorporating in-app billing into your application.</dd>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security and Design</a></strong></dt>
-    <dd>Review these best practices to help ensure that your in-app billing implementation is secure and well designed.</dd>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app Billing</a></strong></dt>
-    <dd>Understand how the in-app billing test tools work and learn how to test your in-app billing implementation.</dd>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering In-app Billing</a></strong></dt>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_overview.html">Overview of In-app
+  Billing</a></strong></dt>
+    <dd>Learn how the service works and what a typical in-app billing implementation looks
+    like.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_integrate.html">Implementing
+  In-app Billing</a></strong></dt>
+    <dd>Use this step-by-step guide to start incorporating in-app billing into your
+    application.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_best_practices.html">Security
+  and Design</a></strong></dt>
+    <dd>Review these best practices to help ensure that your in-app billing implementation is
+    secure and well designed.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_testing.html">Testing In-app
+  Billing</a></strong></dt>
+    <dd>Understand how the in-app billing test tools work and learn how to test your in-app billing
+    implementation.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_admin.html">Administering
+  In-app Billing</a></strong></dt>
     <dd>Learn how to set up your product list, register test accounts, and handle refunds.</dd>
-  <dt><strong><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing Reference</a></strong></dt>
-    <dd>Get detailed information about Android Market response codes and the in-app billing interface.</dd>
+  <dt><strong><a href="{@docRoot}guide/market/billing/billing_reference.html">In-app Billing
+  Reference</a></strong></dt>
+    <dd>Get detailed information about Android Market response codes and the in-app billing
+    interface.</dd>
 </dl>
 
diff --git a/docs/html/guide/topics/data/data-storage.jd b/docs/html/guide/topics/data/data-storage.jd
index e20d1ed..d31afa5 100644
--- a/docs/html/guide/topics/data/data-storage.jd
+++ b/docs/html/guide/topics/data/data-storage.jd
@@ -16,9 +16,22 @@
   <h2>In this document</h2>
   <ol>
     <li><a href="#pref">Using Shared Preferences</a></li>
-    <li><a href="#filesInternal">Using the Internal Storage</a></li>
-    <li><a href="#filesExternal">Using the External Storage</a></li>
-    <li><a href="#db">Using Databases</a></li>
+    <li><a href="#filesInternal">Using the Internal Storage</a>
+      <ol>
+        <li><a href="#InternalCache">Saving cache files</a></li>
+        <li><a href="#InternalMethods">Other useful methods</a></li>
+      </ol></li>
+    <li><a href="#filesExternal">Using the External Storage</a>
+      <ol>
+        <li><a href="#MediaAvail">Checking media availability</a></li>
+        <li><a href="#AccessingExtFiles">Accessing files on external storage</a></li>
+        <li><a href="#SavingSharedFiles">Saving files that should be shared</a></li>
+        <li><a href="#ExternalCache">Saving cache files</a></li>
+      </ol></li>
+    <li><a href="#db">Using Databases</a>
+      <ol>
+        <li><a href="#dbDebugging">Database debugging</a></li>
+      </ol></li>
     <li><a href="#netw">Using a Network Connection</a></li>
   </ol>
 
@@ -238,7 +251,7 @@
 storage and the user can remove them.</p>
 
 
-<h3>Checking media availability</h3>
+<h3 id="MediaAvail">Checking media availability</h3>
 
 <p>Before you do any work with the external storage, you should always call {@link
 android.os.Environment#getExternalStorageState()} to check whether the media is available. The
@@ -271,7 +284,7 @@
 when your application needs to access the media.</p>
 
 
-<h3>Accessing files on external storage</h3>
+<h3 id="AccessingExtFiles">Accessing files on external storage</h3>
 
 <p>If you're using API Level 8 or greater, use {@link
 android.content.Context#getExternalFilesDir(String) getExternalFilesDir()} to open a {@link
@@ -310,7 +323,7 @@
 </div>
 
 
-<h3>Saving files that should be shared</h3>
+<h3 id="SavingSharedFiles">Saving files that should be shared</h3>
 
 <p>If you want to save files that are not specific to your application and that should <em>not</em>
 be deleted when your application is uninstalled, save them to one of the public directories on the
diff --git a/docs/html/guide/topics/fundamentals/fragments.jd b/docs/html/guide/topics/fundamentals/fragments.jd
index f780960..3908a7c 100644
--- a/docs/html/guide/topics/fundamentals/fragments.jd
+++ b/docs/html/guide/topics/fundamentals/fragments.jd
@@ -515,7 +515,7 @@
 </pre>
 
 
-<h4 id="EventCallbacks">Creating event callbacks to the activity</h4>
+<h3 id="EventCallbacks">Creating event callbacks to the activity</h3>
 
 <p>In some cases, you might need a fragment to share events with the activity. A good way to do that
 is to define a callback interface inside the fragment and require that the host activity implement
diff --git a/docs/html/guide/topics/nfc/index.jd b/docs/html/guide/topics/nfc/index.jd
index f907b70..b486d3b 100644
--- a/docs/html/guide/topics/nfc/index.jd
+++ b/docs/html/guide/topics/nfc/index.jd
@@ -1,35 +1,24 @@
 page.title=Near Field Communication
 @jd:body
 
-  <div id="qv-wrapper">
-    <div id="qv">
-      <h2>Near Field Communication quickview</h2>
-
+<div id="qv-wrapper">
+<div id="qv">
+  <h2>In this document</h2>
+  <ol>
+    <li><a href="#api">API Overview</a></li>
+    <li><a href="#manifest">Declaring Android Manifest elements</a></li>
+    <li><a href="#dispatch">The Tag Dispatch System</a>
       <ol>
-        <li><a href="#api">API Overview</a></li>
-
-        <li><a href="#manifest">Declaring Android Manifest Elements</a></li>
-
-        <li>
-          <a href="#dispatch">The Tag Dispatch System</a>
-
-          <ol>
-            <li><a href="#intent-dispatch">Using the intent dispatch system</a></li>
-            
-            <li><a href="#foreground-dispatch">Using the foreground dispatch system</a></li>
-          </ol>
-        </li>
-
-        <li><a href="#ndef">NDEF Messages</a></li>
-
-        <li><a href="#read">Reading an NFC Tag</a></li>
-
-        <li><a href="#write">Writing to an NFC Tag</a></li>
-
-        <li><a href="#p2p">Peer to Peer Data Exchange</a></li>
-      </ol>
-    </div>
-  </div>
+        <li><a href="#intent-dispatch">Using the intent dispatch system</a></li>
+        <li><a href="#foreground-dispatch">Using the foreground dispatch system</a></li>
+      </ol></li>
+    <li><a href="#ndef">Working with Data on NFC Tags</a></li>
+    <li><a href="#read">Reading an NFC Tag</a></li>
+    <li><a href="#write">Writing to an NFC Tag</a></li>
+    <li><a href="#p2p">Peer-to-Peer Data Exchange</a></li>
+  </ol>
+</div>
+</div>
 
   <p>Near Field Communication (NFC) is a set of short-range wireless technologies, typically
   requiring a distance of 4cm or less. NFC operates at 13.56mhz, and at rates ranging from 106
diff --git a/docs/html/guide/topics/resources/providing-resources.jd b/docs/html/guide/topics/resources/providing-resources.jd
index 1da2622..10d25bb 100644
--- a/docs/html/guide/topics/resources/providing-resources.jd
+++ b/docs/html/guide/topics/resources/providing-resources.jd
@@ -383,6 +383,46 @@
 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/wireless/bluetooth.jd b/docs/html/guide/topics/wireless/bluetooth.jd
index ae078b9..48632ea 100644
--- a/docs/html/guide/topics/wireless/bluetooth.jd
+++ b/docs/html/guide/topics/wireless/bluetooth.jd
@@ -18,18 +18,13 @@
     <li><a href="#FindingDevices">Finding Devices</a>
       <ol>
         <li><a href="#QueryingPairedDevices">Querying paired devices</a></li>
-        <li><a href="#DiscoveringDevices">Discovering devices</a>
-          <ol><li><a href="#EnablingDiscoverability">Enabling
-                  discoverability</a></li></ol>
-        </li>
-      </ol>
-    </li>
+        <li><a href="#DiscoveringDevices">Discovering devices</a></li>
+      </ol></li>
     <li><a href="#ConnectingDevices">Connecting Devices</a>
       <ol>
         <li><a href="#ConnectingAsAServer">Connecting as a server</a></li>
         <li><a href="#ConnectingAsAClient">Connecting as a client</a></li>
-      </ol>
-    </li>
+      </ol></li>
     <li><a href="#ManagingAConnection">Managing a Connection</a></li>
   </ol>
 
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java
index b89d36d..cf8749b 100644
--- a/graphics/java/android/renderscript/ProgramRaster.java
+++ b/graphics/java/android/renderscript/ProgramRaster.java
@@ -55,18 +55,6 @@
         mCullMode = CullMode.BACK;
     }
 
-    void setLineWidth(float w) {
-        mRS.validate();
-        mLineWidth = w;
-        mRS.nProgramRasterSetLineWidth(getID(), w);
-    }
-
-    void setCullMode(CullMode m) {
-        mRS.validate();
-        mCullMode = m;
-        mRS.nProgramRasterSetCullMode(getID(), m.mID);
-    }
-
     public static ProgramRaster CULL_BACK(RenderScript rs) {
         if(rs.mProgramRaster_CULL_BACK == null) {
             ProgramRaster.Builder builder = new ProgramRaster.Builder(rs);
@@ -119,16 +107,11 @@
             return this;
         }
 
-        static synchronized ProgramRaster internalCreate(RenderScript rs, Builder b) {
-            int id = rs.nProgramRasterCreate(b.mPointSmooth, b.mLineSmooth, b.mPointSprite);
-            ProgramRaster pr = new ProgramRaster(id, rs);
-            pr.setCullMode(b.mCullMode);
-            return pr;
-        }
-
         public ProgramRaster create() {
             mRS.validate();
-            return internalCreate(mRS, this);
+            int id = mRS.nProgramRasterCreate(mPointSmooth, mLineSmooth, mPointSprite,
+                                             1.f, mCullMode.mID);
+            return new ProgramRaster(id, mRS);
         }
     }
 
diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java
index c46e6b9..7a84d8b 100644
--- a/graphics/java/android/renderscript/ProgramStore.java
+++ b/graphics/java/android/renderscript/ProgramStore.java
@@ -333,27 +333,15 @@
             return this;
         }
 
-        static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) {
-            rs.nProgramStoreBegin(0, 0);
-            rs.nProgramStoreDepthFunc(b.mDepthFunc.mID);
-            rs.nProgramStoreDepthMask(b.mDepthMask);
-            rs.nProgramStoreColorMask(b.mColorMaskR,
-                                              b.mColorMaskG,
-                                              b.mColorMaskB,
-                                              b.mColorMaskA);
-            rs.nProgramStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID);
-            rs.nProgramStoreDither(b.mDither);
-
-            int id = rs.nProgramStoreCreate();
-            return new ProgramStore(id, rs);
-        }
-
         /**
         * Creates a program store from the current state of the builder
         */
         public ProgramStore create() {
             mRS.validate();
-            return internalCreate(mRS, this);
+            int id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA,
+                                             mDepthMask, mDither,
+                                             mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID);
+            return new ProgramStore(id, mRS);
         }
     }
 
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index f577532..8f05dc3 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -485,56 +485,24 @@
         return rsnSamplerCreate(mContext);
     }
 
-    native void rsnProgramStoreBegin(int con, int in, int out);
-    synchronized void nProgramStoreBegin(int in, int out) {
+    native int  rsnProgramStoreCreate(int con, boolean r, boolean g, boolean b, boolean a,
+                                      boolean depthMask, boolean dither,
+                                      int srcMode, int dstMode, int depthFunc);
+    synchronized int nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
+                                         boolean depthMask, boolean dither,
+                                         int srcMode, int dstMode, int depthFunc) {
         validate();
-        rsnProgramStoreBegin(mContext, in, out);
-    }
-    native void rsnProgramStoreDepthFunc(int con, int func);
-    synchronized void nProgramStoreDepthFunc(int func) {
-        validate();
-        rsnProgramStoreDepthFunc(mContext, func);
-    }
-    native void rsnProgramStoreDepthMask(int con, boolean enable);
-    synchronized void nProgramStoreDepthMask(boolean enable) {
-        validate();
-        rsnProgramStoreDepthMask(mContext, enable);
-    }
-    native void rsnProgramStoreColorMask(int con, boolean r, boolean g, boolean b, boolean a);
-    synchronized void nProgramStoreColorMask(boolean r, boolean g, boolean b, boolean a) {
-        validate();
-        rsnProgramStoreColorMask(mContext, r, g, b, a);
-    }
-    native void rsnProgramStoreBlendFunc(int con, int src, int dst);
-    synchronized void nProgramStoreBlendFunc(int src, int dst) {
-        validate();
-        rsnProgramStoreBlendFunc(mContext, src, dst);
-    }
-    native void rsnProgramStoreDither(int con, boolean enable);
-    synchronized void nProgramStoreDither(boolean enable) {
-        validate();
-        rsnProgramStoreDither(mContext, enable);
-    }
-    native int  rsnProgramStoreCreate(int con);
-    synchronized int nProgramStoreCreate() {
-        validate();
-        return rsnProgramStoreCreate(mContext);
+        return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
+                                     dstMode, depthFunc);
     }
 
-    native int  rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth, boolean pointSprite);
-    synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, boolean pointSprite) {
+    native int  rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth,
+                                       boolean pointSprite, float lineWidth, int cullMode);
+    synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth,
+                                          boolean pointSprite, float lineWidth, int cullMode) {
         validate();
-        return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite);
-    }
-    native void rsnProgramRasterSetLineWidth(int con, int pr, float v);
-    synchronized void nProgramRasterSetLineWidth(int pr, float v) {
-        validate();
-        rsnProgramRasterSetLineWidth(mContext, pr, v);
-    }
-    native void rsnProgramRasterSetCullMode(int con, int pr, int mode);
-    synchronized void nProgramRasterSetCullMode(int pr, int mode) {
-        validate();
-        rsnProgramRasterSetCullMode(mContext, pr, mode);
+        return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite, lineWidth,
+                                      cullMode);
     }
 
     native void rsnProgramBindConstants(int con, int pv, int slot, int mID);
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index c7f4809..12c5940 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -897,53 +897,17 @@
 
 // ---------------------------------------------------------------------------
 
-static void
-nProgramStoreBegin(JNIEnv *_env, jobject _this, RsContext con, jint in, jint out)
-{
-    LOG_API("nProgramStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
-    rsProgramStoreBegin(con, (RsElement)in, (RsElement)out);
-}
-
-static void
-nProgramStoreDepthFunc(JNIEnv *_env, jobject _this, RsContext con, jint func)
-{
-    LOG_API("nProgramStoreDepthFunc, con(%p), func(%i)", con, func);
-    rsProgramStoreDepthFunc(con, (RsDepthFunc)func);
-}
-
-static void
-nProgramStoreDepthMask(JNIEnv *_env, jobject _this, RsContext con, jboolean enable)
-{
-    LOG_API("nProgramStoreDepthMask, con(%p), enable(%i)", con, enable);
-    rsProgramStoreDepthMask(con, enable);
-}
-
-static void
-nProgramStoreColorMask(JNIEnv *_env, jobject _this, RsContext con, jboolean r, jboolean g, jboolean b, jboolean a)
-{
-    LOG_API("nProgramStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a);
-    rsProgramStoreColorMask(con, r, g, b, a);
-}
-
-static void
-nProgramStoreBlendFunc(JNIEnv *_env, jobject _this, RsContext con, int src, int dst)
-{
-    LOG_API("nProgramStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst);
-    rsProgramStoreBlendFunc(con, (RsBlendSrcFunc)src, (RsBlendDstFunc)dst);
-}
-
-static void
-nProgramStoreDither(JNIEnv *_env, jobject _this, RsContext con, jboolean enable)
-{
-    LOG_API("nProgramStoreDither, con(%p), enable(%i)", con, enable);
-    rsProgramStoreDither(con, enable);
-}
-
 static jint
-nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con)
+nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
+                    jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
+                    jboolean depthMask, jboolean ditherEnable,
+                    jint srcFunc, jint destFunc,
+                    jint depthFunc)
 {
     LOG_API("nProgramStoreCreate, con(%p)", con);
-    return (jint)rsProgramStoreCreate(con);
+    return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
+                                      depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
+                                      (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
 }
 
 // ---------------------------------------------------------------------------
@@ -1005,25 +969,12 @@
 // ---------------------------------------------------------------------------
 
 static jint
-nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSmooth, jboolean lineSmooth, jboolean pointSprite)
+nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSmooth,
+                     jboolean lineSmooth, jboolean pointSprite, jfloat lineWidth, jint cull)
 {
     LOG_API("nProgramRasterCreate, con(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)",
             con, pointSmooth, lineSmooth, pointSprite);
-    return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite);
-}
-
-static void
-nProgramRasterSetLineWidth(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jfloat v)
-{
-    LOG_API("nProgramRasterSetLineWidth, con(%p), vpf(%p), value(%f)", con, (RsProgramRaster)vpr, v);
-    rsProgramRasterSetLineWidth(con, (RsProgramRaster)vpr, v);
-}
-
-static void
-nProgramRasterSetCullMode(JNIEnv *_env, jobject _this, RsContext con, jint vpr, jint v)
-{
-    LOG_API("nProgramRasterSetCullMode, con(%p), vpf(%p), value(%i)", con, (RsProgramRaster)vpr, v);
-    rsProgramRasterSetCullMode(con, (RsProgramRaster)vpr, (RsCullMode)v);
+    return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite, lineWidth, (RsCullMode)cull);
 }
 
 
@@ -1270,24 +1221,14 @@
 
 {"rsnScriptCCreate",                 "(ILjava/lang/String;Ljava/lang/String;[BI)I",  (void*)nScriptCCreate },
 
-{"rsnProgramStoreBegin",             "(III)V",                                (void*)nProgramStoreBegin },
-{"rsnProgramStoreDepthFunc",         "(II)V",                                 (void*)nProgramStoreDepthFunc },
-{"rsnProgramStoreDepthMask",         "(IZ)V",                                 (void*)nProgramStoreDepthMask },
-{"rsnProgramStoreColorMask",         "(IZZZZ)V",                              (void*)nProgramStoreColorMask },
-{"rsnProgramStoreBlendFunc",         "(III)V",                                (void*)nProgramStoreBlendFunc },
-{"rsnProgramStoreDither",            "(IZ)V",                                 (void*)nProgramStoreDither },
-{"rsnProgramStoreCreate",            "(I)I",                                  (void*)nProgramStoreCreate },
+{"rsnProgramStoreCreate",            "(IZZZZZZIII)I",                         (void*)nProgramStoreCreate },
 
 {"rsnProgramBindConstants",          "(IIII)V",                               (void*)nProgramBindConstants },
 {"rsnProgramBindTexture",            "(IIII)V",                               (void*)nProgramBindTexture },
 {"rsnProgramBindSampler",            "(IIII)V",                               (void*)nProgramBindSampler },
 
 {"rsnProgramFragmentCreate",         "(ILjava/lang/String;[I)I",              (void*)nProgramFragmentCreate },
-
-{"rsnProgramRasterCreate",           "(IZZZ)I",                               (void*)nProgramRasterCreate },
-{"rsnProgramRasterSetLineWidth",     "(IIF)V",                                (void*)nProgramRasterSetLineWidth },
-{"rsnProgramRasterSetCullMode",      "(III)V",                                (void*)nProgramRasterSetCullMode },
-
+{"rsnProgramRasterCreate",           "(IZZZFI)I",                             (void*)nProgramRasterCreate },
 {"rsnProgramVertexCreate",           "(ILjava/lang/String;[I)I",              (void*)nProgramVertexCreate },
 
 {"rsnContextBindRootScript",         "(II)V",                                 (void*)nContextBindRootScript },
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index 2dc4beb..edf4b8b7 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -33,6 +33,7 @@
 {
 public:
 
+    // must match android/media/AudioSystem.java STREAM_* constants
     enum stream_type {
         DEFAULT          =-1,
         VOICE_CALL       = 0,
@@ -54,6 +55,8 @@
         PCM_SUB_8_BIT           = 0x2, // must be 2 for backward compatibility
     };
 
+    // FIXME These sub_format enums are currently unused
+
     // MP3 sub format field definition : can use 11 LSBs in the same way as MP3 frame header to specify
     // bit rate, stereo mode, version...
     enum mp3_sub_format {
@@ -100,7 +103,7 @@
     };
 
 
-    // Channel mask definitions must be kept in sync with JAVA values in /media/java/android/media/AudioFormat.java
+    // Channel mask definitions must be kept in sync with values in /media/java/android/media/AudioFormat.java
     enum audio_channels {
         // output channels
         CHANNEL_OUT_FRONT_LEFT = 0x4,
@@ -150,6 +153,7 @@
                 CHANNEL_IN_VOICE_UPLINK | CHANNEL_IN_VOICE_DNLINK)
     };
 
+    // must match android/media/AudioSystem.java MODE_* values
     enum audio_mode {
         MODE_INVALID = -2,
         MODE_CURRENT = -1,
@@ -189,6 +193,7 @@
     // set/get master volume
     static status_t setMasterVolume(float value);
     static status_t getMasterVolume(float* volume);
+
     // mute/unmute audio outputs
     static status_t setMasterMute(bool mute);
     static status_t getMasterMute(bool* mute);
@@ -234,7 +239,7 @@
     static status_t setVoiceVolume(float volume);
 
     // return the number of audio frames written by AudioFlinger to audio HAL and
-    // audio dsp to DAC since the output on which the specificed stream is playing
+    // audio dsp to DAC since the output on which the specified stream is playing
     // has exited standby.
     // returned status (from utils/Errors.h) can be:
     // - NO_ERROR: successful operation, halFrames and dspFrames point to valid data
@@ -321,7 +326,7 @@
         FORCE_DEFAULT = FORCE_NONE
     };
 
-    // usages used for setForceUse()
+    // usages used for setForceUse(), must match AudioSystem.java
     enum force_use {
         FOR_COMMUNICATION,
         FOR_MEDIA,
diff --git a/include/media/IMediaPlayer.h b/include/media/IMediaPlayer.h
index 70519ef..9b1af6b 100644
--- a/include/media/IMediaPlayer.h
+++ b/include/media/IMediaPlayer.h
@@ -24,7 +24,6 @@
 namespace android {
 
 class Parcel;
-class ISurface;
 class Surface;
 class ISurfaceTexture;
 
diff --git a/include/media/IOMX.h b/include/media/IOMX.h
index 16a9342..3c65147 100644
--- a/include/media/IOMX.h
+++ b/include/media/IOMX.h
@@ -33,7 +33,6 @@
 class IMemory;
 class IOMXObserver;
 class IOMXRenderer;
-class ISurface;
 class Surface;
 
 class IOMX : public IInterface {
diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h
index 117d7eb..447942b 100644
--- a/include/media/MediaPlayerInterface.h
+++ b/include/media/MediaPlayerInterface.h
@@ -32,7 +32,6 @@
 namespace android {
 
 class Parcel;
-class ISurface;
 class Surface;
 class ISurfaceTexture;
 
diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h
index 4610135..1827c3e 100644
--- a/include/private/media/AudioTrackShared.h
+++ b/include/private/media/AudioTrackShared.h
@@ -83,13 +83,12 @@
 
                 uint8_t     frameSize;
                 uint8_t     channelCount;
-                uint16_t    flags;
-
                 uint16_t    bufferTimeoutMs; // Maximum cumulated timeout before restarting audioflinger
-                uint16_t    waitTimeMs;      // Cumulated wait time
 
+                uint16_t    waitTimeMs;      // Cumulated wait time
                 uint16_t    sendLevel;
-                uint16_t    reserved;
+    volatile    int32_t     flags;
+
                 // Cache line boundary (32 bytes)
                             audio_track_cblk_t();
                 uint32_t    stepUser(uint32_t frameCount);
@@ -98,6 +97,7 @@
                 uint32_t    framesAvailable();
                 uint32_t    framesAvailable_l();
                 uint32_t    framesReady();
+                bool        tryLock();
 };
 
 
diff --git a/include/surfaceflinger/Surface.h b/include/surfaceflinger/Surface.h
index a59d9e5..3923e61 100644
--- a/include/surfaceflinger/Surface.h
+++ b/include/surfaceflinger/Surface.h
@@ -102,10 +102,6 @@
     friend class Test;
     // videoEditor preview classes
     friend class VideoEditorPreviewController;
-
-    const sp<ISurface>& getISurface() const { return mSurface; }
-    
-
     friend class Surface;
 
     SurfaceControl(
@@ -169,6 +165,7 @@
     // setSwapRectangle() is intended to be used by GL ES clients
     void        setSwapRectangle(const Rect& r);
 
+    sp<IBinder> asBinder() const;
 
 private:
     /*
@@ -242,7 +239,6 @@
      */
     void init();
     status_t validate(bool inCancelBuffer = false) const;
-    sp<ISurface> getISurface() const;
 
     // When the buffer pool is a fixed size we want to make sure SurfaceFlinger
     // won't stall clients, so we require an extra buffer.
diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h
index 6227f3e..35792dc 100644
--- a/include/utils/ResourceTypes.h
+++ b/include/utils/ResourceTypes.h
@@ -972,6 +972,14 @@
         uint32_t screenConfig;
     };
     
+    union {
+        struct {
+            uint16_t screenWidthDp;
+            uint16_t screenHeightDp;
+        };
+        uint32_t screenSizeDp;
+    };
+
     inline void copyFromDeviceNoSwap(const ResTable_config& o) {
         const size_t size = dtohl(o.size);
         if (size >= sizeof(ResTable_config)) {
@@ -992,6 +1000,8 @@
         screenHeight = dtohs(screenHeight);
         sdkVersion = dtohs(sdkVersion);
         minorVersion = dtohs(minorVersion);
+        screenWidthDp = dtohs(screenWidthDp);
+        screenHeightDp = dtohs(screenHeightDp);
     }
     
     inline void swapHtoD() {
@@ -1003,6 +1013,8 @@
         screenHeight = htods(screenHeight);
         sdkVersion = htods(sdkVersion);
         minorVersion = htods(minorVersion);
+        screenWidthDp = htods(screenWidthDp);
+        screenHeightDp = htods(screenHeightDp);
     }
     
     inline int compare(const ResTable_config& o) const {
@@ -1021,6 +1033,8 @@
         diff = (int32_t)(screenLayout - o.screenLayout);
         if (diff != 0) return diff;
         diff = (int32_t)(uiMode - o.uiMode);
+        if (diff != 0) return diff;
+        diff = (int32_t)(screenSizeDp - o.screenSizeDp);
         return (int)diff;
     }
     
@@ -1061,6 +1075,7 @@
         if (version != o.version) diffs |= CONFIG_VERSION;
         if (screenLayout != o.screenLayout) diffs |= CONFIG_SCREEN_LAYOUT;
         if (uiMode != o.uiMode) diffs |= CONFIG_UI_MODE;
+        if (screenSizeDp != o.screenSizeDp) diffs |= CONFIG_SCREEN_SIZE;
         return diffs;
     }
     
@@ -1105,6 +1120,18 @@
             }
         }
 
+        if (screenSizeDp || o.screenSizeDp) {
+            if (screenWidthDp != o.screenWidthDp) {
+                if (!screenWidthDp) return false;
+                if (!o.screenWidthDp) return true;
+            }
+
+            if (screenHeightDp != o.screenHeightDp) {
+                if (!screenHeightDp) return false;
+                if (!o.screenHeightDp) return true;
+            }
+        }
+
         if (orientation != o.orientation) {
             if (!orientation) return false;
             if (!o.orientation) return true;
@@ -1243,6 +1270,30 @@
                 }
             }
 
+            if (screenSizeDp || o.screenSizeDp) {
+                // Better is based on the sum of the difference between both
+                // width and height from the requested dimensions.  We are
+                // assuming the invalid configs (with smaller dimens) have
+                // already been filtered.  Note that if a particular dimension
+                // is unspecified, we will end up with a large value (the
+                // difference between 0 and the requested dimension), which is
+                // good since we will prefer a config that has specified a
+                // dimension value.
+                int myDelta = 0, otherDelta = 0;
+                if (requested->screenWidthDp) {
+                    myDelta += requested->screenWidthDp - screenWidthDp;
+                    otherDelta += requested->screenWidthDp - o.screenWidthDp;
+                }
+                if (requested->screenHeightDp) {
+                    myDelta += requested->screenHeightDp - screenHeightDp;
+                    otherDelta += requested->screenHeightDp - o.screenHeightDp;
+                }
+                //LOGI("Comparing this %dx%d to other %dx%d in %dx%d: myDelta=%d otherDelta=%d",
+                //    screenWidthDp, screenHeightDp, o.screenWidthDp, o.screenHeightDp,
+                //    requested->screenWidthDp, requested->screenHeightDp, myDelta, otherDelta);
+                return (myDelta <= otherDelta);
+            }
+
             if ((orientation != o.orientation) && requested->orientation) {
                 return (orientation);
             }
@@ -1426,6 +1477,18 @@
                 return false;
             }
         }
+        if (screenSizeDp != 0) {
+            if (settings.screenWidthDp != 0 && screenWidthDp != 0
+                && screenWidthDp > settings.screenWidthDp) {
+                //LOGI("Filtering out width %d in requested %d", screenWidthDp, settings.screenWidthDp);
+                return false;
+            }
+            if (settings.screenHeightDp != 0 && screenHeightDp != 0
+                && screenHeightDp > settings.screenHeightDp) {
+                //LOGI("Filtering out height %d in requested %d", screenHeightDp, settings.screenHeightDp);
+                return false;
+            }
+        }
         if (screenType != 0) {
             if (settings.orientation != 0 && orientation != 0
                 && orientation != settings.orientation) {
@@ -1505,13 +1568,13 @@
     String8 toString() const {
         char buf[200];
         sprintf(buf, "imsi=%d/%d lang=%c%c reg=%c%c orient=%d touch=%d dens=%d "
-                "kbd=%d nav=%d input=%d scrnW=%d scrnH=%d sz=%d long=%d "
+                "kbd=%d nav=%d input=%d ssz=%dx%d %ddp x %ddp sz=%d long=%d "
                 "ui=%d night=%d vers=%d.%d",
                 mcc, mnc,
                 language[0] ? language[0] : '-', language[1] ? language[1] : '-',
                 country[0] ? country[0] : '-', country[1] ? country[1] : '-',
                 orientation, touchscreen, density, keyboard, navigation, inputFlags,
-                screenWidth, screenHeight,
+                screenWidth, screenHeight, screenWidthDp, screenHeightDp,
                 screenLayout&MASK_SCREENSIZE, screenLayout&MASK_SCREENLONG,
                 uiMode&MASK_UI_MODE_TYPE, uiMode&MASK_UI_MODE_NIGHT,
                 sdkVersion, minorVersion);
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 0dfbf01..44d9b4b 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -502,8 +502,8 @@
     return NO_ERROR;
 }
 
-sp<ISurface> Surface::getISurface() const {
-    return mSurface;
+sp<IBinder> Surface::asBinder() const {
+    return mSurface!=0 ? mSurface->asBinder() : 0;
 }
 
 // ----------------------------------------------------------------------------
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 9100693..ea7f477 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -116,7 +116,10 @@
 	rsType.cpp \
 	rsVertexArray.cpp \
 	driver/rsdBcc.cpp \
-	driver/rsdCore.cpp
+	driver/rsdCore.cpp \
+	driver/rsdGL.cpp \
+	driver/rsdProgramRaster.cpp \
+	driver/rsdProgramStore.cpp
 
 
 LOCAL_SHARED_LIBRARIES += libz libcutils libutils libEGL libGLESv1_CM libGLESv2 libui libbcc
diff --git a/libs/rs/driver/rsdBcc.h b/libs/rs/driver/rsdBcc.h
index 6723a36..ae7a7af 100644
--- a/libs/rs/driver/rsdBcc.h
+++ b/libs/rs/driver/rsdBcc.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * 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.
diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp
index 6546110..75f4d6b 100644
--- a/libs/rs/driver/rsdCore.cpp
+++ b/libs/rs/driver/rsdCore.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * 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.
@@ -16,6 +16,9 @@
 
 #include "rsdCore.h"
 #include "rsdBcc.h"
+#include "rsdGL.h"
+#include "rsdProgramStore.h"
+#include "rsdProgramRaster.h"
 
 #include <malloc.h>
 #include "rsContext.h"
@@ -35,6 +38,11 @@
 static void SetPriority(const Context *rsc, int32_t priority);
 
 static RsdHalFunctions FunctionTable = {
+    rsdGLInit,
+    rsdGLShutdown,
+    rsdGLSetSurface,
+    rsdGLSwap,
+
     Shutdown,
     NULL,
     SetPriority,
@@ -48,7 +56,21 @@
         rsdScriptSetGlobalBind,
         rsdScriptSetGlobalObj,
         rsdScriptDestroy
+    },
+
+
+    {
+        rsdProgramStoreInit,
+        rsdProgramStoreSetActive,
+        rsdProgramStoreDestroy
+    },
+
+    {
+        rsdProgramRasterInit,
+        rsdProgramRasterSetActive,
+        rsdProgramRasterDestroy
     }
+
 };
 
 
diff --git a/libs/rs/driver/rsdCore.h b/libs/rs/driver/rsdCore.h
index 02b2fbc..e37698b 100644
--- a/libs/rs/driver/rsdCore.h
+++ b/libs/rs/driver/rsdCore.h
@@ -23,6 +23,7 @@
 #include "rsMutex.h"
 #include "rsSignal.h"
 
+#include "rsdGL.h"
 
 typedef void (* InvokeFunc_t)(void);
 typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
@@ -45,6 +46,8 @@
     };
     Workers mWorkers;
     bool mExit;
+
+    RsdGL gl;
 } RsHal;
 
 
diff --git a/libs/rs/driver/rsdGL.cpp b/libs/rs/driver/rsdGL.cpp
new file mode 100644
index 0000000..86dfa0f
--- /dev/null
+++ b/libs/rs/driver/rsdGL.cpp
@@ -0,0 +1,333 @@
+/*
+ * 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.
+ */
+
+#include <ui/FramebufferNativeWindow.h>
+#include <ui/PixelFormat.h>
+#include <ui/EGLUtils.h>
+#include <ui/egl/android_natives.h>
+
+#include <sys/types.h>
+#include <sys/resource.h>
+#include <sched.h>
+
+#include <cutils/properties.h>
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+
+//#include <cutils/sched_policy.h>
+//#include <sys/syscall.h>
+#include <string.h>
+
+
+#include "rsdCore.h"
+#include "rsdGL.h"
+
+#include <malloc.h>
+#include "rsContext.h"
+
+using namespace android;
+using namespace android::renderscript;
+
+static int32_t gGLContextCount = 0;
+
+static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE) {
+    if (returnVal != EGL_TRUE) {
+        fprintf(stderr, "%s() returned %d\n", op, returnVal);
+    }
+
+    for (EGLint error = eglGetError(); error != EGL_SUCCESS; error
+            = eglGetError()) {
+        fprintf(stderr, "after %s() eglError %s (0x%x)\n", op, EGLUtils::strerror(error),
+                error);
+    }
+}
+
+static void printEGLConfiguration(EGLDisplay dpy, EGLConfig config) {
+
+#define X(VAL) {VAL, #VAL}
+    struct {EGLint attribute; const char* name;} names[] = {
+    X(EGL_BUFFER_SIZE),
+    X(EGL_ALPHA_SIZE),
+    X(EGL_BLUE_SIZE),
+    X(EGL_GREEN_SIZE),
+    X(EGL_RED_SIZE),
+    X(EGL_DEPTH_SIZE),
+    X(EGL_STENCIL_SIZE),
+    X(EGL_CONFIG_CAVEAT),
+    X(EGL_CONFIG_ID),
+    X(EGL_LEVEL),
+    X(EGL_MAX_PBUFFER_HEIGHT),
+    X(EGL_MAX_PBUFFER_PIXELS),
+    X(EGL_MAX_PBUFFER_WIDTH),
+    X(EGL_NATIVE_RENDERABLE),
+    X(EGL_NATIVE_VISUAL_ID),
+    X(EGL_NATIVE_VISUAL_TYPE),
+    X(EGL_SAMPLES),
+    X(EGL_SAMPLE_BUFFERS),
+    X(EGL_SURFACE_TYPE),
+    X(EGL_TRANSPARENT_TYPE),
+    X(EGL_TRANSPARENT_RED_VALUE),
+    X(EGL_TRANSPARENT_GREEN_VALUE),
+    X(EGL_TRANSPARENT_BLUE_VALUE),
+    X(EGL_BIND_TO_TEXTURE_RGB),
+    X(EGL_BIND_TO_TEXTURE_RGBA),
+    X(EGL_MIN_SWAP_INTERVAL),
+    X(EGL_MAX_SWAP_INTERVAL),
+    X(EGL_LUMINANCE_SIZE),
+    X(EGL_ALPHA_MASK_SIZE),
+    X(EGL_COLOR_BUFFER_TYPE),
+    X(EGL_RENDERABLE_TYPE),
+    X(EGL_CONFORMANT),
+   };
+#undef X
+
+    for (size_t j = 0; j < sizeof(names) / sizeof(names[0]); j++) {
+        EGLint value = -1;
+        EGLint returnVal = eglGetConfigAttrib(dpy, config, names[j].attribute, &value);
+        EGLint error = eglGetError();
+        if (returnVal && error == EGL_SUCCESS) {
+            LOGV(" %s: %d (0x%x)", names[j].name, value, value);
+        }
+    }
+}
+
+static void DumpDebug(RsHal *dc) {
+    LOGE(" EGL ver %i %i", dc->gl.egl.majorVersion, dc->gl.egl.minorVersion);
+    LOGE(" EGL context %p  surface %p,  Display=%p", dc->gl.egl.context, dc->gl.egl.surface,
+         dc->gl.egl.display);
+    LOGE(" GL vendor: %s", dc->gl.gl.vendor);
+    LOGE(" GL renderer: %s", dc->gl.gl.renderer);
+    LOGE(" GL Version: %s", dc->gl.gl.version);
+    LOGE(" GL Extensions: %s", dc->gl.gl.extensions);
+    LOGE(" GL int Versions %i %i", dc->gl.gl.majorVersion, dc->gl.gl.minorVersion);
+
+    LOGV("MAX Textures %i, %i  %i", dc->gl.gl.maxVertexTextureUnits,
+         dc->gl.gl.maxFragmentTextureImageUnits, dc->gl.gl.maxTextureImageUnits);
+    LOGV("MAX Attribs %i", dc->gl.gl.maxVertexAttribs);
+    LOGV("MAX Uniforms %i, %i", dc->gl.gl.maxVertexUniformVectors,
+         dc->gl.gl.maxFragmentUniformVectors);
+    LOGV("MAX Varyings %i", dc->gl.gl.maxVaryingVectors);
+}
+
+void rsdGLShutdown(const Context *rsc) {
+    RsHal *dc = (RsHal *)rsc->mHal.drv;
+
+    LOGV("%p, deinitEGL", rsc);
+
+    if (dc->gl.egl.context != EGL_NO_CONTEXT) {
+        eglMakeCurrent(dc->gl.egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+        eglDestroySurface(dc->gl.egl.display, dc->gl.egl.surfaceDefault);
+        if (dc->gl.egl.surface != EGL_NO_SURFACE) {
+            eglDestroySurface(dc->gl.egl.display, dc->gl.egl.surface);
+        }
+        eglDestroyContext(dc->gl.egl.display, dc->gl.egl.context);
+        checkEglError("eglDestroyContext");
+    }
+
+    gGLContextCount--;
+    if (!gGLContextCount) {
+        eglTerminate(dc->gl.egl.display);
+    }
+}
+
+bool rsdGLInit(const Context *rsc) {
+    RsHal *dc = (RsHal *)rsc->mHal.drv;
+
+    dc->gl.egl.numConfigs = -1;
+    EGLint configAttribs[128];
+    EGLint *configAttribsPtr = configAttribs;
+    EGLint context_attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
+
+    memset(configAttribs, 0, sizeof(configAttribs));
+
+    configAttribsPtr[0] = EGL_SURFACE_TYPE;
+    configAttribsPtr[1] = EGL_WINDOW_BIT;
+    configAttribsPtr += 2;
+
+    configAttribsPtr[0] = EGL_RENDERABLE_TYPE;
+    configAttribsPtr[1] = EGL_OPENGL_ES2_BIT;
+    configAttribsPtr += 2;
+
+    if (rsc->mUserSurfaceConfig.depthMin > 0) {
+        configAttribsPtr[0] = EGL_DEPTH_SIZE;
+        configAttribsPtr[1] = rsc->mUserSurfaceConfig.depthMin;
+        configAttribsPtr += 2;
+    }
+
+    if (rsc->mDev->mForceSW) {
+        configAttribsPtr[0] = EGL_CONFIG_CAVEAT;
+        configAttribsPtr[1] = EGL_SLOW_CONFIG;
+        configAttribsPtr += 2;
+    }
+
+    configAttribsPtr[0] = EGL_NONE;
+    rsAssert(configAttribsPtr < (configAttribs + (sizeof(configAttribs) / sizeof(EGLint))));
+
+    LOGV("%p initEGL start", rsc);
+    dc->gl.egl.display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+    checkEglError("eglGetDisplay");
+
+    eglInitialize(dc->gl.egl.display, &dc->gl.egl.majorVersion, &dc->gl.egl.minorVersion);
+    checkEglError("eglInitialize");
+
+    PixelFormat pf = PIXEL_FORMAT_RGBA_8888;
+    if (rsc->mUserSurfaceConfig.alphaMin == 0) {
+        pf = PIXEL_FORMAT_RGBX_8888;
+    }
+
+    status_t err = EGLUtils::selectConfigForPixelFormat(dc->gl.egl.display, configAttribs,
+                                                        pf, &dc->gl.egl.config);
+    if (err) {
+       LOGE("%p, couldn't find an EGLConfig matching the screen format\n", rsc);
+    }
+    //if (props.mLogVisual) {
+        printEGLConfiguration(dc->gl.egl.display, dc->gl.egl.config);
+    //}
+
+    dc->gl.egl.context = eglCreateContext(dc->gl.egl.display, dc->gl.egl.config,
+                                          EGL_NO_CONTEXT, context_attribs2);
+    checkEglError("eglCreateContext");
+    if (dc->gl.egl.context == EGL_NO_CONTEXT) {
+        LOGE("%p, eglCreateContext returned EGL_NO_CONTEXT", rsc);
+        return false;
+    }
+    gGLContextCount++;
+
+
+    EGLint pbuffer_attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
+    dc->gl.egl.surfaceDefault = eglCreatePbufferSurface(dc->gl.egl.display, dc->gl.egl.config,
+                                                        pbuffer_attribs);
+    checkEglError("eglCreatePbufferSurface");
+    if (dc->gl.egl.surfaceDefault == EGL_NO_SURFACE) {
+        LOGE("eglCreatePbufferSurface returned EGL_NO_SURFACE");
+        rsdGLShutdown(rsc);
+        return false;
+    }
+
+    EGLBoolean ret = eglMakeCurrent(dc->gl.egl.display, dc->gl.egl.surfaceDefault,
+                                    dc->gl.egl.surfaceDefault, dc->gl.egl.context);
+    if (ret == EGL_FALSE) {
+        LOGE("eglMakeCurrent returned EGL_FALSE");
+        checkEglError("eglMakeCurrent", ret);
+        rsdGLShutdown(rsc);
+        return false;
+    }
+
+    dc->gl.gl.version = glGetString(GL_VERSION);
+    dc->gl.gl.vendor = glGetString(GL_VENDOR);
+    dc->gl.gl.renderer = glGetString(GL_RENDERER);
+    dc->gl.gl.extensions = glGetString(GL_EXTENSIONS);
+
+    //LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
+    //LOGV("GL Version %s", mGL.mVersion);
+    //LOGV("GL Vendor %s", mGL.mVendor);
+    //LOGV("GL Renderer %s", mGL.mRenderer);
+    //LOGV("GL Extensions %s", mGL.mExtensions);
+
+    const char *verptr = NULL;
+    if (strlen((const char *)dc->gl.gl.version) > 9) {
+        if (!memcmp(dc->gl.gl.version, "OpenGL ES-CM", 12)) {
+            verptr = (const char *)dc->gl.gl.version + 12;
+        }
+        if (!memcmp(dc->gl.gl.version, "OpenGL ES ", 10)) {
+            verptr = (const char *)dc->gl.gl.version + 9;
+        }
+    }
+
+    if (!verptr) {
+        LOGE("Error, OpenGL ES Lite not supported");
+        rsdGLShutdown(rsc);
+        return false;
+    } else {
+        sscanf(verptr, " %i.%i", &dc->gl.gl.majorVersion, &dc->gl.gl.minorVersion);
+    }
+
+    glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &dc->gl.gl.maxVertexAttribs);
+    glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &dc->gl.gl.maxVertexUniformVectors);
+    glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &dc->gl.gl.maxVertexTextureUnits);
+
+    glGetIntegerv(GL_MAX_VARYING_VECTORS, &dc->gl.gl.maxVaryingVectors);
+    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &dc->gl.gl.maxTextureImageUnits);
+
+    glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &dc->gl.gl.maxFragmentTextureImageUnits);
+    glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &dc->gl.gl.maxFragmentUniformVectors);
+
+    dc->gl.gl.OES_texture_npot = NULL != strstr((const char *)dc->gl.gl.extensions,
+                                                "GL_OES_texture_npot");
+    dc->gl.gl.GL_IMG_texture_npot = NULL != strstr((const char *)dc->gl.gl.extensions,
+                                                   "GL_IMG_texture_npot");
+    dc->gl.gl.GL_NV_texture_npot_2D_mipmap = NULL != strstr((const char *)dc->gl.gl.extensions,
+                                                            "GL_NV_texture_npot_2D_mipmap");
+    dc->gl.gl.EXT_texture_max_aniso = 1.0f;
+    bool hasAniso = NULL != strstr((const char *)dc->gl.gl.extensions,
+                                   "GL_EXT_texture_filter_anisotropic");
+    if (hasAniso) {
+        glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &dc->gl.gl.EXT_texture_max_aniso);
+    }
+
+    DumpDebug(dc);
+
+    LOGV("initGLThread end %p", rsc);
+    return true;
+}
+
+
+bool rsdGLSetSurface(const Context *rsc, uint32_t w, uint32_t h, ANativeWindow *sur) {
+    RsHal *dc = (RsHal *)rsc->mHal.drv;
+
+    EGLBoolean ret;
+    // WAR: Some drivers fail to handle 0 size surfaces correcntly.
+    // Use the pbuffer to avoid this pitfall.
+    if ((dc->gl.egl.surface != NULL) || (w == 0) || (h == 0)) {
+        ret = eglMakeCurrent(dc->gl.egl.display, dc->gl.egl.surfaceDefault,
+                             dc->gl.egl.surfaceDefault, dc->gl.egl.context);
+        checkEglError("eglMakeCurrent", ret);
+
+        ret = eglDestroySurface(dc->gl.egl.display, dc->gl.egl.surface);
+        checkEglError("eglDestroySurface", ret);
+
+        dc->gl.egl.surface = NULL;
+        dc->gl.width = 1;
+        dc->gl.height = 1;
+    }
+
+    dc->gl.wndSurface = sur;
+    if (dc->gl.wndSurface != NULL) {
+        dc->gl.width = w;
+        dc->gl.height = h;
+
+        dc->gl.egl.surface = eglCreateWindowSurface(dc->gl.egl.display, dc->gl.egl.config,
+                                                    dc->gl.wndSurface, NULL);
+        checkEglError("eglCreateWindowSurface");
+        if (dc->gl.egl.surface == EGL_NO_SURFACE) {
+            LOGE("eglCreateWindowSurface returned EGL_NO_SURFACE");
+        }
+
+        ret = eglMakeCurrent(dc->gl.egl.display, dc->gl.egl.surface,
+                             dc->gl.egl.surface, dc->gl.egl.context);
+        checkEglError("eglMakeCurrent", ret);
+    }
+    return true;
+}
+
+void rsdGLSwap(const android::renderscript::Context *rsc) {
+    RsHal *dc = (RsHal *)rsc->mHal.drv;
+    eglSwapBuffers(dc->gl.egl.display, dc->gl.egl.surface);
+}
+
diff --git a/libs/rs/driver/rsdGL.h b/libs/rs/driver/rsdGL.h
new file mode 100644
index 0000000..246931f
--- /dev/null
+++ b/libs/rs/driver/rsdGL.h
@@ -0,0 +1,78 @@
+/*
+ * 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 RSD_GL_H
+#define RSD_GL_H
+
+#include <rs_hal.h>
+
+
+
+typedef void (* InvokeFunc_t)(void);
+typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
+
+typedef struct RsdGLRec {
+    struct {
+        EGLint numConfigs;
+        EGLint majorVersion;
+        EGLint minorVersion;
+        EGLConfig config;
+        EGLContext context;
+        EGLSurface surface;
+        EGLSurface surfaceDefault;
+        EGLDisplay display;
+    } egl;
+
+    struct {
+        const uint8_t * vendor;
+        const uint8_t * renderer;
+        const uint8_t * version;
+        const uint8_t * extensions;
+
+        uint32_t majorVersion;
+        uint32_t minorVersion;
+
+        int32_t maxVaryingVectors;
+        int32_t maxTextureImageUnits;
+
+        int32_t maxFragmentTextureImageUnits;
+        int32_t maxFragmentUniformVectors;
+
+        int32_t maxVertexAttribs;
+        int32_t maxVertexUniformVectors;
+        int32_t maxVertexTextureUnits;
+
+        bool OES_texture_npot;
+        bool GL_IMG_texture_npot;
+        bool GL_NV_texture_npot_2D_mipmap;
+        float EXT_texture_max_aniso;
+    } gl;
+
+    ANativeWindow *wndSurface;
+    uint32_t width;
+    uint32_t height;
+} RsdGL;
+
+
+
+bool rsdGLInit(const android::renderscript::Context *rsc);
+void rsdGLShutdown(const android::renderscript::Context *rsc);
+bool rsdGLSetSurface(const android::renderscript::Context *rsc,
+                     uint32_t w, uint32_t h, ANativeWindow *sur);
+void rsdGLSwap(const android::renderscript::Context *rsc);
+
+#endif
+
diff --git a/libs/rs/driver/rsdProgramRaster.cpp b/libs/rs/driver/rsdProgramRaster.cpp
new file mode 100644
index 0000000..65995be
--- /dev/null
+++ b/libs/rs/driver/rsdProgramRaster.cpp
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+
+#include "rsdCore.h"
+#include "rsdProgramStore.h"
+
+#include "rsContext.h"
+#include "rsProgramStore.h"
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+
+
+using namespace android;
+using namespace android::renderscript;
+
+bool rsdProgramRasterInit(const Context *, const ProgramRaster *) {
+    return true;
+}
+
+void rsdProgramRasterSetActive(const Context *, const ProgramRaster *pr) {
+    switch (pr->mHal.state.cull) {
+        case RS_CULL_BACK:
+            glEnable(GL_CULL_FACE);
+            glCullFace(GL_BACK);
+            break;
+        case RS_CULL_FRONT:
+            glEnable(GL_CULL_FACE);
+            glCullFace(GL_FRONT);
+            break;
+        case RS_CULL_NONE:
+            glDisable(GL_CULL_FACE);
+            break;
+    }
+
+}
+
+void rsdProgramRasterDestroy(const Context *, const ProgramRaster *) {
+}
+
+
diff --git a/libs/rs/driver/rsdProgramRaster.h b/libs/rs/driver/rsdProgramRaster.h
new file mode 100644
index 0000000..20adaad
--- /dev/null
+++ b/libs/rs/driver/rsdProgramRaster.h
@@ -0,0 +1,31 @@
+/*
+ * 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 RSD_PROGRAM_RASTER_H
+#define RSD_PROGRAM_RASTER_H
+
+#include <rs_hal.h>
+
+
+bool rsdProgramRasterInit(const android::renderscript::Context *rsc,
+                         const android::renderscript::ProgramRaster *);
+void rsdProgramRasterSetActive(const android::renderscript::Context *rsc,
+                              const android::renderscript::ProgramRaster *);
+void rsdProgramRasterDestroy(const android::renderscript::Context *rsc,
+                            const android::renderscript::ProgramRaster *);
+
+
+#endif
diff --git a/libs/rs/driver/rsdProgramStore.cpp b/libs/rs/driver/rsdProgramStore.cpp
new file mode 100644
index 0000000..e591453
--- /dev/null
+++ b/libs/rs/driver/rsdProgramStore.cpp
@@ -0,0 +1,204 @@
+/*
+ * 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.
+ */
+
+
+#include "rsdCore.h"
+#include "rsdProgramStore.h"
+
+#include "rsContext.h"
+#include "rsProgramStore.h"
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+
+
+using namespace android;
+using namespace android::renderscript;
+
+struct DrvProgramStore {
+    GLenum blendSrc;
+    GLenum blendDst;
+    bool blendEnable;
+
+    GLenum depthFunc;
+    bool depthTestEnable;
+};
+
+bool rsdProgramStoreInit(const Context *rsc, const ProgramStore *ps) {
+    DrvProgramStore *drv = (DrvProgramStore *)calloc(1, sizeof(DrvProgramStore));
+    if (drv == NULL) {
+        return false;
+    }
+
+    ps->mHal.drv = drv;
+    drv->depthTestEnable = true;
+
+    switch (ps->mHal.state.depthFunc) {
+    case RS_DEPTH_FUNC_ALWAYS:
+        drv->depthTestEnable = false;
+        drv->depthFunc = GL_ALWAYS;
+        break;
+    case RS_DEPTH_FUNC_LESS:
+        drv->depthFunc = GL_LESS;
+        break;
+    case RS_DEPTH_FUNC_LEQUAL:
+        drv->depthFunc = GL_LEQUAL;
+        break;
+    case RS_DEPTH_FUNC_GREATER:
+        drv->depthFunc = GL_GREATER;
+        break;
+    case RS_DEPTH_FUNC_GEQUAL:
+        drv->depthFunc = GL_GEQUAL;
+        break;
+    case RS_DEPTH_FUNC_EQUAL:
+        drv->depthFunc = GL_EQUAL;
+        break;
+    case RS_DEPTH_FUNC_NOTEQUAL:
+        drv->depthFunc = GL_NOTEQUAL;
+        break;
+    default:
+        LOGE("Unknown depth function.");
+        goto error;
+    }
+
+
+
+    drv->blendEnable = true;
+    if ((ps->mHal.state.blendSrc == RS_BLEND_SRC_ONE) &&
+        (ps->mHal.state.blendDst == RS_BLEND_DST_ZERO)) {
+        drv->blendEnable = false;
+    }
+
+    switch (ps->mHal.state.blendSrc) {
+    case RS_BLEND_SRC_ZERO:
+        drv->blendSrc = GL_ZERO;
+        break;
+    case RS_BLEND_SRC_ONE:
+        drv->blendSrc = GL_ONE;
+        break;
+    case RS_BLEND_SRC_DST_COLOR:
+        drv->blendSrc = GL_DST_COLOR;
+        break;
+    case RS_BLEND_SRC_ONE_MINUS_DST_COLOR:
+        drv->blendSrc = GL_ONE_MINUS_DST_COLOR;
+        break;
+    case RS_BLEND_SRC_SRC_ALPHA:
+        drv->blendSrc = GL_SRC_ALPHA;
+        break;
+    case RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA:
+        drv->blendSrc = GL_ONE_MINUS_SRC_ALPHA;
+        break;
+    case RS_BLEND_SRC_DST_ALPHA:
+        drv->blendSrc = GL_DST_ALPHA;
+        break;
+    case RS_BLEND_SRC_ONE_MINUS_DST_ALPHA:
+        drv->blendSrc = GL_ONE_MINUS_DST_ALPHA;
+        break;
+    case RS_BLEND_SRC_SRC_ALPHA_SATURATE:
+        drv->blendSrc = GL_SRC_ALPHA_SATURATE;
+        break;
+    default:
+        LOGE("Unknown blend src mode.");
+        goto error;
+    }
+
+    switch (ps->mHal.state.blendDst) {
+    case RS_BLEND_DST_ZERO:
+        drv->blendDst = GL_ZERO;
+        break;
+    case RS_BLEND_DST_ONE:
+        drv->blendDst = GL_ONE;
+        break;
+    case RS_BLEND_DST_SRC_COLOR:
+        drv->blendDst = GL_SRC_COLOR;
+        break;
+    case RS_BLEND_DST_ONE_MINUS_SRC_COLOR:
+        drv->blendDst = GL_ONE_MINUS_SRC_COLOR;
+        break;
+    case RS_BLEND_DST_SRC_ALPHA:
+        drv->blendDst = GL_SRC_ALPHA;
+        break;
+    case RS_BLEND_DST_ONE_MINUS_SRC_ALPHA:
+        drv->blendDst = GL_ONE_MINUS_SRC_ALPHA;
+        break;
+    case RS_BLEND_DST_DST_ALPHA:
+        drv->blendDst = GL_DST_ALPHA;
+        break;
+    case RS_BLEND_DST_ONE_MINUS_DST_ALPHA:
+        drv->blendDst = GL_ONE_MINUS_DST_ALPHA;
+        break;
+    default:
+        LOGE("Unknown blend dst mode.");
+        goto error;
+    }
+
+    return true;
+
+error:
+    free(drv);
+    ps->mHal.drv = NULL;
+    return false;
+}
+
+void rsdProgramStoreSetActive(const Context *rsc, const ProgramStore *ps) {
+    DrvProgramStore *drv = (DrvProgramStore *)ps->mHal.drv;
+
+    glColorMask(ps->mHal.state.colorRWriteEnable,
+                ps->mHal.state.colorGWriteEnable,
+                ps->mHal.state.colorBWriteEnable,
+                ps->mHal.state.colorAWriteEnable);
+
+    if (drv->blendEnable) {
+        glEnable(GL_BLEND);
+        glBlendFunc(drv->blendSrc, drv->blendDst);
+    } else {
+        glDisable(GL_BLEND);
+    }
+
+    if (rsc->mUserSurfaceConfig.depthMin > 0) {
+        glDepthMask(ps->mHal.state.depthWriteEnable);
+        if (drv->depthTestEnable || ps->mHal.state.depthWriteEnable) {
+            glEnable(GL_DEPTH_TEST);
+            glDepthFunc(drv->depthFunc);
+        } else {
+            glDisable(GL_DEPTH_TEST);
+        }
+    } else {
+        glDepthMask(false);
+        glDisable(GL_DEPTH_TEST);
+    }
+
+    /*
+    if (rsc->mUserSurfaceConfig.stencilMin > 0) {
+    } else {
+        glStencilMask(0);
+        glDisable(GL_STENCIL_TEST);
+    }
+    */
+
+    if (ps->mHal.state.ditherEnable) {
+        glEnable(GL_DITHER);
+    } else {
+        glDisable(GL_DITHER);
+    }
+}
+
+void rsdProgramStoreDestroy(const Context *rsc, const ProgramStore *ps) {
+    free(ps->mHal.drv);
+    ps->mHal.drv = NULL;
+}
+
+
diff --git a/libs/rs/driver/rsdProgramStore.h b/libs/rs/driver/rsdProgramStore.h
new file mode 100644
index 0000000..217a0ce
--- /dev/null
+++ b/libs/rs/driver/rsdProgramStore.h
@@ -0,0 +1,31 @@
+/*
+ * 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 RSD_PROGRAM_STORE_H
+#define RSD_PROGRAM_STORE_H
+
+#include <rs_hal.h>
+
+
+bool rsdProgramStoreInit(const android::renderscript::Context *rsc,
+                         const android::renderscript::ProgramStore *ps);
+void rsdProgramStoreSetActive(const android::renderscript::Context *rsc,
+                              const android::renderscript::ProgramStore *ps);
+void rsdProgramStoreDestroy(const android::renderscript::Context *rsc,
+                            const android::renderscript::ProgramStore *ps);
+
+
+#endif
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index bbb6200..a7f473c 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -251,36 +251,16 @@
 	}
 
 
-ProgramStoreBegin {
-	param RsElement in
-	param RsElement out
-	}
-
-ProgramStoreColorMask {
-	param bool r
-	param bool g
-	param bool b
-	param bool a
-	}
-
-ProgramStoreBlendFunc {
+ProgramStoreCreate {
+	param bool colorMaskR
+	param bool colorMaskG
+	param bool colorMaskB
+	param bool colorMaskA
+        param bool depthMask
+        param bool ditherEnable
 	param RsBlendSrcFunc srcFunc
 	param RsBlendDstFunc destFunc
-	}
-
-ProgramStoreDepthMask {
-	param bool enable
-}
-
-ProgramStoreDither {
-	param bool enable
-}
-
-ProgramStoreDepthFunc {
-	param RsDepthFunc func
-}
-
-ProgramStoreCreate {
+        param RsDepthFunc depthFunc
 	ret RsProgramStore
 	}
 
@@ -288,19 +268,11 @@
 	param bool pointSmooth
 	param bool lineSmooth
 	param bool pointSprite
+	param float lineWidth
+	param RsCullMode cull
 	ret RsProgramRaster
 }
 
-ProgramRasterSetLineWidth {
-	param RsProgramRaster pr
-	param float lw
-}
-
-ProgramRasterSetCullMode {
-	param RsProgramRaster pr
-	param RsCullMode mode
-}
-
 ProgramBindConstants {
 	param RsProgram vp
 	param uint32_t slot
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index d727ba1..0f61789 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -19,7 +19,6 @@
 #include "rsThreadIO.h"
 #include <ui/FramebufferNativeWindow.h>
 #include <ui/PixelFormat.h>
-#include <ui/EGLUtils.h>
 #include <ui/egl/android_natives.h>
 
 #include <sys/types.h>
@@ -42,188 +41,22 @@
 
 pthread_key_t Context::gThreadTLSKey = 0;
 uint32_t Context::gThreadTLSKeyCount = 0;
-uint32_t Context::gGLContextCount = 0;
 pthread_mutex_t Context::gInitMutex = PTHREAD_MUTEX_INITIALIZER;
 pthread_mutex_t Context::gLibMutex = PTHREAD_MUTEX_INITIALIZER;
 
-static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE) {
-    if (returnVal != EGL_TRUE) {
-        fprintf(stderr, "%s() returned %d\n", op, returnVal);
-    }
-
-    for (EGLint error = eglGetError(); error != EGL_SUCCESS; error
-            = eglGetError()) {
-        fprintf(stderr, "after %s() eglError %s (0x%x)\n", op, EGLUtils::strerror(error),
-                error);
-    }
-}
-
-void printEGLConfiguration(EGLDisplay dpy, EGLConfig config) {
-
-#define X(VAL) {VAL, #VAL}
-    struct {EGLint attribute; const char* name;} names[] = {
-    X(EGL_BUFFER_SIZE),
-    X(EGL_ALPHA_SIZE),
-    X(EGL_BLUE_SIZE),
-    X(EGL_GREEN_SIZE),
-    X(EGL_RED_SIZE),
-    X(EGL_DEPTH_SIZE),
-    X(EGL_STENCIL_SIZE),
-    X(EGL_CONFIG_CAVEAT),
-    X(EGL_CONFIG_ID),
-    X(EGL_LEVEL),
-    X(EGL_MAX_PBUFFER_HEIGHT),
-    X(EGL_MAX_PBUFFER_PIXELS),
-    X(EGL_MAX_PBUFFER_WIDTH),
-    X(EGL_NATIVE_RENDERABLE),
-    X(EGL_NATIVE_VISUAL_ID),
-    X(EGL_NATIVE_VISUAL_TYPE),
-    X(EGL_SAMPLES),
-    X(EGL_SAMPLE_BUFFERS),
-    X(EGL_SURFACE_TYPE),
-    X(EGL_TRANSPARENT_TYPE),
-    X(EGL_TRANSPARENT_RED_VALUE),
-    X(EGL_TRANSPARENT_GREEN_VALUE),
-    X(EGL_TRANSPARENT_BLUE_VALUE),
-    X(EGL_BIND_TO_TEXTURE_RGB),
-    X(EGL_BIND_TO_TEXTURE_RGBA),
-    X(EGL_MIN_SWAP_INTERVAL),
-    X(EGL_MAX_SWAP_INTERVAL),
-    X(EGL_LUMINANCE_SIZE),
-    X(EGL_ALPHA_MASK_SIZE),
-    X(EGL_COLOR_BUFFER_TYPE),
-    X(EGL_RENDERABLE_TYPE),
-    X(EGL_CONFORMANT),
-   };
-#undef X
-
-    for (size_t j = 0; j < sizeof(names) / sizeof(names[0]); j++) {
-        EGLint value = -1;
-        EGLint returnVal = eglGetConfigAttrib(dpy, config, names[j].attribute, &value);
-        EGLint error = eglGetError();
-        if (returnVal && error == EGL_SUCCESS) {
-            LOGV(" %s: %d (0x%x)", names[j].name, value, value);
-        }
-    }
-}
 
 
 bool Context::initGLThread() {
     pthread_mutex_lock(&gInitMutex);
     LOGV("initGLThread start %p", this);
 
-    mEGL.mNumConfigs = -1;
-    EGLint configAttribs[128];
-    EGLint *configAttribsPtr = configAttribs;
-    EGLint context_attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
-
-    memset(configAttribs, 0, sizeof(configAttribs));
-
-    configAttribsPtr[0] = EGL_SURFACE_TYPE;
-    configAttribsPtr[1] = EGL_WINDOW_BIT;
-    configAttribsPtr += 2;
-
-    configAttribsPtr[0] = EGL_RENDERABLE_TYPE;
-    configAttribsPtr[1] = EGL_OPENGL_ES2_BIT;
-    configAttribsPtr += 2;
-
-    if (mUserSurfaceConfig.depthMin > 0) {
-        configAttribsPtr[0] = EGL_DEPTH_SIZE;
-        configAttribsPtr[1] = mUserSurfaceConfig.depthMin;
-        configAttribsPtr += 2;
-    }
-
-    if (mDev->mForceSW) {
-        configAttribsPtr[0] = EGL_CONFIG_CAVEAT;
-        configAttribsPtr[1] = EGL_SLOW_CONFIG;
-        configAttribsPtr += 2;
-    }
-
-    configAttribsPtr[0] = EGL_NONE;
-    rsAssert(configAttribsPtr < (configAttribs + (sizeof(configAttribs) / sizeof(EGLint))));
-
-    LOGV("%p initEGL start", this);
-    mEGL.mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-    checkEglError("eglGetDisplay");
-
-    eglInitialize(mEGL.mDisplay, &mEGL.mMajorVersion, &mEGL.mMinorVersion);
-    checkEglError("eglInitialize");
-
-#if 1
-    PixelFormat pf = PIXEL_FORMAT_RGBA_8888;
-    if (mUserSurfaceConfig.alphaMin == 0) {
-        pf = PIXEL_FORMAT_RGBX_8888;
-    }
-
-    status_t err = EGLUtils::selectConfigForPixelFormat(mEGL.mDisplay, configAttribs, pf, &mEGL.mConfig);
-    if (err) {
-       LOGE("%p, couldn't find an EGLConfig matching the screen format\n", this);
-    }
-    if (props.mLogVisual) {
-        printEGLConfiguration(mEGL.mDisplay, mEGL.mConfig);
-    }
-#else
-    eglChooseConfig(mEGL.mDisplay, configAttribs, &mEGL.mConfig, 1, &mEGL.mNumConfigs);
-#endif
-
-    mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, context_attribs2);
-    checkEglError("eglCreateContext");
-    if (mEGL.mContext == EGL_NO_CONTEXT) {
+    if (!mHal.funcs.initGraphics(this)) {
         pthread_mutex_unlock(&gInitMutex);
-        LOGE("%p, eglCreateContext returned EGL_NO_CONTEXT", this);
-        return false;
-    }
-    gGLContextCount++;
-
-
-    EGLint pbuffer_attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
-    mEGL.mSurfaceDefault = eglCreatePbufferSurface(mEGL.mDisplay, mEGL.mConfig, pbuffer_attribs);
-    checkEglError("eglCreatePbufferSurface");
-    if (mEGL.mSurfaceDefault == EGL_NO_SURFACE) {
-        LOGE("eglCreatePbufferSurface returned EGL_NO_SURFACE");
-        pthread_mutex_unlock(&gInitMutex);
-        deinitEGL();
+        LOGE("%p, initGraphics failed", this);
         return false;
     }
 
-    EGLBoolean ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurfaceDefault, mEGL.mSurfaceDefault, mEGL.mContext);
-    if (ret == EGL_FALSE) {
-        LOGE("eglMakeCurrent returned EGL_FALSE");
-        checkEglError("eglMakeCurrent", ret);
-        pthread_mutex_unlock(&gInitMutex);
-        deinitEGL();
-        return false;
-    }
-
-    mGL.mVersion = glGetString(GL_VERSION);
-    mGL.mVendor = glGetString(GL_VENDOR);
-    mGL.mRenderer = glGetString(GL_RENDERER);
-    mGL.mExtensions = glGetString(GL_EXTENSIONS);
-
-    //LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
-    //LOGV("GL Version %s", mGL.mVersion);
-    //LOGV("GL Vendor %s", mGL.mVendor);
-    //LOGV("GL Renderer %s", mGL.mRenderer);
-    //LOGV("GL Extensions %s", mGL.mExtensions);
-
-    const char *verptr = NULL;
-    if (strlen((const char *)mGL.mVersion) > 9) {
-        if (!memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
-            verptr = (const char *)mGL.mVersion + 12;
-        }
-        if (!memcmp(mGL.mVersion, "OpenGL ES ", 10)) {
-            verptr = (const char *)mGL.mVersion + 9;
-        }
-    }
-
-    if (!verptr) {
-        LOGE("Error, OpenGL ES Lite not supported");
-        pthread_mutex_unlock(&gInitMutex);
-        deinitEGL();
-        return false;
-    } else {
-        sscanf(verptr, " %i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
-    }
+    const char * ext = (const char *)glGetString(GL_EXTENSIONS);
 
     glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &mGL.mMaxVertexAttribs);
     glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &mGL.mMaxVertexUniformVectors);
@@ -235,11 +68,11 @@
     glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mGL.mMaxFragmentTextureImageUnits);
     glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &mGL.mMaxFragmentUniformVectors);
 
-    mGL.OES_texture_npot = NULL != strstr((const char *)mGL.mExtensions, "GL_OES_texture_npot");
-    mGL.GL_IMG_texture_npot = NULL != strstr((const char *)mGL.mExtensions, "GL_IMG_texture_npot");
-    mGL.GL_NV_texture_npot_2D_mipmap = NULL != strstr((const char *)mGL.mExtensions, "GL_NV_texture_npot_2D_mipmap");
+    mGL.OES_texture_npot = NULL != strstr(ext, "GL_OES_texture_npot");
+    mGL.GL_IMG_texture_npot = NULL != strstr(ext, "GL_IMG_texture_npot");
+    mGL.GL_NV_texture_npot_2D_mipmap = NULL != strstr(ext, "GL_NV_texture_npot_2D_mipmap");
     mGL.EXT_texture_max_aniso = 1.0f;
-    bool hasAniso = NULL != strstr((const char *)mGL.mExtensions, "GL_EXT_texture_filter_anisotropic");
+    bool hasAniso = NULL != strstr(ext, "GL_EXT_texture_filter_anisotropic");
     if (hasAniso) {
         glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &mGL.EXT_texture_max_aniso);
     }
@@ -251,21 +84,7 @@
 
 void Context::deinitEGL() {
     LOGV("%p, deinitEGL", this);
-
-    if (mEGL.mContext != EGL_NO_CONTEXT) {
-        eglMakeCurrent(mEGL.mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-        eglDestroySurface(mEGL.mDisplay, mEGL.mSurfaceDefault);
-        if (mEGL.mSurface != EGL_NO_SURFACE) {
-            eglDestroySurface(mEGL.mDisplay, mEGL.mSurface);
-        }
-        eglDestroyContext(mEGL.mDisplay, mEGL.mContext);
-        checkEglError("eglDestroyContext");
-    }
-
-    gGLContextCount--;
-    if (!gGLContextCount) {
-        eglTerminate(mEGL.mDisplay);
-    }
+    mHal.funcs.shutdownGraphics(this);
 }
 
 Context::PushState::PushState(Context *con) {
@@ -405,16 +224,16 @@
         return false;
     }
 
-    mFragmentStore->setupGL2(this, &mStateFragmentStore);
+    mFragmentStore->setup(this, &mStateFragmentStore);
     mFragment->setupGL2(this, &mStateFragment, &mShaderCache);
-    mRaster->setupGL2(this, &mStateRaster);
+    mRaster->setup(this, &mStateRaster);
     mVertex->setupGL2(this, &mStateVertex, &mShaderCache);
     mFBOCache.setupGL2(this);
     return true;
 }
 
 void Context::setupProgramStore() {
-    mFragmentStore->setupGL2(this, &mStateFragmentStore);
+    mFragmentStore->setup(this, &mStateFragmentStore);
 }
 
 static bool getProp(const char *str) {
@@ -507,7 +326,7 @@
 
              mDraw = targetTime && !rsc->mPaused;
              rsc->timerSet(RS_TIMER_CLEAR_SWAP);
-             eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface);
+             rsc->mHal.funcs.swap(rsc);
              rsc->timerFrame();
              rsc->timerSet(RS_TIMER_INTERNAL);
              rsc->timerPrint();
@@ -604,7 +423,6 @@
         memset(&mUserSurfaceConfig, 0, sizeof(mUserSurfaceConfig));
     }
 
-    memset(&mEGL, 0, sizeof(mEGL));
     memset(&mGL, 0, sizeof(mGL));
     mIsGraphicsContext = sc != NULL;
 
@@ -693,36 +511,13 @@
 
 void Context::setSurface(uint32_t w, uint32_t h, ANativeWindow *sur) {
     rsAssert(mIsGraphicsContext);
-
-    EGLBoolean ret;
-    // WAR: Some drivers fail to handle 0 size surfaces correcntly.
-    // Use the pbuffer to avoid this pitfall.
-    if ((mEGL.mSurface != NULL) || (w == 0) || (h == 0)) {
-        ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurfaceDefault, mEGL.mSurfaceDefault, mEGL.mContext);
-        checkEglError("eglMakeCurrent", ret);
-
-        ret = eglDestroySurface(mEGL.mDisplay, mEGL.mSurface);
-        checkEglError("eglDestroySurface", ret);
-
-        mEGL.mSurface = NULL;
-        mWidth = 1;
-        mHeight = 1;
-    }
+    mHal.funcs.setSurface(this, w, h, sur);
 
     mWndSurface = sur;
-    if (mWndSurface != NULL) {
-        mWidth = w;
-        mHeight = h;
+    mWidth = w;
+    mHeight = h;
 
-        mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL);
-        checkEglError("eglCreateWindowSurface");
-        if (mEGL.mSurface == EGL_NO_SURFACE) {
-            LOGE("eglCreateWindowSurface returned EGL_NO_SURFACE");
-        }
-
-        ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext);
-        checkEglError("eglMakeCurrent", ret);
-
+    if (mWidth && mHeight) {
         mStateVertex.updateSize(this);
     }
 }
@@ -887,21 +682,9 @@
     LOGE("RS Context debug %p", this);
     LOGE("RS Context debug");
 
-    LOGE(" EGL ver %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
-    LOGE(" EGL context %p  surface %p,  Display=%p", mEGL.mContext, mEGL.mSurface, mEGL.mDisplay);
-    LOGE(" GL vendor: %s", mGL.mVendor);
-    LOGE(" GL renderer: %s", mGL.mRenderer);
-    LOGE(" GL Version: %s", mGL.mVersion);
-    LOGE(" GL Extensions: %s", mGL.mExtensions);
-    LOGE(" GL int Versions %i %i", mGL.mMajorVersion, mGL.mMinorVersion);
     LOGE(" RS width %i, height %i", mWidth, mHeight);
     LOGE(" RS running %i, exit %i, paused %i", mRunning, mExit, mPaused);
     LOGE(" RS pThreadID %li, nativeThreadID %i", mThreadId, mNativeThreadId);
-
-    LOGV("MAX Textures %i, %i  %i", mGL.mMaxVertexTextureUnits, mGL.mMaxFragmentTextureImageUnits, mGL.mMaxTextureImageUnits);
-    LOGV("MAX Attribs %i", mGL.mMaxVertexAttribs);
-    LOGV("MAX Uniforms %i, %i", mGL.mMaxVertexUniformVectors, mGL.mMaxFragmentUniformVectors);
-    LOGV("MAX Varyings %i", mGL.mMaxVaryingVectors);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index eacfdf7..4dd186c 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -222,29 +222,10 @@
     uint32_t getDPI() const {return mDPI;}
     void setDPI(uint32_t dpi) {mDPI = dpi;}
 
-protected:
     Device *mDev;
+protected:
 
     struct {
-        EGLint mNumConfigs;
-        EGLint mMajorVersion;
-        EGLint mMinorVersion;
-        EGLConfig mConfig;
-        EGLContext mContext;
-        EGLSurface mSurface;
-        EGLSurface mSurfaceDefault;
-        EGLDisplay mDisplay;
-    } mEGL;
-
-    struct {
-        const uint8_t * mVendor;
-        const uint8_t * mRenderer;
-        const uint8_t * mVersion;
-        const uint8_t * mExtensions;
-
-        uint32_t mMajorVersion;
-        uint32_t mMinorVersion;
-
         int32_t mMaxVaryingVectors;
         int32_t mMaxTextureImageUnits;
 
diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp
index 595c89a..c30b857 100644
--- a/libs/rs/rsFont.cpp
+++ b/libs/rs/rsFont.cpp
@@ -507,12 +507,13 @@
     mFontSampler.set(sampler);
     mFontShaderF->bindSampler(mRSC, 0, sampler);
 
-    ProgramStore *fontStore = new ProgramStore(mRSC);
+    ProgramStore *fontStore = new ProgramStore(mRSC, true, true, true, true,
+                                               false, false,
+                                               RS_BLEND_SRC_SRC_ALPHA,
+                                               RS_BLEND_DST_ONE_MINUS_SRC_ALPHA,
+                                               RS_DEPTH_FUNC_ALWAYS);
     mFontProgramStore.set(fontStore);
-    mFontProgramStore->setDepthFunc(RS_DEPTH_FUNC_ALWAYS);
-    mFontProgramStore->setBlendFunc(RS_BLEND_SRC_SRC_ALPHA, RS_BLEND_DST_ONE_MINUS_SRC_ALPHA);
-    mFontProgramStore->setDitherEnable(false);
-    mFontProgramStore->setDepthMask(false);
+    mFontProgramStore->init();
 }
 
 void FontState::initTextTexture() {
diff --git a/libs/rs/rsProgramRaster.cpp b/libs/rs/rsProgramRaster.cpp
index ace1572..9617c4d 100644
--- a/libs/rs/rsProgramRaster.cpp
+++ b/libs/rs/rsProgramRaster.cpp
@@ -15,11 +15,6 @@
  */
 
 #include "rsContext.h"
-#ifndef ANDROID_RS_SERIALIZE
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-#endif //ANDROID_RS_SERIALIZE
-
 #include "rsProgramRaster.h"
 
 using namespace android;
@@ -27,49 +22,33 @@
 
 
 ProgramRaster::ProgramRaster(Context *rsc, bool pointSmooth,
-                             bool lineSmooth, bool pointSprite)
+                             bool lineSmooth, bool pointSprite,
+                             float lineWidth, RsCullMode cull)
     : Program(rsc) {
 
-    mPointSmooth = pointSmooth;
-    mLineSmooth = lineSmooth;
-    mPointSprite = pointSprite;
-    mLineWidth = 1.0f;
-    mCull = RS_CULL_BACK;
+    memset(&mHal, 0, sizeof(mHal));
+
+    mHal.state.pointSmooth = pointSmooth;
+    mHal.state.lineSmooth = lineSmooth;
+    mHal.state.pointSprite = pointSprite;
+    mHal.state.lineWidth = lineWidth;
+    mHal.state.cull = cull;
+
+    rsc->mHal.funcs.raster.init(rsc, this);
 }
 
 ProgramRaster::~ProgramRaster() {
+    mRSC->mHal.funcs.raster.destroy(mRSC, this);
 }
 
-void ProgramRaster::setLineWidth(float s) {
-    mLineWidth = s;
-    mDirty = true;
-}
-
-void ProgramRaster::setCullMode(RsCullMode mode) {
-    mCull = mode;
-    mDirty = true;
-}
-
-void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state) {
+void ProgramRaster::setup(const Context *rsc, ProgramRasterState *state) {
     if (state->mLast.get() == this && !mDirty) {
         return;
     }
     state->mLast.set(this);
     mDirty = false;
 
-    switch (mCull) {
-        case RS_CULL_BACK:
-            glEnable(GL_CULL_FACE);
-            glCullFace(GL_BACK);
-            break;
-        case RS_CULL_FRONT:
-            glEnable(GL_CULL_FACE);
-            glCullFace(GL_FRONT);
-            break;
-        case RS_CULL_NONE:
-            glDisable(GL_CULL_FACE);
-            break;
-    }
+    rsc->mHal.funcs.raster.setActive(rsc, this);
 }
 
 void ProgramRaster::serialize(OStream *stream) const {
@@ -86,7 +65,7 @@
 }
 
 void ProgramRasterState::init(Context *rsc) {
-    ProgramRaster *pr = new ProgramRaster(rsc, false, false, false);
+    ProgramRaster *pr = new ProgramRaster(rsc, false, false, false, 1.f, RS_CULL_BACK);
     mDefault.set(pr);
 }
 
@@ -101,27 +80,15 @@
 RsProgramRaster rsi_ProgramRasterCreate(Context * rsc,
                                       bool pointSmooth,
                                       bool lineSmooth,
-                                      bool pointSprite) {
+                                      bool pointSprite,
+                                      float lineWidth,
+                                      RsCullMode cull) {
     ProgramRaster *pr = new ProgramRaster(rsc, pointSmooth,
-                                          lineSmooth, pointSprite);
+                                          lineSmooth, pointSprite, lineWidth, cull);
     pr->incUserRef();
     return pr;
 }
 
-void rsi_ProgramRasterSetLineWidth(Context * rsc,
-                                   RsProgramRaster vpr,
-                                   float s) {
-    ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
-    pr->setLineWidth(s);
-}
-
-void rsi_ProgramRasterSetCullMode(Context * rsc,
-                                  RsProgramRaster vpr,
-                                  RsCullMode mode) {
-    ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
-    pr->setCullMode(mode);
-}
-
 }
 }
 
diff --git a/libs/rs/rsProgramRaster.h b/libs/rs/rsProgramRaster.h
index 7958af9..045a7c1 100644
--- a/libs/rs/rsProgramRaster.h
+++ b/libs/rs/rsProgramRaster.h
@@ -30,23 +30,31 @@
     ProgramRaster(Context *rsc,
                   bool pointSmooth,
                   bool lineSmooth,
-                  bool pointSprite);
+                  bool pointSprite,
+                  float lineWidth,
+                  RsCullMode cull);
     virtual ~ProgramRaster();
 
-    virtual void setupGL2(const Context *, ProgramRasterState *);
+    virtual void setup(const Context *, ProgramRasterState *);
     virtual void serialize(OStream *stream) const;
     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_RASTER; }
     static ProgramRaster *createFromStream(Context *rsc, IStream *stream);
 
-    void setLineWidth(float w);
-    void setCullMode(RsCullMode mode);
+    struct Hal {
+        mutable void *drv;
+
+        struct State {
+            bool pointSmooth;
+            bool lineSmooth;
+            bool pointSprite;
+            float lineWidth;
+            RsCullMode cull;
+        };
+        State state;
+    };
+    Hal mHal;
 
 protected:
-    bool mPointSmooth;
-    bool mLineSmooth;
-    bool mPointSprite;
-    float mLineWidth;
-    RsCullMode mCull;
 };
 
 class ProgramRasterState {
diff --git a/libs/rs/rsProgramStore.cpp b/libs/rs/rsProgramStore.cpp
index 09b759d..2ad65e9 100644
--- a/libs/rs/rsProgramStore.cpp
+++ b/libs/rs/rsProgramStore.cpp
@@ -15,82 +15,43 @@
  */
 
 #include "rsContext.h"
-#ifndef ANDROID_RS_SERIALIZE
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-#endif //ANDROID_RS_SERIALIZE
-
 #include "rsProgramStore.h"
 
 using namespace android;
 using namespace android::renderscript;
 
 
-ProgramStore::ProgramStore(Context *rsc) : Program(rsc) {
-    mDitherEnable = true;
-    mBlendEnable = false;
-    mColorRWriteEnable = true;
-    mColorGWriteEnable = true;
-    mColorBWriteEnable = true;
-    mColorAWriteEnable = true;
-    mBlendSrc = GL_ONE;
-    mBlendDst = GL_ZERO;
+ProgramStore::ProgramStore(Context *rsc,
+                           bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
+                           bool depthMask, bool ditherEnable,
+                           RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
+                           RsDepthFunc depthFunc) : Program(rsc) {
+    memset(&mHal, 0, sizeof(mHal));
 
-    mDepthTestEnable = false;
-    mDepthWriteEnable = true;
-    mDepthFunc = GL_LESS;
+    mHal.state.ditherEnable = ditherEnable;
+
+    mHal.state.colorRWriteEnable = colorMaskR;
+    mHal.state.colorGWriteEnable = colorMaskG;
+    mHal.state.colorBWriteEnable = colorMaskB;
+    mHal.state.colorAWriteEnable = colorMaskA;
+    mHal.state.blendSrc = srcFunc;
+    mHal.state.blendDst = destFunc;
+
+    mHal.state.depthWriteEnable = depthMask;
+    mHal.state.depthFunc = depthFunc;
 }
 
 ProgramStore::~ProgramStore() {
+    mRSC->mHal.funcs.store.destroy(mRSC, this);
 }
 
-void ProgramStore::setupGL2(const Context *rsc, ProgramStoreState *state) {
+void ProgramStore::setup(const Context *rsc, ProgramStoreState *state) {
     if (state->mLast.get() == this) {
         return;
     }
     state->mLast.set(this);
 
-    glColorMask(mColorRWriteEnable,
-                mColorGWriteEnable,
-                mColorBWriteEnable,
-                mColorAWriteEnable);
-    if (mBlendEnable) {
-        glEnable(GL_BLEND);
-        glBlendFunc(mBlendSrc, mBlendDst);
-    } else {
-        glDisable(GL_BLEND);
-    }
-
-    //LOGE("pfs  %i, %i, %x", mDepthWriteEnable, mDepthTestEnable, mDepthFunc);
-
-    if (rsc->mUserSurfaceConfig.depthMin > 0) {
-        glDepthMask(mDepthWriteEnable);
-        if (mDepthTestEnable || mDepthWriteEnable) {
-            glEnable(GL_DEPTH_TEST);
-            glDepthFunc(mDepthFunc);
-        } else {
-            glDisable(GL_DEPTH_TEST);
-        }
-    } else {
-        glDepthMask(false);
-        glDisable(GL_DEPTH_TEST);
-    }
-
-    if (rsc->mUserSurfaceConfig.stencilMin > 0) {
-    } else {
-        glStencilMask(0);
-        glDisable(GL_STENCIL_TEST);
-    }
-
-    if (mDitherEnable) {
-        glEnable(GL_DITHER);
-    } else {
-        glDisable(GL_DITHER);
-    }
-}
-
-void ProgramStore::setDitherEnable(bool enable) {
-    mDitherEnable = enable;
+    rsc->mHal.funcs.store.setActive(rsc, this);
 }
 
 void ProgramStore::serialize(OStream *stream) const {
@@ -100,123 +61,24 @@
     return NULL;
 }
 
-void ProgramStore::setDepthFunc(RsDepthFunc func) {
-    mDepthTestEnable = true;
-
-    switch (func) {
-    case RS_DEPTH_FUNC_ALWAYS:
-        mDepthTestEnable = false;
-        mDepthFunc = GL_ALWAYS;
-        break;
-    case RS_DEPTH_FUNC_LESS:
-        mDepthFunc = GL_LESS;
-        break;
-    case RS_DEPTH_FUNC_LEQUAL:
-        mDepthFunc = GL_LEQUAL;
-        break;
-    case RS_DEPTH_FUNC_GREATER:
-        mDepthFunc = GL_GREATER;
-        break;
-    case RS_DEPTH_FUNC_GEQUAL:
-        mDepthFunc = GL_GEQUAL;
-        break;
-    case RS_DEPTH_FUNC_EQUAL:
-        mDepthFunc = GL_EQUAL;
-        break;
-    case RS_DEPTH_FUNC_NOTEQUAL:
-        mDepthFunc = GL_NOTEQUAL;
-        break;
-    }
-}
-
-void ProgramStore::setDepthMask(bool mask) {
-    mDepthWriteEnable = mask;
-}
-
-void ProgramStore::setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst) {
-    mBlendEnable = true;
-    if ((src == RS_BLEND_SRC_ONE) &&
-        (dst == RS_BLEND_DST_ZERO)) {
-        mBlendEnable = false;
-    }
-
-    switch (src) {
-    case RS_BLEND_SRC_ZERO:
-        mBlendSrc = GL_ZERO;
-        break;
-    case RS_BLEND_SRC_ONE:
-        mBlendSrc = GL_ONE;
-        break;
-    case RS_BLEND_SRC_DST_COLOR:
-        mBlendSrc = GL_DST_COLOR;
-        break;
-    case RS_BLEND_SRC_ONE_MINUS_DST_COLOR:
-        mBlendSrc = GL_ONE_MINUS_DST_COLOR;
-        break;
-    case RS_BLEND_SRC_SRC_ALPHA:
-        mBlendSrc = GL_SRC_ALPHA;
-        break;
-    case RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA:
-        mBlendSrc = GL_ONE_MINUS_SRC_ALPHA;
-        break;
-    case RS_BLEND_SRC_DST_ALPHA:
-        mBlendSrc = GL_DST_ALPHA;
-        break;
-    case RS_BLEND_SRC_ONE_MINUS_DST_ALPHA:
-        mBlendSrc = GL_ONE_MINUS_DST_ALPHA;
-        break;
-    case RS_BLEND_SRC_SRC_ALPHA_SATURATE:
-        mBlendSrc = GL_SRC_ALPHA_SATURATE;
-        break;
-    }
-
-    switch (dst) {
-    case RS_BLEND_DST_ZERO:
-        mBlendDst = GL_ZERO;
-        break;
-    case RS_BLEND_DST_ONE:
-        mBlendDst = GL_ONE;
-        break;
-    case RS_BLEND_DST_SRC_COLOR:
-        mBlendDst = GL_SRC_COLOR;
-        break;
-    case RS_BLEND_DST_ONE_MINUS_SRC_COLOR:
-        mBlendDst = GL_ONE_MINUS_SRC_COLOR;
-        break;
-    case RS_BLEND_DST_SRC_ALPHA:
-        mBlendDst = GL_SRC_ALPHA;
-        break;
-    case RS_BLEND_DST_ONE_MINUS_SRC_ALPHA:
-        mBlendDst = GL_ONE_MINUS_SRC_ALPHA;
-        break;
-    case RS_BLEND_DST_DST_ALPHA:
-        mBlendDst = GL_DST_ALPHA;
-        break;
-    case RS_BLEND_DST_ONE_MINUS_DST_ALPHA:
-        mBlendDst = GL_ONE_MINUS_DST_ALPHA;
-        break;
-    }
-}
-
-void ProgramStore::setColorMask(bool r, bool g, bool b, bool a) {
-    mColorRWriteEnable = r;
-    mColorGWriteEnable = g;
-    mColorBWriteEnable = b;
-    mColorAWriteEnable = a;
+void ProgramStore::init() {
+    mRSC->mHal.funcs.store.init(mRSC, this);
 }
 
 ProgramStoreState::ProgramStoreState() {
-    mPFS = NULL;
 }
 
 ProgramStoreState::~ProgramStoreState() {
-    ObjectBase::checkDelete(mPFS);
-    mPFS = NULL;
 }
 
 void ProgramStoreState::init(Context *rsc) {
-    ProgramStore *pfs = new ProgramStore(rsc);
-    mDefault.set(pfs);
+    ProgramStore *ps = new ProgramStore(rsc,
+                                        true, true, true, true,
+                                        true, true,
+                                        RS_BLEND_SRC_ONE, RS_BLEND_DST_ZERO,
+                                        RS_DEPTH_FUNC_LESS);
+    ps->init();
+    mDefault.set(ps);
 }
 
 void ProgramStoreState::deinit(Context *rsc) {
@@ -224,40 +86,24 @@
     mLast.clear();
 }
 
+
 namespace android {
 namespace renderscript {
 
-void rsi_ProgramStoreBegin(Context * rsc, RsElement in, RsElement out) {
-    ObjectBase::checkDelete(rsc->mStateFragmentStore.mPFS);
-    rsc->mStateFragmentStore.mPFS = new ProgramStore(rsc);
-}
+RsProgramStore rsi_ProgramStoreCreate(Context *rsc,
+                                      bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
+                                      bool depthMask, bool ditherEnable,
+                                      RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
+                                      RsDepthFunc depthFunc) {
 
-void rsi_ProgramStoreDepthFunc(Context *rsc, RsDepthFunc func) {
-    rsc->mStateFragmentStore.mPFS->setDepthFunc(func);
-}
-
-void rsi_ProgramStoreDepthMask(Context *rsc, bool mask) {
-    rsc->mStateFragmentStore.mPFS->setDepthMask(mask);
-}
-
-void rsi_ProgramStoreColorMask(Context *rsc, bool r, bool g, bool b, bool a) {
-    rsc->mStateFragmentStore.mPFS->setColorMask(r, g, b, a);
-}
-
-void rsi_ProgramStoreBlendFunc(Context *rsc, RsBlendSrcFunc src, RsBlendDstFunc dst) {
-    rsc->mStateFragmentStore.mPFS->setBlendFunc(src, dst);
-}
-
-RsProgramStore rsi_ProgramStoreCreate(Context *rsc) {
-    ProgramStore *pfs = rsc->mStateFragmentStore.mPFS;
+    ProgramStore *pfs = new ProgramStore(rsc,
+                                         colorMaskR, colorMaskG, colorMaskB, colorMaskA,
+                                         depthMask, ditherEnable,
+                                         srcFunc, destFunc, depthFunc);
+    pfs->init();
     pfs->incUserRef();
-    rsc->mStateFragmentStore.mPFS = 0;
     return pfs;
 }
 
-void rsi_ProgramStoreDither(Context *rsc, bool enable) {
-    rsc->mStateFragmentStore.mPFS->setDitherEnable(enable);
-}
-
 }
 }
diff --git a/libs/rs/rsProgramStore.h b/libs/rs/rsProgramStore.h
index f8eb7cf..bfe276d 100644
--- a/libs/rs/rsProgramStore.h
+++ b/libs/rs/rsProgramStore.h
@@ -28,39 +28,46 @@
 
 class ProgramStore : public Program {
 public:
-    ProgramStore(Context *);
+    ProgramStore(Context *,
+                 bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
+                 bool depthMask, bool ditherEnable,
+                 RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
+                 RsDepthFunc depthFunc);
     virtual ~ProgramStore();
 
-    virtual void setupGL2(const Context *, ProgramStoreState *);
-
-    void setDepthFunc(RsDepthFunc);
-    void setDepthMask(bool);
-
-    void setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst);
-    void setColorMask(bool, bool, bool, bool);
-
-    void setDitherEnable(bool);
+    virtual void setup(const Context *, ProgramStoreState *);
 
     virtual void serialize(OStream *stream) const;
     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_STORE; }
     static ProgramStore *createFromStream(Context *rsc, IStream *stream);
 
+    void init();
+
+    struct Hal {
+        mutable void *drv;
+
+        struct State {
+            bool ditherEnable;
+
+            //bool blendEnable;
+            bool colorRWriteEnable;
+            bool colorGWriteEnable;
+            bool colorBWriteEnable;
+            bool colorAWriteEnable;
+            RsBlendSrcFunc blendSrc;
+            RsBlendDstFunc blendDst;
+
+            //bool depthTestEnable;
+            bool depthWriteEnable;
+            RsDepthFunc depthFunc;
+        };
+        State state;
+
+
+    };
+    Hal mHal;
+
 protected:
-    bool mDitherEnable;
-
-    bool mBlendEnable;
-    bool mColorRWriteEnable;
-    bool mColorGWriteEnable;
-    bool mColorBWriteEnable;
-    bool mColorAWriteEnable;
-    int32_t mBlendSrc;
-    int32_t mBlendDst;
-
-    bool mDepthTestEnable;
-    bool mDepthWriteEnable;
-    int32_t mDepthFunc;
-
-    bool mStencilTestEnable;
 };
 
 class ProgramStoreState {
@@ -72,9 +79,6 @@
 
     ObjectBaseRef<ProgramStore> mDefault;
     ObjectBaseRef<ProgramStore> mLast;
-
-
-    ProgramStore *mPFS;
 };
 
 }
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index d5c486b..8e95891 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -185,7 +185,7 @@
 
     //LOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen);
 
-    rsc->mHal.funcs.script.scriptInit(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0, symbolLookup);
+    rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0, symbolLookup);
 
     mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
     mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
diff --git a/libs/rs/rs_hal.h b/libs/rs/rs_hal.h
index 17983ce..a4ca936 100644
--- a/libs/rs/rs_hal.h
+++ b/libs/rs/rs_hal.h
@@ -18,6 +18,7 @@
 #define RS_HAL_H
 
 #include <RenderScriptDefines.h>
+#include <ui/egl/android_natives.h>
 
 namespace android {
 namespace renderscript {
@@ -29,7 +30,8 @@
 class Allocation;
 class Script;
 class ScriptC;
-
+class ProgramStore;
+class ProgramRaster;
 
 typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName);
 
@@ -43,6 +45,11 @@
  * Script management functions
  */
 typedef struct {
+    bool (*initGraphics)(const Context *);
+    void (*shutdownGraphics)(const Context *);
+    bool (*setSurface)(const Context *, uint32_t w, uint32_t h, ANativeWindow *);
+    void (*swap)(const Context *);
+
     void (*shutdownDriver)(Context *);
     void (*getVersion)(unsigned int *major, unsigned int *minor);
     void (*setPriority)(const Context *, int32_t priority);
@@ -50,13 +57,13 @@
 
 
     struct {
-        bool (*scriptInit)(const Context *rsc, ScriptC *s,
-                           char const *resName,
-                           char const *cacheDir,
-                           uint8_t const *bitcode,
-                           size_t bitcodeSize,
-                           uint32_t flags,
-                           RsHalSymbolLookupFunc lookupFunc);
+        bool (*init)(const Context *rsc, ScriptC *s,
+                     char const *resName,
+                     char const *cacheDir,
+                     uint8_t const *bitcode,
+                     size_t bitcodeSize,
+                     uint32_t flags,
+                     RsHalSymbolLookupFunc lookupFunc);
 
         void (*invokeFunction)(const Context *rsc, Script *s,
                                uint32_t slot,
@@ -86,6 +93,17 @@
         void (*destroy)(const Context *rsc, Script *s);
     } script;
 
+    struct {
+        bool (*init)(const Context *rsc, const ProgramStore *ps);
+        void (*setActive)(const Context *rsc, const ProgramStore *ps);
+        void (*destroy)(const Context *rsc, const ProgramStore *ps);
+    } store;
+
+    struct {
+        bool (*init)(const Context *rsc, const ProgramRaster *ps);
+        void (*setActive)(const Context *rsc, const ProgramRaster *ps);
+        void (*destroy)(const Context *rsc, const ProgramRaster *ps);
+    } raster;
 
 
 } RsdHalFunctions;
diff --git a/libs/ui/InputTransport.cpp b/libs/ui/InputTransport.cpp
index 9d1b8b9..93d0d1f 100644
--- a/libs/ui/InputTransport.cpp
+++ b/libs/ui/InputTransport.cpp
@@ -27,8 +27,14 @@
 
 namespace android {
 
+#define ROUND_UP(value, boundary) (((value) + (boundary) - 1) & ~((boundary) - 1))
+#define MIN_HISTORY_DEPTH 20
+
 // Must be at least sizeof(InputMessage) + sufficient space for pointer data
-static const int DEFAULT_MESSAGE_BUFFER_SIZE = 16384;
+static const int DEFAULT_MESSAGE_BUFFER_SIZE = ROUND_UP(
+        sizeof(InputMessage) + MIN_HISTORY_DEPTH
+                * (sizeof(InputMessage::SampleData) + MAX_POINTERS * sizeof(PointerCoords)),
+        4096);
 
 // Signal sent by the producer to the consumer to inform it that a new message is
 // available to be consumed in the shared memory buffer.
diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp
index 7197ad7..ac9cdf9 100644
--- a/libs/utils/ResourceTypes.cpp
+++ b/libs/utils/ResourceTypes.cpp
@@ -2424,7 +2424,7 @@
 {
     mLock.lock();
     TABLE_GETENTRY(LOGI("Setting parameters: imsi:%d/%d lang:%c%c cnt:%c%c "
-                        "orien:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d\n",
+                        "orien:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d %ddp x %ddp\n",
                        params->mcc, params->mnc,
                        params->language[0] ? params->language[0] : '-',
                        params->language[1] ? params->language[1] : '-',
@@ -2437,7 +2437,9 @@
                        params->inputFlags,
                        params->navigation,
                        params->screenWidth,
-                       params->screenHeight));
+                       params->screenHeight,
+                       params->screenWidthDp,
+                       params->screenHeightDp));
     mParams = *params;
     for (size_t i=0; i<mPackageGroups.size(); i++) {
         TABLE_NOISY(LOGI("CLEARING BAGS FOR GROUP %d!", i));
@@ -3758,8 +3760,10 @@
         ResTable_config thisConfig;
         thisConfig.copyFromDtoH(thisType->config);
 
-        TABLE_GETENTRY(LOGI("Match entry 0x%x in type 0x%x (sz 0x%x): imsi:%d/%d=%d/%d lang:%c%c=%c%c cnt:%c%c=%c%c "
-                            "orien:%d=%d touch:%d=%d density:%d=%d key:%d=%d inp:%d=%d nav:%d=%d w:%d=%d h:%d=%d\n",
+        TABLE_GETENTRY(LOGI("Match entry 0x%x in type 0x%x (sz 0x%x): imsi:%d/%d=%d/%d "
+                            "lang:%c%c=%c%c cnt:%c%c=%c%c orien:%d=%d touch:%d=%d "
+                            "density:%d=%d key:%d=%d inp:%d=%d nav:%d=%d w:%d=%d h:%d=%d "
+                            "wdp:%d=%d hdp:%d=%d\n",
                            entryIndex, typeIndex+1, dtohl(thisType->config.size),
                            thisConfig.mcc, thisConfig.mnc,
                            config ? config->mcc : 0, config ? config->mnc : 0,
@@ -3786,7 +3790,11 @@
                            thisConfig.screenWidth,
                            config ? config->screenWidth : 0,
                            thisConfig.screenHeight,
-                           config ? config->screenHeight : 0));
+                           config ? config->screenHeight : 0,
+                           thisConfig.screenWidthDp,
+                           config ? config->screenWidthDp : 0,
+                           thisConfig.screenHeightDp,
+                           config ? config->screenHeightDp : 0));
         
         // Check to make sure this one is valid for the current parameters.
         if (config && !thisConfig.match(*config)) {
@@ -4067,7 +4075,8 @@
                 ResTable_config thisConfig;
                 thisConfig.copyFromDtoH(type->config);
                 LOGI("Adding config to type %d: imsi:%d/%d lang:%c%c cnt:%c%c "
-                     "orien:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d\n",
+                     "orien:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d "
+                     "wdp:%d hdp:%d\n",
                       type->id,
                       thisConfig.mcc, thisConfig.mnc,
                       thisConfig.language[0] ? thisConfig.language[0] : '-',
@@ -4081,7 +4090,9 @@
                       thisConfig.inputFlags,
                       thisConfig.navigation,
                       thisConfig.screenWidth,
-                      thisConfig.screenHeight));
+                      thisConfig.screenHeight,
+                      thisConfig.screenWidthDp,
+                      thisConfig.screenHeightDp));
             t->configs.add(type);
         } else {
             status_t err = validate_chunk(chunk, sizeof(ResChunk_header),
@@ -4444,6 +4455,12 @@
                     if (type->config.screenHeight != 0) {
                         printf(" h=%d", dtohs(type->config.screenHeight));
                     }
+                    if (type->config.screenWidthDp != 0) {
+                        printf(" wdp=%d", dtohs(type->config.screenWidthDp));
+                    }
+                    if (type->config.screenHeightDp != 0) {
+                        printf(" hdp=%d", dtohs(type->config.screenHeightDp));
+                    }
                     if (type->config.sdkVersion != 0) {
                         printf(" sdk=%d", dtohs(type->config.sdkVersion));
                     }
diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java
index 2492d47..95d93b2 100644
--- a/media/java/android/media/AudioSystem.java
+++ b/media/java/android/media/AudioSystem.java
@@ -64,44 +64,20 @@
     /*
      * Sets the microphone mute on or off.
      *
-     * param on set <var>true</var> to mute the microphone;
+     * @param on set <var>true</var> to mute the microphone;
      *           <var>false</var> to turn mute off
-     * return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR
+     * @return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR
      */
     public static native int muteMicrophone(boolean on);
 
     /*
      * Checks whether the microphone mute is on or off.
      *
-     * return true if microphone is muted, false if it's not
+     * @return true if microphone is muted, false if it's not
      */
     public static native boolean isMicrophoneMuted();
 
-    /*
-     * Sets the audio mode.
-     *
-     * param mode  the requested audio mode (NORMAL, RINGTONE, or IN_CALL).
-     *              Informs the HAL about the current audio state so that
-     *              it can route the audio appropriately.
-     * return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR
-     */
-    /** @deprecated use {@link #setPhoneState(int)} */
-    public static int setMode(int mode) {
-        return AUDIO_STATUS_ERROR;
-    }
-    /*
-     * Returns the current audio mode.
-     *
-     * return      the current audio mode (NORMAL, RINGTONE, or IN_CALL).
-     *              Returns the current current audio state from the HAL.
-     *              
-     */
-    /** @deprecated Do not use. */
-    public static int getMode() {
-        return MODE_INVALID;
-    }
-
-    /* modes for setPhoneState */
+    /* modes for setPhoneState, must match AudioSystem.h audio_mode */
     public static final int MODE_INVALID            = -2;
     public static final int MODE_CURRENT            = -1;
     public static final int MODE_NORMAL             = 0;
@@ -111,7 +87,7 @@
     public static final int NUM_MODES               = 4;
 
 
-    /* Routing bits for setRouting/getRouting API */
+    /* Routing bits for the former setRouting/getRouting API */
     /** @deprecated */
     @Deprecated public static final int ROUTE_EARPIECE          = (1 << 0);
     /** @deprecated */
@@ -128,33 +104,6 @@
     @Deprecated public static final int ROUTE_ALL               = 0xFFFFFFFF;
 
     /*
-     * Sets the audio routing for a specified mode
-     *
-     * param mode   audio mode to change route. E.g., MODE_RINGTONE.
-     * param routes bit vector of routes requested, created from one or
-     *               more of ROUTE_xxx types. Set bits indicate that route should be on
-     * param mask   bit vector of routes to change, created from one or more of
-     * ROUTE_xxx types. Unset bits indicate the route should be left unchanged
-     * return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR
-     */
-    /** @deprecated use {@link #setDeviceConnectionState(int,int,String)} */
-    public static int setRouting(int mode, int routes, int mask) {
-        return AUDIO_STATUS_ERROR;
-    }
-
-    /*
-     * Returns the current audio routing bit vector for a specified mode.
-     *
-     * param mode audio mode to change route (e.g., MODE_RINGTONE)
-     * return an audio route bit vector that can be compared with ROUTE_xxx
-     * bits
-     */
-    /** @deprecated use {@link #getDeviceConnectionState(int,String)} */
-    public static int getRouting(int mode) {
-        return 0;
-    }
-
-    /*
      * Checks whether the specified stream type is active.
      *
      * return true if any track playing on this stream is active.
@@ -163,7 +112,7 @@
 
     /*
      * Sets a group generic audio configuration parameters. The use of these parameters
-     * are platform dependant, see libaudio
+     * are platform dependent, see libaudio
      *
      * param keyValuePairs  list of parameters key value pairs in the form:
      *    key1=value1;key2=value2;...
@@ -172,7 +121,7 @@
 
     /*
      * Gets a group generic audio configuration parameters. The use of these parameters
-     * are platform dependant, see libaudio
+     * are platform dependent, see libaudio
      *
      * param keys  list of parameters
      * return value: list of parameters key value pairs in the form:
@@ -180,15 +129,7 @@
      */
     public static native String getParameters(String keys);
 
-    /*
-    private final static String TAG = "audio";
-
-    private void log(String msg) {
-        Log.d(TAG, "[AudioSystem] " + msg);
-    }
-    */
-
-    // These match the enum in libs/android_runtime/android_media_AudioSystem.cpp
+    // These match the enum AudioError in frameworks/base/core/jni/android_media_AudioSystem.cpp
     /* Command sucessful or Media server restarted. see ErrorCallback */
     public static final int AUDIO_STATUS_OK = 0;
     /* Command failed or unspecified audio error.  see ErrorCallback */
@@ -215,7 +156,7 @@
 
     /*
      * Registers a callback to be invoked when an error occurs.
-     * param cb the callback to run
+     * @param cb the callback to run
      */
     public static void setErrorCallback(ErrorCallback cb)
     {
@@ -272,16 +213,17 @@
     public static final int DEVICE_IN_AUX_DIGITAL = 0x800000;
     public static final int DEVICE_IN_DEFAULT = 0x80000000;
 
-    // device states
+    // device states, must match AudioSystem::device_connection_state
     public static final int DEVICE_STATE_UNAVAILABLE = 0;
     public static final int DEVICE_STATE_AVAILABLE = 1;
+    private static final int NUM_DEVICE_STATES = 1;
 
-    // phone state
+    // phone state, match audio_mode???
     public static final int PHONE_STATE_OFFCALL = 0;
     public static final int PHONE_STATE_RINGING = 1;
     public static final int PHONE_STATE_INCALL = 2;
 
-    // config for setForceUse
+    // device categories config for setForceUse, must match AudioSystem::forced_config
     public static final int FORCE_NONE = 0;
     public static final int FORCE_SPEAKER = 1;
     public static final int FORCE_HEADPHONES = 2;
@@ -292,13 +234,15 @@
     public static final int FORCE_BT_DESK_DOCK = 7;
     public static final int FORCE_ANALOG_DOCK = 8;
     public static final int FORCE_DIGITAL_DOCK = 9;
+    private static final int NUM_FORCE_CONFIG = 10;
     public static final int FORCE_DEFAULT = FORCE_NONE;
 
-    // usage for serForceUse
+    // usage for setForceUse, must match AudioSystem::force_use
     public static final int FOR_COMMUNICATION = 0;
     public static final int FOR_MEDIA = 1;
     public static final int FOR_RECORD = 2;
     public static final int FOR_DOCK = 3;
+    private static final int NUM_FORCE_USE = 4;
 
     public static native int setDeviceConnectionState(int device, int state, String device_address);
     public static native int getDeviceConnectionState(int device, String device_address);
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index e2dee00..0b0d145a 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -1462,11 +1462,16 @@
     public interface OnBufferingUpdateListener
     {
         /**
-         * Called to update status in buffering a media stream.
+         * Called to update status in buffering a media stream received through
+         * progressive HTTP download. The received buffering percentage
+         * indicates how much of the content has been buffered or played.
+         * For example a buffering update of 80 percent when half the content
+         * has already been played indicates that the next 30 percent of the
+         * content to play has been buffered.
          *
          * @param mp      the MediaPlayer the update pertains to
-         * @param percent the percentage (0-100) of the buffer
-         *                that has been filled thus far
+         * @param percent the percentage (0-100) of the content
+         *                that has been buffered or played thus far
          */
         void onBufferingUpdate(MediaPlayer mp, int percent);
     }
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java
index b4a4689..b900671 100644
--- a/media/java/android/mtp/MtpDatabase.java
+++ b/media/java/android/mtp/MtpDatabase.java
@@ -50,7 +50,8 @@
     private final IContentProvider mMediaProvider;
     private final String mVolumeName;
     private final Uri mObjectsUri;
-    private final String mMediaStoragePath;
+    private final String mMediaStoragePath; // path to primary storage
+    private final HashMap<String, MtpStorage> mStorageMap = new HashMap<String, MtpStorage>();
 
     // cached property groups for single properties
     private final HashMap<Integer, MtpPropertyGroup> mPropertyGroupsByProperty
@@ -67,9 +68,6 @@
     private SharedPreferences mDeviceProperties;
     private static final int DEVICE_PROPERTIES_DATABASE_VERSION = 1;
 
-    // FIXME - this should be passed in via the constructor
-    private final int mStorageID = 0x00010001;
-
     private static final String[] ID_PROJECTION = new String[] {
             Files.FileColumns._ID, // 0
     };
@@ -85,17 +83,22 @@
     };
     private static final String[] OBJECT_INFO_PROJECTION = new String[] {
             Files.FileColumns._ID, // 0
-            Files.FileColumns.DATA, // 1
+            Files.FileColumns.STORAGE_ID, // 1
             Files.FileColumns.FORMAT, // 2
             Files.FileColumns.PARENT, // 3
-            Files.FileColumns.SIZE, // 4
-            Files.FileColumns.DATE_MODIFIED, // 5
+            Files.FileColumns.DATA, // 4
+            Files.FileColumns.SIZE, // 5
+            Files.FileColumns.DATE_MODIFIED, // 6
     };
     private static final String ID_WHERE = Files.FileColumns._ID + "=?";
     private static final String PATH_WHERE = Files.FileColumns.DATA + "=?";
     private static final String PARENT_WHERE = Files.FileColumns.PARENT + "=?";
     private static final String PARENT_FORMAT_WHERE = PARENT_WHERE + " AND "
                                             + Files.FileColumns.FORMAT + "=?";
+    private static final String PARENT_STORAGE_WHERE = PARENT_WHERE + " AND "
+                                            + Files.FileColumns.STORAGE_ID + "=?";
+    private static final String PARENT_STORAGE_FORMAT_WHERE = PARENT_STORAGE_WHERE + " AND "
+                                            + Files.FileColumns.FORMAT + "=?";
 
     private final MediaScanner mMediaScanner;
 
@@ -124,6 +127,14 @@
         }
     }
 
+    public void addStorage(MtpStorage storage) {
+        mStorageMap.put(storage.getPath(), storage);
+    }
+
+    public void removeStorage(MtpStorage storage) {
+        mStorageMap.remove(storage.getPath());
+    }
+
     private void initDeviceProperties(Context context) {
         final String devicePropertiesName = "device-properties";
         mDeviceProperties = context.getSharedPreferences(devicePropertiesName, Context.MODE_PRIVATE);
@@ -160,7 +171,7 @@
     }
 
     private int beginSendObject(String path, int format, int parent,
-                         int storage, long size, long modified) {
+                         int storageId, long size, long modified) {
         // first make sure the object does not exist
         if (path != null) {
             Cursor c = null;
@@ -185,7 +196,7 @@
         values.put(Files.FileColumns.DATA, path);
         values.put(Files.FileColumns.FORMAT, format);
         values.put(Files.FileColumns.PARENT, parent);
-        // storage is ignored for now
+        values.put(Files.FileColumns.STORAGE_ID, storageId);
         values.put(Files.FileColumns.SIZE, size);
         values.put(Files.FileColumns.DATE_MODIFIED, modified);
 
@@ -237,19 +248,35 @@
         }
     }
 
-    private int[] getObjectList(int storageID, int format, int parent) {
-        // we can ignore storageID until we support multiple storages
-        Cursor c = null;
-        try {
+    private Cursor createObjectQuery(int storageID, int format, int parent) throws RemoteException {
+        if (storageID != 0) {
             if (format != 0) {
-                c = mMediaProvider.query(mObjectsUri, ID_PROJECTION,
+                return mMediaProvider.query(mObjectsUri, ID_PROJECTION,
+                        PARENT_STORAGE_FORMAT_WHERE,
+                        new String[] { Integer.toString(parent), Integer.toString(storageID),
+                                Integer.toString(format) }, null);
+            } else {
+                return mMediaProvider.query(mObjectsUri, ID_PROJECTION,
+                        PARENT_STORAGE_WHERE, new String[]
+                                { Integer.toString(parent), Integer.toString(storageID) }, null);
+            }
+        } else {
+            if (format != 0) {
+                return mMediaProvider.query(mObjectsUri, ID_PROJECTION,
                             PARENT_FORMAT_WHERE,
                             new String[] { Integer.toString(parent), Integer.toString(format) },
                              null);
             } else {
-                c = mMediaProvider.query(mObjectsUri, ID_PROJECTION,
+                return mMediaProvider.query(mObjectsUri, ID_PROJECTION,
                             PARENT_WHERE, new String[] { Integer.toString(parent) }, null);
             }
+        }
+    }
+
+    private int[] getObjectList(int storageID, int format, int parent) {
+        Cursor c = null;
+        try {
+            c = createObjectQuery(storageID, format, parent);
             if (c == null) {
                 return null;
             }
@@ -273,18 +300,9 @@
     }
 
     private int getNumObjects(int storageID, int format, int parent) {
-        // we can ignore storageID until we support multiple storages
         Cursor c = null;
         try {
-            if (format != 0) {
-                c = mMediaProvider.query(mObjectsUri, ID_PROJECTION,
-                            PARENT_FORMAT_WHERE,
-                            new String[] { Integer.toString(parent), Integer.toString(format) },
-                             null);
-            } else {
-                c = mMediaProvider.query(mObjectsUri, ID_PROJECTION,
-                            PARENT_WHERE, new String[] { Integer.toString(parent) }, null);
-            }
+            c = createObjectQuery(storageID, format, parent);
             if (c != null) {
                 return c.getCount();
             }
@@ -508,7 +526,7 @@
             }
         }
 
-        return propertyGroup.getPropertyList((int)handle, format, depth, mStorageID);
+        return propertyGroup.getPropertyList((int)handle, format, depth);
     }
 
     private int renameFile(int handle, String newName) {
@@ -631,12 +649,12 @@
             c = mMediaProvider.query(mObjectsUri, OBJECT_INFO_PROJECTION,
                             ID_WHERE, new String[] {  Integer.toString(handle) }, null);
             if (c != null && c.moveToNext()) {
-                outStorageFormatParent[0] = mStorageID;
+                outStorageFormatParent[0] = c.getInt(1);
                 outStorageFormatParent[1] = c.getInt(2);
                 outStorageFormatParent[2] = c.getInt(3);
 
                 // extract name from path
-                String path = c.getString(1);
+                String path = c.getString(4);
                 int lastSlash = path.lastIndexOf('/');
                 int start = (lastSlash >= 0 ? lastSlash + 1 : 0);
                 int end = path.length();
@@ -646,8 +664,8 @@
                 path.getChars(start, end, outName, 0);
                 outName[end - start] = 0;
 
-                outSizeModified[0] = c.getLong(4);
-                outSizeModified[1] = c.getLong(5);
+                outSizeModified[0] = c.getLong(5);
+                outSizeModified[1] = c.getLong(6);
                 return true;
             }
         } catch (RemoteException e) {
diff --git a/media/java/android/mtp/MtpPropertyGroup.java b/media/java/android/mtp/MtpPropertyGroup.java
index fceedd2..b75b11a 100644
--- a/media/java/android/mtp/MtpPropertyGroup.java
+++ b/media/java/android/mtp/MtpPropertyGroup.java
@@ -93,7 +93,7 @@
 
          switch (code) {
             case MtpConstants.PROPERTY_STORAGE_ID:
-                // no query needed until we support multiple storage units
+                column = Files.FileColumns.STORAGE_ID;
                 type = MtpConstants.TYPE_UINT32;
                 break;
              case MtpConstants.PROPERTY_OBJECT_FORMAT:
@@ -134,6 +134,7 @@
                 break;
             case MtpConstants.PROPERTY_PERSISTENT_UID:
                 // PUID is concatenation of storageID and object handle
+                column = Files.FileColumns.STORAGE_ID;
                 type = MtpConstants.TYPE_UINT128;
                 break;
             case MtpConstants.PROPERTY_DURATION:
@@ -280,7 +281,7 @@
         return path.substring(start, end);
     }
 
-    MtpPropertyList getPropertyList(int handle, int format, int depth, int storageID) {
+    MtpPropertyList getPropertyList(int handle, int format, int depth) {
         //Log.d(TAG, "getPropertyList handle: " + handle + " format: " + format + " depth: " + depth);
         if (depth > 1) {
             // we only support depth 0 and 1
@@ -348,10 +349,6 @@
 
                     // handle some special cases
                     switch (propertyCode) {
-                        case MtpConstants.PROPERTY_STORAGE_ID:
-                            result.append(handle, propertyCode, MtpConstants.TYPE_UINT32,
-                                    storageID);
-                            break;
                         case MtpConstants.PROPERTY_PROTECTION_STATUS:
                             // protection status is always 0
                             result.append(handle, propertyCode, MtpConstants.TYPE_UINT16, 0);
@@ -398,7 +395,7 @@
                             break;
                         case MtpConstants.PROPERTY_PERSISTENT_UID:
                             // PUID is concatenation of storageID and object handle
-                            long puid = storageID;
+                            long puid = c.getLong(column);
                             puid <<= 32;
                             puid += handle;
                             result.append(handle, propertyCode, MtpConstants.TYPE_UINT128, puid);
diff --git a/media/java/android/mtp/MtpServer.java b/media/java/android/mtp/MtpServer.java
index 006fa6d..c065ca8 100644
--- a/media/java/android/mtp/MtpServer.java
+++ b/media/java/android/mtp/MtpServer.java
@@ -33,8 +33,8 @@
         System.loadLibrary("media_jni");
     }
 
-    public MtpServer(MtpDatabase database, String storagePath, long reserveSpace) {
-        native_setup(database, storagePath, reserveSpace);
+    public MtpServer(MtpDatabase database) {
+        native_setup(database);
     }
 
     public void start() {
@@ -65,18 +65,20 @@
         native_set_ptp_mode(usePtp);
     }
 
-    // Used to disable MTP by removing all storage units.
-    // This is done to disable access to file transfer when the device is locked.
-    public void setLocked(boolean locked) {
-        native_set_locked(locked);
+    public void addStorage(MtpStorage storage) {
+        native_add_storage(storage);
     }
 
-    private native final void native_setup(MtpDatabase database, String storagePath,
-            long reserveSpace);
+    public void removeStorage(MtpStorage storage) {
+        native_remove_storage(storage.getStorageId());
+    }
+
+    private native final void native_setup(MtpDatabase database);
     private native final void native_start();
     private native final void native_stop();
     private native final void native_send_object_added(int handle);
     private native final void native_send_object_removed(int handle);
     private native final void native_set_ptp_mode(boolean usePtp);
-    private native final void native_set_locked(boolean locked);
+    private native final void native_add_storage(MtpStorage storage);
+    private native final void native_remove_storage(int storageId);
 }
diff --git a/media/java/android/mtp/MtpStorage.java b/media/java/android/mtp/MtpStorage.java
new file mode 100644
index 0000000..33146e7
--- /dev/null
+++ b/media/java/android/mtp/MtpStorage.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.mtp;
+
+/**
+ * This class represents a storage unit on an MTP device.
+ * Used only for MTP support in USB responder mode.
+ * MtpStorageInfo is used in MTP host mode
+ *
+ * @hide
+ */
+public class MtpStorage {
+
+    private final int mStorageId;
+    private final String mPath;
+    private final String mDescription;
+    private final long mReserveSpace;
+
+    public MtpStorage(int id, String path, String description, long reserveSpace) {
+        mStorageId = id;
+        mPath = path;
+        mDescription = description;
+        mReserveSpace = reserveSpace;
+    }
+
+    /**
+     * Returns the storage ID for the storage unit
+     *
+     * @return the storage ID
+     */
+    public final int getStorageId() {
+        return mStorageId;
+    }
+
+    /**
+     * Generates a storage ID for storage of given index.
+     * Index 0 is for primary external storage
+     *
+     * @return the storage ID
+     */
+    public static int getStorageId(int index) {
+        // storage ID is 0x00010001 for primary storage,
+        // then 0x00020001, 0x00030001, etc. for secondary storages
+        return ((index + 1) << 16) + 1;
+    }
+
+   /**
+     * Returns the file path for the storage unit's storage in the file system
+     *
+     * @return the storage file path
+     */
+    public final String getPath() {
+        return mPath;
+    }
+
+   /**
+     * Returns the description string for the storage unit
+     *
+     * @return the storage unit description
+     */
+    public final String getDescription() {
+        return mDescription;
+    }
+
+   /**
+     * Returns the amount of space to reserve on the storage file system.
+     * This can be set to a non-zero value to prevent MTP from filling up the entire storage.
+     *
+     * @return the storage unit description
+     */
+    public final long getReserveSpace() {
+        return mReserveSpace;
+    }
+
+}
diff --git a/media/jni/android_media_MediaMetadataRetriever.cpp b/media/jni/android_media_MediaMetadataRetriever.cpp
index 5d9a3c5..a219623 100644
--- a/media/jni/android_media_MediaMetadataRetriever.cpp
+++ b/media/jni/android_media_MediaMetadataRetriever.cpp
@@ -34,11 +34,11 @@
 
 struct fields_t {
     jfieldID context;
-    jclass bitmapClazz;
+    jclass bitmapClazz;  // Must be a global ref
     jfieldID nativeBitmap;
     jmethodID createBitmapMethod;
     jmethodID createScaledBitmapMethod;
-    jclass configClazz;
+    jclass configClazz;  // Must be a global ref
     jmethodID createConfigMethod;
 };
 
@@ -120,33 +120,71 @@
     if (headers) {
         // Get the Map's entry Set.
         jclass mapClass = env->FindClass("java/util/Map");
+        if (mapClass == NULL) {
+            return;
+        }
 
         jmethodID entrySet =
             env->GetMethodID(mapClass, "entrySet", "()Ljava/util/Set;");
+        if (entrySet == NULL) {
+            return;
+        }
 
         jobject set = env->CallObjectMethod(headers, entrySet);
+        if (set == NULL) {
+            return;
+        }
+
         // Obtain an iterator over the Set
         jclass setClass = env->FindClass("java/util/Set");
+        if (setClass == NULL) {
+            return;
+        }
 
         jmethodID iterator =
             env->GetMethodID(setClass, "iterator", "()Ljava/util/Iterator;");
+        if (iterator == NULL) {
+            return;
+        }
 
         jobject iter = env->CallObjectMethod(set, iterator);
+        if (iter == NULL) {
+            return;
+        }
+
         // Get the Iterator method IDs
         jclass iteratorClass = env->FindClass("java/util/Iterator");
+        if (iteratorClass == NULL) {
+            return;
+        }
         jmethodID hasNext = env->GetMethodID(iteratorClass, "hasNext", "()Z");
+        if (hasNext == NULL) {
+            return;
+        }
 
         jmethodID next =
             env->GetMethodID(iteratorClass, "next", "()Ljava/lang/Object;");
+        if (next == NULL) {
+            return;
+        }
 
         // Get the Entry class method IDs
         jclass entryClass = env->FindClass("java/util/Map$Entry");
+        if (entryClass == NULL) {
+            return;
+        }
 
         jmethodID getKey =
             env->GetMethodID(entryClass, "getKey", "()Ljava/lang/Object;");
+        if (getKey == NULL) {
+            return;
+        }
 
         jmethodID getValue =
             env->GetMethodID(entryClass, "getValue", "()Ljava/lang/Object;");
+        if (getValue == NULL) {
+            return;
+        }
 
         // Iterate over the entry Set
         while (env->CallBooleanMethod(iter, hasNext)) {
@@ -161,6 +199,7 @@
 
             const char* valueStr = env->GetStringUTFChars(value, NULL);
             if (!valueStr) {  // Out of memory
+                env->ReleaseStringUTFChars(key, keyStr);
                 return;
             }
 
@@ -171,14 +210,8 @@
             env->DeleteLocalRef(key);
             env->ReleaseStringUTFChars(value, valueStr);
             env->DeleteLocalRef(value);
-      }
+        }
 
-      env->DeleteLocalRef(entryClass);
-      env->DeleteLocalRef(iteratorClass);
-      env->DeleteLocalRef(iter);
-      env->DeleteLocalRef(setClass);
-      env->DeleteLocalRef(set);
-      env->DeleteLocalRef(mapClass);
     }
 
     process_media_retriever_call(
@@ -441,19 +474,20 @@
 {
     jclass clazz = env->FindClass(kClassPathName);
     if (clazz == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException", "Can't find android/media/MediaMetadataRetriever");
         return;
     }
 
     fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
     if (fields.context == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException", "Can't find MediaMetadataRetriever.mNativeContext");
         return;
     }
 
-    fields.bitmapClazz = env->FindClass("android/graphics/Bitmap");
+    jclass bitmapClazz = env->FindClass("android/graphics/Bitmap");
+    if (bitmapClazz == NULL) {
+        return;
+    }
+    fields.bitmapClazz = (jclass) env->NewGlobalRef(bitmapClazz);
     if (fields.bitmapClazz == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException", "Can't find android/graphics/Bitmap");
         return;
     }
     fields.createBitmapMethod =
@@ -461,8 +495,6 @@
                     "(IILandroid/graphics/Bitmap$Config;)"
                     "Landroid/graphics/Bitmap;");
     if (fields.createBitmapMethod == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find Bitmap.createBitmap(int, int, Config)  method");
         return;
     }
     fields.createScaledBitmapMethod =
@@ -470,28 +502,25 @@
                     "(Landroid/graphics/Bitmap;IIZ)"
                     "Landroid/graphics/Bitmap;");
     if (fields.createScaledBitmapMethod == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find Bitmap.createScaledBitmap(Bitmap, int, int, boolean)  method");
         return;
     }
     fields.nativeBitmap = env->GetFieldID(fields.bitmapClazz, "mNativeBitmap", "I");
     if (fields.nativeBitmap == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find Bitmap.mNativeBitmap field");
+        return;
     }
 
-    fields.configClazz = env->FindClass("android/graphics/Bitmap$Config");
+    jclass configClazz = env->FindClass("android/graphics/Bitmap$Config");
+    if (configClazz == NULL) {
+        return;
+    }
+    fields.configClazz = (jclass) env->NewGlobalRef(configClazz);
     if (fields.configClazz == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                               "Can't find Bitmap$Config class");
         return;
     }
     fields.createConfigMethod =
             env->GetStaticMethodID(fields.configClazz, "nativeToConfig",
                     "(I)Landroid/graphics/Bitmap$Config;");
     if (fields.createConfigMethod == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find Bitmap$Config.nativeToConfig(int)  method");
         return;
     }
 }
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index 0f9cbec..ecbd288 100644
--- a/media/jni/android_media_MediaPlayer.cpp
+++ b/media/jni/android_media_MediaPlayer.cpp
@@ -1,4 +1,4 @@
-/* //device/libs/android_runtime/android_media_MediaPlayer.cpp
+/*
 **
 ** Copyright 2007, The Android Open Source Project
 **
@@ -185,45 +185,87 @@
         return;
     }
 
-    const char *pathStr = env->GetStringUTFChars(path, NULL);
-    if (pathStr == NULL) {  // Out of memory
-        jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
+    const char *tmp = env->GetStringUTFChars(path, NULL);
+    if (tmp == NULL) {  // Out of memory
         return;
     }
 
+    String8 pathStr(tmp);
+    env->ReleaseStringUTFChars(path, tmp);
+    tmp = NULL;
+
     // headers is a Map<String, String>.
     // We build a similar KeyedVector out of it.
     KeyedVector<String8, String8> headersVector;
     if (headers) {
         // Get the Map's entry Set.
         jclass mapClass = env->FindClass("java/util/Map");
+        if (mapClass == NULL) {
+            return;
+        }
 
         jmethodID entrySet =
             env->GetMethodID(mapClass, "entrySet", "()Ljava/util/Set;");
+        if (entrySet == NULL) {
+            return;
+        }
 
         jobject set = env->CallObjectMethod(headers, entrySet);
+        if (set == NULL) {
+            return;
+        }
+
         // Obtain an iterator over the Set
         jclass setClass = env->FindClass("java/util/Set");
+        if (setClass == NULL) {
+            return;
+        }
 
         jmethodID iterator =
             env->GetMethodID(setClass, "iterator", "()Ljava/util/Iterator;");
+        if (iterator == NULL) {
+            return;
+        }
 
         jobject iter = env->CallObjectMethod(set, iterator);
+        if (iter == NULL) {
+            return;
+        }
+
         // Get the Iterator method IDs
         jclass iteratorClass = env->FindClass("java/util/Iterator");
+        if (iteratorClass == NULL) {
+            return;
+        }
+
         jmethodID hasNext = env->GetMethodID(iteratorClass, "hasNext", "()Z");
+        if (hasNext == NULL) {
+            return;
+        }
 
         jmethodID next =
             env->GetMethodID(iteratorClass, "next", "()Ljava/lang/Object;");
+        if (next == NULL) {
+            return;
+        }
 
         // Get the Entry class method IDs
         jclass entryClass = env->FindClass("java/util/Map$Entry");
+        if (entryClass == NULL) {
+            return;
+        }
 
         jmethodID getKey =
             env->GetMethodID(entryClass, "getKey", "()Ljava/lang/Object;");
+        if (getKey == NULL) {
+            return;
+        }
 
         jmethodID getValue =
             env->GetMethodID(entryClass, "getValue", "()Ljava/lang/Object;");
+        if (getValue == NULL) {
+            return;
+        }
 
         // Iterate over the entry Set
         while (env->CallBooleanMethod(iter, hasNext)) {
@@ -233,15 +275,12 @@
 
             const char* keyStr = env->GetStringUTFChars(key, NULL);
             if (!keyStr) {  // Out of memory
-                jniThrowException(
-                        env, "java/lang/RuntimeException", "Out of memory");
                 return;
             }
 
             const char* valueStr = env->GetStringUTFChars(value, NULL);
             if (!valueStr) {  // Out of memory
-                jniThrowException(
-                        env, "java/lang/RuntimeException", "Out of memory");
+                env->ReleaseStringUTFChars(key, keyStr);
                 return;
             }
 
@@ -252,25 +291,16 @@
             env->DeleteLocalRef(key);
             env->ReleaseStringUTFChars(value, valueStr);
             env->DeleteLocalRef(value);
-      }
+        }
 
-      env->DeleteLocalRef(entryClass);
-      env->DeleteLocalRef(iteratorClass);
-      env->DeleteLocalRef(iter);
-      env->DeleteLocalRef(setClass);
-      env->DeleteLocalRef(set);
-      env->DeleteLocalRef(mapClass);
     }
 
     LOGV("setDataSource: path %s", pathStr);
     status_t opStatus =
         mp->setDataSource(
-                String8(pathStr),
+                pathStr,
                 headers ? &headersVector : NULL);
 
-    // Make sure that local ref is released before a potential exception
-    env->ReleaseStringUTFChars(path, pathStr);
-
     process_media_player_call(
             env, thiz, opStatus, "java/io/IOException",
             "setDataSource failed." );
@@ -628,62 +658,49 @@
 
     clazz = env->FindClass("android/media/MediaPlayer");
     if (clazz == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException", "Can't find android/media/MediaPlayer");
         return;
     }
 
     fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
     if (fields.context == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException", "Can't find MediaPlayer.mNativeContext");
         return;
     }
 
     fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
                                                "(Ljava/lang/Object;IIILjava/lang/Object;)V");
     if (fields.post_event == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException", "Can't find MediaPlayer.postEventFromNative");
         return;
     }
 
     fields.surface = env->GetFieldID(clazz, "mSurface", "Landroid/view/Surface;");
     if (fields.surface == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException", "Can't find MediaPlayer.mSurface");
         return;
     }
 
     jclass surface = env->FindClass("android/view/Surface");
     if (surface == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException", "Can't find android/view/Surface");
         return;
     }
 
     fields.surface_native = env->GetFieldID(surface, ANDROID_VIEW_SURFACE_JNI_ID, "I");
     if (fields.surface_native == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find Surface." ANDROID_VIEW_SURFACE_JNI_ID);
         return;
     }
 
     fields.surfaceTexture = env->GetFieldID(clazz, "mSurfaceTexture",
             "Landroid/graphics/SurfaceTexture;");
     if (fields.surfaceTexture == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find MediaPlayer.mSurfaceTexture");
         return;
     }
 
     jclass surfaceTexture = env->FindClass("android/graphics/SurfaceTexture");
     if (surfaceTexture == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find android/graphics/SurfaceTexture");
         return;
     }
 
     fields.surfaceTexture_native = env->GetFieldID(surfaceTexture,
             ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "I");
     if (fields.surfaceTexture_native == NULL) {
-        jniThrowException(env, "java/lang/RuntimeException",
-                "Can't find SurfaceTexture." ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID);
         return;
     }
 
diff --git a/media/jni/android_media_MediaScanner.cpp b/media/jni/android_media_MediaScanner.cpp
index 9d7bf2c..06058dc 100644
--- a/media/jni/android_media_MediaScanner.cpp
+++ b/media/jni/android_media_MediaScanner.cpp
@@ -213,7 +213,6 @@
 
     const char *pathStr = env->GetStringUTFChars(path, NULL);
     if (pathStr == NULL) {  // Out of memory
-        jniThrowException(env, kRunTimeException, "Out of memory");
         return;
     }
 
@@ -243,15 +242,14 @@
 
     const char *pathStr = env->GetStringUTFChars(path, NULL);
     if (pathStr == NULL) {  // Out of memory
-        jniThrowException(env, kRunTimeException, "Out of memory");
         return;
     }
 
     const char *mimeTypeStr =
         (mimeType ? env->GetStringUTFChars(mimeType, NULL) : NULL);
     if (mimeType && mimeTypeStr == NULL) {  // Out of memory
+        // ReleaseStringUTFChars can be called with an exception pending.
         env->ReleaseStringUTFChars(path, pathStr);
-        jniThrowException(env, kRunTimeException, "Out of memory");
         return;
     }
 
@@ -281,7 +279,6 @@
     }
     const char *localeStr = env->GetStringUTFChars(locale, NULL);
     if (localeStr == NULL) {  // Out of memory
-        jniThrowException(env, kRunTimeException, "Out of memory");
         return;
     }
     mp->setLocale(localeStr);
diff --git a/media/jni/android_mtp_MtpDatabase.cpp b/media/jni/android_mtp_MtpDatabase.cpp
index 17d39e3..2f88fd1 100644
--- a/media/jni/android_mtp_MtpDatabase.cpp
+++ b/media/jni/android_mtp_MtpDatabase.cpp
@@ -427,6 +427,9 @@
                 jstring stringValue = (jstring)env->GetObjectArrayElement(stringValuesArray, 0);
                 if (stringValue) {
                     const char* str = env->GetStringUTFChars(stringValue, NULL);
+                    if (str == NULL) {
+                        return MTP_RESPONSE_GENERAL_ERROR;
+                    }
                     packet.putString(str);
                     env->ReleaseStringUTFChars(stringValue, str);
                 } else {
diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp
index f5fcb4e..40bbaa3 100644
--- a/media/jni/android_mtp_MtpDevice.cpp
+++ b/media/jni/android_mtp_MtpDevice.cpp
@@ -110,6 +110,10 @@
 #ifdef HAVE_ANDROID_OS
     LOGD("open\n");
     const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
+    if (deviceNameStr == NULL) {
+        return false;
+    }
+
     MtpDevice* device = MtpDevice::open(deviceNameStr, fd);
     env->ReleaseStringUTFChars(deviceName, deviceNameStr);
 
@@ -426,12 +430,16 @@
     MtpDevice* device = get_device_from_object(env, thiz);
     if (device) {
         const char *destPathStr = env->GetStringUTFChars(dest_path, NULL);
+        if (destPathStr == NULL) {
+            return false;
+        }
+
         bool result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664);
         env->ReleaseStringUTFChars(dest_path, destPathStr);
         return result;
     }
 #endif
-    return NULL;
+    return false;
 }
 
 // ----------------------------------------------------------------------------
diff --git a/media/jni/android_mtp_MtpServer.cpp b/media/jni/android_mtp_MtpServer.cpp
index e025ef1..84c2c7e 100644
--- a/media/jni/android_mtp_MtpServer.cpp
+++ b/media/jni/android_mtp_MtpServer.cpp
@@ -39,6 +39,17 @@
 
 using namespace android;
 
+// MtpStorage class
+jclass clazz_MtpStorage;
+
+// MtpStorage fields
+static jfieldID field_MtpStorage_storageId;
+static jfieldID field_MtpStorage_path;
+static jfieldID field_MtpStorage_description;
+static jfieldID field_MtpStorage_reserveSpace;
+
+static Mutex sMutex;
+
 // ----------------------------------------------------------------------------
 
 // in android_mtp_MtpDatabase.cpp
@@ -57,70 +68,77 @@
 private:
     MtpDatabase*    mDatabase;
     MtpServer*      mServer;
-    MtpStorage*     mStorage;
-    Mutex           mMutex;
+    MtpStorageList  mStorageList;
     bool            mUsePtp;
-    bool            mLocked;
     int             mFd;
 
 public:
-    MtpThread(MtpDatabase* database, MtpStorage* storage)
+    MtpThread(MtpDatabase* database)
         :   mDatabase(database),
             mServer(NULL),
-            mStorage(storage),
             mUsePtp(false),
-            mLocked(false),
             mFd(-1)
     {
     }
 
     virtual ~MtpThread() {
-        delete mStorage;
     }
 
     void setPtpMode(bool usePtp) {
-        mMutex.lock();
         mUsePtp = usePtp;
-        mMutex.unlock();
     }
 
-    void setLocked(bool locked) {
-        mMutex.lock();
-        if (locked != mLocked) {
-            if (mServer) {
-                if (locked)
-                    mServer->removeStorage(mStorage);
-                else
-                    mServer->addStorage(mStorage);
+    void addStorage(MtpStorage *storage) {
+        mStorageList.push(storage);
+        if (mServer)
+            mServer->addStorage(storage);
+    }
+
+    void removeStorage(MtpStorageID id) {
+        MtpStorage* storage = mServer->getStorage(id);
+        if (storage) {
+            for (size_t i = 0; i < mStorageList.size(); i++) {
+                if (mStorageList[i] == storage) {
+                    mStorageList.removeAt(i);
+                    break;
+                }
             }
-            mLocked = locked;
+            if (mServer)
+                mServer->removeStorage(storage);
+            delete storage;
         }
-        mMutex.unlock();
+    }
+
+    void start() {
+        run("MtpThread");
     }
 
     virtual bool threadLoop() {
-        mMutex.lock();
+        sMutex.lock();
+
         mFd = open("/dev/mtp_usb", O_RDWR);
         if (mFd >= 0) {
             ioctl(mFd, MTP_SET_INTERFACE_MODE,
                     (mUsePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP));
 
             mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
-            if (!mLocked)
-                mServer->addStorage(mStorage);
-
-            mMutex.unlock();
-            mServer->run();
-            mMutex.lock();
-
-            close(mFd);
-            mFd = -1;
-            delete mServer;
-            mServer = NULL;
+            for (size_t i = 0; i < mStorageList.size(); i++) {
+                mServer->addStorage(mStorageList[i]);
+            }
         } else {
             LOGE("could not open MTP driver, errno: %d", errno);
         }
-        mMutex.unlock();
+
+        sMutex.unlock();
+        mServer->run();
+        sMutex.lock();
+
+        close(mFd);
+        mFd = -1;
+        delete mServer;
+        mServer = NULL;
+
+        sMutex.unlock();
         // delay a bit before retrying to avoid excessive spin
         if (!exitPending()) {
             sleep(1);
@@ -130,17 +148,13 @@
     }
 
     void sendObjectAdded(MtpObjectHandle handle) {
-        mMutex.lock();
         if (mServer)
             mServer->sendObjectAdded(handle);
-        mMutex.unlock();
     }
 
     void sendObjectRemoved(MtpObjectHandle handle) {
-        mMutex.lock();
         if (mServer)
             mServer->sendObjectRemoved(handle);
-        mMutex.unlock();
     }
 };
 
@@ -150,18 +164,11 @@
 #endif // HAVE_ANDROID_OS
 
 static void
-android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase,
-        jstring storagePath, jlong reserveSpace)
+android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase)
 {
 #ifdef HAVE_ANDROID_OS
-    MtpDatabase* database = getMtpDatabase(env, javaDatabase);
-    const char *storagePathStr = env->GetStringUTFChars(storagePath, NULL);
-
     // create the thread and assign it to the smart pointer
-    MtpStorage* storage = new MtpStorage(MTP_FIRST_STORAGE_ID, storagePathStr, reserveSpace);
-    sThread = new MtpThread(database, storage);
-
-    env->ReleaseStringUTFChars(storagePath, storagePathStr);
+    sThread = new MtpThread(getMtpDatabase(env, javaDatabase));
 #endif
 }
 
@@ -169,9 +176,11 @@
 android_mtp_MtpServer_start(JNIEnv *env, jobject thiz)
 {
 #ifdef HAVE_ANDROID_OS
+   sMutex.lock();
     MtpThread *thread = sThread.get();
     if (thread)
-        thread->run("MtpThread");
+        thread->start();
+    sMutex.unlock();
 #endif // HAVE_ANDROID_OS
 }
 
@@ -179,11 +188,13 @@
 android_mtp_MtpServer_stop(JNIEnv *env, jobject thiz)
 {
 #ifdef HAVE_ANDROID_OS
+    sMutex.lock();
     MtpThread *thread = sThread.get();
     if (thread) {
         thread->requestExitAndWait();
         sThread = NULL;
     }
+    sMutex.unlock();
 #endif
 }
 
@@ -191,9 +202,11 @@
 android_mtp_MtpServer_send_object_added(JNIEnv *env, jobject thiz, jint handle)
 {
 #ifdef HAVE_ANDROID_OS
+    sMutex.lock();
     MtpThread *thread = sThread.get();
     if (thread)
         thread->sendObjectAdded(handle);
+    sMutex.unlock();
 #endif
 }
 
@@ -201,9 +214,11 @@
 android_mtp_MtpServer_send_object_removed(JNIEnv *env, jobject thiz, jint handle)
 {
 #ifdef HAVE_ANDROID_OS
+    sMutex.lock();
     MtpThread *thread = sThread.get();
     if (thread)
         thread->sendObjectRemoved(handle);
+    sMutex.unlock();
 #endif
 }
 
@@ -211,33 +226,72 @@
 android_mtp_MtpServer_set_ptp_mode(JNIEnv *env, jobject thiz, jboolean usePtp)
 {
 #ifdef HAVE_ANDROID_OS
+    sMutex.lock();
     MtpThread *thread = sThread.get();
     if (thread)
         thread->setPtpMode(usePtp);
+    sMutex.unlock();
 #endif
 }
 
 static void
-android_mtp_MtpServer_set_locked(JNIEnv *env, jobject thiz, jboolean locked)
+android_mtp_MtpServer_add_storage(JNIEnv *env, jobject thiz, jobject jstorage)
 {
 #ifdef HAVE_ANDROID_OS
+    sMutex.lock();
+    MtpThread *thread = sThread.get();
+    if (thread) {
+        jint storageID = env->GetIntField(jstorage, field_MtpStorage_storageId);
+        jstring path = (jstring)env->GetObjectField(jstorage, field_MtpStorage_path);
+        jstring description = (jstring)env->GetObjectField(jstorage, field_MtpStorage_description);
+        jlong reserveSpace = env->GetLongField(jstorage, field_MtpStorage_reserveSpace);
+
+        const char *pathStr = env->GetStringUTFChars(path, NULL);
+        if (pathStr != NULL) {
+            const char *descriptionStr = env->GetStringUTFChars(description, NULL);
+            if (descriptionStr != NULL) {
+                MtpStorage* storage = new MtpStorage(storageID, pathStr, descriptionStr, reserveSpace);
+                thread->addStorage(storage);
+                env->ReleaseStringUTFChars(path, pathStr);
+                env->ReleaseStringUTFChars(description, descriptionStr);
+            } else {
+                env->ReleaseStringUTFChars(path, pathStr);
+            }
+        }
+    } else {
+        LOGE("MtpThread is null in add_storage");
+    }
+    sMutex.unlock();
+#endif
+}
+
+static void
+android_mtp_MtpServer_remove_storage(JNIEnv *env, jobject thiz, jint storageId)
+{
+#ifdef HAVE_ANDROID_OS
+    sMutex.lock();
     MtpThread *thread = sThread.get();
     if (thread)
-        thread->setLocked(locked);
+        thread->removeStorage(storageId);
+    else
+        LOGE("MtpThread is null in remove_storage");
+    sMutex.unlock();
 #endif
 }
 
 // ----------------------------------------------------------------------------
 
 static JNINativeMethod gMethods[] = {
-    {"native_setup",                "(Landroid/mtp/MtpDatabase;Ljava/lang/String;J)V",
+    {"native_setup",                "(Landroid/mtp/MtpDatabase;)V",
                                             (void *)android_mtp_MtpServer_setup},
     {"native_start",                "()V",  (void *)android_mtp_MtpServer_start},
     {"native_stop",                 "()V",  (void *)android_mtp_MtpServer_stop},
     {"native_send_object_added",    "(I)V", (void *)android_mtp_MtpServer_send_object_added},
     {"native_send_object_removed",  "(I)V", (void *)android_mtp_MtpServer_send_object_removed},
     {"native_set_ptp_mode",         "(Z)V", (void *)android_mtp_MtpServer_set_ptp_mode},
-    {"native_set_locked",           "(Z)V", (void *)android_mtp_MtpServer_set_locked},
+    {"native_add_storage",          "(Landroid/mtp/MtpStorage;)V",
+                                            (void *)android_mtp_MtpServer_add_storage},
+    {"native_remove_storage",       "(I)V", (void *)android_mtp_MtpServer_remove_storage},
 };
 
 static const char* const kClassPathName = "android/mtp/MtpServer";
@@ -246,6 +300,33 @@
 {
     jclass clazz;
 
+    clazz = env->FindClass("android/mtp/MtpStorage");
+    if (clazz == NULL) {
+        LOGE("Can't find android/mtp/MtpStorage");
+        return -1;
+    }
+    field_MtpStorage_storageId = env->GetFieldID(clazz, "mStorageId", "I");
+    if (field_MtpStorage_storageId == NULL) {
+        LOGE("Can't find MtpStorage.mStorageId");
+        return -1;
+    }
+    field_MtpStorage_path = env->GetFieldID(clazz, "mPath", "Ljava/lang/String;");
+    if (field_MtpStorage_path == NULL) {
+        LOGE("Can't find MtpStorage.mPath");
+        return -1;
+    }
+    field_MtpStorage_description = env->GetFieldID(clazz, "mDescription", "Ljava/lang/String;");
+    if (field_MtpStorage_description == NULL) {
+        LOGE("Can't find MtpStorage.mDescription");
+        return -1;
+    }
+    field_MtpStorage_reserveSpace = env->GetFieldID(clazz, "mReserveSpace", "J");
+    if (field_MtpStorage_reserveSpace == NULL) {
+        LOGE("Can't find MtpStorage.mStorageId");
+        return -1;
+    }
+    clazz_MtpStorage = (jclass)env->NewGlobalRef(clazz);
+
     clazz = env->FindClass("android/mtp/MtpServer");
     if (clazz == NULL) {
         LOGE("Can't find android/mtp/MtpServer");
diff --git a/media/libmedia/AudioEffect.cpp b/media/libmedia/AudioEffect.cpp
index aadeba5..a043329 100644
--- a/media/libmedia/AudioEffect.cpp
+++ b/media/libmedia/AudioEffect.cpp
@@ -170,7 +170,6 @@
     LOGV("Destructor %p", this);
 
     if (mStatus == NO_ERROR || mStatus == ALREADY_EXISTS) {
-        setEnabled(false);
         if (mIEffect != NULL) {
             mIEffect->disconnect();
             mIEffect->asBinder()->unlinkToDeath(mIEffectClient);
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index cee1c75..5d74a0a 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -35,6 +35,7 @@
 #include <binder/Parcel.h>
 #include <binder/IPCThreadState.h>
 #include <utils/Timers.h>
+#include <utils/Atomic.h>
 
 #define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
 #define UNLIKELY( exp )     (__builtin_expect( (exp) != 0, false ))
@@ -299,7 +300,7 @@
             ret = mAudioRecord->start();
             cblk->lock.lock();
             if (ret == DEAD_OBJECT) {
-                cblk->flags |= CBLK_INVALID_MSK;
+                android_atomic_or(CBLK_INVALID_ON, &cblk->flags);
             }
         }
         if (cblk->flags & CBLK_INVALID_MSK) {
@@ -467,7 +468,7 @@
     mCblkMemory = cblk;
     mCblk = static_cast<audio_track_cblk_t*>(cblk->pointer());
     mCblk->buffers = (char*)mCblk + sizeof(audio_track_cblk_t);
-    mCblk->flags &= ~CBLK_DIRECTION_MSK;
+    android_atomic_and(~CBLK_DIRECTION_MSK, &mCblk->flags);
     mCblk->bufferTimeoutMs = MAX_RUN_TIMEOUT_MS;
     mCblk->waitTimeMs = 0;
     return NO_ERROR;
@@ -522,7 +523,7 @@
                     result = mAudioRecord->start();
                     cblk->lock.lock();
                     if (result == DEAD_OBJECT) {
-                        cblk->flags |= CBLK_INVALID_MSK;
+                        android_atomic_or(CBLK_INVALID_ON, &cblk->flags);
 create_new_record:
                         result = AudioRecord::restoreRecord_l(cblk);
                     }
@@ -722,12 +723,8 @@
     // Manage overrun callback
     if (mActive && (cblk->framesAvailable() == 0)) {
         LOGV("Overrun user: %x, server: %x, flags %04x", cblk->user, cblk->server, cblk->flags);
-        AutoMutex _l(cblk->lock);
-        if ((cblk->flags & CBLK_UNDERRUN_MSK) == CBLK_UNDERRUN_OFF) {
-            cblk->flags |= CBLK_UNDERRUN_ON;
-            cblk->lock.unlock();
+        if (!(android_atomic_or(CBLK_UNDERRUN_ON, &cblk->flags) & CBLK_UNDERRUN_MSK)) {
             mCbf(EVENT_OVERRUN, mUserData, 0);
-            cblk->lock.lock();
         }
     }
 
@@ -746,10 +743,8 @@
 {
     status_t result;
 
-    if (!(cblk->flags & CBLK_RESTORING_MSK)) {
+    if (!(android_atomic_or(CBLK_RESTORING_ON, &cblk->flags) & CBLK_RESTORING_MSK)) {
         LOGW("dead IAudioRecord, creating a new one");
-
-        cblk->flags |= CBLK_RESTORING_ON;
         // signal old cblk condition so that other threads waiting for available buffers stop
         // waiting now
         cblk->cv.broadcast();
@@ -768,10 +763,8 @@
         }
 
         // signal old cblk condition for other threads waiting for restore completion
-        cblk->lock.lock();
-        cblk->flags |= CBLK_RESTORED_MSK;
+        android_atomic_or(CBLK_RESTORED_ON, &cblk->flags);
         cblk->cv.broadcast();
-        cblk->lock.unlock();
     } else {
         if (!(cblk->flags & CBLK_RESTORED_MSK)) {
             LOGW("dead IAudioRecord, waiting for a new one to be created");
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index fb2ee0f..66e11d2 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -35,6 +35,7 @@
 #include <binder/Parcel.h>
 #include <binder/IPCThreadState.h>
 #include <utils/Timers.h>
+#include <utils/Atomic.h>
 
 #define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
 #define UNLIKELY( exp )     (__builtin_expect( (exp) != 0, false ))
@@ -332,7 +333,7 @@
         cblk->lock.lock();
         cblk->bufferTimeoutMs = MAX_STARTUP_TIMEOUT_MS;
         cblk->waitTimeMs = 0;
-        cblk->flags &= ~CBLK_DISABLED_ON;
+        android_atomic_and(~CBLK_DISABLED_ON, &cblk->flags);
         if (t != 0) {
            t->run("AudioTrackThread", THREAD_PRIORITY_AUDIO_CLIENT);
         } else {
@@ -345,7 +346,7 @@
             status = mAudioTrack->start();
             cblk->lock.lock();
             if (status == DEAD_OBJECT) {
-                cblk->flags |= CBLK_INVALID_MSK;
+                android_atomic_or(CBLK_INVALID_ON, &cblk->flags);
             }
         }
         if (cblk->flags & CBLK_INVALID_MSK) {
@@ -636,7 +637,7 @@
     if (position > mCblk->user) return BAD_VALUE;
 
     mCblk->server = position;
-    mCblk->flags |= CBLK_FORCEREADY_ON;
+    android_atomic_or(CBLK_FORCEREADY_ON, &mCblk->flags);
 
     return NO_ERROR;
 }
@@ -793,7 +794,7 @@
     mCblkMemory.clear();
     mCblkMemory = cblk;
     mCblk = static_cast<audio_track_cblk_t*>(cblk->pointer());
-    mCblk->flags |= CBLK_DIRECTION_OUT;
+    android_atomic_or(CBLK_DIRECTION_OUT, &mCblk->flags);
     if (sharedBuffer == 0) {
         mCblk->buffers = (char*)mCblk + sizeof(audio_track_cblk_t);
     } else {
@@ -873,7 +874,7 @@
                         result = mAudioTrack->start();
                         cblk->lock.lock();
                         if (result == DEAD_OBJECT) {
-                            cblk->flags |= CBLK_INVALID_MSK;
+                            android_atomic_or(CBLK_INVALID_ON, &cblk->flags);
 create_new_track:
                             result = restoreTrack_l(cblk, false);
                         }
@@ -900,14 +901,9 @@
 
     // restart track if it was disabled by audioflinger due to previous underrun
     if (mActive && (cblk->flags & CBLK_DISABLED_MSK)) {
-        AutoMutex _l(cblk->lock);
-        if (mActive && (cblk->flags & CBLK_DISABLED_MSK)) {
-            cblk->flags &= ~CBLK_DISABLED_ON;
-            cblk->lock.unlock();
-            LOGW("obtainBuffer() track %p disabled, restarting", this);
-            mAudioTrack->start();
-            cblk->lock.lock();
-        }
+        android_atomic_and(~CBLK_DISABLED_ON, &cblk->flags);
+        LOGW("obtainBuffer() track %p disabled, restarting", this);
+        mAudioTrack->start();
     }
 
     cblk->waitTimeMs = 0;
@@ -1026,17 +1022,13 @@
     mLock.unlock();
 
     // Manage underrun callback
-    if (mActive && (cblk->framesReady() == 0)) {
+    if (mActive && (cblk->framesAvailable() == cblk->frameCount)) {
         LOGV("Underrun user: %x, server: %x, flags %04x", cblk->user, cblk->server, cblk->flags);
-        AutoMutex _l(cblk->lock);
-        if ((cblk->flags & CBLK_UNDERRUN_MSK) == CBLK_UNDERRUN_OFF) {
-            cblk->flags |= CBLK_UNDERRUN_ON;
-            cblk->lock.unlock();
+        if (!(android_atomic_or(CBLK_UNDERRUN_ON, &cblk->flags) & CBLK_UNDERRUN_MSK)) {
             mCbf(EVENT_UNDERRUN, mUserData, 0);
             if (cblk->server == cblk->frameCount) {
                 mCbf(EVENT_BUFFER_END, mUserData, 0);
             }
-            cblk->lock.lock();
             if (mSharedBuffer != 0) return false;
         }
     }
@@ -1150,12 +1142,10 @@
 {
     status_t result;
 
-    if (!(cblk->flags & CBLK_RESTORING_MSK)) {
+    if (!(android_atomic_or(CBLK_RESTORING_ON, &cblk->flags) & CBLK_RESTORING_MSK)) {
         LOGW("dead IAudioTrack, creating a new one from %s",
              fromStart ? "start()" : "obtainBuffer()");
 
-        cblk->flags |= CBLK_RESTORING_ON;
-
         // signal old cblk condition so that other threads waiting for available buffers stop
         // waiting now
         cblk->cv.broadcast();
@@ -1198,10 +1188,8 @@
         }
 
         // signal old cblk condition for other threads waiting for restore completion
-        cblk->lock.lock();
-        cblk->flags |= CBLK_RESTORED_MSK;
+        android_atomic_or(CBLK_RESTORED_ON, &cblk->flags);
         cblk->cv.broadcast();
-        cblk->lock.unlock();
     } else {
         if (!(cblk->flags & CBLK_RESTORED_MSK)) {
             LOGW("dead IAudioTrack, waiting for a new one");
@@ -1275,11 +1263,12 @@
 
 // =========================================================================
 
+
 audio_track_cblk_t::audio_track_cblk_t()
     : lock(Mutex::SHARED), cv(Condition::SHARED), user(0), server(0),
     userBase(0), serverBase(0), buffers(0), frameCount(0),
     loopStart(UINT_MAX), loopEnd(UINT_MAX), loopCount(0), volumeLR(0),
-    flags(0), sendLevel(0)
+    sendLevel(0), flags(0)
 {
 }
 
@@ -1307,10 +1296,7 @@
 
     // Clear flow control error condition as new data has been written/read to/from buffer.
     if (flags & CBLK_UNDERRUN_MSK) {
-        AutoMutex _l(lock);
-        if (flags & CBLK_UNDERRUN_MSK) {
-            flags &= ~CBLK_UNDERRUN_MSK;
-        }
+        android_atomic_and(~CBLK_UNDERRUN_MSK, &flags);
     }
 
     return u;
@@ -1318,18 +1304,8 @@
 
 bool audio_track_cblk_t::stepServer(uint32_t frameCount)
 {
-    // the code below simulates lock-with-timeout
-    // we MUST do this to protect the AudioFlinger server
-    // as this lock is shared with the client.
-    status_t err;
-
-    err = lock.tryLock();
-    if (err == -EBUSY) { // just wait a bit
-        usleep(1000);
-        err = lock.tryLock();
-    }
-    if (err != NO_ERROR) {
-        // probably, the client just died.
+    if (!tryLock()) {
+        LOGW("stepServer() could not lock cblk");
         return false;
     }
 
@@ -1406,18 +1382,42 @@
         if (u < loopEnd) {
             return u - s;
         } else {
-            Mutex::Autolock _l(lock);
-            if (loopCount >= 0) {
-                return (loopEnd - loopStart)*loopCount + u - s;
-            } else {
-                return UINT_MAX;
+            // do not block on mutex shared with client on AudioFlinger side
+            if (!tryLock()) {
+                LOGW("framesReady() could not lock cblk");
+                return 0;
             }
+            uint32_t frames = UINT_MAX;
+            if (loopCount >= 0) {
+                frames = (loopEnd - loopStart)*loopCount + u - s;
+            }
+            lock.unlock();
+            return frames;
         }
     } else {
         return s - u;
     }
 }
 
+bool audio_track_cblk_t::tryLock()
+{
+    // the code below simulates lock-with-timeout
+    // we MUST do this to protect the AudioFlinger server
+    // as this lock is shared with the client.
+    status_t err;
+
+    err = lock.tryLock();
+    if (err == -EBUSY) { // just wait a bit
+        usleep(1000);
+        err = lock.tryLock();
+    }
+    if (err != NO_ERROR) {
+        // probably, the client just died.
+        return false;
+    }
+    return true;
+}
+
 // -------------------------------------------------------------------------
 
 }; // namespace android
diff --git a/media/mtp/MtpServer.h b/media/mtp/MtpServer.h
index 1efa715..fa729a8 100644
--- a/media/mtp/MtpServer.h
+++ b/media/mtp/MtpServer.h
@@ -70,6 +70,9 @@
                                     int fileGroup, int filePerm, int directoryPerm);
     virtual             ~MtpServer();
 
+    MtpStorage*         getStorage(MtpStorageID id);
+    inline bool         hasStorage() { return mStorages.size() > 0; }
+    bool                hasStorage(MtpStorageID id);
     void                addStorage(MtpStorage* storage);
     void                removeStorage(MtpStorage* storage);
 
@@ -79,9 +82,6 @@
     void                sendObjectRemoved(MtpObjectHandle handle);
 
 private:
-    MtpStorage*         getStorage(MtpStorageID id);
-    inline bool         hasStorage() { return mStorages.size() > 0; }
-    bool                hasStorage(MtpStorageID id);
     void                sendStoreAdded(MtpStorageID id);
     void                sendStoreRemoved(MtpStorageID id);
     void                sendEvent(MtpEventCode code, uint32_t param1);
diff --git a/media/mtp/MtpStorage.cpp b/media/mtp/MtpStorage.cpp
index 6cb88b3..fff0b5f 100644
--- a/media/mtp/MtpStorage.cpp
+++ b/media/mtp/MtpStorage.cpp
@@ -32,9 +32,11 @@
 
 namespace android {
 
-MtpStorage::MtpStorage(MtpStorageID id, const char* filePath, uint64_t reserveSpace)
+MtpStorage::MtpStorage(MtpStorageID id, const char* filePath,
+        const char* description, uint64_t reserveSpace)
     :   mStorageID(id),
         mFilePath(filePath),
+        mDescription(description),
         mMaxCapacity(0),
         mReserveSpace(reserveSpace)
 {
@@ -75,7 +77,7 @@
 }
 
 const char* MtpStorage::getDescription() const {
-    return "Device Storage";
+    return (const char *)mDescription;
 }
 
 }  // namespace android
diff --git a/media/mtp/MtpStorage.h b/media/mtp/MtpStorage.h
index 858c9d3..d6ad25f 100644
--- a/media/mtp/MtpStorage.h
+++ b/media/mtp/MtpStorage.h
@@ -29,13 +29,14 @@
 private:
     MtpStorageID            mStorageID;
     MtpString               mFilePath;
+    MtpString               mDescription;
     uint64_t                mMaxCapacity;
     // amount of free space to leave unallocated
     uint64_t                mReserveSpace;
 
 public:
                             MtpStorage(MtpStorageID id, const char* filePath,
-                                    uint64_t reserveSpace);
+                                    const char* description, uint64_t reserveSpace);
     virtual                 ~MtpStorage();
 
     inline MtpStorageID     getStorageID() const { return mStorageID; }
diff --git a/media/mtp/mtp.h b/media/mtp/mtp.h
index 6fedc16..8bc2e22 100644
--- a/media/mtp/mtp.h
+++ b/media/mtp/mtp.h
@@ -22,8 +22,6 @@
 
 #define MTP_STANDARD_VERSION            100
 
-#define MTP_FIRST_STORAGE_ID            0x00010001
-
 // Container Types
 #define MTP_CONTAINER_TYPE_UNDEFINED    0
 #define MTP_CONTAINER_TYPE_COMMAND      1
diff --git a/packages/SystemUI/res/drawable-mdpi/stat_sys_signal_4g.png b/packages/SystemUI/res/drawable-mdpi/stat_sys_signal_4g.png
index 84ac927..ade3716 100644
--- a/packages/SystemUI/res/drawable-mdpi/stat_sys_signal_4g.png
+++ b/packages/SystemUI/res/drawable-mdpi/stat_sys_signal_4g.png
Binary files differ
diff --git a/packages/SystemUI/res/values-ar/strings.xml b/packages/SystemUI/res/values-ar/strings.xml
index 0660a17..399a774 100644
--- a/packages/SystemUI/res/values-ar/strings.xml
+++ b/packages/SystemUI/res/values-ar/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"تم إنشاء الاتصال بالإنترنت عن طريق البلوتوث."</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"تهيئة طرق الإدخال"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"استخدام لوحة المفاتيح الفعلية"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"هل تريد السماح للتطبيق <xliff:g id="APPLICATION">%1$s</xliff:g> بالدخول إلى جهاز USB؟"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"هل تريد السماح للتطبيق <xliff:g id="APPLICATION">%1$s</xliff:g> بالدخول إلى ملحق USB؟"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"هل تريد فتح <xliff:g id="ACTIVITY">%1$s</xliff:g> عند توصيل جهاز USB هذا؟"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"هل تريد فتح <xliff:g id="ACTIVITY">%1$s</xliff:g> عند توصيل ملحق USB هذا؟"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"لا يعمل أي تطبيق مثبت مع ملحق UEB هذا. تعرف على المزيد عن هذا الملحق على <xliff:g id="URL">%1$s</xliff:g>."</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"ملحق USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"عرض"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"الاستخدام بشكل افتراضي لجهاز USB هذا"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"الاستخدام بشكل افتراضي لملحق USB هذا"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-bg/strings.xml b/packages/SystemUI/res/values-bg/strings.xml
index 4c9ecfc..0fddf23 100644
--- a/packages/SystemUI/res/values-bg/strings.xml
+++ b/packages/SystemUI/res/values-bg/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth има връзка с тетъринг"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Конфигуриране на въвеждането"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Използване на физ. клав."</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Да се разреши ли на приложението <xliff:g id="APPLICATION">%1$s</xliff:g> достъп до USB устройството?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Да се разреши ли на приложението <xliff:g id="APPLICATION">%1$s</xliff:g> достъп до аксесоара за USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Да се отвори ли <xliff:g id="ACTIVITY">%1$s</xliff:g>, когато това USB устройство е свързано?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Да се отвори ли <xliff:g id="ACTIVITY">%1$s</xliff:g>, когато този аксесоар за USB е свързан?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Инсталираните приложения не работят с този аксесоар за USB. Научете повече на адрес <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Аксесоар за USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Преглед"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Използване по подразб. за това USB устройство"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Използване по подразб. за този аксесоар за USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-ca/strings.xml b/packages/SystemUI/res/values-ca/strings.xml
index 9a4a360..64f53d0 100644
--- a/packages/SystemUI/res/values-ca/strings.xml
+++ b/packages/SystemUI/res/values-ca/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth sense fil"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Configura mètodes d\'entrada"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Utilitza un teclat físic"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Vols permetre que l\'aplicació <xliff:g id="APPLICATION">%1$s</xliff:g> accedeixi al dispositiu USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Vols permetre que l\'aplicació <xliff:g id="APPLICATION">%1$s</xliff:g> accedeixi a l\'accessori USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Vols que s\'obri <xliff:g id="ACTIVITY">%1$s</xliff:g> quan aquest dispositiu USB estigui connectat?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Vols que s\'obri <xliff:g id="ACTIVITY">%1$s</xliff:g> quan aquest accessori USB estigui connectat?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Cap de les aplicacions instal·lades no funciona amb aquest accessori USB. Més informació a <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Accessori USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Mostra"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Utilitza de manera predet. per al dispositiu USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Utilitza de manera predet. per a l\'accessori USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-cs/strings.xml b/packages/SystemUI/res/values-cs/strings.xml
index 31aa1a7..f1bab7e 100644
--- a/packages/SystemUI/res/values-cs/strings.xml
+++ b/packages/SystemUI/res/values-cs/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Datové připojení Bluetooth se sdílí"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Nakonfigurovat metody vstupu"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Použít fyz. klávesnici"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Povolit aplikaci <xliff:g id="APPLICATION">%1$s</xliff:g> přístup k zařízení USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Povolit aplikaci <xliff:g id="APPLICATION">%1$s</xliff:g> přístup k perifernímu zařízení USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Chcete při připojení tohoto zařízení USB otevřít aplikaci <xliff:g id="ACTIVITY">%1$s</xliff:g>?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Chcete při připojení tohoto periferního zařízení USB otevřít aplikaci <xliff:g id="ACTIVITY">%1$s</xliff:g>?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"S tímto periferním zařízením USB nefunguje žádná nainstalovaná aplikace. Další informace naleznete na stránkách <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Periferní zařízení USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Zobrazit"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Pro toto zařízení USB použít jako výchozí"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Pro toto periferní zařízení USB použít jako výchozí"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-da/strings.xml b/packages/SystemUI/res/values-da/strings.xml
index ddbcf25..054b53c 100644
--- a/packages/SystemUI/res/values-da/strings.xml
+++ b/packages/SystemUI/res/values-da/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth-tethering anvendt"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Konfigurer inputmetoder"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Brug fysisk tastatur"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Vil du tillade, at programmet <xliff:g id="APPLICATION">%1$s</xliff:g> får adgang til USB-enheden?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Vil du tillade, at programmet <xliff:g id="APPLICATION">%1$s</xliff:g> får adgang til USB-ekstraudstyret?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Vil du åbne <xliff:g id="ACTIVITY">%1$s</xliff:g>, når denne USB-enhed er tilsluttet?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Vil du åbne <xliff:g id="ACTIVITY">%1$s</xliff:g>, når dette USB-ekstraudstyr er tilsluttet?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Ingen inst. programmer virker med USB-ekstraudstyret. Få oplysninger om ekstraudstyret på <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB-ekstraudstyr"</string>
+    <string name="label_view" msgid="6304565553218192990">"Vis"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Brug som standard til denne USB-enhed"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Brug som standard til dette USB-tilbehør"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-de/strings.xml b/packages/SystemUI/res/values-de/strings.xml
index c7d9502..857d3a0 100644
--- a/packages/SystemUI/res/values-de/strings.xml
+++ b/packages/SystemUI/res/values-de/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth-Tethering aktiv"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Eingabemethoden konfigurieren"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Physische Tastatur"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Anwendung <xliff:g id="APPLICATION">%1$s</xliff:g> Zugriff auf USB-Gerät gewähren?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Anwendung <xliff:g id="APPLICATION">%1$s</xliff:g> Zugriff auf USB-Zubehör gewähren?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"<xliff:g id="ACTIVITY">%1$s</xliff:g> öffnen, wenn dieses USB-Gerät verbunden ist?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"<xliff:g id="ACTIVITY">%1$s</xliff:g> öffnen, wenn dieses USB-Zubehör verbunden ist?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Keine installierten Anwendungen für dieses USB-Zubehör. Weitere Informationen unter <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB-Zubehör"</string>
+    <string name="label_view" msgid="6304565553218192990">"Anzeigen"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Standardmäßig für dieses USB-Gerät verwenden"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Standardmäßig für dieses USB-Zubehör verwenden"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-el/strings.xml b/packages/SystemUI/res/values-el/strings.xml
index 7e15f7f..424faab 100644
--- a/packages/SystemUI/res/values-el/strings.xml
+++ b/packages/SystemUI/res/values-el/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Έγινε σύνδεση μέσω Bluetooth"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Διαμόρφωση μεθόδων εισαγωγής"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Χρήση κανονικού πληκτρολ."</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Να επιτρέπεται στην εφαρμογή <xliff:g id="APPLICATION">%1$s</xliff:g> η πρόσβαση στη συσκευή USB;"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Να επιτρέπεται στην εφαρμογή <xliff:g id="APPLICATION">%1$s</xliff:g> η πρόσβαση στο αξεσουάρ USB;"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Άνοιγμα του <xliff:g id="ACTIVITY">%1$s</xliff:g> κατά τη σύνδεση αυτής της συσκευής USB;"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Άνοιγμα του <xliff:g id="ACTIVITY">%1$s</xliff:g> κατά τη σύνδεση αυτού του αξεσουάρ USB;"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Καμία εγκατ. εφαρμ. δεν συνεργ. με το αξ. USB. Μάθετε περισ. για το αξ. στο <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Αξεσουάρ USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Προβολή"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Χρήση από προεπιλογή για αυτή τη συσκευή USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Χρήση από προεπιλογή για αυτό το εξάρτημα USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-en-rGB/strings.xml b/packages/SystemUI/res/values-en-rGB/strings.xml
index 350913a..8c84b67 100644
--- a/packages/SystemUI/res/values-en-rGB/strings.xml
+++ b/packages/SystemUI/res/values-en-rGB/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth tethered"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Configure input methods"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Use physical keyboard"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Allow the application <xliff:g id="APPLICATION">%1$s</xliff:g> to access the USB device?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Allow the application <xliff:g id="APPLICATION">%1$s</xliff:g> to access the USB accessory?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Open <xliff:g id="ACTIVITY">%1$s</xliff:g> when this USB device is connected?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Open <xliff:g id="ACTIVITY">%1$s</xliff:g> when this USB accessory is connected?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"No installed applications work with this USB accessory. Learn more about this accessory at <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB accessory"</string>
+    <string name="label_view" msgid="6304565553218192990">"View"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Use by default for this USB device"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Use by default for this USB accessory"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-es-rUS/strings.xml b/packages/SystemUI/res/values-es-rUS/strings.xml
index 43d9337..ae747d4 100644
--- a/packages/SystemUI/res/values-es-rUS/strings.xml
+++ b/packages/SystemUI/res/values-es-rUS/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth anclado"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Configurar métodos de entrada"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Usar teclado físico"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"¿Permitir la aplicación <xliff:g id="APPLICATION">%1$s</xliff:g> para acceder al dispositivo USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"¿Permitir la aplicación <xliff:g id="APPLICATION">%1$s</xliff:g> para acceder al accesorio USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"¿Abrir <xliff:g id="ACTIVITY">%1$s</xliff:g> cuando este dispositivo USB esté conectado?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"¿Abrir <xliff:g id="ACTIVITY">%1$s</xliff:g> cuando este accesorio USB esté conectado?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Las aplicaciones instaladas no funcionan con este accesorio USB. Obtener más información acerca de este accesorio en <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Accesorio USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Ver"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Se usa de forma predeterminada para este dispositivo USB."</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Se usa de forma predeterminada para este accesorio USB."</string>
 </resources>
diff --git a/packages/SystemUI/res/values-es/strings.xml b/packages/SystemUI/res/values-es/strings.xml
index e6c1ce2..d58af48 100644
--- a/packages/SystemUI/res/values-es/strings.xml
+++ b/packages/SystemUI/res/values-es/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth anclado"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Configurar métodos de introducción"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Utilizar teclado físico"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"¿Permitir que la aplicación <xliff:g id="APPLICATION">%1$s</xliff:g> acceda al dispositivo USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"¿Permitir que la aplicación <xliff:g id="APPLICATION">%1$s</xliff:g> acceda al accesorio USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"¿Quieres abrir <xliff:g id="ACTIVITY">%1$s</xliff:g> al conectar este dispositivo USB?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"¿Quieres abrir <xliff:g id="ACTIVITY">%1$s</xliff:g> al conectar este accesorio USB?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Ninguna aplicación instalada funciona con este accesorio USB. Más información: <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Accesorio USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Ver"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Usar de forma predeterminada para este dispositivo USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Usar de forma predeterminada para este accesorio USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-fa/strings.xml b/packages/SystemUI/res/values-fa/strings.xml
index 9e70d5a..b763771 100644
--- a/packages/SystemUI/res/values-fa/strings.xml
+++ b/packages/SystemUI/res/values-fa/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"اتصال اینترنتی با بلوتوث تلفن همراه"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"پیکربندی روش های ورودی"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"از صفحه کلید فیزیکی استفاده کنید"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"به برنامه <xliff:g id="APPLICATION">%1$s</xliff:g> اجازه می دهید به دستگاه USB وصل شود؟"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"به برنامه <xliff:g id="APPLICATION">%1$s</xliff:g> اجازه می دهید به وسیله جانبی USB وصل شود؟"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"وقتی این دستگاه USB وصل است، <xliff:g id="ACTIVITY">%1$s</xliff:g> باز شود؟"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"وقتی این وسیله جانبی USB وصل است، <xliff:g id="ACTIVITY">%1$s</xliff:g> باز شود؟"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"برنامه های نصب شده با این وسیله جانبی USB کار می کنند. در <xliff:g id="URL">%1$s</xliff:g>راجع به این لوازم جانبی بیشتر بیاموزید"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"لوازم جانبی USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"مشاهده"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"استفاده به صورت پیش فرض برای این دستگاه USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"استفاده به صورت پیش فرض برای این دستگاه USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-fi/strings.xml b/packages/SystemUI/res/values-fi/strings.xml
index 47b3220..9255dbd 100644
--- a/packages/SystemUI/res/values-fi/strings.xml
+++ b/packages/SystemUI/res/values-fi/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth yhdistetty"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Määritä syöttötavat"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Käytä fyysistä näppäimistöä"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Annetaanko sovellukselle <xliff:g id="APPLICATION">%1$s</xliff:g> lupa käyttää USB-laitetta?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Annetaanko sovellukselle <xliff:g id="APPLICATION">%1$s</xliff:g> lupa käyttää USB-lisälaitetta?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Avataanko <xliff:g id="ACTIVITY">%1$s</xliff:g> tämän USB-laitteen ollessa kytkettynä?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Avataanko <xliff:g id="ACTIVITY">%1$s</xliff:g> tämän USB-lisälaitteen ollessa kytkettynä?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Asennetut sov. eivät toimi tämän USB-lisälaitteen kanssa. Lisätietoja lisälaitteesta os. <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB-lisälaite"</string>
+    <string name="label_view" msgid="6304565553218192990">"Näytä"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Käytä oletuksena tällä USB-laitteella"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Käytä oletuksena tällä USB-lisälaitteella"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-fr/strings.xml b/packages/SystemUI/res/values-fr/strings.xml
index a4a287e..c41acd3 100644
--- a/packages/SystemUI/res/values-fr/strings.xml
+++ b/packages/SystemUI/res/values-fr/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Connexion Bluetooth partagée"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Configurer les modes de saisie"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Utiliser clavier physique"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Autoriser l\'application <xliff:g id="APPLICATION">%1$s</xliff:g> à accéder au périphérique USB ?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Autoriser l\'application <xliff:g id="APPLICATION">%1$s</xliff:g> à accéder à l\'accessoire USB ?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Ouvrir <xliff:g id="ACTIVITY">%1$s</xliff:g> lors de la connexion de ce périphérique USB ?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Ouvrir <xliff:g id="ACTIVITY">%1$s</xliff:g> lors de la connexion de cet accessoire USB ?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Aucune application installée n\'est compatible avec cet accessoire USB. En savoir plus sur <xliff:g id="URL">%1$s</xliff:g>."</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Accessoire USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Afficher"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Utiliser par défaut pour ce périphérique USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Utiliser par défaut pour cet accessoire USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-hr/strings.xml b/packages/SystemUI/res/values-hr/strings.xml
index 680a3e3..eda1a93 100644
--- a/packages/SystemUI/res/values-hr/strings.xml
+++ b/packages/SystemUI/res/values-hr/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth posredno povezan"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Konfiguriraj načine ulaza"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Rabi fizičku tipkovnicu"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Dopustiti aplikaciji <xliff:g id="APPLICATION">%1$s</xliff:g> da pristupi ovom USB uređaju?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Dopustiti aplikaciji <xliff:g id="APPLICATION">%1$s</xliff:g> da pristupi ovom USB dodatku?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Otvoriti <xliff:g id="ACTIVITY">%1$s</xliff:g> kad se spoji ovaj USB uređaj?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Otvoriti <xliff:g id="ACTIVITY">%1$s</xliff:g> kad se spoji ovaj USB dodatak?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Nijedna instalirana aplikacija ne radi s ovim USB dodatkom. Saznajte više o ovom dodatku na <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB pribor"</string>
+    <string name="label_view" msgid="6304565553218192990">"Prikaži"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Koristi se prema zadanim postavkama za ovaj USB uređaj"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Koristi se prema zadanim postavkama za ovaj USB pribor"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-hu/strings.xml b/packages/SystemUI/res/values-hu/strings.xml
index 9a103f7..2261c2b 100644
--- a/packages/SystemUI/res/values-hu/strings.xml
+++ b/packages/SystemUI/res/values-hu/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth megosztva"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Beviteli módok konfigurálása"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Valódi bill. használata"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"<xliff:g id="APPLICATION">%1$s</xliff:g> alkalmazás hozzáférhet az USB-eszközhöz?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"<xliff:g id="APPLICATION">%1$s</xliff:g> alkalmazás hozzáférhet az USB-kiegészítőhöz?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"<xliff:g id="ACTIVITY">%1$s</xliff:g> megnyitása, ha USB-kiegészítő csatlakoztatva van?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"<xliff:g id="ACTIVITY">%1$s</xliff:g> megnyitása, ha ez az USB-kiegészítő csatlakoztatva van?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"A telepített alkalmazások nem működnek ezzel az USB-kiegészítővel. Bővebben: <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB-kellék"</string>
+    <string name="label_view" msgid="6304565553218192990">"Megtekintés"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Alapértelmezett használat ehhez az USB-eszközhöz"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Alapértelmezett használat ehhez az USB-kiegészítőhöz"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-in/strings.xml b/packages/SystemUI/res/values-in/strings.xml
index e7fbbbe..53bfc76 100644
--- a/packages/SystemUI/res/values-in/strings.xml
+++ b/packages/SystemUI/res/values-in/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth tertambat"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Konfigurasikan metode masukan"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Gunakan keyboard fisik"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Izinkan aplikasi <xliff:g id="APPLICATION">%1$s</xliff:g> mengakses perangkat USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Izinkan aplikasi <xliff:g id="APPLICATION">%1$s</xliff:g> mengakses aksesori USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Buka <xliff:g id="ACTIVITY">%1$s</xliff:g> ketika perangkat USB ini tersambung?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Buka <xliff:g id="ACTIVITY">%1$s</xliff:g> ketika aksesori USB ini tersambung?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Tidak ada aplikasi terpasang yang bekerja dengan aksesori USB ini. Pelajari aksesori ini lebih lanjut di <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Aksesori USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Lihat"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Gunakan secara bawaan untuk perangkat USB ini"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Gunakan secara bawaan untuk aksesori USB ini"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-it/strings.xml b/packages/SystemUI/res/values-it/strings.xml
index b541374..055e783 100644
--- a/packages/SystemUI/res/values-it/strings.xml
+++ b/packages/SystemUI/res/values-it/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth con tethering"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Configura metodi di input"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Utilizza tastiera fisica"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Consentire all\'applicazione <xliff:g id="APPLICATION">%1$s</xliff:g> di accedere al dispositivo USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Consentire all\'applicazione <xliff:g id="APPLICATION">%1$s</xliff:g> di accedere all\'accessorio USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Aprire <xliff:g id="ACTIVITY">%1$s</xliff:g> quando questo dispositivo USB è collegato?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Aprire <xliff:g id="ACTIVITY">%1$s</xliff:g> quando questo accessorio USB è collegato?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Applicazioni installate non funzionano con accessorio USB. Altre informazioni su accessorio su <xliff:g id="URL">%1$s</xliff:g>."</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Accessorio USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Visualizza"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Usa per impostazione predef. per dispositivo USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Usa per impostazione predef. per accessorio USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-iw/strings.xml b/packages/SystemUI/res/values-iw/strings.xml
index 3194cf5..04fa686 100644
--- a/packages/SystemUI/res/values-iw/strings.xml
+++ b/packages/SystemUI/res/values-iw/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth קשור"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"הגדר שיטות קלט"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"השתמש במקלדת הפיזית"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"האם לאפשר ליישום <xliff:g id="APPLICATION">%1$s</xliff:g> לגשת להתקן ה-USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"האם לאפשר ליישום <xliff:g id="APPLICATION">%1$s</xliff:g> לגשת לאביזר ה-USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"האם לפתוח את <xliff:g id="ACTIVITY">%1$s</xliff:g> כאשר התקן USB זה מחובר?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"האם לפתוח את <xliff:g id="ACTIVITY">%1$s</xliff:g> כאשר אביזר USB זה מחובר?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"אין יישומים מותקנים הפועלים עם אביזר ה-USB. למידע נוסף אודות אביזר זה בכתובת <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"עזרי USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"הצג"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"השתמש כברירת מחדל עבור התקן USB זה"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"השתמש כברירת מחדל עבור אביזר USB זה"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-ja/strings.xml b/packages/SystemUI/res/values-ja/strings.xml
index ac82ed4..4ec1d1b 100644
--- a/packages/SystemUI/res/values-ja/strings.xml
+++ b/packages/SystemUI/res/values-ja/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetoothテザリング接続"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"入力方法の設定"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"物理キーボードを使用"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"アプリケーション<xliff:g id="APPLICATION">%1$s</xliff:g>にUSBデバイスへのアクセスを許可しますか?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"アプリケーション<xliff:g id="APPLICATION">%1$s</xliff:g>にUSBアクセサリへのアクセスを許可しますか?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"このUSBデバイスが接続されたときに<xliff:g id="ACTIVITY">%1$s</xliff:g>を開きますか?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"このUSBアクセサリが接続されたときに<xliff:g id="ACTIVITY">%1$s</xliff:g>を開きますか?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"このUSBアクセサリを扱うアプリはインストールされていません。詳細は <xliff:g id="URL">%1$s</xliff:g> をご覧ください。"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USBアクセサリ"</string>
+    <string name="label_view" msgid="6304565553218192990">"表示"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"このUSBデバイスにデフォルトで使用する"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"このUSBアクセサリにデフォルトで使用する"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-ko/strings.xml b/packages/SystemUI/res/values-ko/strings.xml
index 2d4786d..8b80d9d 100644
--- a/packages/SystemUI/res/values-ko/strings.xml
+++ b/packages/SystemUI/res/values-ko/strings.xml
@@ -27,7 +27,7 @@
     <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"진행 중"</string>
     <string name="status_bar_latest_events_title" msgid="6594767438577593172">"알림"</string>
     <string name="battery_low_title" msgid="7923774589611311406">"충전기를 연결하세요."</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"배터리 전원이 부족합니다."</string>
+    <string name="battery_low_subtitle" msgid="1752040062087829196">"배터리가 얼마 남지 않았습니다."</string>
     <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g>개 남음"</string>
     <string name="invalid_charger" msgid="4549105996740522523">"USB 충전이 지원되지 않습니다."\n"제공된 충전기만 사용하세요."</string>
     <string name="battery_low_why" msgid="7279169609518386372">"배터리 사용량"</string>
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"블루투스 테더링됨"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"입력 방법 구성"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"물리적 키보드 사용"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"애플리케이션 <xliff:g id="APPLICATION">%1$s</xliff:g>(이)가 USB 기기에 액세스하도록 허용하시겠습니까?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"애플리케이션 <xliff:g id="APPLICATION">%1$s</xliff:g>(이)가 USB 액세서리에 액세스하도록 허용하시겠습니까"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"USB 기기가 연결될 때 <xliff:g id="ACTIVITY">%1$s</xliff:g>(을)를 여시겠습니까?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"USB 액세서리가 연결될 때 <xliff:g id="ACTIVITY">%1$s</xliff:g>(을)를 여시겠습니까?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"이 USB와 호환되는 설치 애플리케이션이 없습니다. <xliff:g id="URL">%1$s</xliff:g>에서 세부정보를 참조하세요."</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB 액세서리"</string>
+    <string name="label_view" msgid="6304565553218192990">"보기"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"이 USB 기기에 기본값으로 사용"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"이 USB 액세서리에 기본값으로 사용"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-lt/strings.xml b/packages/SystemUI/res/values-lt/strings.xml
index db06596..4c7986c 100644
--- a/packages/SystemUI/res/values-lt/strings.xml
+++ b/packages/SystemUI/res/values-lt/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"„Bluetooth“ susieta"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Konfigūruoti įvesties metodus"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Naudoti fizinę klaviatūrą"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Leisti programai „<xliff:g id="APPLICATION">%1$s</xliff:g>“ pasiekti USB įrenginį?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Leisti programai „<xliff:g id="APPLICATION">%1$s</xliff:g>“ pasiekti USB priedą?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Atidaryti <xliff:g id="ACTIVITY">%1$s</xliff:g>, kai prijungtas šis USB įrenginys?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Atidaryti <xliff:g id="ACTIVITY">%1$s</xliff:g>, kai prijungtas šis USB priedas?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Su šiuo USB pr. nev. jokios įdieg. pr. Suž. daugiau apie šį pr. šiuo adr.: <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB reikmuo"</string>
+    <string name="label_view" msgid="6304565553218192990">"Žiūrėti"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Šiam USB įreng. naudoti pagal numat. nustatymus"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Šiam USB priedui naudoti pagal numat. nustatymus"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-lv/strings.xml b/packages/SystemUI/res/values-lv/strings.xml
index 079591e..2804ffa 100644
--- a/packages/SystemUI/res/values-lv/strings.xml
+++ b/packages/SystemUI/res/values-lv/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth piesaiste"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Konfigurēt ievades metodes"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Izmantot fizisku tastatūru"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Vai ļaut lietojumprogrammai <xliff:g id="APPLICATION">%1$s</xliff:g> piekļūt šai USB ierīcei?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Vai ļaut lietojumprogrammai <xliff:g id="APPLICATION">%1$s</xliff:g> piekļūt šim USB piederumam?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Vai atvērt darbību <xliff:g id="ACTIVITY">%1$s</xliff:g>, kad tiek pievienota šī USB ierīce?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Vai atvērt darbību <xliff:g id="ACTIVITY">%1$s</xliff:g>, kad tiek pievienots šis USB piederums?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Neinst. lietojumpr. darbojas ar šo USB pied. Uzz. vairāk par šo piederumu: <xliff:g id="URL">%1$s</xliff:g>."</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB piederums"</string>
+    <string name="label_view" msgid="6304565553218192990">"Skatīt"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Pēc noklusējuma izmantot šai USB ierīcei"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Pēc noklusējuma izmantot šim USB piederumam"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-nb/strings.xml b/packages/SystemUI/res/values-nb/strings.xml
index b7e7711..0dc1040 100644
--- a/packages/SystemUI/res/values-nb/strings.xml
+++ b/packages/SystemUI/res/values-nb/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth tilknyttet"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Konfigurer inndatametoder"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Bruk fysisk tastatur"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Vil du tillate at applikasjonen <xliff:g id="APPLICATION">%1$s</xliff:g> får tilgang til USB-enheten?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Vil du tillate at applikasjonen <xliff:g id="APPLICATION">%1$s</xliff:g> får tilgang til USB-tilbehøret?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Vil du åpne <xliff:g id="ACTIVITY">%1$s</xliff:g> når denne USB-enheten er tilkoblet?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Vil du åpne <xliff:g id="ACTIVITY">%1$s</xliff:g> når dette USB-tilbehøret er tilkoblet?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Ingen installerte applikasjoner støtter dette USB-tilbehøret. Les mer om tilbehøret på <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB-enhet"</string>
+    <string name="label_view" msgid="6304565553218192990">"Vis"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Bruk som standard for denne USB-enheten"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Bruk som standard for dette USB-tilbehøret"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-nl/strings.xml b/packages/SystemUI/res/values-nl/strings.xml
index cc9e7a3..4682f93 100644
--- a/packages/SystemUI/res/values-nl/strings.xml
+++ b/packages/SystemUI/res/values-nl/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth getetherd"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Invoermethoden configureren"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Fysiek toetsenbord gebruiken"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"De applicatie <xliff:g id="APPLICATION">%1$s</xliff:g> toegang tot het USB-apparaat geven?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"De applicatie <xliff:g id="APPLICATION">%1$s</xliff:g> toegang tot het USB-accessoire geven?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"<xliff:g id="ACTIVITY">%1$s</xliff:g> openen wanneer dit USB-apparaat wordt aangesloten?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"<xliff:g id="ACTIVITY">%1$s</xliff:g> openen wanneer dit USB-accessoire wordt aangesloten?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Er zijn geen geïnstalleerde applicaties die werken met dit USB-accessoire. Meer informatie over dit accessoire vindt u op <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB-accessoire"</string>
+    <string name="label_view" msgid="6304565553218192990">"Weergeven"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Standaard gebruiken voor dit USB-apparaat"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Standaard gebruiken voor dit USB-accessoire"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-pl/strings.xml b/packages/SystemUI/res/values-pl/strings.xml
index 67d9cc1..198e3e3 100644
--- a/packages/SystemUI/res/values-pl/strings.xml
+++ b/packages/SystemUI/res/values-pl/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth – podłączono"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Konfiguruj metody wprowadzania"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Używaj klawiatury fizycznej"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Czy zezwolić aplikacji <xliff:g id="APPLICATION">%1$s</xliff:g> na dostęp do urządzenia USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Czy zezwolić aplikacji <xliff:g id="APPLICATION">%1$s</xliff:g> na dostęp do akcesorium USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Czy otworzyć <xliff:g id="ACTIVITY">%1$s</xliff:g> po podłączeniu tego urządzenia USB?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Czy otworzyć <xliff:g id="ACTIVITY">%1$s</xliff:g> po podłączeniu tego akcesorium USB?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Zainstalowane aplikacje nie działają z tym akcesorium USB. Więcej informacji: <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Akcesorium USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Wyświetl"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Używaj domyślnie dla tego urządzenia USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Używaj domyślnie dla tego akcesorium USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-pt-rPT/strings.xml b/packages/SystemUI/res/values-pt-rPT/strings.xml
index 5ee79a0..c79dbf0 100644
--- a/packages/SystemUI/res/values-pt-rPT/strings.xml
+++ b/packages/SystemUI/res/values-pt-rPT/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth ligado"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Configurar métodos de entrada"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Utilizar teclado físico"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Permitir que a aplicação <xliff:g id="APPLICATION">%1$s</xliff:g> aceda ao dispositivo USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Permitir que a aplicação <xliff:g id="APPLICATION">%1$s</xliff:g> aceda ao acessório USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Abrir <xliff:g id="ACTIVITY">%1$s</xliff:g> quando este dispositivo USB estiver ligado?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Abrir <xliff:g id="ACTIVITY">%1$s</xliff:g> quando este acessório USB estiver ligado?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Nenhuma das aplicações instaladas funciona com este acessório USB. Saiba mais sobre este acessório em <xliff:g id="URL">%1$s</xliff:g>."</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Acessório USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Ver"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Utilizar por predefinição para este aparelho USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Utilizar por predefinição para este acessório USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-pt/strings.xml b/packages/SystemUI/res/values-pt/strings.xml
index a91d406..d37988f 100644
--- a/packages/SystemUI/res/values-pt/strings.xml
+++ b/packages/SystemUI/res/values-pt/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth vinculado"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Configurar métodos de entrada"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Usar o teclado físico"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Permitir que o aplicativo <xliff:g id="APPLICATION">%1$s</xliff:g> acesse o dispositivo USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Permitir que o aplicativo <xliff:g id="APPLICATION">%1$s</xliff:g> acesse o acessório USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Abrir <xliff:g id="ACTIVITY">%1$s</xliff:g> quando este dispositivo USB estiver conectado?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Abrir <xliff:g id="ACTIVITY">%1$s</xliff:g> quando este acessório USB estiver conectado?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Nenhum apl. instalado funciona com o acess. USB. Saiba mais sobre o acessório em <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Acessório USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Visualizar"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Usar por padrão para este dispositivo USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Usar por padrão para este acessório USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-ro/strings.xml b/packages/SystemUI/res/values-ro/strings.xml
index 36628aa..afecb92 100644
--- a/packages/SystemUI/res/values-ro/strings.xml
+++ b/packages/SystemUI/res/values-ro/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Conectat prin tethering prin Bluetooth"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Configuraţi metode de intrare"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Utilizaţi tastat. fizică"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Permiteţi aplicaţiei <xliff:g id="APPLICATION">%1$s</xliff:g> să acceseze dispozitivul USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Permiteţi aplicaţiei <xliff:g id="APPLICATION">%1$s</xliff:g> să acceseze accesoriul USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Deschideţi <xliff:g id="ACTIVITY">%1$s</xliff:g> la conectarea acestui dispozitiv USB?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Deschideţi <xliff:g id="ACTIVITY">%1$s</xliff:g> la conectarea acestui accesoriu USB?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Aplic. instal. nu funcţ. cu acest acces. USB. Aflaţi despre acest acces. la <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Accesoriu USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Afişaţi"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Utilizaţi în mod prestabilit pt. acest dispoz. USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Utiliz. în mod prestabilit pt. acest accesoriu USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-ru/strings.xml b/packages/SystemUI/res/values-ru/strings.xml
index 13da8a3..623bb65 100644
--- a/packages/SystemUI/res/values-ru/strings.xml
+++ b/packages/SystemUI/res/values-ru/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Общий модем доступен через Bluetooth"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Настроить способ ввода"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Использовать физическую клавиатуру"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Разрешить приложению <xliff:g id="APPLICATION">%1$s</xliff:g> доступ к USB-устройству?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Разрешить приложению <xliff:g id="APPLICATION">%1$s</xliff:g> доступ к USB-аксессуару?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Запускать <xliff:g id="ACTIVITY">%1$s</xliff:g> при подключении этого USB-устройства?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Запускать <xliff:g id="ACTIVITY">%1$s</xliff:g> при подключении этого USB-аксессуара?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Установленные приложения не поддерживают этот USB-аксессуар. Подробнее о нем читайте здесь: <xliff:g id="URL">%1$s</xliff:g>."</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB-устройство"</string>
+    <string name="label_view" msgid="6304565553218192990">"Просмотр"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Использовать по умолчанию для этого USB-устройства"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Использовать по умолчанию для этого USB-аксессуара"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-sk/strings.xml b/packages/SystemUI/res/values-sk/strings.xml
index c08eb21..0250461 100644
--- a/packages/SystemUI/res/values-sk/strings.xml
+++ b/packages/SystemUI/res/values-sk/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Zdieľané dátové pripojenie cez Bluetooth"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Konfigurovať metódy vstupu"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Použiť fyzickú klávesnicu"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Povoliť aplikácii <xliff:g id="APPLICATION">%1$s</xliff:g> prístup k zariadeniu USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Povoliť aplikácii <xliff:g id="APPLICATION">%1$s</xliff:g> prístup k periférnemu zariadeniu USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Chcete pri pripojení tohto zariadenia USB otvoriť aplikáciu <xliff:g id="ACTIVITY">%1$s</xliff:g>?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Chcete pri pripojení tohto periférneho zariadenia USB otvoriť aplikáciu <xliff:g id="ACTIVITY">%1$s</xliff:g>?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"S týmto periférnym zariad. USB nefunguje žiadna nainštalovaná aplikácia. Viac informácií nájdete na stránkach <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Periférne zariadenie USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Zobraziť"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Pre toto zariadenie USB použiť ako predvolené"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Pre toto periférne zar. USB použiť ako predvolené"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-sl/strings.xml b/packages/SystemUI/res/values-sl/strings.xml
index d7cb726..d31a30b 100644
--- a/packages/SystemUI/res/values-sl/strings.xml
+++ b/packages/SystemUI/res/values-sl/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Internetna povezava prek Bluetootha"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Nastavitev načinov vnosa"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Uporabi fizično tipkovn."</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Želite programu <xliff:g id="APPLICATION">%1$s</xliff:g> omogočiti dostop do naprave USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Želite programu <xliff:g id="APPLICATION">%1$s</xliff:g> omogočiti dostop do dodatka USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Želite, da se odpre <xliff:g id="ACTIVITY">%1$s</xliff:g>, ko priključite to napravo USB?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Želite, da se odpre <xliff:g id="ACTIVITY">%1$s</xliff:g>, ko priključite ta dodatek USB?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Noben nameščen program ne deluje s tem dodatkom USB. Več o tem dodatku: <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Dodatek USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Prikaži"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Privzeto uporabi za to napravo USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Privzeto uporabi za ta dodatek USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-sr/strings.xml b/packages/SystemUI/res/values-sr/strings.xml
index 6e67293..2c44f67 100644
--- a/packages/SystemUI/res/values-sr/strings.xml
+++ b/packages/SystemUI/res/values-sr/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Веза преко Bluetooth-а"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Конфигуриши методе уноса"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Користи физичку тастатуру"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Желите ли да омогућите апликацији <xliff:g id="APPLICATION">%1$s</xliff:g> да приступи USB уређају?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Желите ли да омогућите апликацији <xliff:g id="APPLICATION">%1$s</xliff:g> да приступи USB додатку?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Желите ли да се отвори <xliff:g id="ACTIVITY">%1$s</xliff:g> када се прикључи овај USB уређај?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Желите ли да се отвори <xliff:g id="ACTIVITY">%1$s</xliff:g> када се прикључи овај USB додатак?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Ниједна инстал. апликација не функционише са овим USB додатком. Сазнајте више о додатку на <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB помоћни уређај"</string>
+    <string name="label_view" msgid="6304565553218192990">"Прикажи"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Користи подразумевано за овај USB уређај"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Користи подразумевано за овај USB додатак"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-sv/strings.xml b/packages/SystemUI/res/values-sv/strings.xml
index e2905b6..343d6a8 100644
--- a/packages/SystemUI/res/values-sv/strings.xml
+++ b/packages/SystemUI/res/values-sv/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Internetdelning via Bluetooth"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Konfigurera inmatningsmetoder"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Använd fysiska tangenter"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Vill du tillåta att programmet <xliff:g id="APPLICATION">%1$s</xliff:g> använder USB-enheten?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Vill du tillåta att programmet <xliff:g id="APPLICATION">%1$s</xliff:g> använder USB-tillbehöret?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Vill du öppna <xliff:g id="ACTIVITY">%1$s</xliff:g> när den här USB-enheten ansluts?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Vill du öppna <xliff:g id="ACTIVITY">%1$s</xliff:g> när det här USB-tillbehöret ansluts?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Inga program fungerar med det här USB-tillbehöret. Läs mer om det på <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB-tillbehör"</string>
+    <string name="label_view" msgid="6304565553218192990">"Visa"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Använd som standard för den här USB-enheten"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Använd som standard för det här USB-tillbehöret"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-th/strings.xml b/packages/SystemUI/res/values-th/strings.xml
index 1e7af69..4db4e24 100644
--- a/packages/SystemUI/res/values-th/strings.xml
+++ b/packages/SystemUI/res/values-th/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"บลูทูธที่ปล่อยสัญญาณ"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"กำหนดค่าวิธีการป้อนข้อมูล"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"ใช้แป้นพิมพ์จริง"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"อนุญาตให้แอปพลิเคชัน <xliff:g id="APPLICATION">%1$s</xliff:g> เข้าถึงอุปกรณ์ USB นี้หรือไม่"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"อนุญาตให้แอปพลิเคชัน <xliff:g id="APPLICATION">%1$s</xliff:g> เข้าถึงอุปกรณ์เสริม USB นี้หรือไม่"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"เปิด <xliff:g id="ACTIVITY">%1$s</xliff:g> เมื่อมีการเชื่อมต่ออุปกรณ์ USB นี้หรือไม่"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"เปิด <xliff:g id="ACTIVITY">%1$s</xliff:g> เมื่อมีการเชื่อมต่ออุปกรณ์เสริม USB นี้หรือไม่"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"แอปพลิเคชันที่ติดตั้งใช้กับอุปกรณ์ USB นี้ไม่ได้ เรียนรู้เพิ่มเติมที่ <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"อุปกรณ์เสริม USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"ดู"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"ใช้ค่าเริ่มต้นสำหรับอุปกรณ์ USB นี้"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"ใช้ค่าเริ่มต้นสำหรับอุปกรณ์เสริม USB นี้"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-tl/strings.xml b/packages/SystemUI/res/values-tl/strings.xml
index 9fadf73..8cd8cfa 100644
--- a/packages/SystemUI/res/values-tl/strings.xml
+++ b/packages/SystemUI/res/values-tl/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Na-tether ang bluetooth"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"I-configure paraan ng input"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Gamitin ang pisikal na keyboard"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Payagan ang application <xliff:g id="APPLICATION">%1$s</xliff:g> na i-access ang USB device?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Payagan ang application <xliff:g id="APPLICATION">%1$s</xliff:g> na i-access ang USB accessory?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Buksan ang <xliff:g id="ACTIVITY">%1$s</xliff:g> kapag nakakonekta ang USB device na ito?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Buksan ang <xliff:g id="ACTIVITY">%1$s</xliff:g> kapag nakakonekta ang accessory na USB na ito?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Walang gumaganang mga naka-install na application sa USB accessory na ito <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB accessory"</string>
+    <string name="label_view" msgid="6304565553218192990">"Tingnan"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Gamitin bilang default para sa USB device"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Gamitin bilang default sa USB accessory na ito"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-tr/strings.xml b/packages/SystemUI/res/values-tr/strings.xml
index 7c3585a..87ffc8b 100644
--- a/packages/SystemUI/res/values-tr/strings.xml
+++ b/packages/SystemUI/res/values-tr/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth paylaşımı tamam"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Giriş yöntemlerini yapılandır"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Fiziksel klavyeyi kullan"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"<xliff:g id="APPLICATION">%1$s</xliff:g> uygulamasının bu USB cihazına erişmesine izin verilsin mi?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"<xliff:g id="APPLICATION">%1$s</xliff:g> uygulamasının bu USB aksesuarına erişmesine izin verilsin mi?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Bu USB cihaz bağlandığında <xliff:g id="ACTIVITY">%1$s</xliff:g> açılsın mı?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Bu USB aksesuarı bağlandığında <xliff:g id="ACTIVITY">%1$s</xliff:g> açılsın mı?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Hiçbir yüklü uyg bu USB aksesuarıyla çalışmıyor. Bu aksesuar hakknd daha fazla bilgi için: <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB aksesuarı"</string>
+    <string name="label_view" msgid="6304565553218192990">"Görüntüle"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Bu USB cihazı için varsayılan olarak kullan"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Bu USB aksesuar için varsayılan olarak kullan"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-uk/strings.xml b/packages/SystemUI/res/values-uk/strings.xml
index a17e59d..6ebad57 100644
--- a/packages/SystemUI/res/values-uk/strings.xml
+++ b/packages/SystemUI/res/values-uk/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Створено прив\'язку Bluetooth"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Налаштувати методи введення"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Викор. реальну клавіатуру"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Надати програмі <xliff:g id="APPLICATION">%1$s</xliff:g> доступ до пристрою USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Надати програмі <xliff:g id="APPLICATION">%1$s</xliff:g> доступ до аксесуара USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Відкривати \"<xliff:g id="ACTIVITY">%1$s</xliff:g>\", коли під’єднано пристрій USB?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Відкривати \"<xliff:g id="ACTIVITY">%1$s</xliff:g>\", коли під’єднано аксесуар USB?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Установлені прогр. не працюють із цим аксесуаром USB. Більше про цей аксесуар: <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Пристрій USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Переглянути"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Використовувати за умовчанням для пристрою USB"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Використовувати за умовчанням для аксесуара USB"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-vi/strings.xml b/packages/SystemUI/res/values-vi/strings.xml
index a994ee0..13a5737 100644
--- a/packages/SystemUI/res/values-vi/strings.xml
+++ b/packages/SystemUI/res/values-vi/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth được dùng làm điểm truy cập Internet"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"Định cấu hình phương pháp nhập liệu"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"Sử dụng bàn phím vật lý"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"Cho phép ứng dụng <xliff:g id="APPLICATION">%1$s</xliff:g> truy cập thiết bị USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"Cho phép ứng dụng <xliff:g id="APPLICATION">%1$s</xliff:g> truy cập phụ kiện USB?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Mở <xliff:g id="ACTIVITY">%1$s</xliff:g> khi thiết bị USB này được kết nối?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Mở <xliff:g id="ACTIVITY">%1$s</xliff:g> khi phụ kiện USB này được kết nối?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"Không có ứng dụng được cài đặt nào hoạt động với phụ kiện USB này. Tìm hiểu thêm về phụ kiện này tại <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"Phụ kiện USB"</string>
+    <string name="label_view" msgid="6304565553218192990">"Xem"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"Sử dụng theo mặc định cho thiết bị USB này"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"Sử dụng theo mặc định cho phụ kiện USB này"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-zh-rCN/strings.xml b/packages/SystemUI/res/values-zh-rCN/strings.xml
index baae9e1..099ed6bf 100644
--- a/packages/SystemUI/res/values-zh-rCN/strings.xml
+++ b/packages/SystemUI/res/values-zh-rCN/strings.xml
@@ -44,22 +44,13 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"蓝牙已绑定"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"配置输入法"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"使用物理键盘"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"允许应用程序<xliff:g id="APPLICATION">%1$s</xliff:g>访问 USB 设备吗?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"允许应用程序<xliff:g id="APPLICATION">%1$s</xliff:g>访问 USB 配件吗?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"要在连接此 USB 设备时打开<xliff:g id="ACTIVITY">%1$s</xliff:g>吗?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"要在连接此 USB 配件时打开<xliff:g id="ACTIVITY">%1$s</xliff:g>吗?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"未安装此 USB 配件适用的应用程序。要了解关于此配件的详情,请访问:<xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB 配件"</string>
+    <string name="label_view" msgid="6304565553218192990">"查看"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"默认情况下用于该 USB 设备"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"默认情况下用于该 USB 配件"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-zh-rTW/strings.xml b/packages/SystemUI/res/values-zh-rTW/strings.xml
index 0d83d44..1c06dc2 100644
--- a/packages/SystemUI/res/values-zh-rTW/strings.xml
+++ b/packages/SystemUI/res/values-zh-rTW/strings.xml
@@ -41,25 +41,16 @@
     <string name="recent_tasks_title" msgid="3691764623638127888">"最新的"</string>
     <string name="recent_tasks_empty" msgid="1905484479067697884">"沒有最近用過的應用程式。"</string>
     <string name="recent_tasks_app_label" msgid="3796483981246752469">"應用程式"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"已透過藍牙進行網際網路共用"</string>
+    <string name="bluetooth_tethered" msgid="7094101612161133267">"已透過 Bluetooth 進行網路共用"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="737483394044014246">"設定輸入方式"</string>
     <string name="status_bar_use_physical_keyboard" msgid="3695516942412442936">"使用實體鍵盤"</string>
-    <!-- no translation found for usb_device_permission_prompt (3816016361969816903) -->
-    <skip />
-    <!-- no translation found for usb_accessory_permission_prompt (6888598803988889959) -->
-    <skip />
-    <!-- no translation found for usb_device_confirm_prompt (5161205258635253206) -->
-    <skip />
-    <!-- no translation found for usb_accessory_confirm_prompt (3808984931830229888) -->
-    <skip />
-    <!-- no translation found for usb_accessory_uri_prompt (6332150684964235705) -->
-    <skip />
-    <!-- no translation found for title_usb_accessory (4966265263465181372) -->
-    <skip />
-    <!-- no translation found for label_view (6304565553218192990) -->
-    <skip />
-    <!-- no translation found for always_use_device (1450287437017315906) -->
-    <skip />
-    <!-- no translation found for always_use_accessory (1210954576979621596) -->
-    <skip />
+    <string name="usb_device_permission_prompt" msgid="3816016361969816903">"允許 <xliff:g id="APPLICATION">%1$s</xliff:g> 應用程式存取 USB 裝置嗎?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="6888598803988889959">"允許 <xliff:g id="APPLICATION">%1$s</xliff:g> 應用程式存取 USB 配件嗎?"</string>
+    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"連接這個 USB 裝置時啟用 <xliff:g id="ACTIVITY">%1$s</xliff:g> 嗎?"</string>
+    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"連接這個 USB 配件時啟用 <xliff:g id="ACTIVITY">%1$s</xliff:g> 嗎?"</string>
+    <string name="usb_accessory_uri_prompt" msgid="6332150684964235705">"已安裝的應用程式均無法存取這類 USB 配件,如要進一步瞭解這個配件,請造訪 <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="title_usb_accessory" msgid="4966265263465181372">"USB 配件"</string>
+    <string name="label_view" msgid="6304565553218192990">"查看"</string>
+    <string name="always_use_device" msgid="1450287437017315906">"預設用於這個 USB 裝置"</string>
+    <string name="always_use_accessory" msgid="1210954576979621596">"預設用於這個 USB 配件"</string>
 </resources>
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
index 3401441..a549f51 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
@@ -139,7 +139,6 @@
                     showInvalidChargerDialog();
                     return;
                 } else if (oldInvalidCharger != 0 && mInvalidCharger == 0) {
-                    Slog.d(TAG, "closing invalid charger warning");
                     dismissInvalidChargerDialog();
                 } else if (mInvalidChargerDialog != null) {
                     // if invalid charger is showing, don't show low battery
@@ -150,10 +149,9 @@
                         && (bucket < oldBucket || oldPlugged)
                         && mBatteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN
                         && bucket < 0) {
-                    Slog.d(TAG, "showing low battery warning: level=" + mBatteryLevel);
+                    Slog.i(TAG, "showing low battery warning: level=" + mBatteryLevel);
                     showLowBatteryWarning();
                 } else if (plugged || (bucket > oldBucket && bucket > 0)) {
-                    Slog.d(TAG, "closing low battery warning: level=" + mBatteryLevel);
                     dismissLowBatteryWarning();
                 } else if (mBatteryLevelTextView != null) {
                     showLowBatteryWarning();
@@ -166,6 +164,7 @@
 
     void dismissLowBatteryWarning() {
         if (mLowBatteryDialog != null) {
+            Slog.i(TAG, "closing low battery warning: level=" + mBatteryLevel);
             mLowBatteryDialog.dismiss();
         }
     }
@@ -237,6 +236,7 @@
 
     void dismissInvalidChargerDialog() {
         if (mInvalidChargerDialog != null) {
+            Slog.d(TAG, "closing invalid charger warning");
             mInvalidChargerDialog.dismiss();
         }
     }
diff --git a/packages/TtsService/jni/android_tts_SynthProxy.cpp b/packages/TtsService/jni/android_tts_SynthProxy.cpp
index 27d1fc0..e00fa85 100644
--- a/packages/TtsService/jni/android_tts_SynthProxy.cpp
+++ b/packages/TtsService/jni/android_tts_SynthProxy.cpp
@@ -53,7 +53,6 @@
 // ----------------------------------------------------------------------------
 struct fields_t {
     jfieldID    synthProxyFieldJniData;
-    jclass      synthProxyClass;
     jmethodID   synthProxyMethodPost;
 };
 
@@ -1043,7 +1042,6 @@
         goto bail;
     }
 
-    javaTTSFields.synthProxyClass = clazz;
     javaTTSFields.synthProxyFieldJniData = NULL;
     javaTTSFields.synthProxyMethodPost = NULL;
 
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 44f55b3..5f84547 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -626,7 +626,7 @@
         }
 
         if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) {
-            showRecentAppsDialog(0);
+            showOrHideRecentAppsDialog(0, true /*dismissIfShown*/);
         } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_ACTIVITY) {
             try {
                 Intent intent = new Intent();
@@ -643,16 +643,24 @@
     }
 
     /**
-     * Create (if necessary) and launch the recent apps dialog
+     * Create (if necessary) and launch the recent apps dialog, or hide it if it is
+     * already shown.
      */
-    void showRecentAppsDialog(final int initialModifiers) {
+    void showOrHideRecentAppsDialog(final int heldModifiers, final boolean dismissIfShown) {
         mHandler.post(new Runnable() {
             @Override
             public void run() {
                 if (mRecentAppsDialog == null) {
-                    mRecentAppsDialog = new RecentApplicationsDialog(mContext, initialModifiers);
+                    mRecentAppsDialog = new RecentApplicationsDialog(mContext);
                 }
-                mRecentAppsDialog.show();
+                if (mRecentAppsDialog.isShowing()) {
+                    if (dismissIfShown) {
+                        mRecentAppsDialog.dismiss();
+                    }
+                } else {
+                    mRecentAppsDialog.setHeldModifiers(heldModifiers);
+                    mRecentAppsDialog.show();
+                }
             }
         });
     }
@@ -728,15 +736,11 @@
         mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
                 com.android.internal.R.array.config_safeModeEnabledVibePattern);
 
-        // watch for HDMI plug messages if the hdmi switch exists
-        if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
-            mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
-        }
-        mHdmiPlugged = !readHdmiState();
-        setHdmiPlugged(!mHdmiPlugged);
-
         // Note: the Configuration is not stable here, so we cannot load mStatusBarCanHide from
         // config_statusBarCanHide because the latter depends on the screen size
+
+        // Controls rotation and the like.
+        initializeHdmiState();
     }
 
     public void updateSettings() {
@@ -1392,7 +1396,7 @@
             return false;
         } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
             if (down && repeatCount == 0) {
-                showRecentAppsDialog(event.getMetaState() & KeyEvent.getModifierMetaStateMask());
+                showOrHideRecentAppsDialog(0, true /*dismissIfShown*/);
             }
             return true;
         }
@@ -1434,6 +1438,7 @@
     /** {@inheritDoc} */
     @Override
     public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
+        // Note: This method is only called if the initial down was unhandled.
         if (DEBUG_FALLBACK) {
             Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
                     + ", flags=" + event.getFlags()
@@ -1445,28 +1450,44 @@
         }
 
         if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
-            // Invoke shortcuts using Meta as a fallback.
             final KeyCharacterMap kcm = event.getKeyCharacterMap();
             final int keyCode = event.getKeyCode();
             final int metaState = event.getMetaState();
-            if ((metaState & KeyEvent.META_META_ON) != 0) {
-                Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
-                        metaState & ~(KeyEvent.META_META_ON
-                                | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
-                if (shortcutIntent != null) {
-                    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-                    try {
-                        mContext.startActivity(shortcutIntent);
-                    } catch (ActivityNotFoundException ex) {
-                        Slog.w(TAG, "Dropping shortcut key combination because "
-                                + "the activity to which it is registered was not found: "
-                                + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
+            final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
+                    && event.getRepeatCount() == 0;
+
+            if (initialDown) {
+                // Invoke shortcuts using Meta as a fallback.
+                if ((metaState & KeyEvent.META_META_ON) != 0) {
+                    Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
+                            metaState & ~(KeyEvent.META_META_ON
+                                    | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
+                    if (shortcutIntent != null) {
+                        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                        try {
+                            mContext.startActivity(shortcutIntent);
+                        } catch (ActivityNotFoundException ex) {
+                            Slog.w(TAG, "Dropping shortcut key combination because "
+                                    + "the activity to which it is registered was not found: "
+                                    + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
+                        }
+                        return null;
                     }
-                    return null;
+                }
+
+                // Display task switcher for ALT-TAB or Meta-TAB.
+                if (keyCode == KeyEvent.KEYCODE_TAB) {
+                    final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
+                    if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
+                            || KeyEvent.metaStateHasModifiers(
+                                    shiftlessModifiers, KeyEvent.META_META_ON)) {
+                        showOrHideRecentAppsDialog(shiftlessModifiers, false /*dismissIfShown*/);
+                        return null;
+                    }
                 }
             }
 
-            // Check for fallback actions.
+            // Check for fallback actions specified by the key character map.
             if (getFallbackAction(kcm, keyCode, metaState, mFallbackAction)) {
                 if (DEBUG_FALLBACK) {
                     Slog.d(TAG, "Fallback: keyCode=" + mFallbackAction.keyCode
@@ -2075,31 +2096,37 @@
         }
     }
 
-    boolean readHdmiState() {
-        final String filename = "/sys/class/switch/hdmi/state";
-        FileReader reader = null;
-        try {
-            reader = new FileReader(filename);
-            char[] buf = new char[15];
-            int n = reader.read(buf);
-            if (n > 1) {
-                return 0 != Integer.parseInt(new String(buf, 0, n-1));
-            } else {
-                return false;
-            }
-        } catch (IOException ex) {
-            Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex);
-            return false;
-        } catch (NumberFormatException ex) {
-            Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex);
-            return false;
-        } finally {
-            if (reader != null) {
-                try {
-                    reader.close();
-                } catch (IOException ex) {
+    void initializeHdmiState() {
+        // watch for HDMI plug messages if the hdmi switch exists
+        if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
+            mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
+
+            boolean plugged = false;
+            final String filename = "/sys/class/switch/hdmi/state";
+            FileReader reader = null;
+            try {
+                reader = new FileReader(filename);
+                char[] buf = new char[15];
+                int n = reader.read(buf);
+                if (n > 1) {
+                    plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
+                }
+            } catch (IOException ex) {
+                Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
+            } catch (NumberFormatException ex) {
+                Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
+            } finally {
+                if (reader != null) {
+                    try {
+                        reader.close();
+                    } catch (IOException ex) {
+                    }
                 }
             }
+
+            // This dance forces the code in setHdmiPlugged to run.
+            mHdmiPlugged = !plugged;
+            setHdmiPlugged(!mHdmiPlugged);
         }
     }
 
diff --git a/policy/src/com/android/internal/policy/impl/RecentApplicationsDialog.java b/policy/src/com/android/internal/policy/impl/RecentApplicationsDialog.java
index c4b7822..aa00fbdd 100644
--- a/policy/src/com/android/internal/policy/impl/RecentApplicationsDialog.java
+++ b/policy/src/com/android/internal/policy/impl/RecentApplicationsDialog.java
@@ -71,12 +71,11 @@
         }
     };
 
-    private int mInitialModifiers;
+    private int mHeldModifiers;
 
-    public RecentApplicationsDialog(Context context, int initialModifiers) {
+    public RecentApplicationsDialog(Context context) {
         super(context, com.android.internal.R.style.Theme_Dialog_RecentApplications);
 
-        mInitialModifiers = initialModifiers;
     }
 
     /**
@@ -125,9 +124,20 @@
         }
     }
 
+    /**
+     * Sets the modifier keys that are being held to keep the dialog open, or 0 if none.
+     * Used to make the recent apps dialog automatically dismiss itself when the modifiers
+     * all go up.
+     * @param heldModifiers The held key modifiers, such as {@link KeyEvent#META_ALT_ON}.
+     * Should exclude shift.
+     */
+    public void setHeldModifiers(int heldModifiers) {
+        mHeldModifiers = heldModifiers;
+    }
+
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
-        if (keyCode == KeyEvent.KEYCODE_APP_SWITCH || keyCode == KeyEvent.KEYCODE_TAB) {
+        if (keyCode == KeyEvent.KEYCODE_TAB) {
             // Ignore all meta keys other than SHIFT.  The app switch key could be a
             // fallback action chorded with ALT, META or even CTRL depending on the key map.
             // DPad navigation is handled by the ViewRoot elsewhere.
@@ -166,7 +176,7 @@
 
     @Override
     public boolean onKeyUp(int keyCode, KeyEvent event) {
-        if (mInitialModifiers != 0 && event.hasNoModifiers()) {
+        if (mHeldModifiers != 0 && (event.getModifiers() & mHeldModifiers) == 0) {
             final int numIcons = mIcons.length;
             RecentTag tag = null;
             for (int i = 0; i < numIcons; i++) {
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 2702242..04cfa08 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -31,6 +31,7 @@
 #include <binder/IPCThreadState.h>
 #include <utils/String16.h>
 #include <utils/threads.h>
+#include <utils/Atomic.h>
 
 #include <cutils/properties.h>
 
@@ -1738,10 +1739,7 @@
                     LOGV("BUFFER TIMEOUT: remove(%d) from active list on thread %p", track->name(), this);
                     tracksToRemove->add(track);
                     // indicate to client process that the track was disabled because of underrun
-                    {
-                        AutoMutex _l(cblk->lock);
-                        cblk->flags |= CBLK_DISABLED_ON;
-                    }
+                    android_atomic_or(CBLK_DISABLED_ON, &cblk->flags);
                 } else if (mixerStatus != MIXER_TRACKS_READY) {
                     mixerStatus = MIXER_TRACKS_ENABLED;
                 }
@@ -1790,8 +1788,7 @@
     for (size_t i = 0; i < size; i++) {
         sp<Track> t = mTracks[i];
         if (t->type() == streamType) {
-            AutoMutex _lcblk(t->mCblk->lock);
-            t->mCblk->flags |= CBLK_INVALID_ON;
+            android_atomic_or(CBLK_INVALID_ON, &t->mCblk->flags);
             t->mCblk->cv.signal();
         }
     }
@@ -2950,9 +2947,8 @@
 
     if (mCblk->framesReady() >= mCblk->frameCount ||
             (mCblk->flags & CBLK_FORCEREADY_MSK)) {
-        AutoMutex _l(mCblk->lock);
         mFillingUpStatus = FS_FILLED;
-        mCblk->flags &= ~CBLK_FORCEREADY_MSK;
+        android_atomic_and(~CBLK_FORCEREADY_MSK, &mCblk->flags);
         return true;
     }
     return false;
@@ -3066,26 +3062,25 @@
         // STOPPED state
         mState = STOPPED;
 
-        // NOTE: reset() will reset cblk->user and cblk->server with
-        // the risk that at the same time, the AudioMixer is trying to read
-        // data. In this case, getNextBuffer() would return a NULL pointer
-        // as audio buffer => the AudioMixer code MUST always test that pointer
-        // returned by getNextBuffer() is not NULL!
-        reset();
+        // do not reset the track if it is still in the process of being stopped or paused.
+        // this will be done by prepareTracks_l() when the track is stopped.
+        PlaybackThread *playbackThread = (PlaybackThread *)thread.get();
+        if (playbackThread->mActiveTracks.indexOf(this) < 0) {
+            reset();
+        }
     }
 }
 
 void AudioFlinger::PlaybackThread::Track::reset()
 {
-    AutoMutex _l(mCblk->lock);
     // Do not reset twice to avoid discarding data written just after a flush and before
     // the audioflinger thread detects the track is stopped.
     if (!mResetDone) {
         TrackBase::reset();
         // Force underrun condition to avoid false underrun callback until first data is
         // written to buffer
-        mCblk->flags |= CBLK_UNDERRUN_ON;
-        mCblk->flags &= ~CBLK_FORCEREADY_MSK;
+        android_atomic_and(~CBLK_FORCEREADY_MSK, &mCblk->flags);
+        android_atomic_or(CBLK_UNDERRUN_ON, &mCblk->flags);
         mFillingUpStatus = FS_FILLING;
         mResetDone = true;
     }
@@ -3211,13 +3206,10 @@
     if (thread != 0) {
         RecordThread *recordThread = (RecordThread *)thread.get();
         recordThread->stop(this);
-        {
-            AutoMutex _l(mCblk->lock);
-            TrackBase::reset();
-            // Force overerrun condition to avoid false overrun callback until first data is
-            // read from buffer
-            mCblk->flags |= CBLK_UNDERRUN_ON;
-        }
+        TrackBase::reset();
+        // Force overerrun condition to avoid false overrun callback until first data is
+        // read from buffer
+        android_atomic_or(CBLK_UNDERRUN_ON, &mCblk->flags);
     }
 }
 
@@ -5712,7 +5704,7 @@
         const uint32_t i = 31 - __builtin_clz(device);
         device &= ~(1 << i);
         if (i >= sizeof(sDeviceConvTable)/sizeof(uint32_t)) {
-            LOGE("device convertion error for AudioSystem device 0x%08x", device);
+            LOGE("device conversion error for AudioSystem device 0x%08x", device);
             return 0;
         }
         deviceOut |= (uint32_t)sDeviceConvTable[i];
diff --git a/services/audioflinger/AudioPolicyManagerBase.cpp b/services/audioflinger/AudioPolicyManagerBase.cpp
index f653dc5..c0ac669 100644
--- a/services/audioflinger/AudioPolicyManagerBase.cpp
+++ b/services/audioflinger/AudioPolicyManagerBase.cpp
@@ -542,7 +542,7 @@
     }
 
 
-    LOGW_IF((output ==0), "getOutput() could not find output for stream %d, samplingRate %d, format %d, channels %x, flags %x",
+    LOGW_IF((output == 0), "getOutput() could not find output for stream %d, samplingRate %d, format %d, channels %x, flags %x",
                 stream, samplingRate, format, channels, flags);
 
     return output;
@@ -2107,7 +2107,7 @@
                                     uint32_t device)
 {
    return ((flags & AudioSystem::OUTPUT_FLAG_DIRECT) ||
-          (format !=0 && !AudioSystem::isLinearPCM(format)));
+          (format != 0 && !AudioSystem::isLinearPCM(format)));
 }
 
 uint32_t AudioPolicyManagerBase::getMaxEffectsCpuLoad()
@@ -2159,7 +2159,7 @@
         return;
     }
     mRefCount[stream] += delta;
-    LOGV("changeRefCount() stream %d, count %d", stream, mRefCount[stream]);
+    LOGV("changeRefCount() delta %d, stream %d, refCount %d", delta, stream, mRefCount[stream]);
 }
 
 uint32_t AudioPolicyManagerBase::AudioOutputDescriptor::refCount()
@@ -2215,7 +2215,8 @@
 
 AudioPolicyManagerBase::AudioInputDescriptor::AudioInputDescriptor()
     : mSamplingRate(0), mFormat(0), mChannels(0),
-     mAcoustics((AudioSystem::audio_in_acoustics)0), mDevice(0), mRefCount(0)
+      mAcoustics((AudioSystem::audio_in_acoustics)0), mDevice(0), mRefCount(0),
+      mInputSource(0)
 {
 }
 
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index f3c9959..7e3c643 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -472,15 +472,15 @@
     result = NO_ERROR;
 
     // return if no change in surface.
-    // asBinder() is safe on NULL (returns NULL)
-    if (getISurface(surface)->asBinder() == mSurface) {
+    sp<IBinder> binder(surface != 0 ? surface->asBinder() : 0);
+    if (binder == mSurface) {
         return result;
     }
 
     if (mSurface != 0) {
         LOG1("clearing old preview surface %p", mSurface.get());
     }
-    mSurface = getISurface(surface)->asBinder();
+    mSurface = binder;
     mPreviewWindow = surface;
 
     // If preview has been already started, register preview
@@ -1241,12 +1241,4 @@
     return NO_ERROR;
 }
 
-sp<ISurface> CameraService::getISurface(const sp<Surface>& surface) {
-    if (surface != 0) {
-        return surface->getISurface();
-    } else {
-        return sp<ISurface>(0);
-    }
-}
-
 }; // namespace android
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index 28e8cc0..9a9ab0e 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -79,12 +79,6 @@
     sp<MediaPlayer>     mSoundPlayer[NUM_SOUNDS];
     int                 mSoundRef;  // reference count (release all MediaPlayer when 0)
 
-    // Used by Client objects to extract the ISurface from a Surface object.
-    // This is used because making Client a friend class of Surface would
-    // require including this header in Surface.h since Client is a nested
-    // class.
-    static sp<ISurface> getISurface(const sp<Surface>& surface);
-
     class Client : public BnCamera
     {
     public:
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp
index 9a9d9e5..ff4b11a 100644
--- a/services/input/EventHub.cpp
+++ b/services/input/EventHub.cpp
@@ -539,7 +539,24 @@
                                 (int) iev.time.tv_sec, (int) iev.time.tv_usec,
                                 iev.type, iev.code, iev.value);
 
+#ifdef HAVE_POSIX_CLOCKS
+                        // Use the time specified in the event instead of the current time
+                        // so that downstream code can get more accurate estimates of
+                        // event dispatch latency from the time the event is enqueued onto
+                        // the evdev client buffer.
+                        //
+                        // The event's timestamp fortuitously uses the same monotonic clock
+                        // time base as the rest of Android.  The kernel event device driver
+                        // (drivers/input/evdev.c) obtains timestamps using ktime_get_ts().
+                        // The systemTime(SYSTEM_TIME_MONOTONIC) function we use everywhere
+                        // calls clock_gettime(CLOCK_MONOTONIC) which is implemented as a
+                        // system call that also queries ktime_get_ts().
+                        event->when = nsecs_t(iev.time.tv_sec) * 1000000000LL
+                                + nsecs_t(iev.time.tv_usec) * 1000LL;
+                        LOGV("event time %lld, now %lld", event->when, now);
+#else
                         event->when = now;
+#endif
                         event->deviceId = deviceId;
                         event->type = iev.type;
                         event->scanCode = iev.code;
diff --git a/services/input/InputDispatcher.cpp b/services/input/InputDispatcher.cpp
index 253d070..46de933 100644
--- a/services/input/InputDispatcher.cpp
+++ b/services/input/InputDispatcher.cpp
@@ -79,6 +79,22 @@
 // before considering it stale and dropping it.
 const nsecs_t STALE_EVENT_TIMEOUT = 10000 * 1000000LL; // 10sec
 
+// Motion samples that are received within this amount of time are simply coalesced
+// when batched instead of being appended.  This is done because some drivers update
+// the location of pointers one at a time instead of all at once.
+// For example, when there are 10 fingers down, the input dispatcher may receive 10
+// samples in quick succession with only one finger's location changed in each sample.
+//
+// This value effectively imposes an upper bound on the touch sampling rate.
+// Touch sensors typically have a 50Hz - 200Hz sampling rate, so we expect distinct
+// samples to become available 5-20ms apart but individual finger reports can trickle
+// in over a period of 2-4ms or so.
+//
+// Empirical testing shows that a 2ms coalescing interval (500Hz) is not enough,
+// a 3ms coalescing interval (333Hz) works well most of the time and doesn't introduce
+// significant quantization noise on current hardware.
+const nsecs_t MOTION_SAMPLE_COALESCE_INTERVAL = 3 * 1000000LL; // 3ms, 333Hz
+
 
 static inline nsecs_t now() {
     return systemTime(SYSTEM_TIME_MONOTONIC);
@@ -2505,25 +2521,43 @@
                     continue;
                 }
 
-                if (motionEntry->action != action
-                        || motionEntry->pointerCount != pointerCount
-                        || motionEntry->isInjected()) {
+                if (!motionEntry->canAppendSamples(action, pointerCount, pointerIds)) {
                     // Last motion event in the queue for this device and source is
                     // not compatible for appending new samples.  Stop here.
                     goto NoBatchingOrStreaming;
                 }
 
-                // The last motion event is a move and is compatible for appending.
                 // Do the batching magic.
-                mAllocator.appendMotionSample(motionEntry, eventTime, pointerCoords);
-#if DEBUG_BATCHING
-                LOGD("Appended motion sample onto batch for most recent "
-                        "motion event for this device in the inbound queue.");
-#endif
+                batchMotionLocked(motionEntry, eventTime, metaState, pointerCoords,
+                        "most recent motion event for this device and source in the inbound queue");
                 mLock.unlock();
                 return; // done!
             }
 
+            // BATCHING ONTO PENDING EVENT CASE
+            //
+            // Try to append a move sample to the currently pending event, if there is one.
+            // We can do this as long as we are still waiting to find the targets for the
+            // event.  Once the targets are locked-in we can only do streaming.
+            if (mPendingEvent
+                    && (!mPendingEvent->dispatchInProgress || !mCurrentInputTargetsValid)
+                    && mPendingEvent->type == EventEntry::TYPE_MOTION) {
+                MotionEntry* motionEntry = static_cast<MotionEntry*>(mPendingEvent);
+                if (motionEntry->deviceId == deviceId && motionEntry->source == source) {
+                    if (!motionEntry->canAppendSamples(action, pointerCount, pointerIds)) {
+                        // Pending motion event is for this device and source but it is
+                        // not compatible for appending new samples.  Stop here.
+                        goto NoBatchingOrStreaming;
+                    }
+
+                    // Do the batching magic.
+                    batchMotionLocked(motionEntry, eventTime, metaState, pointerCoords,
+                            "pending motion event");
+                    mLock.unlock();
+                    return; // done!
+                }
+            }
+
             // STREAMING CASE
             //
             // There is no pending motion event (of any kind) for this device in the inbound queue.
@@ -2601,7 +2635,7 @@
                     mAllocator.appendMotionSample(motionEntry, eventTime, pointerCoords);
 #if DEBUG_BATCHING
                     LOGD("Appended motion sample onto batch for most recently dispatched "
-                            "motion event for this device in the outbound queues.  "
+                            "motion event for this device and source in the outbound queues.  "
                             "Attempting to stream the motion sample.");
 #endif
                     nsecs_t currentTime = now();
@@ -2632,6 +2666,36 @@
     }
 }
 
+void InputDispatcher::batchMotionLocked(MotionEntry* entry, nsecs_t eventTime,
+        int32_t metaState, const PointerCoords* pointerCoords, const char* eventDescription) {
+    // Combine meta states.
+    entry->metaState |= metaState;
+
+    // Coalesce this sample if not enough time has elapsed since the last sample was
+    // initially appended to the batch.
+    MotionSample* lastSample = entry->lastSample;
+    long interval = eventTime - lastSample->eventTimeBeforeCoalescing;
+    if (interval <= MOTION_SAMPLE_COALESCE_INTERVAL) {
+        uint32_t pointerCount = entry->pointerCount;
+        for (uint32_t i = 0; i < pointerCount; i++) {
+            lastSample->pointerCoords[i].copyFrom(pointerCoords[i]);
+        }
+        lastSample->eventTime = eventTime;
+#if DEBUG_BATCHING
+        LOGD("Coalesced motion into last sample of batch for %s, events were %0.3f ms apart",
+                eventDescription, interval * 0.000001f);
+#endif
+        return;
+    }
+
+    // Append the sample.
+    mAllocator.appendMotionSample(entry, eventTime, pointerCoords);
+#if DEBUG_BATCHING
+    LOGD("Appended motion sample onto batch for %s, events were %0.3f ms apart",
+            eventDescription, interval * 0.000001f);
+#endif
+}
+
 void InputDispatcher::notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue,
         uint32_t policyFlags) {
 #if DEBUG_INBOUND_EVENT_DETAILS
@@ -3727,6 +3791,7 @@
     entry->downTime = downTime;
     entry->pointerCount = pointerCount;
     entry->firstSample.eventTime = eventTime;
+    entry->firstSample.eventTimeBeforeCoalescing = eventTime;
     entry->firstSample.next = NULL;
     entry->lastSample = & entry->firstSample;
     for (uint32_t i = 0; i < pointerCount; i++) {
@@ -3836,6 +3901,7 @@
         nsecs_t eventTime, const PointerCoords* pointerCoords) {
     MotionSample* sample = mMotionSamplePool.alloc();
     sample->eventTime = eventTime;
+    sample->eventTimeBeforeCoalescing = eventTime;
     uint32_t pointerCount = motionEntry->pointerCount;
     for (uint32_t i = 0; i < pointerCount; i++) {
         sample->pointerCoords[i].copyFrom(pointerCoords[i]);
@@ -3865,6 +3931,21 @@
     return count;
 }
 
+bool InputDispatcher::MotionEntry::canAppendSamples(int32_t action, uint32_t pointerCount,
+        const int32_t* pointerIds) const {
+    if (this->action != action
+            || this->pointerCount != pointerCount
+            || this->isInjected()) {
+        return false;
+    }
+    for (uint32_t i = 0; i < pointerCount; i++) {
+        if (this->pointerIds[i] != pointerIds[i]) {
+            return false;
+        }
+    }
+    return true;
+}
+
 
 // --- InputDispatcher::InputState ---
 
diff --git a/services/input/InputDispatcher.h b/services/input/InputDispatcher.h
index 162e606..af0153b 100644
--- a/services/input/InputDispatcher.h
+++ b/services/input/InputDispatcher.h
@@ -409,7 +409,7 @@
 
         bool dispatchInProgress; // initially false, set to true while dispatching
 
-        inline bool isInjected() { return injectionState != NULL; }
+        inline bool isInjected() const { return injectionState != NULL; }
     };
 
     struct ConfigurationChangedEntry : EventEntry {
@@ -439,7 +439,8 @@
     struct MotionSample {
         MotionSample* next;
 
-        nsecs_t eventTime;
+        nsecs_t eventTime; // may be updated during coalescing
+        nsecs_t eventTimeBeforeCoalescing; // not updated during coalescing
         PointerCoords pointerCoords[MAX_POINTERS];
     };
 
@@ -461,6 +462,10 @@
         MotionSample* lastSample;
 
         uint32_t countSamples() const;
+
+        // Checks whether we can append samples, assuming the device id and source are the same.
+        bool canAppendSamples(int32_t action, uint32_t pointerCount,
+                const int32_t* pointerIds) const;
     };
 
     // Tracks the progress of dispatching a particular event to a particular connection.
@@ -802,6 +807,11 @@
     void dispatchOnceInnerLocked(nsecs_t keyRepeatTimeout, nsecs_t keyRepeatDelay,
             nsecs_t* nextWakeupTime);
 
+    // Batches a new sample onto a motion entry.
+    // Assumes that the we have already checked that we can append samples.
+    void batchMotionLocked(MotionEntry* entry, nsecs_t eventTime, int32_t metaState,
+            const PointerCoords* pointerCoords, const char* eventDescription);
+
     // Enqueues an inbound event.  Returns true if mLooper->wake() should be called.
     bool enqueueInboundEventLocked(EventEntry* entry);
 
diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java
index 47599c8..1aff9a2 100644
--- a/services/java/com/android/server/BatteryService.java
+++ b/services/java/com/android/server/BatteryService.java
@@ -390,7 +390,7 @@
         intent.putExtra(BatteryManager.EXTRA_TECHNOLOGY, mBatteryTechnology);
         intent.putExtra(BatteryManager.EXTRA_INVALID_CHARGER, mInvalidCharger);
 
-        if (true) {
+        if (false) {
             Slog.d(TAG, "level:" + mBatteryLevel +
                     " scale:" + BATTERY_SCALE + " status:" + mBatteryStatus +
                     " health:" + mBatteryHealth +  " present:" + mBatteryPresent +
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index f57f32e..6c3b3d3 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -28,6 +28,7 @@
 import android.net.IConnectivityManager;
 import android.net.LinkProperties;
 import android.net.MobileDataStateTracker;
+import android.net.NetworkConfig;
 import android.net.NetworkInfo;
 import android.net.NetworkStateTracker;
 import android.net.NetworkUtils;
@@ -189,6 +190,14 @@
     private static final int EVENT_APPLY_GLOBAL_HTTP_PROXY =
             MAX_NETWORK_STATE_TRACKER_EVENT + 9;
 
+    /**
+     * used internally to set external dependency met/unmet
+     * arg1 = ENABLED (met) or DISABLED (unmet)
+     * arg2 = NetworkType
+     */
+    private static final int EVENT_SET_DEPENDENCY_MET =
+            MAX_NETWORK_STATE_TRACKER_EVENT + 10;
+
     private Handler mHandler;
 
     // list of DeathRecipients used to make sure features are turned off when
@@ -217,28 +226,7 @@
 
     private SettingsObserver mSettingsObserver;
 
-    private static class NetworkAttributes {
-        /**
-         * Class for holding settings read from resources.
-         */
-        public String mName;
-        public int mType;
-        public int mRadio;
-        public int mPriority;
-        public NetworkInfo.State mLastState;
-        public NetworkAttributes(String init) {
-            String fragments[] = init.split(",");
-            mName = fragments[0].toLowerCase();
-            mType = Integer.parseInt(fragments[1]);
-            mRadio = Integer.parseInt(fragments[2]);
-            mPriority = Integer.parseInt(fragments[3]);
-            mLastState = NetworkInfo.State.UNKNOWN;
-        }
-        public boolean isDefault() {
-            return (mType == mRadio);
-        }
-    }
-    NetworkAttributes[] mNetAttributes;
+    NetworkConfig[] mNetConfigs;
     int mNetworksDefined;
 
     private static class RadioAttributes {
@@ -305,7 +293,7 @@
         mNetworkPreference = getPersistedNetworkPreference();
 
         mRadioAttributes = new RadioAttributes[ConnectivityManager.MAX_RADIO_TYPE+1];
-        mNetAttributes = new NetworkAttributes[ConnectivityManager.MAX_NETWORK_TYPE+1];
+        mNetConfigs = new NetworkConfig[ConnectivityManager.MAX_NETWORK_TYPE+1];
 
         // Load device network attributes from resources
         String[] raStrings = context.getResources().getStringArray(
@@ -328,23 +316,23 @@
                 com.android.internal.R.array.networkAttributes);
         for (String naString : naStrings) {
             try {
-                NetworkAttributes n = new NetworkAttributes(naString);
-                if (n.mType > ConnectivityManager.MAX_NETWORK_TYPE) {
+                NetworkConfig n = new NetworkConfig(naString);
+                if (n.type > ConnectivityManager.MAX_NETWORK_TYPE) {
                     loge("Error in networkAttributes - ignoring attempt to define type " +
-                            n.mType);
+                            n.type);
                     continue;
                 }
-                if (mNetAttributes[n.mType] != null) {
+                if (mNetConfigs[n.type] != null) {
                     loge("Error in networkAttributes - ignoring attempt to redefine type " +
-                            n.mType);
+                            n.type);
                     continue;
                 }
-                if (mRadioAttributes[n.mRadio] == null) {
+                if (mRadioAttributes[n.radio] == null) {
                     loge("Error in networkAttributes - ignoring attempt to use undefined " +
-                            "radio " + n.mRadio + " in network type " + n.mType);
+                            "radio " + n.radio + " in network type " + n.type);
                     continue;
                 }
-                mNetAttributes[n.mType] = n;
+                mNetConfigs[n.type] = n;
                 mNetworksDefined++;
             } catch(Exception e) {
                 // ignore it - leave the entry null
@@ -358,16 +346,16 @@
             int currentLowest = 0;
             int nextLowest = 0;
             while (insertionPoint > -1) {
-                for (NetworkAttributes na : mNetAttributes) {
+                for (NetworkConfig na : mNetConfigs) {
                     if (na == null) continue;
-                    if (na.mPriority < currentLowest) continue;
-                    if (na.mPriority > currentLowest) {
-                        if (na.mPriority < nextLowest || nextLowest == 0) {
-                            nextLowest = na.mPriority;
+                    if (na.priority < currentLowest) continue;
+                    if (na.priority > currentLowest) {
+                        if (na.priority < nextLowest || nextLowest == 0) {
+                            nextLowest = na.priority;
                         }
                         continue;
                     }
-                    mPriorityList[insertionPoint--] = na.mType;
+                    mPriorityList[insertionPoint--] = na.type;
                 }
                 currentLowest = nextLowest;
                 nextLowest = 0;
@@ -393,7 +381,7 @@
          * to change very often.
          */
         for (int netType : mPriorityList) {
-            switch (mNetAttributes[netType].mRadio) {
+            switch (mNetConfigs[netType].radio) {
             case ConnectivityManager.TYPE_WIFI:
                 if (DBG) log("Starting Wifi Service.");
                 WifiStateTracker wst = new WifiStateTracker();
@@ -409,12 +397,12 @@
                 break;
             case ConnectivityManager.TYPE_MOBILE:
                 mNetTrackers[netType] = new MobileDataStateTracker(netType,
-                        mNetAttributes[netType].mName);
+                        mNetConfigs[netType].name);
                 mNetTrackers[netType].startMonitoring(context, mHandler);
                 break;
             case ConnectivityManager.TYPE_DUMMY:
                 mNetTrackers[netType] = new DummyDataStateTracker(netType,
-                        mNetAttributes[netType].mName);
+                        mNetConfigs[netType].name);
                 mNetTrackers[netType].startMonitoring(context, mHandler);
                 break;
             case ConnectivityManager.TYPE_BLUETOOTH:
@@ -427,7 +415,7 @@
                 break;
             default:
                 loge("Trying to create a DataStateTracker for an unknown radio type " +
-                        mNetAttributes[netType].mRadio);
+                        mNetConfigs[netType].radio);
                 continue;
             }
         }
@@ -474,8 +462,8 @@
 
     private void handleSetNetworkPreference(int preference) {
         if (ConnectivityManager.isNetworkTypeValid(preference) &&
-                mNetAttributes[preference] != null &&
-                mNetAttributes[preference].isDefault()) {
+                mNetConfigs[preference] != null &&
+                mNetConfigs[preference].isDefault()) {
             if (mNetworkPreference != preference) {
                 final ContentResolver cr = mContext.getContentResolver();
                 Settings.Secure.putInt(cr, Settings.Secure.NETWORK_PREFERENCE, preference);
@@ -580,7 +568,7 @@
     public LinkProperties getActiveLinkProperties() {
         enforceAccessPermission();
         for (int type=0; type <= ConnectivityManager.MAX_NETWORK_TYPE; type++) {
-            if (mNetAttributes[type] == null || !mNetAttributes[type].isDefault()) {
+            if (mNetConfigs[type] == null || !mNetConfigs[type].isDefault()) {
                 continue;
             }
             NetworkStateTracker t = mNetTrackers[type];
@@ -682,7 +670,7 @@
         }
         enforceChangePermission();
         if (!ConnectivityManager.isNetworkTypeValid(networkType) ||
-                mNetAttributes[networkType] == null) {
+                mNetConfigs[networkType] == null) {
             return Phone.APN_REQUEST_FAILED;
         }
 
@@ -994,6 +982,24 @@
         return retVal;
     }
 
+    public void setDataDependency(int networkType, boolean met) {
+        enforceChangePermission();
+        if (DBG) {
+            log("setDataDependency(" + networkType + ", " + met + ")");
+        }
+        mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_DEPENDENCY_MET,
+                (met ? ENABLED : DISABLED), networkType));
+    }
+
+    private void handleSetDependencyMet(int networkType, boolean met) {
+        if (mNetTrackers[networkType] != null) {
+            if (DBG) {
+                log("handleSetDependencyMet(" + networkType + ", " + met + ")");
+            }
+            mNetTrackers[networkType].setDependencyMet(met);
+        }
+    }
+
     /**
      * @see ConnectivityManager#setMobileDataEnabled(boolean)
      */
@@ -1002,7 +1008,7 @@
         if (DBG) log("setMobileDataEnabled(" + enabled + ")");
 
         mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_MOBILE_DATA,
-            (enabled ? ENABLED : DISABLED), 0));
+                (enabled ? ENABLED : DISABLED), 0));
     }
 
     private void handleSetMobileData(boolean enabled) {
@@ -1063,7 +1069,7 @@
          * getting the disconnect for a network that we explicitly disabled
          * in accordance with network preference policies.
          */
-        if (!mNetAttributes[prevNetType].isDefault()) {
+        if (!mNetConfigs[prevNetType].isDefault()) {
             List pids = mNetRequestersPids[prevNetType];
             for (int i = 0; i<pids.size(); i++) {
                 Integer pid = (Integer)pids.get(i);
@@ -1088,7 +1094,7 @@
                     info.getExtraInfo());
         }
 
-        if (mNetAttributes[prevNetType].isDefault()) {
+        if (mNetConfigs[prevNetType].isDefault()) {
             tryFailover(prevNetType);
             if (mActiveDefaultNetwork != -1) {
                 NetworkInfo switchTo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
@@ -1118,7 +1124,7 @@
          * Try to reconnect on all available and let them hash it out when
          * more than one connects.
          */
-        if (mNetAttributes[prevNetType].isDefault()) {
+        if (mNetConfigs[prevNetType].isDefault()) {
             if (mActiveDefaultNetwork == prevNetType) {
                 mActiveDefaultNetwork = -1;
             }
@@ -1128,12 +1134,12 @@
             // TODO - don't filter by priority now - nice optimization but risky
 //            int currentPriority = -1;
 //            if (mActiveDefaultNetwork != -1) {
-//                currentPriority = mNetAttributes[mActiveDefaultNetwork].mPriority;
+//                currentPriority = mNetConfigs[mActiveDefaultNetwork].mPriority;
 //            }
             for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) {
                 if (checkType == prevNetType) continue;
-                if (mNetAttributes[checkType] == null) continue;
-                if (!mNetAttributes[checkType].isDefault()) continue;
+                if (mNetConfigs[checkType] == null) continue;
+                if (!mNetConfigs[checkType].isDefault()) continue;
 
 // Enabling the isAvailable() optimization caused mobile to not get
 // selected if it was in the middle of error handling. Specifically
@@ -1145,7 +1151,7 @@
 // complete before it is really complete.
 //                if (!mNetTrackers[checkType].isAvailable()) continue;
 
-//                if (currentPriority >= mNetAttributes[checkType].mPriority) continue;
+//                if (currentPriority >= mNetConfigs[checkType].mPriority) continue;
 
                 NetworkStateTracker checkTracker = mNetTrackers[checkType];
                 NetworkInfo checkInfo = checkTracker.getNetworkInfo();
@@ -1218,7 +1224,7 @@
             info.setFailover(false);
         }
 
-        if (mNetAttributes[info.getType()].isDefault()) {
+        if (mNetConfigs[info.getType()].isDefault()) {
             tryFailover(info.getType());
             if (mActiveDefaultNetwork != -1) {
                 NetworkInfo switchTo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
@@ -1271,11 +1277,11 @@
 
         // if this is a default net and other default is running
         // kill the one not preferred
-        if (mNetAttributes[type].isDefault()) {
+        if (mNetConfigs[type].isDefault()) {
             if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != type) {
                 if ((type != mNetworkPreference &&
-                        mNetAttributes[mActiveDefaultNetwork].mPriority >
-                        mNetAttributes[type].mPriority) ||
+                        mNetConfigs[mActiveDefaultNetwork].priority >
+                        mNetConfigs[type].priority) ||
                         mNetworkPreference == mActiveDefaultNetwork) {
                         // don't accept this one
                         if (DBG) {
@@ -1340,7 +1346,7 @@
         handleDnsConfigurationChange(netType);
 
         if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
-            if (mNetAttributes[netType].isDefault()) {
+            if (mNetConfigs[netType].isDefault()) {
                 handleApplyDefaultProxy(netType);
                 addDefaultRoute(mNetTrackers[netType]);
             } else {
@@ -1360,7 +1366,7 @@
                 addPrivateDnsRoutes(mNetTrackers[netType]);
             }
         } else {
-            if (mNetAttributes[netType].isDefault()) {
+            if (mNetConfigs[netType].isDefault()) {
                 removeDefaultRoute(mNetTrackers[netType]);
             } else {
                 removePrivateDnsRoutes(mNetTrackers[netType]);
@@ -1521,7 +1527,7 @@
     {
         if (DBG) log("reassessPidDns for pid " + myPid);
         for(int i : mPriorityList) {
-            if (mNetAttributes[i].isDefault()) {
+            if (mNetConfigs[i].isDefault()) {
                 continue;
             }
             NetworkStateTracker nt = mNetTrackers[i];
@@ -1603,7 +1609,7 @@
             if (p == null) return;
             Collection<InetAddress> dnses = p.getDnses();
             boolean changed = false;
-            if (mNetAttributes[netType].isDefault()) {
+            if (mNetConfigs[netType].isDefault()) {
                 int j = 1;
                 if (dnses.size() == 0 && mDefaultDns != null) {
                     String dnsString = mDefaultDns.getHostAddress();
@@ -1734,23 +1740,6 @@
                     info = (NetworkInfo) msg.obj;
                     int type = info.getType();
                     NetworkInfo.State state = info.getState();
-                    // only do this optimization for wifi.  It going into scan mode for location
-                    // services generates alot of noise.  Meanwhile the mms apn won't send out
-                    // subsequent notifications when on default cellular because it never
-                    // disconnects..  so only do this to wifi notifications.  Fixed better when the
-                    // APN notifications are standardized.
-                    if (mNetAttributes[type].mLastState == state &&
-                            mNetAttributes[type].mRadio == ConnectivityManager.TYPE_WIFI) {
-                        if (DBG) {
-                            // TODO - remove this after we validate the dropping doesn't break
-                            // anything
-                            log("Dropping ConnectivityChange for " +
-                                    info.getTypeName() + ": " +
-                                    state + "/" + info.getDetailedState());
-                        }
-                        return;
-                    }
-                    mNetAttributes[type].mLastState = state;
 
                     if (DBG) log("ConnectivityChange for " +
                             info.getTypeName() + ": " +
@@ -1789,8 +1778,7 @@
                     break;
                 case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED:
                     info = (NetworkInfo) msg.obj;
-                    type = info.getType();
-                    handleConnectivityChange(type);
+                    handleConnectivityChange(info.getType());
                     break;
                 case EVENT_CLEAR_NET_TRANSITION_WAKELOCK:
                     String causedBy = null;
@@ -1844,6 +1832,13 @@
                 case EVENT_APPLY_GLOBAL_HTTP_PROXY:
                 {
                     handleDeprecatedGlobalHttpProxy();
+                    break;
+                }
+                case EVENT_SET_DEPENDENCY_MET:
+                {
+                    boolean met = (msg.arg1 == ENABLED);
+                    handleSetDependencyMet(msg.arg2, met);
+                    break;
                 }
             }
         }
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
index 7e5fd29..c18ccc8 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -448,34 +448,56 @@
                  * to make the media scanner run.
                  */
                 if ("simulator".equals(SystemProperties.get("ro.product.device"))) {
-                    notifyVolumeStateChange(null, "/sdcard", VolumeState.NoMedia, VolumeState.Mounted);
+                    notifyVolumeStateChange(null, "/sdcard", VolumeState.NoMedia,
+                            VolumeState.Mounted);
                     return;
                 }
                 new Thread() {
                     @Override
                     public void run() {
                         try {
+                            // it is not safe to call vold with mVolumeStates locked
+                            // so we make a copy of the paths and states and process them
+                            // outside the lock
+                            String[] paths, states;
+                            int count;
                             synchronized (mVolumeStates) {
-                                for (String path : mVolumeStates.keySet()) {
-                                    String state = mVolumeStates.get(path);
-
-                                    if (state.equals(Environment.MEDIA_UNMOUNTED)) {
-                                        int rc = doMountVolume(path);
-                                        if (rc != StorageResultCode.OperationSucceeded) {
-                                            Slog.e(TAG, String.format("Boot-time mount failed (%d)",
-                                                    rc));
-                                        }
-                                    } else if (state.equals(Environment.MEDIA_SHARED)) {
-                                        /*
-                                         * Bootstrap UMS enabled state since vold indicates
-                                         * the volume is shared (runtime restart while ums enabled)
-                                         */
-                                        notifyVolumeStateChange(null, path, VolumeState.NoMedia,
-                                                VolumeState.Shared);
-                                    }
+                                Set<String> keys = mVolumeStates.keySet();
+                                count = keys.size();
+                                paths = (String[])keys.toArray(new String[count]);
+                                states = new String[count];
+                                for (int i = 0; i < count; i++) {
+                                    states[i] = mVolumeStates.get(paths[i]);
                                 }
                             }
 
+                            for (int i = 0; i < count; i++) {
+                                String path = paths[i];
+                                String state = states[i];
+
+                                if (state.equals(Environment.MEDIA_UNMOUNTED)) {
+                                    int rc = doMountVolume(path);
+                                    if (rc != StorageResultCode.OperationSucceeded) {
+                                        Slog.e(TAG, String.format("Boot-time mount failed (%d)",
+                                                rc));
+                                    }
+                                } else if (state.equals(Environment.MEDIA_SHARED)) {
+                                    /*
+                                     * Bootstrap UMS enabled state since vold indicates
+                                     * the volume is shared (runtime restart while ums enabled)
+                                     */
+                                    notifyVolumeStateChange(null, path, VolumeState.NoMedia,
+                                            VolumeState.Shared);
+                                }
+                            }
+
+                            /* notify external storage has mounted to trigger media scanner */
+                            if (mEmulateExternalStorage) {
+                                notifyVolumeStateChange(null,
+                                        Environment.getExternalStorageDirectory().getPath(),
+                                        VolumeState.NoMedia, VolumeState.Mounted);
+                            }
+
                             /*
                              * If UMS was connected on boot, send the connected event
                              * now that we're up.
diff --git a/services/java/com/android/server/TelephonyRegistry.java b/services/java/com/android/server/TelephonyRegistry.java
index eb14180..948118f 100644
--- a/services/java/com/android/server/TelephonyRegistry.java
+++ b/services/java/com/android/server/TelephonyRegistry.java
@@ -279,7 +279,6 @@
         if (!checkNotifyPermission("notifyServiceState()")){
             return;
         }
-        Slog.i(TAG, "notifyServiceState: " + state);
         synchronized (mRecords) {
             mServiceState = state;
             for (Record r : mRecords) {
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 915b679..a2d10df 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -937,7 +937,7 @@
                 evaluateTrafficStatsPolling();
                 mWifiStateMachine.enableRssiPolling(true);
                 if (mBackgroundScanSupported) {
-                    mWifiStateMachine.enableBackgroundScan(false);
+                    mWifiStateMachine.enableBackgroundScanCommand(false);
                 }
                 mWifiStateMachine.enableAllNetworks();
                 updateWifiState();
@@ -949,7 +949,7 @@
                 evaluateTrafficStatsPolling();
                 mWifiStateMachine.enableRssiPolling(false);
                 if (mBackgroundScanSupported) {
-                    mWifiStateMachine.enableBackgroundScan(true);
+                    mWifiStateMachine.enableBackgroundScanCommand(true);
                 }
                 /*
                  * Set a timer to put Wi-Fi to sleep, but only if the screen is off
diff --git a/services/java/com/android/server/pm/Installer.java b/services/java/com/android/server/pm/Installer.java
index 8d40000..da3ebaf 100644
--- a/services/java/com/android/server/pm/Installer.java
+++ b/services/java/com/android/server/pm/Installer.java
@@ -28,7 +28,7 @@
 class Installer {
     private static final String TAG = "Installer";
 
-    private static final boolean LOCAL_DEBUG = true;
+    private static final boolean LOCAL_DEBUG = false;
 
     InputStream mIn;
 
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 79c4518..e2874f8 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -5453,6 +5453,9 @@
         mDisplay.getMetrics(dm);
         CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
 
+        config.screenWidthDp = (int)(dm.widthPixels / dm.density);
+        config.screenHeightDp = (int)(dm.heightPixels / dm.density);
+
         if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
             // Note we only do this once because at this point we don't
             // expect the screen to change in this way at runtime, and want
diff --git a/services/jni/com_android_server_UsbService.cpp b/services/jni/com_android_server_UsbService.cpp
index 6aeede2..00ee7e3 100644
--- a/services/jni/com_android_server_UsbService.cpp
+++ b/services/jni/com_android_server_UsbService.cpp
@@ -260,7 +260,7 @@
         return -1;
     }
 
-   clazz = env->FindClass("java/io/FileDescriptor");
+    clazz = env->FindClass("java/io/FileDescriptor");
     LOG_FATAL_IF(clazz == NULL, "Unable to find class java.io.FileDescriptor");
     gFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz);
     gFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "()V");
@@ -268,7 +268,7 @@
     LOG_FATAL_IF(gFileDescriptorOffsets.mDescriptor == NULL,
                  "Unable to find descriptor field in java.io.FileDescriptor");
 
-   clazz = env->FindClass("android/os/ParcelFileDescriptor");
+    clazz = env->FindClass("android/os/ParcelFileDescriptor");
     LOG_FATAL_IF(clazz == NULL, "Unable to find class android.os.ParcelFileDescriptor");
     gParcelFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz);
     gParcelFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "(Ljava/io/FileDescriptor;)V");
diff --git a/services/surfaceflinger/tests/resize/resize.cpp b/services/surfaceflinger/tests/resize/resize.cpp
index 0ccca77..18c54b3 100644
--- a/services/surfaceflinger/tests/resize/resize.cpp
+++ b/services/surfaceflinger/tests/resize/resize.cpp
@@ -29,13 +29,6 @@
 using namespace android;
 
 namespace android {
-class Test {
-public:
-    static const sp<ISurface>& getISurface(const sp<Surface>& s) {
-        return s->getISurface();
-    }
-};
-};
 
 int main(int argc, char** argv)
 {
diff --git a/telephony/java/com/android/internal/telephony/ApnContext.java b/telephony/java/com/android/internal/telephony/ApnContext.java
index a86ea7e..2e7c3a3 100644
--- a/telephony/java/com/android/internal/telephony/ApnContext.java
+++ b/telephony/java/com/android/internal/telephony/ApnContext.java
@@ -20,7 +20,6 @@
 
 import android.util.Log;
 import java.util.ArrayList;
-import com.android.internal.telephony.gsm.GsmDataConnection;
 
 /**
  * Maintain the Apn context
@@ -30,9 +29,13 @@
     public static final int PENDING_ACTION_NONE = 1;
     public static final int PENDING_ACTION_RECONNECT = 2;
     public static final int PENDING_ACTION_APN_DISABLE = 3;
+
+    public static final int DATA_ENABLED = 1;
+    public static final int DATA_DISABLED = 2;
+
     public final String LOG_TAG;
 
-    int pendingAction;
+    int mPendingAction;
 
     protected static final boolean DBG = true;
 
@@ -47,37 +50,49 @@
 
     ApnSetting mApnSetting;
 
-    GsmDataConnection mDataConnection;
+    DataConnection mDataConnection;
 
     String mReason;
 
     PendingIntent mReconnectIntent;
 
+    /**
+     * user/app requested connection on this APN
+     */
+    boolean mDataEnabled;
+
+    /**
+     * carrier requirements met
+     */
+    boolean mDependencyMet;
+
     public ApnContext(String apnType, String logTag) {
         mApnType = apnType;
         mState = DataConnectionTracker.State.IDLE;
         setReason(Phone.REASON_DATA_ENABLED);
-        pendingAction = PENDING_ACTION_NONE;
+        mPendingAction = PENDING_ACTION_NONE;
+        mDataEnabled = false;
+        mDependencyMet = true;
         LOG_TAG = logTag;
     }
 
     public int getPendingAction() {
-        return pendingAction;
+        return mPendingAction;
     }
 
     public void setPendingAction(int pa) {
-        pendingAction = pa;
+        mPendingAction = pa;
     }
 
     public String getApnType() {
         return mApnType;
     }
 
-    public GsmDataConnection getDataConnection() {
+    public DataConnection getDataConnection() {
         return mDataConnection;
     }
 
-    public void setDataConnection(GsmDataConnection dataConnection) {
+    public void setDataConnection(DataConnection dataConnection) {
         mDataConnection = dataConnection;
     }
 
@@ -160,6 +175,34 @@
         return mReconnectIntent;
     }
 
+    public boolean isReady() {
+        return mDataEnabled && mDependencyMet;
+    }
+
+    public void setEnabled(boolean enabled) {
+        if (DBG) {
+            log("set enabled as " + enabled + ", for type " +
+                    mApnType + ", current state is " + mDataEnabled);
+        }
+        mDataEnabled = enabled;
+    }
+
+    public boolean isEnabled() {
+        return mDataEnabled;
+    }
+
+    public void setDependencyMet(boolean met) {
+        if (DBG) {
+            log("set mDependencyMet as " + met + ", for type " + mApnType +
+                    ", current state is " + mDependencyMet);
+        }
+        mDependencyMet = met;
+    }
+
+    public boolean getDependencyMet() {
+       return mDependencyMet;
+    }
+
     protected void log(String s) {
         Log.d(LOG_TAG, "[ApnContext] " + s);
     }
diff --git a/telephony/java/com/android/internal/telephony/BaseCommands.java b/telephony/java/com/android/internal/telephony/BaseCommands.java
index 0fc81b0..076db8b 100644
--- a/telephony/java/com/android/internal/telephony/BaseCommands.java
+++ b/telephony/java/com/android/internal/telephony/BaseCommands.java
@@ -71,6 +71,7 @@
     protected RegistrantList mCdmaSubscriptionChangedRegistrants = new RegistrantList();
     protected RegistrantList mCdmaPrlChangedRegistrants = new RegistrantList();
     protected RegistrantList mExitEmergencyCallbackModeRegistrants = new RegistrantList();
+    protected RegistrantList mRilConnectedRegistrants = new RegistrantList();
 
     protected Registrant mSMSRegistrant;
     protected Registrant mNITZTimeRegistrant;
@@ -96,7 +97,8 @@
     protected int mCdmaSubscription;
     // Type of Phone, GSM or CDMA. Set by CDMAPhone or GSMPhone.
     protected int mPhoneType;
-
+    // RIL Version
+    protected int mRilVersion = -1;
 
     public BaseCommands(Context context) {
         mContext = context;  // May be null (if so we won't log statistics)
@@ -639,6 +641,25 @@
         mExitEmergencyCallbackModeRegistrants.remove(h);
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void registerForRilConnected(Handler h, int what, Object obj) {
+        Log.d(LOG_TAG, "registerForRilConnected h=" + h + " w=" + what);
+        Registrant r = new Registrant (h, what, obj);
+        mRilConnectedRegistrants.add(r);
+        if (mRilVersion != -1) {
+            Log.d(LOG_TAG, "Notifying: ril connected mRilVersion=" + mRilVersion);
+            r.notifyRegistrant(new AsyncResult(null, new Integer(mRilVersion), null));
+        }
+    }
+
+    @Override
+    public void unregisterForRilConnected(Handler h) {
+        mRilConnectedRegistrants.remove(h);
+    }
+
     //***** Protected Methods
     /**
      * Store new RadioState and send notification based on the changes
diff --git a/telephony/java/com/android/internal/telephony/CommandsInterface.java b/telephony/java/com/android/internal/telephony/CommandsInterface.java
index 9e1e0c6..1d574ca 100644
--- a/telephony/java/com/android/internal/telephony/CommandsInterface.java
+++ b/telephony/java/com/android/internal/telephony/CommandsInterface.java
@@ -604,6 +604,20 @@
      void registerForExitEmergencyCallbackMode(Handler h, int what, Object obj);
      void unregisterForExitEmergencyCallbackMode(Handler h);
 
+     /**
+      * Registers the handler for RIL_UNSOL_RIL_CONNECT events.
+      *
+      * When ril connects or disconnects a message is sent to the registrant
+      * which contains an AsyncResult, ar, in msg.obj. The ar.result is an
+      * Integer which is the version of the ril or -1 if the ril disconnected.
+      *
+      * @param h Handler for notification message.
+      * @param what User-defined message code.
+      * @param obj User object.
+      */
+     void registerForRilConnected(Handler h, int what, Object obj);
+     void unregisterForRilConnected(Handler h);
+
     /**
      * Supply the ICC PIN to the ICC card
      *
@@ -1441,6 +1455,12 @@
     void setCdmaSubscriptionSource(int cdmaSubscriptionType, Message response);
 
     /**
+     *  Requests to get the CDMA subscription srouce
+     * @param response is callback message
+     */
+    void getCdmaSubscriptionSource(Message response);
+
+    /**
      *  Set the TTY mode
      *
      * @param ttyMode one of the following:
diff --git a/telephony/java/com/android/internal/telephony/DataCallState.java b/telephony/java/com/android/internal/telephony/DataCallState.java
index fda1e47..a883e8e 100644
--- a/telephony/java/com/android/internal/telephony/DataCallState.java
+++ b/telephony/java/com/android/internal/telephony/DataCallState.java
@@ -17,11 +17,26 @@
 
 package com.android.internal.telephony;
 
+import android.net.LinkAddress;
+import android.net.LinkProperties;
+import android.net.NetworkUtils;
+import android.os.SystemProperties;
+import android.util.Log;
+
+import com.android.internal.telephony.DataConnection.FailCause;
+
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
 /**
  * This is RIL_Data_Call_Response_v5 from ril.h
  * TODO: Rename to DataCallResponse.
  */
 public class DataCallState {
+    private final boolean DBG = true;
+    private final String LOG_TAG = "GSM";
+
     public int version = 0;
     public int status = 0;
     public int cid = 0;
@@ -32,6 +47,29 @@
     public String [] dnses = new String[0];
     public String[] gateways = new String[0];
 
+    /**
+     * Class returned by onSetupConnectionCompleted.
+     */
+    protected enum SetupResult {
+        SUCCESS,
+        ERR_BadCommand,
+        ERR_UnacceptableParameter,
+        ERR_GetLastErrorFromRil,
+        ERR_Stale,
+        ERR_RilError;
+
+        public FailCause mFailCause;
+
+        SetupResult() {
+            mFailCause = FailCause.fromInt(0);
+        }
+
+        @Override
+        public String toString() {
+            return name() + "  SetupResult.mFailCause=" + mFailCause;
+        }
+    }
+
     @Override
     public String toString() {
         StringBuffer sb = new StringBuffer();
@@ -63,4 +101,127 @@
         sb.append("]}");
         return sb.toString();
     }
+
+    public SetupResult setLinkProperties(LinkProperties linkProperties,
+            boolean okToUseSystemPropertyDns) {
+        SetupResult result;
+
+        // Start with clean network properties and if we have
+        // a failure we'll clear again at the bottom of this code.
+        if (linkProperties == null)
+            linkProperties = new LinkProperties();
+        else
+            linkProperties.clear();
+
+        if (status == FailCause.NONE.getErrorCode()) {
+            String propertyPrefix = "net." + ifname + ".";
+
+            try {
+                // set interface name
+                linkProperties.setInterfaceName(ifname);
+
+                // set link addresses
+                if (addresses != null && addresses.length > 0) {
+                    for (String addr : addresses) {
+                        LinkAddress la;
+                        int addrPrefixLen;
+
+                        String [] ap = addr.split("/");
+                        if (ap.length == 2) {
+                            addr = ap[0];
+                            addrPrefixLen = Integer.parseInt(ap[1]);
+                        } else {
+                            addrPrefixLen = 0;
+                        }
+                        InetAddress ia;
+                        try {
+                            ia = NetworkUtils.numericToInetAddress(addr);
+                        } catch (IllegalArgumentException e) {
+                            throw new UnknownHostException("Non-numeric ip addr=" + addr);
+                        }
+                        if (addrPrefixLen == 0) {
+                            // Assume point to point
+                            addrPrefixLen = (ia instanceof Inet4Address) ? 32 : 128;
+                        }
+                        if (DBG) Log.d(LOG_TAG, "addr/pl=" + addr + "/" + addrPrefixLen);
+                        la = new LinkAddress(ia, addrPrefixLen);
+                        linkProperties.addLinkAddress(la);
+                    }
+                } else {
+                    throw new UnknownHostException("no address for ifname=" + ifname);
+                }
+
+                // set dns servers
+                if (dnses != null && dnses.length > 0) {
+                    for (String addr : dnses) {
+                        InetAddress ia;
+                        try {
+                            ia = NetworkUtils.numericToInetAddress(addr);
+                        } catch (IllegalArgumentException e) {
+                            throw new UnknownHostException("Non-numeric dns addr=" + addr);
+                        }
+                        linkProperties.addDns(ia);
+                    }
+                } else if (okToUseSystemPropertyDns){
+                    String dnsServers[] = new String[2];
+                    dnsServers[0] = SystemProperties.get(propertyPrefix + "dns1");
+                    dnsServers[1] = SystemProperties.get(propertyPrefix + "dns2");
+                    for (String dnsAddr : dnsServers) {
+                            InetAddress ia;
+                            try {
+                                ia = NetworkUtils.numericToInetAddress(dnsAddr);
+                            } catch (IllegalArgumentException e) {
+                                throw new UnknownHostException("Non-numeric dns addr="
+                                            + dnsAddr);
+                            }
+                            linkProperties.addDns(ia);
+                    }
+                } else {
+                    throw new UnknownHostException("Empty dns response and no system default dns");
+                }
+
+                // set gateways
+                if ((gateways == null) || (gateways.length == 0)) {
+                    String sysGateways = SystemProperties.get(propertyPrefix + "gw");
+                    if (sysGateways != null) {
+                        gateways = sysGateways.split(" ");
+                    } else {
+                        gateways = new String[0];
+                    }
+                }
+                for (String addr : gateways) {
+                    InetAddress ia;
+                    try {
+                        ia = NetworkUtils.numericToInetAddress(addr);
+                    } catch (IllegalArgumentException e) {
+                        throw new UnknownHostException("Non-numeric gateway addr=" + addr);
+                    }
+                    linkProperties.addGateway(ia);
+                }
+
+                result = SetupResult.SUCCESS;
+            } catch (UnknownHostException e) {
+                Log.d(LOG_TAG, "onSetupCompleted: UnknownHostException " + e);
+                e.printStackTrace();
+                result = SetupResult.ERR_UnacceptableParameter;
+            }
+        } else {
+            if (version < 4) {
+                result = SetupResult.ERR_GetLastErrorFromRil;
+            } else {
+                result = SetupResult.ERR_RilError;
+            }
+        }
+
+        // An error occurred so clear properties
+        if (result != SetupResult.SUCCESS) {
+            if(DBG) Log.d(LOG_TAG,
+                    "onSetupConnectionCompleted with an error, clearing LinkProperties");
+            linkProperties.clear();
+        }
+
+        return result;
+    }
 }
+
+
diff --git a/telephony/java/com/android/internal/telephony/DataConnection.java b/telephony/java/com/android/internal/telephony/DataConnection.java
index e21e951..0ad5296 100644
--- a/telephony/java/com/android/internal/telephony/DataConnection.java
+++ b/telephony/java/com/android/internal/telephony/DataConnection.java
@@ -62,29 +62,6 @@
     protected static int mCount;
 
     /**
-     * Class returned by onSetupConnectionCompleted.
-     */
-    protected enum SetupResult {
-        SUCCESS,
-        ERR_BadCommand,
-        ERR_UnacceptableParameter,
-        ERR_GetLastErrorFromRil,
-        ERR_Stale,
-        ERR_RilError;
-
-        public FailCause mFailCause;
-
-        SetupResult() {
-            mFailCause = FailCause.fromInt(0);
-        }
-
-        @Override
-        public String toString() {
-            return name() + "  SetupResult.mFailCause=" + mFailCause;
-        }
-    }
-
-    /**
      * Used internally for saving connecting parameters.
      */
     protected static class ConnectionParams {
@@ -217,6 +194,7 @@
     protected static final int EVENT_GET_LAST_FAIL_DONE = 4;
     protected static final int EVENT_DEACTIVATE_DONE = 5;
     protected static final int EVENT_DISCONNECT = 6;
+    protected static final int EVENT_RIL_CONNECTED = 7;
 
     //***** Tag IDs for EventLog
     protected static final int EVENT_LOG_BAD_DNS_ADDRESS = 50100;
@@ -225,6 +203,7 @@
     protected ApnSetting mApn;
     protected int mTag;
     protected PhoneBase phone;
+    protected int mRilVersion = -1;
     protected int cid;
     protected LinkProperties mLinkProperties = new LinkProperties();
     protected LinkCapabilities mCapabilities = new LinkCapabilities();
@@ -343,6 +322,16 @@
         clearSettings();
     }
 
+    protected int getRadioTechnology(int defaultRadioTechnology) {
+        int radioTechnology;
+        if (mRilVersion < 6) {
+            radioTechnology = defaultRadioTechnology;
+        } else {
+            radioTechnology = phone.getServiceState().getRadioTechnology() + 2;
+        }
+        return radioTechnology;
+    }
+
     /*
      * **************************************************************************
      * Begin Members and methods owned by DataConnectionTracker but stored
@@ -445,10 +434,10 @@
      * @param ar is the result
      * @return SetupResult.
      */
-    private SetupResult onSetupConnectionCompleted(AsyncResult ar) {
+    private DataCallState.SetupResult onSetupConnectionCompleted(AsyncResult ar) {
         DataCallState response = (DataCallState) ar.result;
         ConnectionParams cp = (ConnectionParams) ar.userObj;
-        SetupResult result;
+        DataCallState.SetupResult result;
 
         if (ar.exception != null) {
             if (DBG) {
@@ -459,148 +448,35 @@
             if (ar.exception instanceof CommandException
                     && ((CommandException) (ar.exception)).getCommandError()
                     == CommandException.Error.RADIO_NOT_AVAILABLE) {
-                result = SetupResult.ERR_BadCommand;
+                result = DataCallState.SetupResult.ERR_BadCommand;
                 result.mFailCause = FailCause.RADIO_NOT_AVAILABLE;
             } else if ((response == null) || (response.version < 4)) {
-                result = SetupResult.ERR_GetLastErrorFromRil;
+                result = DataCallState.SetupResult.ERR_GetLastErrorFromRil;
             } else {
-                result = SetupResult.ERR_RilError;
+                result = DataCallState.SetupResult.ERR_RilError;
                 result.mFailCause = FailCause.fromInt(response.status);
             }
         } else if (cp.tag != mTag) {
             if (DBG) {
                 log("BUG: onSetupConnectionCompleted is stale cp.tag=" + cp.tag + ", mtag=" + mTag);
             }
-            result = SetupResult.ERR_Stale;
+            result = DataCallState.SetupResult.ERR_Stale;
         } else {
             log("onSetupConnectionCompleted received DataCallState: " + response);
 
-            // Start with clean network properties and if we have
-            // a failure we'll clear again at the bottom of this code.
-            LinkProperties linkProperties = new LinkProperties();
-            if (response.status == FailCause.NONE.getErrorCode()) {
-                String propertyPrefix = "net." + response.ifname + ".";
+            // Check if system property dns usable
+            boolean okToUseSystemPropertyDns = false;
+            String propertyPrefix = "net." + response.ifname + ".";
+            String dnsServers[] = new String[2];
+            dnsServers[0] = SystemProperties.get(propertyPrefix + "dns1");
+            dnsServers[1] = SystemProperties.get(propertyPrefix + "dns2");
+            okToUseSystemPropertyDns = isDnsOk(dnsServers);
 
-                try {
-                    cid = response.cid;
-                    linkProperties.setInterfaceName(response.ifname);
-                    if (response.addresses != null && response.addresses.length > 0) {
-                        for (String addr : response.addresses) {
-                            LinkAddress la;
-                            int addrPrefixLen;
-
-                            String [] ap = addr.split("/");
-                            if (ap.length == 2) {
-                                addr = ap[0];
-                                addrPrefixLen = Integer.parseInt(ap[1]);
-                            } else {
-                                addrPrefixLen = 0;
-                            }
-                            InetAddress ia;
-                            try {
-                                ia = NetworkUtils.numericToInetAddress(addr);
-                            } catch (IllegalArgumentException e) {
-                                EventLogTags.writeBadIpAddress(addr);
-                                throw new UnknownHostException("Non-numeric ip addr=" + addr);
-                            }
-                            if (addrPrefixLen == 0) {
-                                // Assume point to point
-                                addrPrefixLen = (ia instanceof Inet4Address) ? 32 : 128;
-                            }
-                            if (DBG) log("addr/pl=" + addr + "/" + addrPrefixLen);
-                            la = new LinkAddress(ia, addrPrefixLen);
-                            linkProperties.addLinkAddress(la);
-                        }
-                    } else {
-                        EventLogTags.writeBadIpAddress("no address for ifname=" + response.ifname);
-                        throw new UnknownHostException("no address for ifname=" + response.ifname);
-                    }
-                    if (response.dnses != null && response.dnses.length > 0) {
-                        for (String addr : response.dnses) {
-                            InetAddress ia;
-                            try {
-                                ia = NetworkUtils.numericToInetAddress(addr);
-                            } catch (IllegalArgumentException e) {
-                                EventLogTags.writePdpBadDnsAddress("dns=" + addr); 
-                                throw new UnknownHostException("Non-numeric dns addr=" + addr);
-                            }
-                            linkProperties.addDns(ia);
-                        }
-                        result = SetupResult.SUCCESS;
-                    } else {
-                        String dnsServers[] = new String[2];
-                        dnsServers[0] = SystemProperties.get(propertyPrefix + "dns1");
-                        dnsServers[1] = SystemProperties.get(propertyPrefix + "dns2");
-                        if (isDnsOk(dnsServers)) {
-                            for (String dnsAddr : dnsServers) {
-                                InetAddress ia;
-                                try {
-                                    ia = NetworkUtils.numericToInetAddress(dnsAddr);
-                                } catch (IllegalArgumentException e) {
-                                    EventLogTags.writePdpBadDnsAddress("dnsAddr=" + dnsAddr);
-                                    throw new UnknownHostException("Non-numeric dns addr="
-                                                + dnsAddr);
-                                }
-                                linkProperties.addDns(ia);
-                            }
-                            result = SetupResult.SUCCESS;
-                        } else {
-                            StringBuilder sb = new StringBuilder();
-                            for (String dnsAddr : dnsServers) {
-                                sb.append(dnsAddr);
-                                sb.append(" ");
-                            }
-                            EventLogTags.writePdpBadDnsAddress("Unacceptable dns addresses=" + sb);
-                            throw new UnknownHostException("Unacceptable dns addresses=" + sb);
-                        }
-                    }
-                    if ((response.gateways == null) || (response.gateways.length == 0)) {
-                        String gateways = SystemProperties.get(propertyPrefix + "gw");
-                        if (gateways != null) {
-                            response.gateways = gateways.split(" ");
-                        } else {
-                            response.gateways = new String[0];
-                        }
-                    }
-                    for (String addr : response.gateways) {
-                        InetAddress ia;
-                        try {
-                            ia = NetworkUtils.numericToInetAddress(addr);
-                        } catch (IllegalArgumentException e) {
-                            EventLogTags.writePdpBadDnsAddress("gateway=" + addr);
-                            throw new UnknownHostException("Non-numeric gateway addr=" + addr);
-                        }
-                        linkProperties.addGateway(ia);
-                    }
-                    result = SetupResult.SUCCESS;
-                } catch (UnknownHostException e) {
-                    log("onSetupCompleted: UnknownHostException " + e);
-                    e.printStackTrace();
-                    result = SetupResult.ERR_UnacceptableParameter;
-                }
-            } else {
-                if (response.version < 4) {
-                    result = SetupResult.ERR_GetLastErrorFromRil;
-                } else {
-                    result = SetupResult.ERR_RilError;
-                }
-            }
-
-            // An error occurred so clear properties
-            if (result != SetupResult.SUCCESS) {
-                log("onSetupConnectionCompleted with an error, clearing LinkProperties");
-                linkProperties.clear();
-            }
-            mLinkProperties = linkProperties;
+            // set link properties based on data call response
+            result = response.setLinkProperties(mLinkProperties,
+                    okToUseSystemPropertyDns);
         }
 
-        if (DBG) {
-            log("onSetupConnectionCompleted: DataConnection setup result='"
-                    + result + "' on cid=" + cid);
-            if (result == SetupResult.SUCCESS) {
-                log("onSetupConnectionCompleted: LinkProperties: " + mLinkProperties.toString());
-            }
-        }
         return result;
     }
 
@@ -609,6 +485,14 @@
      */
     private class DcDefaultState extends HierarchicalState {
         @Override
+        protected void enter() {
+            phone.mCM.registerForRilConnected(getHandler(), EVENT_RIL_CONNECTED, null);
+        }
+        @Override
+        protected void exit() {
+            phone.mCM.unregisterForRilConnected(getHandler());
+        }
+        @Override
         protected boolean processMessage(Message msg) {
             AsyncResult ar;
 
@@ -633,6 +517,20 @@
                     notifyDisconnectCompleted((DisconnectParams) msg.obj);
                     break;
 
+                case EVENT_RIL_CONNECTED:
+                    ar = (AsyncResult)msg.obj;
+                    if (ar.exception == null) {
+                        mRilVersion = (Integer)ar.result;
+                        if (DBG) {
+                            log("DcDefaultState: msg.what=EVENT_RIL_CONNECTED mRilVersion=" +
+                                mRilVersion);
+                        }
+                    } else {
+                        log("Unexpected exception on EVENT_RIL_CONNECTED");
+                        mRilVersion = -1;
+                    }
+                    break;
+
                 default:
                     if (DBG) {
                         log("DcDefaultState: shouldn't happen but ignore msg.what=" + msg.what);
@@ -746,7 +644,7 @@
                     ar = (AsyncResult) msg.obj;
                     cp = (ConnectionParams) ar.userObj;
 
-                    SetupResult result = onSetupConnectionCompleted(ar);
+                    DataCallState.SetupResult result = onSetupConnectionCompleted(ar);
                     if (DBG) log("DcActivatingState onSetupConnectionCompleted result=" + result);
                     switch (result) {
                         case SUCCESS:
@@ -780,7 +678,7 @@
                             // Request is stale, ignore.
                             break;
                         default:
-                            throw new RuntimeException("Unkown SetupResult, should not happen");
+                            throw new RuntimeException("Unknown SetupResult, should not happen");
                     }
                     retVal = true;
                     break;
@@ -1097,4 +995,8 @@
     public ApnSetting getApn() {
         return mApn;
     }
+
+    public int getCid() {
+        return cid;
+    }
 }
diff --git a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
index fba73fb5..d5b65e1 100644
--- a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
@@ -28,6 +28,7 @@
 import android.net.NetworkInfo;
 import android.net.wifi.WifiManager;
 import android.os.AsyncResult;
+import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
 import android.os.Messenger;
@@ -122,6 +123,7 @@
     protected static final int EVENT_RESET_DONE = 38;
     public static final int CMD_SET_DATA_ENABLE = 39;
     public static final int EVENT_CLEAN_UP_ALL_CONNECTIONS = 40;
+    public static final int CMD_SET_DEPENDENCY_MET = 41;
 
     /***** Constants *****/
 
@@ -139,6 +141,8 @@
     public static final int DISABLED = 0;
     public static final int ENABLED = 1;
 
+    public static final String APN_TYPE_KEY = "apnType";
+
     // responds to the setInternalDataEnabled call - used internally to turn off data
     // for example during emergency calls
     protected boolean mInternalDataEnabled = true;
@@ -541,6 +545,19 @@
                 break;
             }
 
+            case CMD_SET_DEPENDENCY_MET: {
+                log("CMD_SET_DEPENDENCY_MET msg=" + msg);
+                boolean met = (msg.arg1 == ENABLED) ? true : false;
+                Bundle bundle = msg.getData();
+                if (bundle != null) {
+                    String apnType = (String)bundle.get(APN_TYPE_KEY);
+                    if (apnType != null) {
+                        onSetDependencyMet(apnType, met);
+                    }
+                }
+                break;
+            }
+
             default:
                 Log.e("DATA", "Unidentified event = " + msg.what);
                 break;
@@ -810,7 +827,7 @@
         }
     }
 
-    private void setEnabled(int id, boolean enable) {
+    protected void setEnabled(int id, boolean enable) {
         if (DBG) {
             log("setEnabled(" + id + ", " + enable + ") with old state = " + dataEnabled[id]
                     + " and enabledCount = " + enabledCount);
@@ -821,7 +838,7 @@
         sendMessage(msg);
     }
 
-    protected synchronized void onEnableApn(int apnId, int enabled) {
+    protected void onEnableApn(int apnId, int enabled) {
         if (DBG) {
             log("EVENT_APN_ENABLE_REQUEST apnId=" + apnId + ", apnType=" + apnIdToType(apnId) +
                     ", enabled=" + enabled + ", dataEnabled = " + dataEnabled[apnId] +
@@ -829,9 +846,11 @@
                     isApnTypeActive(apnIdToType(apnId)));
         }
         if (enabled == ENABLED) {
-            if (!dataEnabled[apnId]) {
-                dataEnabled[apnId] = true;
-                enabledCount++;
+            synchronized (this) {
+                if (!dataEnabled[apnId]) {
+                    dataEnabled[apnId] = true;
+                    enabledCount++;
+                }
             }
             String type = apnIdToType(apnId);
             if (!isApnTypeActive(type)) {
@@ -842,12 +861,16 @@
             }
         } else {
             // disable
-            if (dataEnabled[apnId]) {
-                dataEnabled[apnId] = false;
-                enabledCount--;
-                if (enabledCount == 0) {
-                    onCleanUpConnection(true, apnId, Phone.REASON_DATA_DISABLED);
+            boolean didDisable = false;
+            synchronized (this) {
+                if (dataEnabled[apnId]) {
+                    dataEnabled[apnId] = false;
+                    enabledCount--;
+                    didDisable = true;
                 }
+            }
+            if (didDisable && enabledCount == 0) {
+                onCleanUpConnection(true, apnId, Phone.REASON_DATA_DISABLED);
 
                 // send the disconnect msg manually, since the normal route wont send
                 // it (it's not enabled)
@@ -961,6 +984,10 @@
         }
     }
 
+    protected void onSetDependencyMet(String apnType, boolean met) {
+    }
+
+
     protected void resetAllRetryCounts() {
         for (DataConnection dc : mDataConnections.values()) {
             dc.resetRetryCount();
diff --git a/telephony/java/com/android/internal/telephony/Phone.java b/telephony/java/com/android/internal/telephony/Phone.java
index 7450047..9f16d31 100644
--- a/telephony/java/com/android/internal/telephony/Phone.java
+++ b/telephony/java/com/android/internal/telephony/Phone.java
@@ -175,6 +175,8 @@
     static final String REASON_PS_RESTRICT_DISABLED = "psRestrictDisabled";
     static final String REASON_SIM_LOADED = "simLoaded";
     static final String REASON_NW_TYPE_CHANGED = "nwTypeChanged";
+    static final String REASON_DATA_DEPENDENCY_MET = "dependencyMet";
+    static final String REASON_DATA_DEPENDENCY_UNMET = "dependencyUnmet";
 
     // Used for band mode selection methods
     static final int BM_UNSPECIFIED = 0; // selected by baseband automatically
diff --git a/telephony/java/com/android/internal/telephony/RIL.java b/telephony/java/com/android/internal/telephony/RIL.java
index 1d47405..2633ca6 100644
--- a/telephony/java/com/android/internal/telephony/RIL.java
+++ b/telephony/java/com/android/internal/telephony/RIL.java
@@ -605,6 +605,9 @@
             }} catch (Throwable tr) {
                 Log.e(LOG_TAG,"Uncaught exception", tr);
             }
+
+            /* We're disconnected so we don't know the ril version */
+            notifyRegistrantsRilConnectionChanged(-1);
         }
     }
 
@@ -2468,6 +2471,7 @@
             case RIL_UNSOL_CDMA_SUBSCRIPTION_CHANGED: ret = responseInts(p); break;
             case RIL_UNSOl_CDMA_PRL_CHANGED: ret = responseInts(p); break;
             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
+            case RIL_UNSOL_RIL_CONNECTED: ret = responseInts(p); break;
 
             default:
                 throw new RuntimeException("Unrecognized unsol response: " + response);
@@ -2798,6 +2802,25 @@
                                         new AsyncResult (null, null, null));
                 }
                 break;
+
+            case RIL_UNSOL_RIL_CONNECTED: {
+                if (RILJ_LOGD) unsljLogRet(response, ret);
+                notifyRegistrantsRilConnectionChanged(((int[])ret)[0]);
+                break;
+            }
+        }
+    }
+
+    /**
+     * Notifiy all registrants that the ril has connected or disconnected.
+     *
+     * @param rilVer is the version of the ril or -1 if disconnected.
+     */
+    private void notifyRegistrantsRilConnectionChanged(int rilVer) {
+        mRilVersion = rilVer;
+        if (mRilConnectedRegistrants != null) {
+            mRilConnectedRegistrants.notifyRegistrants(
+                                new AsyncResult (null, new Integer(rilVer), null));
         }
     }
 
@@ -3535,6 +3558,7 @@
             case RIL_UNSOL_CDMA_SUBSCRIPTION_CHANGED: return "CDMA_SUBSCRIPTION_CHANGED";
             case RIL_UNSOl_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
+            case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
             default: return "<unknown reponse>";
         }
     }
@@ -3634,12 +3658,12 @@
     /**
      * {@inheritDoc}
      */
-    public void getCdmaSubscriptionSource(int cdmaSubscription , Message response) {
+    @Override
+    public void getCdmaSubscriptionSource(Message response) {
         RILRequest rr = RILRequest.obtain(
                 RILConstants.RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE, response);
 
-        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
-                + " : " + cdmaSubscription);
+        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
 
         send(rr);
     }
diff --git a/telephony/java/com/android/internal/telephony/RILConstants.java b/telephony/java/com/android/internal/telephony/RILConstants.java
index 4faf297..73dfdc0 100644
--- a/telephony/java/com/android/internal/telephony/RILConstants.java
+++ b/telephony/java/com/android/internal/telephony/RILConstants.java
@@ -289,4 +289,5 @@
     int RIL_UNSOL_CDMA_SUBSCRIPTION_CHANGED = 1031;
     int RIL_UNSOl_CDMA_PRL_CHANGED = 1032;
     int RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE = 1033;
+    int RIL_UNSOL_RIL_CONNECTED = 1034;
 }
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnection.java b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnection.java
index cccc053..124c888 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnection.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnection.java
@@ -84,7 +84,7 @@
         Message msg = obtainMessage(EVENT_SETUP_DATA_CONNECTION_DONE, cp);
         msg.obj = cp;
         phone.mCM.setupDataCall(
-                Integer.toString(RILConstants.SETUP_DATA_TECH_CDMA),
+                Integer.toString(getRadioTechnology(RILConstants.SETUP_DATA_TECH_CDMA)),
                 Integer.toString(dataProfile),
                 null, null, null,
                 Integer.toString(RILConstants.SETUP_DATA_AUTH_PAP_CHAP),
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java
index b0b2ac5..f4672d1 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java
@@ -102,7 +102,7 @@
         }
 
         phone.mCM.setupDataCall(
-                Integer.toString(RILConstants.SETUP_DATA_TECH_GSM),
+                Integer.toString(getRadioTechnology(RILConstants.SETUP_DATA_TECH_GSM)),
                 Integer.toString(mProfileId),
                 mApn.apn, mApn.user, mApn.password,
                 Integer.toString(authType),
@@ -117,11 +117,6 @@
         return mProfileId;
     }
 
-    public int getCid() {
-        // 'cid' has been defined in parent class
-        return cid;
-    }
-
     public void setActiveApnType(String apnType) {
         mActiveApnType = apnType;
     }
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
index 891a237..b5dadf6 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
@@ -25,11 +25,13 @@
 import android.content.SharedPreferences;
 import android.database.ContentObserver;
 import android.database.Cursor;
+import android.net.ConnectivityManager;
 import android.net.ProxyProperties;
 import android.net.TrafficStats;
 import android.net.Uri;
 import android.net.LinkCapabilities;
 import android.net.LinkProperties;
+import android.net.NetworkConfig;
 import android.os.AsyncResult;
 import android.os.Message;
 import android.os.SystemClock;
@@ -164,9 +166,8 @@
         p.getContext().getContentResolver().registerContentObserver(
                 Telephony.Carriers.CONTENT_URI, true, mApnObserver);
 
-        /** Create the default connection */
         mApnContexts = new ConcurrentHashMap<String, ApnContext>();
-        initApncontextsAndDataConnection();
+        initApnContextsAndDataConnection();
         broadcastMessenger();
     }
 
@@ -206,6 +207,7 @@
      * because the phone is out of coverage or some like reason.</li>
      * </ul>
      * @return {@code true} if data connectivity is possible, {@code false} otherwise.
+     * TODO - do per-apn notifications of availability using dependencyMet values.
      */
     @Override
     protected boolean isDataPossible() {
@@ -227,14 +229,57 @@
         return INTENT_RECONNECT_ALARM;
     }
 
-    protected void initApncontextsAndDataConnection() {
+    private ApnContext addApnContext(String type) {
+        ApnContext apnContext = new ApnContext(type, LOG_TAG);
+        apnContext.setDependencyMet(false);
+        mApnContexts.put(type, apnContext);
+        return apnContext;
+    }
+
+    protected void initApnContextsAndDataConnection() {
         SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
         boolean defaultEnabled = !sp.getBoolean(PhoneBase.DATA_DISABLED_ON_BOOT_KEY, false);
-        // create default type context only if enabled
-        if (defaultEnabled) {
-            ApnContext apnContext = new ApnContext(Phone.APN_TYPE_DEFAULT, LOG_TAG);
-            mApnContexts.put(apnContext.getApnType(), apnContext);
-            createDataConnection(Phone.APN_TYPE_DEFAULT);
+        // Load device network attributes from resources
+        String[] networkConfigStrings = mPhone.getContext().getResources().getStringArray(
+                com.android.internal.R.array.networkAttributes);
+        for (String networkConfigString : networkConfigStrings) {
+            NetworkConfig networkConfig = new NetworkConfig(networkConfigString);
+            ApnContext apnContext = null;
+
+            switch (networkConfig.type) {
+            case ConnectivityManager.TYPE_MOBILE:
+                apnContext = addApnContext(Phone.APN_TYPE_DEFAULT);
+                apnContext.setEnabled(defaultEnabled);
+                break;
+            case ConnectivityManager.TYPE_MOBILE_MMS:
+                apnContext = addApnContext(Phone.APN_TYPE_MMS);
+                break;
+            case ConnectivityManager.TYPE_MOBILE_SUPL:
+                apnContext = addApnContext(Phone.APN_TYPE_SUPL);
+                break;
+            case ConnectivityManager.TYPE_MOBILE_DUN:
+                apnContext = addApnContext(Phone.APN_TYPE_DUN);
+                break;
+            case ConnectivityManager.TYPE_MOBILE_HIPRI:
+                apnContext = addApnContext(Phone.APN_TYPE_HIPRI);
+                break;
+            case ConnectivityManager.TYPE_MOBILE_FOTA:
+                apnContext = addApnContext(Phone.APN_TYPE_FOTA);
+                break;
+            case ConnectivityManager.TYPE_MOBILE_IMS:
+                apnContext = addApnContext(Phone.APN_TYPE_IMS);
+                break;
+            case ConnectivityManager.TYPE_MOBILE_CBS:
+                apnContext = addApnContext(Phone.APN_TYPE_CBS);
+                break;
+            default:
+                // skip unknown types
+                continue;
+            }
+            if (apnContext != null) {
+                // set the prop, but also apply the newly set enabled and dependency values
+                onSetDependencyMet(apnContext.getApnType(), networkConfig.dependencyMet);
+            }
         }
     }
 
@@ -271,7 +316,9 @@
         Iterator<ApnContext> it = mApnContexts.values().iterator();
         while (it.hasNext()) {
             ApnContext apnContext = it.next();
+            if (apnContext.isReady()) {
                 result.add(apnContext.getApnType());
+            }
         }
 
         return (String[])result.toArray(new String[0]);
@@ -353,24 +400,12 @@
     public synchronized int enableApnType(String apnType) {
         if (DBG) log("calling enableApnType with type:" + apnType);
 
-        if (!isApnTypeAvailable(apnType)) {
+        ApnContext apnContext = mApnContexts.get(apnType);
+        if (apnContext == null || !isApnTypeAvailable(apnType)) {
             if (DBG) log("type not available");
             return Phone.APN_TYPE_NOT_AVAILABLE;
         }
 
-        ApnContext apnContext = mApnContexts.get(apnType);
-        if (apnContext==null) {
-            // Is there a Proxy type for this?
-            apnContext = getProxyActiveApnType(apnType);
-            if (apnContext != null ) {
-                notifyApnIdUpToCurrent(Phone.REASON_APN_SWITCHED, apnContext, apnType);
-                return Phone.APN_REQUEST_STARTED;
-            }
-            apnContext = new ApnContext(apnType, LOG_TAG);
-            if (DBG) log("New apn type context for type "+apnType);
-            mApnContexts.put(apnType, apnContext);
-        }
-
         // If already active, return
         log("enableApnType(" + apnType + ")" + ", mState(" + apnContext.getState() + ")");
 
@@ -389,24 +424,11 @@
         }
 
         if (DBG) log("new apn request for type " + apnType + " is to be handled");
-        sendMessage(obtainMessage(EVENT_ENABLE_NEW_APN, apnContext));
+        setEnabled(apnTypeToId(apnType), true);
         if (DBG) log("return APN_REQUEST_STARTED");
         return Phone.APN_REQUEST_STARTED;
     }
 
-    // Returns for ex: if HIGHPRI is supported by DEFAULT
-    public ApnContext getProxyActiveApnType(String type) {
-
-        Iterator<ApnContext> it = mApnContexts.values().iterator();
-
-        while(it.hasNext()) {
-            ApnContext apnContext = it.next();
-            if (apnContext.getApnSetting() != null && mActiveApn.canHandleType(type))
-            return apnContext;
-        }
-        return null;
-    }
-
     // A new APN has gone active and needs to send events to catch up with the
     // current condition
     private void notifyApnIdUpToCurrent(String reason, ApnContext apnContext, String type) {
@@ -437,6 +459,8 @@
             if (apnContext.getState() != State.IDLE && apnContext.getState() != State.FAILED) {
                 Message msg = obtainMessage(EVENT_CLEAN_UP_CONNECTION);
                 msg.arg1 = 1; // tearDown is true;
+                // TODO - don't set things on apnContext from public functions.
+                // Maybe pass reason as arg2?
                 apnContext.setReason(Phone.REASON_DATA_DISABLED);
                 msg.obj = apnContext;
                 sendMessage(msg);
@@ -487,16 +511,11 @@
      */
     @Override
     public synchronized boolean getAnyDataEnabled() {
-        Iterator<ApnContext> it = mApnContexts.values().iterator();
-
         if (!(mInternalDataEnabled && mDataEnabled)) return false;
-        if (mApnContexts.isEmpty()) return false;
-        while (it.hasNext()) {
-            ApnContext apnContext= it.next();
+        for (ApnContext apnContext : mApnContexts.values()) {
             // Make sure we dont have a context that going down
             // and is explicitly disabled.
-            if (!(apnContext.getState() == State.DISCONNECTING
-                    && apnContext.getPendingAction() == ApnContext.PENDING_ACTION_APN_DISABLE)) {
+            if (isDataAllowed(apnContext)) {
                 return true;
             }
         }
@@ -508,7 +527,7 @@
                 && apnContext.getPendingAction() == ApnContext.PENDING_ACTION_APN_DISABLE) {
             return false;
         }
-        return isDataAllowed();
+        return apnContext.isReady() && isDataAllowed();
     }
 
     //****** Called from ServiceStateTracker
@@ -532,11 +551,13 @@
         } else {
             // Only check for default APN state
             ApnContext defaultApnContext = mApnContexts.get(Phone.APN_TYPE_DEFAULT);
-            if (defaultApnContext.getState() == State.FAILED) {
-                cleanUpConnection(false, defaultApnContext);
-                defaultApnContext.getDataConnection().resetRetryCount();
+            if (defaultApnContext != null) {
+                if (defaultApnContext.getState() == State.FAILED) {
+                    cleanUpConnection(false, defaultApnContext);
+                    defaultApnContext.getDataConnection().resetRetryCount();
+                }
+                trySetupData(Phone.REASON_GPRS_ATTACHED, Phone.APN_TYPE_DEFAULT);
             }
-            trySetupData(Phone.REASON_GPRS_ATTACHED, Phone.APN_TYPE_DEFAULT);
         }
     }
 
@@ -599,10 +620,11 @@
 
     private boolean trySetupData(ApnContext apnContext) {
 
-        if (DBG)
+        if (DBG) {
             log("trySetupData for type:" + apnContext.getApnType() +
-                " due to " + apnContext.getReason());
-        log("[DSAC DEB] " + "trySetupData with mIsPsRestricted=" + mIsPsRestricted);
+                    " due to " + apnContext.getReason());
+            log("[DSAC DEB] " + "trySetupData with mIsPsRestricted=" + mIsPsRestricted);
+        }
 
         if (mPhone.getSimulatedRadioControl() != null) {
             // Assume data is connected on the simulator
@@ -656,12 +678,8 @@
         if (mAvailability == availability) return;
         mAvailability = availability;
 
-        Iterator<ApnContext> it = mApnContexts.values().iterator();
-        while (it.hasNext()) {
-            ApnContext apnContext = it.next();
-            // FIXME: Dont understand why this needs to be done!!
-            // This information is not available (DISABLED APNS)
-            if (false) {
+        for (ApnContext apnContext : mApnContexts.values()) {
+            if (!apnContext.isReady()) {
                 if (DBG) log("notify disconnected for type:" + apnContext.getApnType());
                 mPhone.notifyDataConnection(reason != null ? reason : apnContext.getReason(),
                                             apnContext.getApnType(),
@@ -738,10 +756,10 @@
             return;
         }
 
-        GsmDataConnection conn = apnContext.getDataConnection();
+        DataConnection conn = apnContext.getDataConnection();
         if (conn != null) {
             apnContext.setState(State.DISCONNECTING);
-            if (tearDown ) {
+            if (tearDown) {
                 Message msg = obtainMessage(EVENT_DISCONNECT_DONE, apnContext);
                 conn.disconnect(apnContext.getReason(), msg);
             } else {
@@ -750,10 +768,6 @@
                 mPhone.notifyDataConnection(apnContext.getReason(), apnContext.getApnType());
             }
         }
-
-        if (apnContext.getPendingAction() == ApnContext.PENDING_ACTION_APN_DISABLE) {
-           mApnContexts.remove(apnContext.getApnType());
-        }
     }
 
 
@@ -853,6 +867,10 @@
         }
 
         if (dc == null) {
+            dc = createDataConnection(apnContext);
+        }
+
+        if (dc == null) {
             if (DBG) log("setupData: No free GsmDataConnection found!");
             return false;
         }
@@ -1272,42 +1290,98 @@
 
     private void onRecordsLoaded() {
         createAllApnList();
-        ApnContext defaultApnContext = mApnContexts.get(Phone.APN_TYPE_DEFAULT);
-        if (defaultApnContext!=null ) {
-            defaultApnContext.setReason(Phone.REASON_SIM_LOADED);
-            if (defaultApnContext.getState() == State.FAILED) {
-                if (DBG) log("onRecordsLoaded clean connection");
-                cleanUpConnection(false, defaultApnContext);
+        for (ApnContext apnContext : mApnContexts.values()) {
+            if (apnContext.isReady()) {
+                apnContext.setReason(Phone.REASON_SIM_LOADED);
+                if (apnContext.getState() == State.FAILED) {
+                    if (DBG) {
+                        log("onRecordsLoaded clean connection for " + apnContext.getApnType());
+                    }
+                    cleanUpConnection(false, apnContext);
+                }
+                sendMessage(obtainMessage(EVENT_TRY_SETUP_DATA, apnContext));
             }
-            sendMessage(obtainMessage(EVENT_TRY_SETUP_DATA,defaultApnContext ));
         }
     }
 
-    protected void onEnableNewApn(ApnContext apnContext ) {
-        // change our retry manager to use the appropriate numbers for the new APN
-        log("onEnableNewApn with ApnContext E");
-        if (apnContext.getApnType().equals(Phone.APN_TYPE_DEFAULT)) {
-            log("onEnableNewApn default type");
-            ApnContext defaultApnContext = mApnContexts.get(Phone.APN_TYPE_DEFAULT);
-            defaultApnContext.getDataConnection().resetRetryCount();
-        } else if (mApnToDataConnectionId.get(apnContext.getApnType()) == null) {
-            log("onEnableNewApn ApnType=" + apnContext.getApnType() +
-                    " missing, make a new connection");
-            int id = createDataConnection(apnContext.getApnType());
-            mDataConnections.get(id).resetRetryCount();
-        } else {
-            log("oneEnableNewApn connection already exists, nothing to setup");
+    @Override
+    protected void onSetDependencyMet(String apnType, boolean met) {
+        ApnContext apnContext = mApnContexts.get(apnType);
+        if (apnContext == null) {
+            log("ApnContext not found in onSetDependencyMet(" + apnType + ", " + met + ")");
+            return;
         }
+        applyNewState(apnContext, apnContext.isEnabled(), met);
+    }
 
-        // TODO:  To support simultaneous PDP contexts, this should really only call
-        // cleanUpConnection if it needs to free up a GsmDataConnection.
-        if (DBG) log("onEnableNewApn setup data");
-        if (apnContext.getState() == State.FAILED) {
-            if (DBG) log("previous state is FAILED, reset to IDLE");
-            apnContext.setState(State.IDLE);
+    private void applyNewState(ApnContext apnContext, boolean enabled, boolean met) {
+        boolean cleanup = false;
+        boolean trySetup = false;
+        if (DBG) {
+            log("applyNewState(" + apnContext.getApnType() + ", " + enabled +
+                    "(" + apnContext.isEnabled() + "), " + met + "(" +
+                    apnContext.getDependencyMet() +"))");
         }
-        trySetupData(apnContext);
-        log("onEnableNewApn with ApnContext X");
+        if (apnContext.isReady()) {
+            if (enabled && met) return;
+            if (!enabled) {
+                apnContext.setReason(Phone.REASON_DATA_DISABLED);
+            } else {
+                apnContext.setReason(Phone.REASON_DATA_DEPENDENCY_UNMET);
+            }
+            cleanup = true;
+        } else {
+            if (enabled && met) {
+                if (apnContext.isEnabled()) {
+                    apnContext.setReason(Phone.REASON_DATA_DEPENDENCY_MET);
+                } else {
+                    apnContext.setReason(Phone.REASON_DATA_ENABLED);
+                }
+                DataConnection conn = checkForConnectionForApnContext(apnContext);
+                if (conn == null) {
+                    if (apnContext.getState() == State.FAILED) {
+                        apnContext.setState(State.IDLE);
+                    }
+                    trySetup = true;
+                } else {
+                    // TODO send notifications
+                    if (DBG) {
+                        log("Found existing connection for " + apnContext.getApnType() +
+                                ": " + conn);
+                    }
+                    apnContext.setDataConnection(conn);
+                }
+            }
+        }
+        apnContext.setEnabled(enabled);
+        apnContext.setDependencyMet(met);
+        if (cleanup) cleanUpConnection(true, apnContext);
+        if (trySetup) trySetupData(apnContext);
+    }
+
+    private DataConnection checkForConnectionForApnContext(ApnContext apnContext) {
+        // Loop through all apnContexts looking for one with a conn that satisfies this apnType
+        String apnType = apnContext.getApnType();
+        for (ApnContext c : mApnContexts.values()) {
+            DataConnection conn = c.getDataConnection();
+            if (conn != null) {
+                ApnSetting apnSetting = c.getApnSetting();
+                if (apnSetting != null && apnSetting.canHandleType(apnType)) return conn;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    protected void onEnableApn(int apnId, int enabled) {
+        ApnContext apnContext = mApnContexts.get(apnIdToType(apnId));
+        if (apnContext == null) {
+            log("ApnContext not found in onEnableApn(" + apnId + ", " + enabled + ")");
+            return;
+        }
+        // TODO change our retry manager to use the appropriate numbers for the new APN
+        log("onEnableApn with ApnContext E");
+        applyNewState(apnContext, enabled == ENABLED, apnContext.getDependencyMet());
     }
 
     @Override
@@ -1392,7 +1466,7 @@
             mLinkProperties = getLinkProperties(apnContext.getDataConnection());
             mLinkCapabilities = getLinkCapabilities(apnContext.getDataConnection());
 
-            ApnSetting apn = apnContext.getDataConnection().getApn();
+            ApnSetting apn = apnContext.getApnSetting();
             if (apn.proxy != null && apn.proxy.length() != 0) {
                 try {
                     ProxyProperties proxy = new ProxyProperties(apn.proxy,
@@ -1508,8 +1582,8 @@
 
         // Check if APN disabled.
         if (apnContext.getPendingAction() == ApnContext.PENDING_ACTION_APN_DISABLE) {
-           mApnContexts.remove(apnContext.getApnType());
-           return;
+           apnContext.setEnabled(false);
+           apnContext.setPendingAction(ApnContext.PENDING_ACTION_NONE);
         }
 
         if (TextUtils.equals(apnContext.getApnType(), Phone.APN_TYPE_DEFAULT)
@@ -1553,10 +1627,12 @@
         } else {
             // reset reconnect timer
             ApnContext defaultApnContext = mApnContexts.get(Phone.APN_TYPE_DEFAULT);
-            defaultApnContext.getDataConnection().resetRetryCount();
-            mReregisterOnReconnectFailure = false;
-            // in case data setup was attempted when we were on a voice call
-            trySetupData(Phone.REASON_VOICE_CALL_ENDED, Phone.APN_TYPE_DEFAULT);
+            if (defaultApnContext != null) {
+                defaultApnContext.getDataConnection().resetRetryCount();
+                mReregisterOnReconnectFailure = false;
+                // in case data setup was attempted when we were on a voice call
+                trySetupData(Phone.REASON_VOICE_CALL_ENDED, Phone.APN_TYPE_DEFAULT);
+            }
         }
     }
 
@@ -1584,9 +1660,11 @@
         Iterator<ApnContext> it = mApnContexts.values().iterator();
         while (it.hasNext()) {
             ApnContext apnContext = it.next();
-            if (DBG) log("notify for type:"+apnContext.getApnType());
-            mPhone.notifyDataConnection(reason != null ? reason : apnContext.getReason(),
-                    apnContext.getApnType());
+            if (apnContext.isReady()) {
+                if (DBG) log("notify for type:"+apnContext.getApnType());
+                mPhone.notifyDataConnection(reason != null ? reason : apnContext.getReason(),
+                        apnContext.getApnType());
+            }
         }
         notifyDataAvailability(reason);
     }
@@ -1598,7 +1676,6 @@
     private void createAllApnList() {
         mAllApns = new ArrayList<ApnSetting>();
         String operator = mPhone.mSIMRecords.getSIMOperatorNumeric();
-
         if (operator != null) {
             String selection = "numeric = '" + operator + "'";
             if (DBG) log("createAllApnList: selection=" + selection);
@@ -1631,7 +1708,8 @@
     }
 
     /** Return the id for a new data connection */
-    private int createDataConnection(String apnType) {
+    private GsmDataConnection createDataConnection(ApnContext apnContext) {
+        String apnType = apnContext.getApnType();
         log("createDataConnection(" + apnType + ") E");
         RetryManager rm = new RetryManager();
 
@@ -1656,12 +1734,13 @@
         }
 
         int id = mUniqueIdGenerator.getAndIncrement();
-        DataConnection conn = GsmDataConnection.makeDataConnection(mPhone, id, rm);
+        GsmDataConnection conn = GsmDataConnection.makeDataConnection(mPhone, id, rm);
+        conn.resetRetryCount();
         mDataConnections.put(id, conn);
-        mApnToDataConnectionId.put(apnType, id);
+        apnContext.setDataConnection(conn);
 
         log("createDataConnection(" + apnType + ") X id=" + id);
-        return id;
+        return conn;
     }
 
     private void destroyDataConnections() {
@@ -1691,7 +1770,6 @@
         }
 
         String operator = mPhone.mSIMRecords.getSIMOperatorNumeric();
-
         if (requestedApnType.equals(Phone.APN_TYPE_DEFAULT)) {
             if (canSetPreferApn && mPreferredApn != null) {
                 log("Preferred APN:" + operator + ":"
@@ -1707,13 +1785,14 @@
                 }
             }
         }
-
         if (mAllApns != null) {
             for (ApnSetting apn : mAllApns) {
                 if (apn.canHandleType(requestedApnType)) {
                     apnList.add(apn);
                 }
             }
+        } else {
+            loge("mAllApns is empty!");
         }
         if (DBG) log("buildWaitingApns: X apnList=" + apnList);
         return apnList;
@@ -1797,14 +1876,6 @@
                 onRecordsLoaded();
                 break;
 
-        case EVENT_ENABLE_NEW_APN:
-                ApnContext apnContext = null;
-                if (msg.obj instanceof ApnContext) {
-                    apnContext = (ApnContext)msg.obj;
-                }
-                onEnableNewApn(apnContext);
-                break;
-
             case EVENT_DATA_CONNECTION_DETACHED:
                 onDataConnectionDetached();
                 break;
@@ -1883,8 +1954,7 @@
                 if (msg.obj instanceof ApnContext) {
                     cleanUpConnection(tearDown, (ApnContext)msg.obj);
                 } else {
-                    Log.e(LOG_TAG,
-                          "[GsmDataConnectionTracker] connectpion cleanup request w/o apn context");
+                    loge("[GsmDataConnectionTracker] connectpion cleanup request w/o apn context");
                 }
                 break;
             default:
diff --git a/telephony/java/com/android/internal/telephony/sip/SipCommandInterface.java b/telephony/java/com/android/internal/telephony/sip/SipCommandInterface.java
index f2ece7f..5208ccd 100644
--- a/telephony/java/com/android/internal/telephony/sip/SipCommandInterface.java
+++ b/telephony/java/com/android/internal/telephony/sip/SipCommandInterface.java
@@ -326,6 +326,10 @@
     public void reportStkServiceIsRunning(Message result) {
     }
 
+    @Override
+    public void getCdmaSubscriptionSource(Message response) {
+    }
+
     public void getGsmBroadcastConfig(Message response) {
     }
 
diff --git a/telephony/java/com/android/internal/telephony/test/SimulatedCommands.java b/telephony/java/com/android/internal/telephony/test/SimulatedCommands.java
index d9bd7e8..80de9f3 100644
--- a/telephony/java/com/android/internal/telephony/test/SimulatedCommands.java
+++ b/telephony/java/com/android/internal/telephony/test/SimulatedCommands.java
@@ -1001,6 +1001,11 @@
         resultSuccess(result, null);
     }
 
+    @Override
+    public void getCdmaSubscriptionSource(Message result) {
+        unimplemented(result);
+    }
+
     private boolean isSimLocked() {
         if (mSimLockedState != SimLockState.NONE) {
             return true;
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp
index 2b2ec7b..a2271d9 100644
--- a/tools/aapt/AaptAssets.cpp
+++ b/tools/aapt/AaptAssets.cpp
@@ -156,6 +156,20 @@
         return 0;
     }
 
+    // screen dp width
+    if (getScreenWidthDpName(part.string(), &config)) {
+        *axis = AXIS_SCREENWIDTHDP;
+        *value = config.screenWidthDp;
+        return 0;
+    }
+
+    // screen dp height
+    if (getScreenHeightDpName(part.string(), &config)) {
+        *axis = AXIS_SCREENHEIGHTDP;
+        *value = config.screenHeightDp;
+        return 0;
+    }
+
     // orientation
     if (getOrientationName(part.string(), &config)) {
         *axis = AXIS_ORIENTATION;
@@ -243,7 +257,7 @@
 
     String8 mcc, mnc, loc, layoutsize, layoutlong, orient, den;
     String8 touch, key, keysHidden, nav, navHidden, size, vers;
-    String8 uiModeType, uiModeNight;
+    String8 uiModeType, uiModeNight, widthdp, heightdp;
 
     const char *p = dir;
     const char *q;
@@ -354,6 +368,30 @@
         //printf("not screen layout long: %s\n", part.string());
     }
 
+    if (getScreenWidthDpName(part.string())) {
+        widthdp = part;
+
+        index++;
+        if (index == N) {
+            goto success;
+        }
+        part = parts[index];
+    } else {
+        //printf("not screen width dp: %s\n", part.string());
+    }
+
+    if (getScreenHeightDpName(part.string())) {
+        heightdp = part;
+
+        index++;
+        if (index == N) {
+            goto success;
+        }
+        part = parts[index];
+    } else {
+        //printf("not screen height dp: %s\n", part.string());
+    }
+
     // orientation
     if (getOrientationName(part.string())) {
         orient = part;
@@ -503,6 +541,8 @@
     this->locale = loc;
     this->screenLayoutSize = layoutsize;
     this->screenLayoutLong = layoutlong;
+    this->screenWidthDp = widthdp;
+    this->screenHeightDp = heightdp;
     this->orientation = orient;
     this->uiModeType = uiModeType;
     this->uiModeNight = uiModeNight;
@@ -534,6 +574,10 @@
     s += ",";
     s += screenLayoutLong;
     s += ",";
+    s += screenWidthDp;
+    s += ",";
+    s += screenHeightDp;
+    s += ",";
     s += this->orientation;
     s += ",";
     s += uiModeType;
@@ -582,6 +626,14 @@
         s += "-";
         s += screenLayoutLong;
     }
+    if (this->screenWidthDp != "") {
+        s += "-";
+        s += screenWidthDp;
+    }
+    if (this->screenHeightDp != "") {
+        s += "-";
+        s += screenHeightDp;
+    }
     if (this->orientation != "") {
         s += "-";
         s += orientation;
@@ -1039,8 +1091,7 @@
     return false;
 }
 
-bool AaptGroupEntry::getScreenSizeName(const char* name,
-                                       ResTable_config* out)
+bool AaptGroupEntry::getScreenSizeName(const char* name, ResTable_config* out)
 {
     if (strcmp(name, kWildcardName) == 0) {
         if (out) {
@@ -1075,8 +1126,53 @@
     return true;
 }
 
-bool AaptGroupEntry::getVersionName(const char* name,
-                                    ResTable_config* out)
+bool AaptGroupEntry::getScreenWidthDpName(const char* name, ResTable_config* out)
+{
+    if (strcmp(name, kWildcardName) == 0) {
+        if (out) {
+            out->screenWidthDp = out->SCREENWIDTH_ANY;
+        }
+        return true;
+    }
+
+    if (*name != 'w') return false;
+    name++;
+    const char* x = name;
+    while (*x >= '0' && *x <= '9') x++;
+    if (x == name || x[0] != 'd' || x[1] != 'p' || x[2] != 0) return false;
+    String8 xName(name, x-name);
+
+    if (out) {
+        out->screenWidthDp = (uint16_t)atoi(xName.string());
+    }
+
+    return true;
+}
+
+bool AaptGroupEntry::getScreenHeightDpName(const char* name, ResTable_config* out)
+{
+    if (strcmp(name, kWildcardName) == 0) {
+        if (out) {
+            out->screenHeightDp = out->SCREENWIDTH_ANY;
+        }
+        return true;
+    }
+
+    if (*name != 'h') return false;
+    name++;
+    const char* x = name;
+    while (*x >= '0' && *x <= '9') x++;
+    if (x == name || x[0] != 'd' || x[1] != 'p' || x[2] != 0) return false;
+    String8 xName(name, x-name);
+
+    if (out) {
+        out->screenHeightDp = (uint16_t)atoi(xName.string());
+    }
+
+    return true;
+}
+
+bool AaptGroupEntry::getVersionName(const char* name, ResTable_config* out)
 {
     if (strcmp(name, kWildcardName) == 0) {
         if (out) {
@@ -1112,6 +1208,8 @@
     if (v == 0) v = vendor.compare(o.vendor);
     if (v == 0) v = screenLayoutSize.compare(o.screenLayoutSize);
     if (v == 0) v = screenLayoutLong.compare(o.screenLayoutLong);
+    if (v == 0) v = screenWidthDp.compare(o.screenWidthDp);
+    if (v == 0) v = screenHeightDp.compare(o.screenHeightDp);
     if (v == 0) v = orientation.compare(o.orientation);
     if (v == 0) v = uiModeType.compare(o.uiModeType);
     if (v == 0) v = uiModeNight.compare(o.uiModeNight);
@@ -1135,6 +1233,8 @@
     getLocaleName(locale.string(), &params);
     getScreenLayoutSizeName(screenLayoutSize.string(), &params);
     getScreenLayoutLongName(screenLayoutLong.string(), &params);
+    getScreenWidthDpName(screenWidthDp.string(), &params);
+    getScreenHeightDpName(screenHeightDp.string(), &params);
     getOrientationName(orientation.string(), &params);
     getUiModeTypeName(uiModeType.string(), &params);
     getUiModeNightName(uiModeNight.string(), &params);
@@ -1149,7 +1249,10 @@
     
     // Fix up version number based on specified parameters.
     int minSdk = 0;
-    if ((params.uiMode&ResTable_config::MASK_UI_MODE_TYPE)
+    if (params.screenWidthDp != ResTable_config::SCREENWIDTH_ANY
+            || params.screenHeightDp != ResTable_config::SCREENHEIGHT_ANY) {
+        minSdk = SDK_ICS;
+    } else if ((params.uiMode&ResTable_config::MASK_UI_MODE_TYPE)
                 != ResTable_config::UI_MODE_TYPE_ANY
             ||  (params.uiMode&ResTable_config::MASK_UI_MODE_NIGHT)
                 != ResTable_config::UI_MODE_NIGHT_ANY) {
diff --git a/tools/aapt/AaptAssets.h b/tools/aapt/AaptAssets.h
index eeb00c0..e5afd1b 100644
--- a/tools/aapt/AaptAssets.h
+++ b/tools/aapt/AaptAssets.h
@@ -42,6 +42,8 @@
     AXIS_NAVHIDDEN,
     AXIS_NAVIGATION,
     AXIS_SCREENSIZE,
+    AXIS_SCREENWIDTHDP,
+    AXIS_SCREENHEIGHTDP,
     AXIS_VERSION
 };
 
@@ -52,6 +54,7 @@
     SDK_ECLAIR_0_1 = 6,
     SDK_MR1 = 7,
     SDK_FROYO = 8,
+    SDK_ICS = 13,
 };
 
 /**
@@ -71,6 +74,8 @@
     String8 vendor;
     String8 screenLayoutSize;
     String8 screenLayoutLong;
+    String8 screenWidthDp;
+    String8 screenHeightDp;
     String8 orientation;
     String8 uiModeType;
     String8 uiModeNight;
@@ -102,6 +107,8 @@
     static bool getNavigationName(const char* name, ResTable_config* out = NULL);
     static bool getNavHiddenName(const char* name, ResTable_config* out = NULL);
     static bool getScreenSizeName(const char* name, ResTable_config* out = NULL);
+    static bool getScreenWidthDpName(const char* name, ResTable_config* out = NULL);
+    static bool getScreenHeightDpName(const char* name, ResTable_config* out = NULL);
     static bool getVersionName(const char* name, ResTable_config* out = NULL);
 
     int compare(const AaptGroupEntry& o) const;
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp
index 10815a1..3dcc093 100644
--- a/tools/aapt/ResourceTable.cpp
+++ b/tools/aapt/ResourceTable.cpp
@@ -2607,6 +2607,12 @@
     if (!match(AXIS_SCREENSIZE, config.screenSize)) {
         return false;
     }
+    if (!match(AXIS_SCREENWIDTHDP, config.screenWidthDp)) {
+        return false;
+    }
+    if (!match(AXIS_SCREENHEIGHTDP, config.screenHeightDp)) {
+        return false;
+    }
     if (!match(AXIS_SCREENLAYOUTSIZE, config.screenLayout&ResTable_config::MASK_SCREENSIZE)) {
         return false;
     }
@@ -2803,7 +2809,7 @@
                 ConfigDescription config = t->getUniqueConfigs().itemAt(ci);
 
                 NOISY(printf("Writing config %d config: imsi:%d/%d lang:%c%c cnt:%c%c "
-                     "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d\n",
+                     "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d %ddp x %ddp\n",
                       ti+1,
                       config.mcc, config.mnc,
                       config.language[0] ? config.language[0] : '-',
@@ -2818,7 +2824,9 @@
                       config.inputFlags,
                       config.navigation,
                       config.screenWidth,
-                      config.screenHeight));
+                      config.screenHeight,
+                      config.screenWidthDp,
+                      config.screenHeightDp));
                       
                 if (filterable && !filter.match(config)) {
                     continue;
@@ -2841,7 +2849,7 @@
                 tHeader->entriesStart = htodl(typeSize);
                 tHeader->config = config;
                 NOISY(printf("Writing type %d config: imsi:%d/%d lang:%c%c cnt:%c%c "
-                     "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d\n",
+                     "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d %ddp x %ddp\n",
                       ti+1,
                       tHeader->config.mcc, tHeader->config.mnc,
                       tHeader->config.language[0] ? tHeader->config.language[0] : '-',
@@ -2856,7 +2864,9 @@
                       tHeader->config.inputFlags,
                       tHeader->config.navigation,
                       tHeader->config.screenWidth,
-                      tHeader->config.screenHeight));
+                      tHeader->config.screenHeight,
+                      tHeader->config.screenWidthDp,
+                      tHeader->config.screenHeightDp));
                 tHeader->config.swapHtoD();
 
                 // Build the entries inside of this type.
@@ -3438,7 +3448,7 @@
     if (e == NULL) {
         if (config != NULL) {
             NOISY(printf("New entry at %s:%d: imsi:%d/%d lang:%c%c cnt:%c%c "
-                    "orien:%d touch:%d density:%d key:%d inp:%d nav:%d w:%d h:%d\n",
+                    "orien:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d %ddp x %ddp\n",
                       sourcePos.file.string(), sourcePos.line,
                       config->mcc, config->mnc,
                       config->language[0] ? config->language[0] : '-',
@@ -3452,7 +3462,9 @@
                       config->inputFlags,
                       config->navigation,
                       config->screenWidth,
-                      config->screenHeight));
+                      config->screenHeight,
+                      config->screenWidthDp,
+                      config->screenHeightDp));
         } else {
             NOISY(printf("New entry at %s:%d: NULL config\n",
                       sourcePos.file.string(), sourcePos.line));
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index 2fd58e4..c5eaef9 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -372,8 +372,6 @@
             if (mViewRoot == null) {
                 return ERROR_NOT_INFLATED.createResult();
             }
-            // measure the views
-            int w_spec, h_spec;
 
             RenderingMode renderingMode = params.getRenderingMode();
 
@@ -385,38 +383,64 @@
                 mMeasuredScreenHeight = params.getScreenHeight();
 
                 if (renderingMode != RenderingMode.NORMAL) {
-                    // measure the full size needed by the layout.
-                    w_spec = MeasureSpec.makeMeasureSpec(mMeasuredScreenWidth,
-                            renderingMode.isHorizExpand() ?
-                                    MeasureSpec.UNSPECIFIED // this lets us know the actual needed size
-                                    : MeasureSpec.EXACTLY);
-                    h_spec = MeasureSpec.makeMeasureSpec(mMeasuredScreenHeight,
-                            renderingMode.isVertExpand() ?
-                                    MeasureSpec.UNSPECIFIED // this lets us know the actual needed size
-                                    : MeasureSpec.EXACTLY);
-                    mViewRoot.measure(w_spec, h_spec);
+                    int widthMeasureSpecMode = renderingMode.isHorizExpand() ?
+                            MeasureSpec.UNSPECIFIED // this lets us know the actual needed size
+                            : MeasureSpec.EXACTLY;
+                    int heightMeasureSpecMode = renderingMode.isVertExpand() ?
+                            MeasureSpec.UNSPECIFIED // this lets us know the actual needed size
+                            : MeasureSpec.EXACTLY;
 
+                    // We used to compare the measured size of the content to the screen size but
+                    // this does not work anymore due to the 2 following issues:
+                    // - If the content is in a decor (system bar, title/action bar), the root view
+                    //   will not resize even with the UNSPECIFIED because of the embedded layout.
+                    // - If there is no decor, but a dialog frame, then the dialog padding prevents
+                    //   comparing the size of the content to the screen frame (as it would not
+                    //   take into account the dialog padding).
+
+                    // The solution is to first get the content size in a normal rendering, inside
+                    // the decor or the dialog padding.
+                    // Then measure only the content with UNSPECIFIED to see the size difference
+                    // and apply this to the screen size.
+
+                    // first measure the full layout, with EXACTLY to get the size of the
+                    // content as it is inside the decor/dialog
+                    Pair<Integer, Integer> exactMeasure = measureView(
+                            mViewRoot, mContentRoot.getChildAt(0),
+                            mMeasuredScreenWidth, MeasureSpec.EXACTLY,
+                            mMeasuredScreenHeight, MeasureSpec.EXACTLY);
+
+                    // now measure the content only using UNSPECIFIED (where applicable, based on
+                    // the rendering mode). This will give us the size the content needs.
+                    Pair<Integer, Integer> result = measureView(
+                            mContentRoot, mContentRoot.getChildAt(0),
+                            mMeasuredScreenWidth, widthMeasureSpecMode,
+                            mMeasuredScreenHeight, heightMeasureSpecMode);
+
+                    // now look at the difference and add what is needed.
                     if (renderingMode.isHorizExpand()) {
-                        int neededWidth = mViewRoot.getChildAt(0).getMeasuredWidth();
-                        if (neededWidth > mMeasuredScreenWidth) {
-                            mMeasuredScreenWidth = neededWidth;
+                        int measuredWidth = exactMeasure.getFirst();
+                        int neededWidth = result.getFirst();
+                        if (neededWidth > measuredWidth) {
+                            mMeasuredScreenWidth += neededWidth - measuredWidth;
                         }
                     }
 
                     if (renderingMode.isVertExpand()) {
-                        int neededHeight = mViewRoot.getChildAt(0).getMeasuredHeight();
-                        if (neededHeight > mMeasuredScreenHeight) {
-                            mMeasuredScreenHeight = neededHeight;
+                        int measuredHeight = exactMeasure.getSecond();
+                        int neededHeight = result.getSecond();
+                        if (neededHeight > measuredHeight) {
+                            mMeasuredScreenHeight += neededHeight - measuredHeight;
                         }
                     }
                 }
             }
 
-            // remeasure with the size we need
+            // measure again with the size we need
             // This must always be done before the call to layout
-            w_spec = MeasureSpec.makeMeasureSpec(mMeasuredScreenWidth, MeasureSpec.EXACTLY);
-            h_spec = MeasureSpec.makeMeasureSpec(mMeasuredScreenHeight, MeasureSpec.EXACTLY);
-            mViewRoot.measure(w_spec, h_spec);
+            measureView(mViewRoot, null /*measuredView*/,
+                    mMeasuredScreenWidth, MeasureSpec.EXACTLY,
+                    mMeasuredScreenHeight, MeasureSpec.EXACTLY);
 
             // now do the layout.
             mViewRoot.layout(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);
@@ -494,6 +518,34 @@
     }
 
     /**
+     * Executes {@link View#measure(int, int)} on a given view with the given parameters (used
+     * to create measure specs with {@link MeasureSpec#makeMeasureSpec(int, int)}.
+     *
+     * if <var>measuredView</var> is non null, the method returns a {@link Pair} of (width, height)
+     * for the view (using {@link View#getMeasuredWidth()} and {@link View#getMeasuredHeight()}).
+     *
+     * @param viewToMeasure the view on which to execute measure().
+     * @param measuredView if non null, the view to query for its measured width/height.
+     * @param width the width to use in the MeasureSpec.
+     * @param widthMode the MeasureSpec mode to use for the width.
+     * @param height the height to use in the MeasureSpec.
+     * @param heightMode the MeasureSpec mode to use for the height.
+     * @return the measured width/height if measuredView is non-null, null otherwise.
+     */
+    private Pair<Integer, Integer> measureView(ViewGroup viewToMeasure, View measuredView,
+            int width, int widthMode, int height, int heightMode) {
+        int w_spec = MeasureSpec.makeMeasureSpec(width, widthMode);
+        int h_spec = MeasureSpec.makeMeasureSpec(height, heightMode);
+        viewToMeasure.measure(w_spec, h_spec);
+
+        if (measuredView != null) {
+            return Pair.of(measuredView.getMeasuredWidth(), measuredView.getMeasuredHeight());
+        }
+
+        return null;
+    }
+
+    /**
      * Animate an object
      * <p>
      * {@link #acquire(long)} must have been called before this.
diff --git a/voip/jni/rtp/AudioGroup.cpp b/voip/jni/rtp/AudioGroup.cpp
index c031eee..41fedce 100644
--- a/voip/jni/rtp/AudioGroup.cpp
+++ b/voip/jni/rtp/AudioGroup.cpp
@@ -30,6 +30,7 @@
 
 #define LOG_TAG "AudioGroup"
 #include <cutils/atomic.h>
+#include <cutils/properties.h>
 #include <utils/Log.h>
 #include <utils/Errors.h>
 #include <utils/RefBase.h>
@@ -619,6 +620,14 @@
     if (mode < 0 || mode > LAST_MODE) {
         return false;
     }
+    //FIXME: temporary code to overcome echo and mic gain issues on herring board.
+    // Must be modified/removed when proper support for voice processing query and control
+    // is included in audio framework
+    char value[PROPERTY_VALUE_MAX];
+    property_get("ro.product.board", value, "");
+    if (mode == NORMAL && !strcmp(value, "herring")) {
+        mode = ECHO_SUPPRESSION;
+    }
     if (mode == ECHO_SUPPRESSION && AudioSystem::getParameters(
         0, String8("ec_supported")) == "ec_supported=yes") {
         mode = NORMAL;
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index 909605d..6e13d0f 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -171,5 +171,7 @@
      */
     public native static String waitForEvent();
 
-    public native static void enableBackgroundScan(boolean enable);
+    public native static void enableBackgroundScanCommand(boolean enable);
+
+    public native static void setScanIntervalCommand(int scanInterval);
 }
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 4346b327..46c07a3 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -339,10 +339,20 @@
     private static final int POWER_MODE_AUTO = 0;
 
     /**
-     * See {@link Settings.Secure#WIFI_SCAN_INTERVAL_MS}. This is the default value if a
-     * Settings.Secure value is not present.
+     * Default framework scan interval in milliseconds. This is used in the scenario in which
+     * wifi chipset does not support background scanning to set up a
+     * periodic wake up scan so that the device can connect to a new access
+     * point on the move. {@link Settings.Secure#WIFI_FRAMEWORK_SCAN_INTERVAL_MS} can
+     * override this.
      */
-    private static final long DEFAULT_SCAN_INTERVAL_MS = 60 * 1000; /* 1 minute */
+    private final int mDefaultFrameworkScanIntervalMs;
+
+    /**
+     * Default supplicant scan interval in milliseconds.
+     * {@link Settings.Secure#WIFI_SUPPLICANT_SCAN_INTERVAL_MS} can override this.
+     */
+    private final int mDefaultSupplicantScanIntervalMs;
+
 
     private static final int MIN_RSSI = -200;
     private static final int MAX_RSSI = 256;
@@ -472,6 +482,12 @@
         Intent scanIntent = new Intent(ACTION_START_SCAN, null);
         mScanIntent = PendingIntent.getBroadcast(mContext, SCAN_REQUEST, scanIntent, 0);
 
+        mDefaultFrameworkScanIntervalMs = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_wifi_framework_scan_interval);
+
+        mDefaultSupplicantScanIntervalMs = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_wifi_supplicant_scan_interval);
+
         mContext.registerReceiver(
             new BroadcastReceiver() {
                 @Override
@@ -819,7 +835,7 @@
        sendMessage(obtainMessage(CMD_ENABLE_RSSI_POLL, enabled ? 1 : 0, 0));
     }
 
-    public void enableBackgroundScan(boolean enabled) {
+    public void enableBackgroundScanCommand(boolean enabled) {
        sendMessage(obtainMessage(CMD_ENABLE_BACKGROUND_SCAN, enabled ? 1 : 0, 0));
     }
 
@@ -1949,6 +1965,11 @@
             mIsScanMode = false;
             /* Wifi is available as long as we have a connection to supplicant */
             mNetworkInfo.setIsAvailable(true);
+            /* Set scan interval */
+            long supplicantScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
+                    Settings.Secure.WIFI_SUPPLICANT_SCAN_INTERVAL_MS,
+                    mDefaultSupplicantScanIntervalMs);
+            WifiNative.setScanIntervalCommand((int)supplicantScanIntervalMs / 1000);
         }
         @Override
         public boolean processMessage(Message message) {
@@ -2800,17 +2821,21 @@
 
     class DisconnectedState extends HierarchicalState {
         private boolean mAlarmEnabled = false;
-        private long mScanIntervalMs;
+        /* This is set from the overlay config file or from a secure setting.
+         * A value of 0 disables scanning in the framework.
+         */
+        private long mFrameworkScanIntervalMs;
 
         private void setScanAlarm(boolean enabled) {
             if (enabled == mAlarmEnabled) return;
             if (enabled) {
-                mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
-                        System.currentTimeMillis() + mScanIntervalMs,
-                        mScanIntervalMs,
-                        mScanIntent);
-
-                mAlarmEnabled = true;
+                if (mFrameworkScanIntervalMs > 0) {
+                    mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
+                            System.currentTimeMillis() + mFrameworkScanIntervalMs,
+                            mFrameworkScanIntervalMs,
+                            mScanIntent);
+                    mAlarmEnabled = true;
+                }
             } else {
                 mAlarmManager.cancel(mScanIntent);
                 mAlarmEnabled = false;
@@ -2822,8 +2847,9 @@
             if (DBG) Log.d(TAG, getName() + "\n");
             EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
 
-            mScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
-                    Settings.Secure.WIFI_SCAN_INTERVAL_MS, DEFAULT_SCAN_INTERVAL_MS);
+            mFrameworkScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
+                    Settings.Secure.WIFI_FRAMEWORK_SCAN_INTERVAL_MS,
+                    mDefaultFrameworkScanIntervalMs);
             /*
              * We initiate background scanning if it is enabled, otherwise we
              * initiate an infrequent scan that wakes up the device to ensure
@@ -2837,7 +2863,7 @@
                  * cleared
                  */
                 if (!mScanResultIsPending) {
-                    WifiNative.enableBackgroundScan(true);
+                    WifiNative.enableBackgroundScanCommand(true);
                 }
             } else {
                 setScanAlarm(true);
@@ -2859,10 +2885,10 @@
                 case CMD_ENABLE_BACKGROUND_SCAN:
                     mEnableBackgroundScan = (message.arg1 == 1);
                     if (mEnableBackgroundScan) {
-                        WifiNative.enableBackgroundScan(true);
+                        WifiNative.enableBackgroundScanCommand(true);
                         setScanAlarm(false);
                     } else {
-                        WifiNative.enableBackgroundScan(false);
+                        WifiNative.enableBackgroundScanCommand(false);
                         setScanAlarm(true);
                     }
                     break;
@@ -2877,14 +2903,14 @@
                 case CMD_START_SCAN:
                     /* Disable background scan temporarily during a regular scan */
                     if (mEnableBackgroundScan) {
-                        WifiNative.enableBackgroundScan(false);
+                        WifiNative.enableBackgroundScanCommand(false);
                     }
                     /* Handled in parent state */
                     return NOT_HANDLED;
                 case SCAN_RESULTS_EVENT:
                     /* Re-enable background scan when a pending scan result is received */
                     if (mEnableBackgroundScan && mScanResultIsPending) {
-                        WifiNative.enableBackgroundScan(true);
+                        WifiNative.enableBackgroundScanCommand(true);
                     }
                     /* Handled in parent state */
                     return NOT_HANDLED;
@@ -2899,7 +2925,7 @@
         public void exit() {
             /* No need for a background scan upon exit from a disconnected state */
             if (mEnableBackgroundScan) {
-                WifiNative.enableBackgroundScan(false);
+                WifiNative.enableBackgroundScanCommand(false);
             }
             setScanAlarm(false);
         }
diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java
index 07900ae..338cb4d 100644
--- a/wifi/java/android/net/wifi/WifiStateTracker.java
+++ b/wifi/java/android/net/wifi/WifiStateTracker.java
@@ -50,6 +50,7 @@
     private LinkProperties mLinkProperties;
     private LinkCapabilities mLinkCapabilities;
     private NetworkInfo mNetworkInfo;
+    private NetworkInfo.State mLastState = NetworkInfo.State.UNKNOWN;
 
     /* For sending events to connectivity service handler */
     private Handler mCsHandler;
@@ -217,6 +218,14 @@
                 if (mLinkCapabilities == null) {
                     mLinkCapabilities = new LinkCapabilities();
                 }
+                // don't want to send redundent state messages
+                // TODO can this be fixed in WifiStateMachine?
+                NetworkInfo.State state = mNetworkInfo.getState();
+                if (mLastState == state) {
+                    return;
+                } else {
+                    mLastState = state;
+                }
                 Message msg = mCsHandler.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo);
                 msg.sendToTarget();
             } else if (intent.getAction().equals(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION)) {
@@ -228,4 +237,7 @@
         }
     }
 
+    public void setDependencyMet(boolean met) {
+        // not supported on this network
+    }
 }