Merge "Fixing bugs exposed when moving accessibility CTS tests to UiAutomation." into jb-mr2-dev
diff --git a/api/current.txt b/api/current.txt
index d71ab35..9125fa5 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -6949,6 +6949,7 @@
     field public static final java.lang.String FEATURE_APP_WIDGETS = "android.software.app_widgets";
     field public static final java.lang.String FEATURE_AUDIO_LOW_LATENCY = "android.hardware.audio.low_latency";
     field public static final java.lang.String FEATURE_BLUETOOTH = "android.hardware.bluetooth";
+    field public static final java.lang.String FEATURE_BLUETOOTH_LE = "android.hardware.bluetooth_le";
     field public static final java.lang.String FEATURE_CAMERA = "android.hardware.camera";
     field public static final java.lang.String FEATURE_CAMERA_ANY = "android.hardware.camera.any";
     field public static final java.lang.String FEATURE_CAMERA_AUTOFOCUS = "android.hardware.camera.autofocus";
@@ -16949,7 +16950,7 @@
     method public static void startMethodTracing(java.lang.String, int);
     method public static void startMethodTracing(java.lang.String, int, int);
     method public static void startNativeTracing();
-    method public static void stopAllocCounting();
+    method public static deprecated void stopAllocCounting();
     method public static void stopMethodTracing();
     method public static void stopNativeTracing();
     method public static long threadCpuTimeNanos();
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 30bdfef..4266d85 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -870,6 +870,14 @@
 
     /**
      * Feature for {@link #getSystemAvailableFeatures} and
+     * {@link #hasSystemFeature}: The device is capable of communicating with
+     * other devices via Bluetooth Low Energy radio.
+     */
+    @SdkConstant(SdkConstantType.FEATURE)
+    public static final String FEATURE_BLUETOOTH_LE = "android.hardware.bluetooth_le";
+
+    /**
+     * Feature for {@link #getSystemAvailableFeatures} and
      * {@link #hasSystemFeature}: The device has a camera facing away
      * from the screen.
      */
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java
index 2e77237..fd01da9 100644
--- a/core/java/android/os/Debug.java
+++ b/core/java/android/os/Debug.java
@@ -577,6 +577,7 @@
      *
      * @see #startAllocCounting()
      */
+    @Deprecated
     public static void stopAllocCounting() {
         VMDebug.stopAllocCounting();
     }
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 39bff68..c7ce999 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -4279,6 +4279,9 @@
                         FLAG_OPTIMIZE_INVALIDATE) {
                 dirty.offset(location[CHILD_LEFT_INDEX] - mScrollX,
                         location[CHILD_TOP_INDEX] - mScrollY);
+                if ((mGroupFlags & FLAG_CLIP_CHILDREN) == 0) {
+                    dirty.union(0, 0, mRight - mLeft, mBottom - mTop);
+                }
 
                 final int left = mLeft;
                 final int top = mTop;
@@ -4378,6 +4381,9 @@
         if ((mPrivateFlags & PFLAG_DRAWN) == PFLAG_DRAWN ||
                 (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID) {
             dirty.offset(left - mScrollX, top - mScrollY);
+            if ((mGroupFlags & FLAG_CLIP_CHILDREN) == 0) {
+                dirty.union(0, 0, mRight - mLeft, mBottom - mTop);
+            }
 
             if ((mGroupFlags & FLAG_CLIP_CHILDREN) == 0 ||
                     dirty.intersect(0, 0, mRight - mLeft, mBottom - mTop)) {
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java
index 906f02d..f940226 100644
--- a/core/java/android/widget/RelativeLayout.java
+++ b/core/java/android/widget/RelativeLayout.java
@@ -231,7 +231,7 @@
      * {@link View#MEASURED_SIZE_MASK}.
      * {@link View#MEASURED_STATE_TOO_SMALL}.
      **/
-    private static final int DEFAULT_WIDTH = 0x008000000;
+    private static final int DEFAULT_WIDTH = 0x00010000;
 
     public RelativeLayout(Context context) {
         super(context);
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp
index 17f205d..bcc1573 100644
--- a/core/jni/android/graphics/TextLayoutCache.cpp
+++ b/core/jni/android/graphics/TextLayoutCache.cpp
@@ -622,11 +622,11 @@
   const hb_script_t init_script = code_point_to_script(init_cp);
   hb_script_t current_script = init_script;
   run->script = init_script;
+  size_t break_iter = *iter;
 
   for (;;) {
     if (*iter < 0)
       break;
-    const ssize_t prev_iter = *iter;
     const uint32_t cp = utf16_to_code_point_prev(chars, len, iter);
     const hb_script_t script = code_point_to_script(cp);
 
@@ -635,21 +635,18 @@
         // If we started off as inherited, we take whatever we can find.
         run->script = script;
         current_script = script;
+        // In cases of script1 + inherited + script2, always group the inherited
+        // with script1.
+        break_iter = *iter;
         continue;
       } else if (script == HB_SCRIPT_INHERITED) {
-        /* BEGIN android-changed
-           We apply the same fix for Chrome to Android.
-           Chrome team will talk with upsteam about it.
-           Just assume that whatever follows this combining character is within
-           the same script.  This is incorrect if you had language1 + combining
-           char + language 2, but that is rare and this code is suspicious
-           anyway.
-           END android-changed */
         continue;
       } else {
-        *iter = prev_iter;
+        *iter = break_iter;
         break;
       }
+    } else {
+        break_iter = *iter;
     }
   }
 
diff --git a/data/keyboards/Vendor_045e_Product_028e.kl b/data/keyboards/Vendor_045e_Product_028e.kl
index ca6fa59..301601a 100644
--- a/data/keyboards/Vendor_045e_Product_028e.kl
+++ b/data/keyboards/Vendor_045e_Product_028e.kl
@@ -22,9 +22,9 @@
 key 308   BUTTON_Y
 key 310   BUTTON_L1
 key 311   BUTTON_R1
-key 314   BUTTON_BACK
+key 314   BACK
 key 315   BUTTON_START
-key 316   BUTTON_HOME
+key 316   HOME
 key 317   BUTTON_THUMBL
 key 318   BUTTON_THUMBR
 
diff --git a/data/keyboards/Vendor_046d_Product_c219.kl b/data/keyboards/Vendor_046d_Product_c219.kl
index 431dd03..2fa964c 100644
--- a/data/keyboards/Vendor_046d_Product_c219.kl
+++ b/data/keyboards/Vendor_046d_Product_c219.kl
@@ -23,7 +23,7 @@
 key 310 BUTTON_L2
 key 311 BUTTON_R2
 key 313 BUTTON_START
-key 312 BUTTON_BACK
+key 312 BACK
 key 314 BUTTON_THUMBL
 key 315 BUTTON_THUMBR
 
diff --git a/data/keyboards/Vendor_046d_Product_c21f.kl b/data/keyboards/Vendor_046d_Product_c21f.kl
index 981d864..a9ba378 100644
--- a/data/keyboards/Vendor_046d_Product_c21f.kl
+++ b/data/keyboards/Vendor_046d_Product_c21f.kl
@@ -21,8 +21,8 @@
 key 310 BUTTON_L1
 key 311 BUTTON_R1
 key 315 BUTTON_START
-key 314 BUTTON_BACK
-key 316 BUTTON_HOME
+key 314 BACK
+key 316 HOME
 key 317 BUTTON_THUMBL
 key 318 BUTTON_THUMBR
 
diff --git a/data/keyboards/Vendor_054c_Product_0268.kl b/data/keyboards/Vendor_054c_Product_0268.kl
index 62c5f4d5..7c60137 100644
--- a/data/keyboards/Vendor_054c_Product_0268.kl
+++ b/data/keyboards/Vendor_054c_Product_0268.kl
@@ -35,7 +35,7 @@
 key 0x122    BUTTON_THUMBR
 
 # PS key
-key 0x2d0    BUTTON_HOME
+key 0x2d0    HOME
 
 # Left Analog Stick
 axis 0x00    X
diff --git a/data/keyboards/Vendor_1689_Product_fd00.kl b/data/keyboards/Vendor_1689_Product_fd00.kl
index 6ce14ed..8407b13 100644
--- a/data/keyboards/Vendor_1689_Product_fd00.kl
+++ b/data/keyboards/Vendor_1689_Product_fd00.kl
@@ -18,11 +18,11 @@
 key 305 BUTTON_B
 key 307 BUTTON_X
 key 308 BUTTON_Y
-key 307 BUTTON_L1
-key 308 BUTTON_R1
+key 310 BUTTON_L1
+key 311 BUTTON_R1
 key 315 BUTTON_START
-key 314 BUTTON_BACK
-key 316 BUTTON_HOME
+key 314 BACK
+key 316 HOME
 key 317 BUTTON_THUMBL
 key 318 BUTTON_THUMBR
 key 706 DPAD_UP
diff --git a/data/keyboards/Vendor_1689_Product_fd01.kl b/data/keyboards/Vendor_1689_Product_fd01.kl
index 8144515..cacc075 100644
--- a/data/keyboards/Vendor_1689_Product_fd01.kl
+++ b/data/keyboards/Vendor_1689_Product_fd01.kl
@@ -19,10 +19,10 @@
 key 307 BUTTON_X
 key 308 BUTTON_Y
 key 310 BUTTON_L1
-key 308 BUTTON_R1
+key 311 BUTTON_R1
 key 315 BUTTON_START
-key 314 BUTTON_BACK
-key 316 BUTTON_HOME
+key 314 BACK
+key 316 HOME
 key 317 BUTTON_THUMBL
 key 318 BUTTON_THUMBR
 
diff --git a/data/keyboards/Vendor_1689_Product_fe00.kl b/data/keyboards/Vendor_1689_Product_fe00.kl
index 90fe4af..467173f 100644
--- a/data/keyboards/Vendor_1689_Product_fe00.kl
+++ b/data/keyboards/Vendor_1689_Product_fe00.kl
@@ -21,8 +21,8 @@
 key 310 BUTTON_L1
 key 311 BUTTON_R1
 key 315 BUTTON_START
-key 314 BUTTON_BACK
-key 316 BUTTON_HOME
+key 314 BACK
+key 316 HOME
 key 317 BUTTON_THUMBL
 key 318 BUTTON_THUMBR
 
diff --git a/data/keyboards/Vendor_1bad_Product_f016.kl b/data/keyboards/Vendor_1bad_Product_f016.kl
index b72fd5ce..00f8559 100644
--- a/data/keyboards/Vendor_1bad_Product_f016.kl
+++ b/data/keyboards/Vendor_1bad_Product_f016.kl
@@ -21,8 +21,8 @@
 key 310 BUTTON_L1
 key 311 BUTTON_R1
 key 315 BUTTON_START
-key 314 BUTTON_BACK
-key 316 BUTTON_HOME
+key 314 BACK
+key 316 HOME
 key 317 BUTTON_THUMBL
 key 318 BUTTON_THUMBR
 
diff --git a/data/keyboards/Vendor_1bad_Product_f023.kl b/data/keyboards/Vendor_1bad_Product_f023.kl
index c1588b2..175a523 100644
--- a/data/keyboards/Vendor_1bad_Product_f023.kl
+++ b/data/keyboards/Vendor_1bad_Product_f023.kl
@@ -21,7 +21,7 @@
 key 310 BUTTON_L1
 key 311 BUTTON_R1
 key 315 BUTTON_START
-key 314 BUTTON_BACK
+key 314 BACK
 key 317 BUTTON_THUMBL
 key 318 BUTTON_THUMBR
 
diff --git a/data/keyboards/Vendor_1bad_Product_f027.kl b/data/keyboards/Vendor_1bad_Product_f027.kl
index ea0aa7a..216e3da 100644
--- a/data/keyboards/Vendor_1bad_Product_f027.kl
+++ b/data/keyboards/Vendor_1bad_Product_f027.kl
@@ -21,8 +21,8 @@
 key 310 BUTTON_L1
 key 311 BUTTON_R1
 key 315 BUTTON_START
-key 314 BUTTON_BACK
-key 316 BUTTON_HOME
+key 314 BACK
+key 316 HOME
 key 317 BUTTON_THUMBL
 key 318 BUTTON_THUMBR
 
diff --git a/data/keyboards/Vendor_1bad_Product_f036.kl b/data/keyboards/Vendor_1bad_Product_f036.kl
index 8cd906a..f27de1c 100644
--- a/data/keyboards/Vendor_1bad_Product_f036.kl
+++ b/data/keyboards/Vendor_1bad_Product_f036.kl
@@ -21,8 +21,8 @@
 key 310 BUTTON_L1
 key 311 BUTTON_R1
 key 315 BUTTON_START
-key 314 BUTTON_BACK
-key 316 BUTTON_HOME
+key 314 BACK
+key 316 HOME
 key 317 BUTTON_THUMBL
 key 318 BUTTON_THUMBR
 
diff --git a/data/keyboards/Vendor_1d79_Product_0009.kl b/data/keyboards/Vendor_1d79_Product_0009.kl
index 78fe2cd..bbfbc37 100644
--- a/data/keyboards/Vendor_1d79_Product_0009.kl
+++ b/data/keyboards/Vendor_1d79_Product_0009.kl
@@ -21,8 +21,8 @@
 key 310 BUTTON_L1
 key 311 BUTTON_R1
 key 315 BUTTON_START
-key 158 BUTTON_BACK
-key 172 BUTTON_HOME
+key 158 BACK
+key 172 HOME
 key 317 BUTTON_THUMBL
 key 318 BUTTON_THUMBR
 
diff --git a/data/keyboards/common.mk b/data/keyboards/common.mk
index 335298c..7b36167 100644
--- a/data/keyboards/common.mk
+++ b/data/keyboards/common.mk
@@ -26,7 +26,23 @@
     Vendor_046d_Product_c532.kl \
     Vendor_054c_Product_0268.kl \
     Vendor_05ac_Product_0239.kl \
-    Vendor_22b8_Product_093d.kl
+    Vendor_22b8_Product_093d.kl \
+    Vendor_0079_Product_0011.kl \
+    Vendor_046d_Product_c219.kl \
+    Vendor_046d_Product_c21f.kl \
+    Vendor_0583_Product_2060.kl \
+    Vendor_0a5c_Product_8502.kl \
+    Vendor_1038_Product_1412.kl \
+    Vendor_12bd_Product_d015.kl \
+    Vendor_1689_Product_fd00.kl \
+    Vendor_1689_Product_fd01.kl \
+    Vendor_1689_Product_fe00.kl \
+    Vendor_1bad_Product_f016.kl \
+    Vendor_1bad_Product_f023.kl \
+    Vendor_1bad_Product_f027.kl \
+    Vendor_1bad_Product_f036.kl \
+    Vendor_1d79_Product_0009.kl \
+    Vendor_2378_Product_100a.kl
 
 keycharmaps := \
     Generic.kcm \
diff --git a/docs/html/index.jd b/docs/html/index.jd
index 29d6a8f..ce3d9ad 100644
--- a/docs/html/index.jd
+++ b/docs/html/index.jd
@@ -14,7 +14,9 @@
             <ul>
                 <li class="item carousel-home">
                     <div class="content-left col-10">
-                    <img src="{@docRoot}images/home/io-extended-2013.png" style="margin:90px 0 0">
+                    <a href="https://developers.google.com/events/io/io-extended/?utm_source=site&utm_medium=emb&utm_campaign=extended-android-site">
+                      <img src="{@docRoot}images/home/io-extended-2013.png" style="margin:90px 0 0">
+                    </a>
                     </div>
                     <div class="content-right col-5">
                     <h1>Google I/O Extended</h1>
diff --git a/services/java/com/android/server/LockSettingsService.java b/services/java/com/android/server/LockSettingsService.java
index 41cc4d7..3f806ae 100644
--- a/services/java/com/android/server/LockSettingsService.java
+++ b/services/java/com/android/server/LockSettingsService.java
@@ -108,24 +108,31 @@
                 final ContentResolver cr = mContext.getContentResolver();
                 List<UserInfo> users = um.getUsers();
                 for (int user = 0; user < users.size(); user++) {
-                    int userId = users.get(user).getUserHandle().getIdentifier();
-                    for (String perUserSetting : MIGRATE_SETTINGS_PER_USER) {
-                        // Handle Strings
-                        String value = Settings.Secure.getStringForUser(cr, perUserSetting, userId);
-                        if (value != null) {
-                            setString(perUserSetting, value, userId);
-                            Settings.Secure.putStringForUser(cr, perUserSetting, "", userId);
-                            continue;
-                        }
+                    // Migrate owner info
+                    final int userId = users.get(user).id;
+                    final String OWNER_INFO = Secure.LOCK_SCREEN_OWNER_INFO;
+                    String ownerInfo = Settings.Secure.getStringForUser(cr, OWNER_INFO, userId);
+                    if (ownerInfo != null) {
+                        setString(OWNER_INFO, ownerInfo, userId);
+                        Settings.Secure.putStringForUser(cr, ownerInfo, "", userId);
+                    }
 
-                        // Handle integers
-                        try {
-                            int ivalue = Settings.Secure.getIntForUser(cr, perUserSetting, userId);
-                            setLong(perUserSetting, ivalue, userId);
-                            Settings.Secure.putIntForUser(cr, perUserSetting, 0, userId);
-                        } catch (SettingNotFoundException e) {
+                    // Migrate owner info enabled.  Note there was a bug where older platforms only
+                    // stored this value if the checkbox was toggled at least once. The code detects
+                    // this case by handling the exception.
+                    final String OWNER_INFO_ENABLED = Secure.LOCK_SCREEN_OWNER_INFO_ENABLED;
+                    boolean enabled;
+                    try {
+                        int ivalue = Settings.Secure.getIntForUser(cr, OWNER_INFO_ENABLED, userId);
+                        enabled = ivalue != 0;
+                        setLong(OWNER_INFO_ENABLED, enabled ? 1 : 0, userId);
+                    } catch (SettingNotFoundException e) {
+                        // Setting was never stored. Store it if the string is not empty.
+                        if (!TextUtils.isEmpty(ownerInfo)) {
+                            setLong(OWNER_INFO_ENABLED, 1, userId);
                         }
                     }
+                    Settings.Secure.putIntForUser(cr, OWNER_INFO_ENABLED, 0, userId);
                 }
                 // No need to move the password / pattern files. They're already in the right place.
                 setString("migrated_user_specific", "true", 0);
@@ -447,7 +454,8 @@
         Secure.LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED
     };
 
-    private static final String[] MIGRATE_SETTINGS_PER_USER = new String[] {
+    // These are protected with a read permission
+    private static final String[] READ_PROFILE_PROTECTED_SETTINGS = new String[] {
         Secure.LOCK_SCREEN_OWNER_INFO_ENABLED,
         Secure.LOCK_SCREEN_OWNER_INFO
     };
diff --git a/services/java/com/android/server/wifi/WifiService.java b/services/java/com/android/server/wifi/WifiService.java
index 9560199..5cf1966 100644
--- a/services/java/com/android/server/wifi/WifiService.java
+++ b/services/java/com/android/server/wifi/WifiService.java
@@ -121,8 +121,6 @@
      * on this */
     private WorkSource mScanWorkSource;
 
-    private boolean mIsReceiverRegistered = false;
-
     /**
      * Asynchronous channel to WifiStateMachine
      */
@@ -272,6 +270,11 @@
                         }
                     }
                 }, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
+
+        // Adding optimizations of only receiving broadcasts when wifi is enabled
+        // can result in race conditions when apps toggle wifi in the background
+        // without active user involvement. Always receive broadcasts.
+        registerForBroadcasts();
     }
 
     private WifiController mWifiController;
@@ -421,17 +424,6 @@
         }
 
         mWifiController.sendMessage(CMD_WIFI_TOGGLED);
-
-        if (enable) {
-            if (!mIsReceiverRegistered) {
-                registerForBroadcasts();
-                mIsReceiverRegistered = true;
-            }
-        } else if (mIsReceiverRegistered) {
-            mContext.unregisterReceiver(mReceiver);
-            mIsReceiverRegistered = false;
-        }
-
         return true;
     }