Merge "Import translations. DO NOT MERGE" into lmp-dev
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 5ba7d50..cc0d51c 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -132,6 +132,7 @@
                 "       am to-uri [INTENT]\n" +
                 "       am to-intent-uri [INTENT]\n" +
                 "       am switch-user <USER_ID>\n" +
+                "       am start-user <USER_ID>\n" +
                 "       am stop-user <USER_ID>\n" +
                 "       am stack start <DISPLAY_ID> <INTENT>\n" +
                 "       am stack movetask <TASK_ID> <STACK_ID> [true|false]\n" +
@@ -233,8 +234,11 @@
                 "am switch-user: switch to put USER_ID in the foreground, starting\n" +
                 "  execution of that user if it is currently stopped.\n" +
                 "\n" +
+                "am start-user: start USER_ID in background if it is currently stopped,\n" +
+                "  use switch-user if you want to start the user in foreground.\n" +
+                "\n" +
                 "am stop-user: stop execution of USER_ID, not allowing it to run any\n" +
-                "  code until a later explicit switch to it.\n" +
+                "  code until a later explicit start or switch to it.\n" +
                 "\n" +
                 "am stack start: start a new activity on <DISPLAY_ID> using <INTENT>.\n" +
                 "\n" +
@@ -340,6 +344,8 @@
             runToUri(true);
         } else if (op.equals("switch-user")) {
             runSwitchUser();
+        } else if (op.equals("start-user")) {
+            runStartUserInBackground();
         } else if (op.equals("stop-user")) {
             runStopUser();
         } else if (op.equals("stack")) {
@@ -1133,6 +1139,16 @@
         mAm.switchUser(Integer.parseInt(user));
     }
 
+    private void runStartUserInBackground() throws Exception {
+        String user = nextArgRequired();
+        boolean success = mAm.startUserInBackground(Integer.parseInt(user));
+        if (success) {
+            System.out.println("Success: user started");
+        } else {
+            System.err.println("Error: could not start user");
+        }
+    }
+
     private void runStopUser() throws Exception {
         String user = nextArgRequired();
         int res = mAm.stopUser(Integer.parseInt(user), null);
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index 3d14c58..cd6088f 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -579,7 +579,7 @@
         public TaskDescription(TaskDescription td) {
             mLabel = td.mLabel;
             mIcon = td.mIcon;
-            setPrimaryColor(td.mColorPrimary);
+            mColorPrimary = td.mColorPrimary;
             mIconFilename = td.mIconFilename;
         }
 
@@ -600,7 +600,11 @@
          * @hide
          */
         public void setPrimaryColor(int primaryColor) {
-            mColorPrimary = 0xFF000000 | primaryColor;
+            // Ensure that the given color is valid
+            if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) {
+                throw new RuntimeException("A TaskDescription's primary color should be opaque");
+            }
+            mColorPrimary = primaryColor;
         }
 
         /**
diff --git a/core/java/android/app/ApplicationErrorReport.java b/core/java/android/app/ApplicationErrorReport.java
index be4e80e..841bd16 100644
--- a/core/java/android/app/ApplicationErrorReport.java
+++ b/core/java/android/app/ApplicationErrorReport.java
@@ -388,7 +388,7 @@
             dest.writeInt(throwLineNumber);
             dest.writeString(stackTrace);
             int total = dest.dataPosition()-start;
-            if (total > 100*1024) {
+            if (total > 10*1024) {
                 Slog.d("Error", "ERR: exClass=" + exceptionClassName);
                 Slog.d("Error", "ERR: exMsg=" + exceptionMessage);
                 Slog.d("Error", "ERR: file=" + throwFileName);
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 31b39ebb2..4b3aefe 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -798,8 +798,8 @@
     public static final String EXTRA_TEMPLATE = "android.template";
 
     /**
-     * {@link #extras} key: An array of people that this notification relates to, specified
-     * by contacts provider contact URI.
+     * {@link #extras} key: A String array containing the people that this notification relates to,
+     * each of which was supplied to {@link Builder#addPerson(String)}.
      */
     public static final String EXTRA_PEOPLE = "android.people";
 
@@ -2393,10 +2393,27 @@
         /**
          * Add a person that is relevant to this notification.
          *
+         * <P>
+         * Depending on user preferences, this annotation may allow the notification to pass
+         * through interruption filters, and to appear more prominently in the user interface.
+         * </P>
+         *
+         * <P>
+         * The person should be specified by the {@code String} representation of a
+         * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}.
+         * </P>
+         *
+         * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema
+         * URIs.  The path part of these URIs must exist in the contacts database, in the
+         * appropriate column, or the reference will be discarded as invalid. Telephone schema
+         * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}.
+         * </P>
+         *
+         * @param uri A URI for the person.
          * @see Notification#EXTRA_PEOPLE
          */
-        public Builder addPerson(String handle) {
-            mPeople.add(handle);
+        public Builder addPerson(String uri) {
+            mPeople.add(uri);
             return this;
         }
 
diff --git a/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java b/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java
index 618195a..03540e1 100644
--- a/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java
+++ b/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java
@@ -1350,6 +1350,14 @@
         m.set(CaptureRequest.LENS_FOCAL_LENGTH,
                 c.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS)[0]);
 
+        /*
+         * jpeg.*
+         */
+
+        // jpeg.thumbnailSize - set smallest non-zero size if possible
+        Size[] sizes = c.get(CameraCharacteristics.JPEG_AVAILABLE_THUMBNAIL_SIZES);
+        m.set(CaptureRequest.JPEG_THUMBNAIL_SIZE, (sizes.length > 1) ? sizes[1] : sizes[0]);
+
         // TODO: map other request template values
         return m;
     }
diff --git a/core/java/android/hardware/camera2/legacy/RequestThreadManager.java b/core/java/android/hardware/camera2/legacy/RequestThreadManager.java
index fd95901..35deb71 100644
--- a/core/java/android/hardware/camera2/legacy/RequestThreadManager.java
+++ b/core/java/android/hardware/camera2/legacy/RequestThreadManager.java
@@ -16,11 +16,13 @@
 
 package android.hardware.camera2.legacy;
 
+import android.graphics.ImageFormat;
 import android.graphics.SurfaceTexture;
 import android.hardware.Camera;
 import android.hardware.camera2.CameraCharacteristics;
 import android.hardware.camera2.CaptureRequest;
 import android.hardware.camera2.impl.CameraDeviceImpl;
+import android.hardware.camera2.params.StreamConfigurationMap;
 import android.hardware.camera2.utils.LongParcelable;
 import android.hardware.camera2.utils.SizeAreaComparator;
 import android.hardware.camera2.impl.CameraMetadataNative;
@@ -36,6 +38,7 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -208,18 +211,23 @@
 
                         int totalSize = data.length + LegacyCameraDevice.nativeGetJpegFooterSize();
                         totalSize = (totalSize + 3) & ~0x3; // round up to nearest octonibble
+                        LegacyCameraDevice.setNextTimestamp(s, timestamp);
 
                         if (USE_BLOB_FORMAT_OVERRIDE) {
                             // Override to RGBA_8888 format.
                             LegacyCameraDevice.setSurfaceFormat(s,
                                     LegacyMetadataMapper.HAL_PIXEL_FORMAT_RGBA_8888);
-                            // divide by 4 if using RGBA format (width is in pixels, not bytes).
-                            totalSize >>= 2;
+
+                            int dimen = (int) Math.ceil(Math.sqrt(totalSize));
+                            dimen = (dimen + 0xf) & ~0xf; // round up to nearest multiple of 16
+                            LegacyCameraDevice.setSurfaceDimens(s, dimen, dimen);
+                            LegacyCameraDevice.produceFrame(s, data, dimen, dimen,
+                                    CameraMetadataNative.NATIVE_JPEG_FORMAT);
+                        } else {
+                            LegacyCameraDevice.setSurfaceDimens(s, totalSize, /*height*/1);
+                            LegacyCameraDevice.produceFrame(s, data, totalSize, /*height*/1,
+                                    CameraMetadataNative.NATIVE_JPEG_FORMAT);
                         }
-                        LegacyCameraDevice.setSurfaceDimens(s, totalSize, /*height*/1);
-                        LegacyCameraDevice.setNextTimestamp(s, timestamp);
-                        LegacyCameraDevice.produceFrame(s, data, totalSize, /*height*/1,
-                                CameraMetadataNative.NATIVE_JPEG_FORMAT);
                     }
                 } catch (LegacyExceptionUtils.BufferQueueAbandonedException e) {
                     Log.w(TAG, "Surface abandoned, dropping frame. ", e);
diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java
index f5fc0d7..bbf6ed8 100644
--- a/core/java/android/os/Binder.java
+++ b/core/java/android/os/Binder.java
@@ -430,16 +430,18 @@
         } catch (RemoteException e) {
             if ((flags & FLAG_ONEWAY) != 0) {
                 Log.w(TAG, "Binder call failed.", e);
+            } else {
+                reply.setDataPosition(0);
+                reply.writeException(e);
             }
-            reply.setDataPosition(0);
-            reply.writeException(e);
             res = true;
         } catch (RuntimeException e) {
             if ((flags & FLAG_ONEWAY) != 0) {
                 Log.w(TAG, "Caught a RuntimeException from the binder stub implementation.", e);
+            } else {
+                reply.setDataPosition(0);
+                reply.writeException(e);
             }
-            reply.setDataPosition(0);
-            reply.writeException(e);
             res = true;
         } catch (OutOfMemoryError e) {
             // Unconditionally log this, since this is generally unrecoverable.
@@ -452,6 +454,14 @@
         checkParcel(this, code, reply, "Unreasonably large binder reply buffer");
         reply.recycle();
         data.recycle();
+
+        // Just in case -- we are done with the IPC, so there should be no more strict
+        // mode violations that have gathered for this thread.  Either they have been
+        // parceled and are now in transport off to the caller, or we are returning back
+        // to the main transaction loop to wait for another incoming transaction.  Either
+        // way, strict mode begone!
+        StrictMode.clearGatheredViolations();
+
         return res;
     }
 }
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index 4e9d1f0..0e561bd 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -1693,7 +1693,7 @@
                 int start = p.dataPosition();
                 violations.get(i).writeToParcel(p, 0 /* unused flags? */);
                 int size = p.dataPosition()-start;
-                if (size > 100*1024) {
+                if (size > 10*1024) {
                     Slog.d(TAG, "Wrote violation #" + i + " of " + violations.size() + ": "
                             + (p.dataPosition()-start) + " bytes");
                 }
@@ -1725,6 +1725,11 @@
         for (int i = 0; i < numViolations; ++i) {
             if (LOG_V) Log.d(TAG, "strict mode violation stacks read from binder call.  i=" + i);
             ViolationInfo info = new ViolationInfo(p, !currentlyGathering);
+            if (info.crashInfo.stackTrace.length() > 5000) {
+                RuntimeException here = new RuntimeException("here");
+                here.fillInStackTrace();
+                Slog.w(TAG, "Stack is getting large: " + info.crashInfo.stackTrace, here);
+            }
             info.crashInfo.stackTrace += "# via Binder call with stack:\n" + ourStack;
             BlockGuard.Policy policy = BlockGuard.getThreadPolicy();
             if (policy instanceof AndroidBlockGuardPolicy) {
@@ -2194,7 +2199,7 @@
             dest.writeString(broadcastIntentAction);
             dest.writeStringArray(tags);
             int total = dest.dataPosition()-start;
-            if (total > 100*1024) {
+            if (total > 10*1024) {
                 Slog.d(TAG, "VIO: policy=" + policy + " dur=" + durationMillis
                         + " numLoop=" + violationNumThisLoop
                         + " anim=" + numAnimationsRunning
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index 35fff74..5d6acd8 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -760,6 +760,9 @@
         /**
          * Returns whether the notification matches the user's interruption
          * filter.
+         *
+         * @return {@code true} if the notification is allowed by the filter, or
+         * {@code false} if it is blocked.
          */
         public boolean matchesInterruptionFilter() {
             return mMatchesInterruptionFilter;
diff --git a/core/java/android/speech/RecognitionService.java b/core/java/android/speech/RecognitionService.java
index 32b2d8f..45eb0bf 100644
--- a/core/java/android/speech/RecognitionService.java
+++ b/core/java/android/speech/RecognitionService.java
@@ -91,9 +91,20 @@
         }
     };
 
-    private void dispatchStartListening(Intent intent, IRecognitionListener listener) {
+    private void dispatchStartListening(Intent intent, final IRecognitionListener listener) {
         if (mCurrentCallback == null) {
             if (DBG) Log.d(TAG, "created new mCurrentCallback, listener = " + listener.asBinder());
+            try {
+                listener.asBinder().linkToDeath(new IBinder.DeathRecipient() {
+                    @Override
+                    public void binderDied() {
+                        mHandler.sendMessage(mHandler.obtainMessage(MSG_CANCEL, listener));
+                    }
+                }, 0);
+            } catch (RemoteException re) {
+                Log.e(TAG, "dead listener on startListening");
+                return;
+            }
             mCurrentCallback = new Callback(listener);
             RecognitionService.this.onStartListening(intent, mCurrentCallback);
         } else {
diff --git a/core/java/android/speech/SpeechRecognizer.java b/core/java/android/speech/SpeechRecognizer.java
index 91c3799..88e2ede 100644
--- a/core/java/android/speech/SpeechRecognizer.java
+++ b/core/java/android/speech/SpeechRecognizer.java
@@ -396,6 +396,14 @@
      * Destroys the {@code SpeechRecognizer} object.
      */
     public void destroy() {
+        if (mService != null) {
+            try {
+                mService.cancel(mListener);
+            } catch (final RemoteException e) {
+                // Not important
+            }
+        }
+
         if (mConnection != null) {
             mContext.unbindService(mConnection);
         }
diff --git a/core/java/android/view/AccessibilityManagerInternal.java b/core/java/android/view/AccessibilityManagerInternal.java
new file mode 100644
index 0000000..7bb2dc5
--- /dev/null
+++ b/core/java/android/view/AccessibilityManagerInternal.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 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.view;
+
+/**
+ * Accessibility manager local system service interface.
+ *
+ * @hide Only for use within the system server.
+ */
+public abstract class AccessibilityManagerInternal {
+
+    /**
+     * Queries if the accessibility manager service permits setting
+     * a non-default encryption password.
+     */
+    public abstract boolean isNonDefaultEncryptionPasswordAllowed();
+}
diff --git a/core/java/android/view/GhostView.java b/core/java/android/view/GhostView.java
index 50c927a..20baad0 100644
--- a/core/java/android/view/GhostView.java
+++ b/core/java/android/view/GhostView.java
@@ -324,19 +324,27 @@
         final ArrayList<View> preorderedList = parent.buildOrderedChildList();
         final boolean customOrder = preorderedList == null
                 && parent.isChildrenDrawingOrderEnabled();
+
+        // This default value shouldn't be used because both view and comparedWith
+        // should be in the list. If there is an error, then just return an arbitrary
+        // view is on top.
+        boolean isOnTop = true;
         for (int i = 0; i < childrenCount; i++) {
             int childIndex = customOrder ? parent.getChildDrawingOrder(childrenCount, i) : i;
             final View child = (preorderedList == null)
                     ? parent.getChildAt(childIndex) : preorderedList.get(childIndex);
             if (child == view) {
-                return false;
+                isOnTop = false;
+                break;
             } else if (child == comparedWith) {
-                return true;
+                isOnTop = true;
+                break;
             }
         }
 
-        // Shouldn't get here. Neither of the children is in the parent.
-        // Just return an arbitrary one.
-        return true;
+        if (preorderedList != null) {
+            preorderedList.clear();
+        }
+        return isOnTop;
     }
 }
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 83dfe85..b454681 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -6601,6 +6601,7 @@
      * @see #fitSystemWindows(Rect)
      * @see #setSystemUiVisibility(int)
      */
+    @ViewDebug.ExportedProperty
     public boolean getFitsSystemWindows() {
         return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS;
     }
diff --git a/core/java/android/widget/FrameLayout.java b/core/java/android/widget/FrameLayout.java
index 235e79f..e317524 100644
--- a/core/java/android/widget/FrameLayout.java
+++ b/core/java/android/widget/FrameLayout.java
@@ -29,6 +29,7 @@
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.view.Gravity;
+import android.view.RemotableViewMethod;
 import android.view.View;
 import android.view.ViewDebug;
 import android.view.ViewGroup;
@@ -201,6 +202,15 @@
         }
     }
 
+    @Override
+    @RemotableViewMethod
+    public void setVisibility(@Visibility int visibility) {
+        super.setVisibility(visibility);
+        if (mForeground != null) {
+            mForeground.setVisible(visibility == VISIBLE, false);
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 42fc613..c00d209 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -6732,7 +6732,6 @@
         Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE);
         m.arg1 = onBattery ? 1 : 0;
         mHandler.sendMessage(m);
-        mOnBattery = mOnBatteryInternal = onBattery;
 
         final long uptime = mSecUptime * 1000;
         final long realtime = mSecRealtime * 1000;
@@ -6745,10 +6744,11 @@
             boolean reset = false;
             if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL
                     || level >= 90
-                    || getLowDischargeAmountSinceCharge() >= 60)
-                    || (getHighDischargeAmountSinceCharge() >= 60
-                            && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER)) {
+                    || (mDischargeCurrentLevel < 20 && level >= 80)
+                    || (getHighDischargeAmountSinceCharge() >= 200
+                            && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) {
                 Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus
+                        + " dischargeLevel=" + mDischargeCurrentLevel
                         + " lowAmount=" + getLowDischargeAmountSinceCharge()
                         + " highAmount=" + getHighDischargeAmountSinceCharge());
                 // Before we write, collect a snapshot of the final aggregated
@@ -6785,6 +6785,7 @@
                 reset = true;
                 mNumDischargeStepDurations = 0;
             }
+            mOnBattery = mOnBatteryInternal = onBattery;
             mLastDischargeStepLevel = level;
             mMinDischargeStepLevel = level;
             mLastDischargeStepTime = -1;
@@ -6812,6 +6813,7 @@
             mDischargeAmountScreenOff = 0;
             updateTimeBasesLocked(true, !screenOn, uptime, realtime);
         } else {
+            mOnBattery = mOnBatteryInternal = onBattery;
             pullPendingStateUpdatesLocked();
             mHistoryCur.batteryLevel = (byte)level;
             mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG;
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index 16fa88e..2b7af4b 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -878,6 +878,30 @@
     }
 
     /**
+     * Gets whether the device is encrypted.
+     *
+     * @return Whether the device is encrypted.
+     */
+    public static boolean isDeviceEncrypted() {
+        IMountService mountService = IMountService.Stub.asInterface(
+                ServiceManager.getService("mount"));
+        try {
+            return mountService.getEncryptionState() != IMountService.ENCRYPTION_STATE_NONE
+                    && mountService.getPasswordType() != StorageManager.CRYPT_TYPE_DEFAULT;
+        } catch (RemoteException re) {
+            Log.e(TAG, "Error getting encryption state", re);
+        }
+        return true;
+    }
+
+    /**
+     * Clears the encryption password.
+     */
+    public void clearEncryptionPassword() {
+        updateEncryptionPassword(StorageManager.CRYPT_TYPE_DEFAULT, null);
+    }
+
+    /**
      * Retrieves the quality mode we're in.
      * {@see DevicePolicyManager#getPasswordQuality(android.content.ComponentName)}
      *
diff --git a/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp b/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp
index b90e493..8440a0e 100644
--- a/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp
+++ b/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp
@@ -193,12 +193,13 @@
     if (err != NO_ERROR) return err;
 
     sp<GraphicBuffer> buf(new GraphicBuffer(anb, /*keepOwnership*/false));
-    uint32_t gBufWidth = buf->getWidth();
-    uint32_t gBufHeight = buf->getHeight();
-    if (gBufWidth != width || gBufHeight != height) {
+    uint32_t grallocBufWidth = buf->getWidth();
+    uint32_t grallocBufHeight = buf->getHeight();
+    uint32_t grallocBufStride = buf->getStride();
+    if (grallocBufWidth != width || grallocBufHeight != height) {
         ALOGE("%s: Received gralloc buffer with bad dimensions %" PRIu32 "x%" PRIu32
-                ", expecting dimensions %zu x %zu",  __FUNCTION__, gBufWidth, gBufHeight,
-                width, height);
+                ", expecting dimensions %zu x %zu",  __FUNCTION__, grallocBufWidth,
+                grallocBufHeight, width, height);
         return BAD_VALUE;
     }
 
@@ -210,11 +211,12 @@
         return err;
     }
 
-    uint64_t tmpSize = width * height;
+    uint64_t tmpSize = (pixelFmt == HAL_PIXEL_FORMAT_BLOB) ? grallocBufWidth :
+            4 * grallocBufHeight * grallocBufWidth;
     if (bufFmt != pixelFmt) {
         if (bufFmt == HAL_PIXEL_FORMAT_RGBA_8888 && pixelFmt == HAL_PIXEL_FORMAT_BLOB) {
             ALOGV("%s: Using BLOB to RGBA format override.", __FUNCTION__);
-            tmpSize *= 4;
+            tmpSize = 4 * (grallocBufWidth + grallocBufStride * (grallocBufHeight - 1));
         } else {
             ALOGW("%s: Format mismatch in produceFrame: expecting format %#" PRIx32
                     ", but received buffer with format %#" PRIx32, __FUNCTION__, pixelFmt, bufFmt);
@@ -311,17 +313,12 @@
             int8_t* img = NULL;
             struct camera3_jpeg_blob footer = {
                 jpeg_blob_id: CAMERA3_JPEG_BLOB_ID,
-                jpeg_size: (uint32_t)width
+                jpeg_size: (uint32_t)bufferLength
             };
 
             size_t totalJpegSize = bufferLength + sizeof(footer);
             totalJpegSize = (totalJpegSize + 3) & ~0x3; // round up to nearest octonibble
 
-            if (height != 1) {
-                ALOGE("%s: Invalid height set for JPEG buffer output, %zu", __FUNCTION__, height);
-                return BAD_VALUE;
-            }
-
             if (totalJpegSize > totalSizeBytes) {
                 ALOGE("%s: Pixel buffer needs size %zu, cannot fit in gralloc buffer of size %zu",
                         __FUNCTION__, totalJpegSize, totalSizeBytes);
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index 4859ee6..8753660 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -1324,7 +1324,21 @@
         config.density = 0;
 
         // Skip through XML attributes until the end or the next possible match.
-        while (ix < NX && curIdent > curXmlAttr) {
+        // We make two assumptions about the order of attributes:
+        // 1) Among attributes with the same package ID, the attributes are
+        //    sorted by increasing resource ID.
+        // 2) Groups of attributes with the same package ID are in the same
+        //    order.
+        // 3) The same sorting is applied to the input attributes as is
+        //    to the attributes in the XML.
+        //
+        // ex: 02010000, 02010001, 010100f4, 010100f5
+        //
+        // The total order of attributes (including package ID) can not be linear
+        // as shared libraries get assigned dynamic package IDs at runtime, which
+        // may break the sort order established at build time.
+        while (ix < NX && (Res_GETPACKAGE(curIdent) != Res_GETPACKAGE(curXmlAttr) ||
+                    curIdent > curXmlAttr)) {
             ix++;
             curXmlAttr = xmlParser->getAttributeNameResID(ix);
         }
@@ -1339,7 +1353,9 @@
         }
 
         // Skip through the style values until the end or the next possible match.
-        while (styleEnt < endStyleEnt && curIdent > styleEnt->map.name.ident) {
+        while (styleEnt < endStyleEnt &&
+                (Res_GETPACKAGE(curIdent) != Res_GETPACKAGE(styleEnt->map.name.ident) ||
+                 curIdent > styleEnt->map.name.ident)) {
             styleEnt++;
         }
         // Retrieve the current style attribute if it matches, and step to next.
@@ -1355,7 +1371,9 @@
         }
 
         // Skip through the default style values until the end or the next possible match.
-        while (defStyleEnt < endDefStyleEnt && curIdent > defStyleEnt->map.name.ident) {
+        while (defStyleEnt < endDefStyleEnt &&
+                (Res_GETPACKAGE(curIdent) != Res_GETPACKAGE(defStyleEnt->map.name.ident) ||
+                 curIdent > defStyleEnt->map.name.ident)) {
             defStyleEnt++;
         }
         // Retrieve the current default style attribute if it matches, and step to next.
@@ -1517,7 +1535,8 @@
         config.density = 0;
 
         // Skip through XML attributes until the end or the next possible match.
-        while (ix < NX && curIdent > curXmlAttr) {
+        while (ix < NX && (Res_GETPACKAGE(curIdent) != Res_GETPACKAGE(curXmlAttr) ||
+                    curIdent > curXmlAttr)) {
             ix++;
             curXmlAttr = xmlParser->getAttributeNameResID(ix);
         }
diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp
index 2dbd382..e400698 100644
--- a/core/jni/android_util_Binder.cpp
+++ b/core/jni/android_util_Binder.cpp
@@ -264,8 +264,7 @@
         ALOGV("onTransact() on %p calling object %p in env %p vm %p\n", this, mObject, env, mVM);
 
         IPCThreadState* thread_state = IPCThreadState::self();
-        const int strict_policy_before = thread_state->getStrictModePolicy();
-        thread_state->setLastTransactionBinderFlags(flags);
+        const int32_t strict_policy_before = thread_state->getStrictModePolicy();
 
         //printf("Transact from %p to Java code sending: ", this);
         //data.print();
@@ -284,15 +283,11 @@
             env->DeleteLocalRef(excep);
         }
 
-        // Restore the Java binder thread's state if it changed while
-        // processing a call (as it would if the Parcel's header had a
-        // new policy mask and Parcel.enforceInterface() changed
-        // it...)
-        const int strict_policy_after = thread_state->getStrictModePolicy();
-        if (strict_policy_after != strict_policy_before) {
-            // Our thread-local...
-            thread_state->setStrictModePolicy(strict_policy_before);
-            // And the Java-level thread-local...
+        // Check if the strict mode state changed while processing the
+        // call.  The Binder state will be restored by the underlying
+        // Binder system in IPCThreadState, however we need to take care
+        // of the parallel Java state as well.
+        if (thread_state->getStrictModePolicy() != strict_policy_before) {
             set_dalvik_blockguard_policy(env, strict_policy_before);
         }
 
diff --git a/core/res/res/color/primary_text_activated_material_dark.xml b/core/res/res/color/primary_text_activated_material_dark.xml
new file mode 100644
index 0000000..f1b742a
--- /dev/null
+++ b/core/res/res/color/primary_text_activated_material_dark.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_activated="true"
+          android:color="@color/primary_text_default_material_light"/>
+    <item android:color="@color/primary_text_default_material_dark"/>
+</selector>
diff --git a/core/res/res/color/primary_text_activated_material_light.xml b/core/res/res/color/primary_text_activated_material_light.xml
new file mode 100644
index 0000000..d92da63
--- /dev/null
+++ b/core/res/res/color/primary_text_activated_material_light.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_activated="true"
+          android:color="@color/primary_text_default_material_dark"/>
+    <item android:color="@color/primary_text_default_material_light"/>
+</selector>
diff --git a/core/res/res/color/secondary_text_activated_material_dark.xml b/core/res/res/color/secondary_text_activated_material_dark.xml
new file mode 100644
index 0000000..7a8428a
--- /dev/null
+++ b/core/res/res/color/secondary_text_activated_material_dark.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_activated="true"
+          android:color="@color/secondary_text_default_material_light"/>
+    <item android:color="@color/secondary_text_default_material_dark"/>
+</selector>
diff --git a/core/res/res/color/secondary_text_activated_material_light.xml b/core/res/res/color/secondary_text_activated_material_light.xml
new file mode 100644
index 0000000..36ff408
--- /dev/null
+++ b/core/res/res/color/secondary_text_activated_material_light.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_activated="true"
+          android:color="@color/secondary_text_default_material_dark"/>
+    <item android:color="@color/secondary_text_default_material_light"/>
+</selector>
diff --git a/core/res/res/layout/alert_dialog_material.xml b/core/res/res/layout/alert_dialog_material.xml
index 545d95e..c961828 100644
--- a/core/res/res/layout/alert_dialog_material.xml
+++ b/core/res/res/layout/alert_dialog_material.xml
@@ -56,7 +56,7 @@
         android:layout_height="wrap_content"
         android:layout_weight="1"
         android:orientation="vertical"
-        android:minHeight="64dp">
+        android:minHeight="48dp">
         <ScrollView android:id="@+id/scrollView"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
@@ -84,7 +84,7 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_weight="1"
-        android:minHeight="64dp">
+        android:minHeight="48dp">
         <FrameLayout android:id="@+id/custom"
             android:layout_width="match_parent"
             android:layout_height="wrap_content" />
diff --git a/core/res/res/layout/preference_header_item_material.xml b/core/res/res/layout/preference_header_item_material.xml
index 594189f..ffb18ae 100644
--- a/core/res/res/layout/preference_header_item_material.xml
+++ b/core/res/res/layout/preference_header_item_material.xml
@@ -45,7 +45,8 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:singleLine="true"
-            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textAppearance="?android:attr/textAppearanceListItem"
+            android:textColor="?android:attr/textColorPrimaryActivated"
             android:ellipsize="marquee"
             android:fadingEdge="horizontal" />
 
@@ -54,7 +55,8 @@
             android:layout_height="wrap_content"
             android:layout_below="@android:id/title"
             android:layout_alignStart="@android:id/title"
-            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:textAppearance="?android:attr/textAppearanceListItemSecondary"
+            android:textColor="?android:attr/textColorSecondaryActivated"
             android:ellipsize="end"
             android:maxLines="2" />
 
diff --git a/core/res/res/layout/preference_list_content_material.xml b/core/res/res/layout/preference_list_content_material.xml
index 7856799..1bc527e 100644
--- a/core/res/res/layout/preference_list_content_material.xml
+++ b/core/res/res/layout/preference_list_content_material.xml
@@ -48,7 +48,8 @@
                 android:drawSelectorOnTop="false"
                 android:cacheColorHint="@color/transparent"
                 android:listPreferredItemHeight="48dp"
-                android:scrollbarAlwaysDrawVerticalTrack="true" />
+                android:scrollbarAlwaysDrawVerticalTrack="true"
+                android:divider="@null" />
 
             <FrameLayout android:id="@+id/list_footer"
                     android:layout_width="match_parent"
diff --git a/core/res/res/values-mcc302-mnc610/config.xml b/core/res/res/values-mcc302-mnc610/config.xml
index 638aa92..81cec96 100644
--- a/core/res/res/values-mcc302-mnc610/config.xml
+++ b/core/res/res/values-mcc302-mnc610/config.xml
@@ -25,6 +25,6 @@
 
     <!-- Configure mobile network MTU. Carrier specific value is set here.
     -->
-    <integer name="config_mobile_mtu">1358</integer>
+    <integer name="config_mobile_mtu">1428</integer>
 
 </resources>
diff --git a/core/res/res/values-mcc310-mnc150/config.xml b/core/res/res/values-mcc310-mnc150/config.xml
index 3f9330d..3588f32 100644
--- a/core/res/res/values-mcc310-mnc150/config.xml
+++ b/core/res/res/values-mcc310-mnc150/config.xml
@@ -24,8 +24,10 @@
         <item>310140</item>
         <item>310400</item>
         <item>310470</item>
+        <item>311170</item>
     </string-array>
     <string-array translatable="false" name="config_operatorConsideredNonRoaming">
+        <item>310</item>
         <item>311</item>
         <item>312</item>
         <item>313</item>
diff --git a/core/res/res/values-mcc310-mnc410/config.xml b/core/res/res/values-mcc310-mnc410/config.xml
index 1cc8d4f..d17509c 100644
--- a/core/res/res/values-mcc310-mnc410/config.xml
+++ b/core/res/res/values-mcc310-mnc410/config.xml
@@ -30,9 +30,11 @@
         <item>310140</item>
         <item>310400</item>
         <item>310470</item>
+        <item>311170</item>
     </string-array>
-    <!-- BEGIN Motorola, xnk746, Feb-12-2014, IKVPREL2KK-1468 -->
+
     <string-array translatable="false" name="config_operatorConsideredNonRoaming">
+        <item>310</item>
         <item>311</item>
         <item>312</item>
         <item>313</item>
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 8ea1814..251652e 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -110,6 +110,11 @@
         <!-- Dim inverse text color. This does not differentiate the disabled state. -->
         <attr name="textColorSecondaryInverseNoDisable" format="reference|color" />
 
+        <!-- Bright text color for use over activated backgrounds. -->
+        <attr name="textColorPrimaryActivated" format="reference|color" />
+        <!-- Dim text color for use over activated backgrounds. -->
+        <attr name="textColorSecondaryActivated" format="reference|color" />
+
         <!-- Text color for urls in search suggestions, used by things like global search and the browser. @hide -->
         <attr name="textColorSearchUrl" format="reference|color" />
 
@@ -5365,11 +5370,11 @@
         <attr name="drawable" />
     </declare-styleable>
 
-    <!-- Defines the target path or group used in the AnimatedVectorDrawable. -->
+    <!-- Defines the target used in the AnimatedVectorDrawable. -->
     <declare-styleable name="AnimatedVectorDrawableTarget">
-        <!-- The name of this target path or group -->
+        <!-- The name of the target path, group or vector drawable -->
         <attr name="name" />
-        <!-- The animation for this target path or group -->
+        <!-- The animation for the target path, group or vector drawable -->
         <attr name="animation" />
     </declare-styleable>
 
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index bd9e2f6..4be9370 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -1636,6 +1636,7 @@
     <bool name="config_stkNoAlphaUsrCnf">true</bool>
 
     <!-- Don't use roaming icon for considered operators.
+         A match on config_sameNamedOperatorConsideredRoaming supersedes a match on this.
          Can use mcc or mcc+mnc as item. For example, 302 or 21407.
          If operators, 21404 and 21407, make roaming agreements, user of 21404 should not see
          the roaming icon as using 21407 network.
@@ -1650,10 +1651,12 @@
     <!-- For some operators, PDU has garbages. To fix it, need to use valid index -->
     <integer name="config_valid_wappush_index">-1</integer>
 
-    <!-- Show roaming icon though same named operators.
+    <!-- This is NOT just for same named operators unlike the name suggests (will blacklist regardless of name).
+         A match on this supersedes a match on config_operatorConsideredNonRoaming.
          Uses "startsWith" so you can use a leading substring like the mcc or
          use the complete mcc+mnc string.
-         Though same mcc and same operator name, some operator want to roam.
+         For a given mcc/mcc-mnc, some operators may want to roam (even if
+         config_operatorConsideredNonRoaming has the mcc/mcc-mnc).
          user of 40485 should see the roaming icon as using 40483 network
          though same Reliance network.
          To do this, add 40483 item to values-mcc404-mnc85/config.xml -->
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index f2b7d7b..081f8ae 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1696,6 +1696,7 @@
   <java-symbol type="string" name="launch_warning_replace" />
   <java-symbol type="string" name="launch_warning_title" />
   <java-symbol type="string" name="low_internal_storage_view_text" />
+  <java-symbol type="string" name="low_internal_storage_view_text_no_boot" />
   <java-symbol type="string" name="low_internal_storage_view_title" />
   <java-symbol type="string" name="notification_listener_binding_label" />
   <java-symbol type="string" name="condition_provider_service_binding_label" />
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index 7a9e1d5..d983440 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -74,6 +74,8 @@
         <item name="textColorPrimaryInverse">@color/primary_text_light</item>
         <item name="textColorSecondaryInverse">@color/secondary_text_light</item>
         <item name="textColorTertiaryInverse">@color/tertiary_text_light</item>
+        <item name="textColorPrimaryActivated">@color/primary_text_dark</item>
+        <item name="textColorSecondaryActivated">@color/secondary_text_dark</item>
         <item name="textColorPrimaryDisableOnly">@color/primary_text_dark_disable_only</item>
         <item name="textColorPrimaryInverseDisableOnly">@color/primary_text_light_disable_only</item>
         <item name="textColorPrimaryNoDisable">@color/primary_text_dark_nodisable</item>
@@ -478,6 +480,8 @@
         <item name="textColorPrimaryInverse">@color/primary_text_dark</item>
         <item name="textColorSecondaryInverse">@color/secondary_text_dark</item>
         <item name="textColorTertiaryInverse">@color/tertiary_text_dark</item>
+        <item name="textColorPrimaryActivated">@color/primary_text_light</item>
+        <item name="textColorSecondaryActivated">@color/secondary_text_light</item>
         <item name="textColorPrimaryDisableOnly">@color/primary_text_light_disable_only</item>
         <item name="textColorPrimaryInverseDisableOnly">@color/primary_text_dark_disable_only</item>
         <item name="textColorPrimaryNoDisable">@color/primary_text_light_nodisable</item>
diff --git a/core/res/res/values/themes_holo.xml b/core/res/res/values/themes_holo.xml
index 9c1d0f3..c30b3d5 100644
--- a/core/res/res/values/themes_holo.xml
+++ b/core/res/res/values/themes_holo.xml
@@ -93,6 +93,8 @@
         <item name="textColorPrimaryInverse">@color/primary_text_holo_light</item>
         <item name="textColorSecondaryInverse">@color/secondary_text_holo_light</item>
         <item name="textColorTertiaryInverse">@color/tertiary_text_holo_light</item>
+        <item name="textColorPrimaryActivated">@color/primary_text_holo_dark</item>
+        <item name="textColorSecondaryActivated">@color/secondary_text_holo_dark</item>
         <item name="textColorPrimaryDisableOnly">@color/primary_text_disable_only_holo_dark</item>
         <item name="textColorPrimaryInverseDisableOnly">@color/primary_text_disable_only_holo_light</item>
         <item name="textColorPrimaryNoDisable">@color/primary_text_nodisable_holo_dark</item>
@@ -429,6 +431,8 @@
         <item name="textColorPrimaryInverse">@color/primary_text_holo_dark</item>
         <item name="textColorSecondaryInverse">@color/secondary_text_holo_dark</item>
         <item name="textColorTertiaryInverse">@color/tertiary_text_holo_dark</item>
+        <item name="textColorPrimaryActivated">@color/primary_text_holo_light</item>
+        <item name="textColorSecondaryActivated">@color/secondary_text_holo_light</item>
         <item name="textColorPrimaryDisableOnly">@color/primary_text_disable_only_holo_light</item>
         <item name="textColorPrimaryInverseDisableOnly">@color/primary_text_disable_only_holo_dark</item>
         <item name="textColorPrimaryNoDisable">@color/primary_text_nodisable_holo_light</item>
diff --git a/core/res/res/values/themes_material.xml b/core/res/res/values/themes_material.xml
index 6420153..b51974e 100644
--- a/core/res/res/values/themes_material.xml
+++ b/core/res/res/values/themes_material.xml
@@ -55,9 +55,11 @@
 
         <item name="textColorPrimary">@color/primary_text_material_dark</item>
         <item name="textColorPrimaryInverse">@color/primary_text_material_light</item>
+        <item name="textColorPrimaryActivated">@color/primary_text_activated_material_dark</item>
         <item name="textColorPrimaryDisableOnly">@color/primary_text_disable_only_material_dark</item>
         <item name="textColorSecondary">@color/secondary_text_material_dark</item>
         <item name="textColorSecondaryInverse">@color/secondary_text_material_light</item>
+        <item name="textColorSecondaryActivated">@color/secondary_text_activated_material_dark</item>
         <item name="textColorTertiary">@color/secondary_text_material_dark</item>
         <item name="textColorTertiaryInverse">@color/secondary_text_material_light</item>
         <item name="textColorHint">@color/hint_foreground_material_dark</item>
@@ -402,8 +404,10 @@
 
         <item name="textColorPrimary">@color/primary_text_material_light</item>
         <item name="textColorPrimaryInverse">@color/primary_text_material_dark</item>
+        <item name="textColorPrimaryActivated">@color/primary_text_activated_material_light</item>
         <item name="textColorSecondary">@color/secondary_text_material_light</item>
         <item name="textColorSecondaryInverse">@color/secondary_text_material_dark</item>
+        <item name="textColorSecondaryActivated">@color/secondary_text_activated_material_light</item>
         <item name="textColorTertiary">@color/secondary_text_material_light</item>
         <item name="textColorTertiaryInverse">@color/secondary_text_material_dark</item>
         <item name="textColorPrimaryDisableOnly">@color/primary_text_disable_only_material_light</item>
@@ -757,8 +761,10 @@
 
         <item name="textColorPrimary">@color/primary_text_material_light</item>
         <item name="textColorPrimaryInverse">@color/primary_text_material_dark</item>
+        <item name="textColorPrimaryActivated">@color/primary_text_activated_material_light</item>
         <item name="textColorSecondary">@color/secondary_text_material_light</item>
         <item name="textColorSecondaryInverse">@color/secondary_text_material_dark</item>
+        <item name="textColorSecondaryActivated">@color/secondary_text_activated_material_light</item>
         <item name="textColorTertiary">@color/secondary_text_material_light</item>
         <item name="textColorTertiaryInverse">@color/secondary_text_material_dark</item>
         <item name="textColorPrimaryDisableOnly">@color/primary_text_disable_only_material_light</item>
@@ -794,9 +800,11 @@
 
         <item name="textColorPrimary">@color/primary_text_material_dark</item>
         <item name="textColorPrimaryInverse">@color/primary_text_material_light</item>
+        <item name="textColorPrimaryActivated">@color/primary_text_activated_material_dark</item>
         <item name="textColorPrimaryDisableOnly">@color/primary_text_disable_only_material_dark</item>
         <item name="textColorSecondary">@color/secondary_text_material_dark</item>
         <item name="textColorSecondaryInverse">@color/secondary_text_material_light</item>
+        <item name="textColorSecondaryActivated">@color/secondary_text_activated_material_dark</item>
         <item name="textColorTertiary">@color/secondary_text_material_dark</item>
         <item name="textColorTertiaryInverse">@color/secondary_text_material_light</item>
         <item name="textColorHint">@color/hint_foreground_material_dark</item>
diff --git a/docs/html/sdk/index.jd b/docs/html/sdk/index.jd
index 2bbdfc8c..9ed70ed 100644
--- a/docs/html/sdk/index.jd
+++ b/docs/html/sdk/index.jd
@@ -246,11 +246,9 @@
 <p>The Android SDK provides you the API libraries and developer tools necessary to build, test,
   and debug apps for Android.</p>
 
-<p>If you're a new Android developer, we recommend you download the ADT Bundle
-to quickly start developing apps. It includes the essential
-Android SDK components and a version of the Eclipse IDE with built-in
-<b>ADT (Android Developer Tools)</b> to
-streamline your Android app development.</p>
+<p>Download the ADT Bundle to quickly start developing apps. It includes the essential Android
+SDK components and a version of the Eclipse IDE with built-in <b>ADT (Android Developer Tools)</b>
+to streamline your Android app development.</p>
 
 
 <!-- this appears when viewing the online docs -->
diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java
index 8014837..4c83e55 100644
--- a/graphics/java/android/graphics/drawable/VectorDrawable.java
+++ b/graphics/java/android/graphics/drawable/VectorDrawable.java
@@ -57,6 +57,8 @@
  * <dl>
  * <dd>Used to defined a vector drawable
  * <dl>
+ * <dt><code>android:name</code></dt>
+ * <dd>Defines the name of this vector drawable.</dd>
  * <dt><code>android:width</code></dt>
  * <dd>Used to defined the intrinsic width of the drawable.
  * This support all the dimension units, normally specified with dp.</dd>
@@ -76,6 +78,8 @@
  * <dt><code>android:autoMirrored</code></dt>
  * <dd>Indicates if the drawable needs to be mirrored when its layout direction is
  * RTL (right-to-left).</dd>
+ * <dt><code>android:alpha</code></dt>
+ * <dd>The opacity of this drawable.</dd>
  * </dl></dd>
  * </dl>
  *
@@ -85,6 +89,8 @@
  * The transformations are defined in the same coordinates as the viewport.
  * And the transformations are applied in the order of scale, rotate then translate.
  * <dl>
+ * <dt><code>android:name</code></dt>
+ * <dd>Defines the name of the group.</dd>
  * <dt><code>android:rotation</code></dt>
  * <dd>The degrees of rotation of the group.</dd>
  * <dt><code>android:pivotX</code></dt>
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp
index 8cef137..61a767c 100644
--- a/libs/androidfw/ResourceTypes.cpp
+++ b/libs/androidfw/ResourceTypes.cpp
@@ -1185,7 +1185,11 @@
 {
     int32_t id = getAttributeNameID(idx);
     if (id >= 0 && (size_t)id < mTree.mNumResIds) {
-        return dtohl(mTree.mResIds[id]);
+        uint32_t resId = dtohl(mTree.mResIds[id]);
+        if (mTree.mDynamicRefTable == NULL ||
+                mTree.mDynamicRefTable->lookupResourceId(&resId) == NO_ERROR) {
+            return resId;
+        }
     }
     return 0;
 }
diff --git a/media/java/android/media/tv/TvContentRating.java b/media/java/android/media/tv/TvContentRating.java
index b4ec2b3..c539290 100644
--- a/media/java/android/media/tv/TvContentRating.java
+++ b/media/java/android/media/tv/TvContentRating.java
@@ -155,14 +155,6 @@
  *         <th>Description</th>
  *     </tr>
  *     <tr>
- *         <td>AM_TV_RS</td>
- *         <td>Range specific TV content rating system strings for Armenia</td>
- *     </tr>
- *     <tr>
- *         <td>AM_TV_AS</td>
- *         <td>Age specific TV content rating system strings for Armenia</td>
- *     </tr>
- *     <tr>
  *         <td>AR_TV</td>
  *         <td>TV content rating system for Argentina</td>
  *     </tr>
@@ -171,182 +163,37 @@
  *         <td>TV content rating system for Australia</td>
  *     </tr>
  *     <tr>
- *         <td>BG_TV</td>
- *         <td>TV content rating system for Bulgaria</td>
- *     </tr>
- *     <tr>
  *         <td>BR_TV</td>
  *         <td>TV content rating system for Brazil</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_CA</td>
- *         <td>TV content rating system for Canada (Canadian)</td>
+ *         <td>DVB</td>
+ *         <td>DVB content rating system</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_QC</td>
- *         <td>TV content rating system for Canada (Quebec)</td>
+ *         <td>ES_DVB</td>
+ *         <td>DVB content rating system for Spain</td>
  *     </tr>
  *     <tr>
- *         <td>CH_TV</td>
- *         <td>TV content rating system for Switzerland</td>
+ *         <td>FR_DVB</td>
+ *         <td>DVB content rating system for France</td>
  *     </tr>
  *     <tr>
- *         <td>CL_TV</td>
- *         <td>TV content rating system for Chile</td>
- *     </tr>
- *     <tr>
- *         <td>DE_TV</td>
- *         <td>TV content rating system for Germany</td>
- *     </tr>
- *     <tr>
- *         <td>DK_TV</td>
- *         <td>TV content rating system for Denmark</td>
- *     </tr>
- *     <tr>
- *         <td>ES_TV</td>
- *         <td>TV content rating system for Spain</td>
- *     </tr>
- *     <tr>
- *         <td>FI_TV</td>
- *         <td>TV content rating system for Finland</td>
- *     </tr>
- *     <tr>
- *         <td>FR_TV</td>
- *         <td>TV content rating system for France</td>
- *     </tr>
- *     <tr>
- *         <td>GR_TV</td>
- *         <td>TV content rating system for Greece</td>
- *     </tr>
- *     <tr>
- *         <td>HK_TV</td>
- *         <td>TV content rating system for Hong Kong</td>
- *     </tr>
- *     <tr>
- *         <td>HU_TV</td>
- *         <td>TV content rating system for Hungary</td>
- *     </tr>
- *     <tr>
- *         <td>ID_TV</td>
- *         <td>TV content rating system for Indonesia</td>
- *     </tr>
- *     <tr>
- *         <td>IE_TV</td>
- *         <td>TV content rating system for Ireland</td>
- *     </tr>
- *     <tr>
- *         <td>IL_TV</td>
- *         <td>TV content rating system for Israel</td>
- *     </tr>
- *     <tr>
- *         <td>IN_TV</td>
- *         <td>TV content rating system for India</td>
- *     </tr>
- *     <tr>
- *         <td>IS_TV</td>
- *         <td>TV content rating system for Iceland</td>
- *     </tr>
- *     <tr>
- *         <td>JP_TV</td>
- *         <td>TV content rating system for Japan</td>
+ *         <td>ISDB</td>
+ *         <td>ISDB content rating system</td>
  *     </tr>
  *     <tr>
  *         <td>KR_TV</td>
  *         <td>TV content rating system for South Korea</td>
  *     </tr>
  *     <tr>
- *         <td>MV_TV</td>
- *         <td>TV content rating system for Maldives</td>
- *     </tr>
- *     <tr>
- *         <td>MX_TV</td>
- *         <td>TV content rating system for Mexico</td>
- *     </tr>
- *     <tr>
- *         <td>MY_TV</td>
- *         <td>TV content rating system for Malaysia</td>
- *     </tr>
- *     <tr>
- *         <td>NL_TV</td>
- *         <td>TV content rating system for Netherlands</td>
- *     </tr>
- *     <tr>
- *         <td>NZ_FTV</td>
- *         <td>TV content rating system for free-to-air channels in New Zealand</td>
- *     </tr>
- *     <tr>
- *         <td>NZ_PTV</td>
- *         <td>TV content rating system for Pay TV channels in New Zealand</td>
- *     </tr>
- *     <tr>
- *         <td>PE_TV</td>
- *         <td>TV content rating system for some Peruvian channels in Peru</td>
- *     </tr>
- *     <tr>
- *         <td>PE_ATV</td>
- *         <td>TV content rating system for America Television in Peru that uses its own rating
- *         system</td>
- *     </tr>
- *     <tr>
- *         <td>PH_TV</td>
- *         <td>TV content rating system for Philippines</td>
- *     </tr>
- *     <tr>
- *         <td>PL_TV</td>
- *         <td>TV content rating system for Poland</td>
- *     </tr>
- *     <tr>
- *         <td>PT_TV</td>
- *         <td>TV content rating system for Portugal</td>
- *     </tr>
- *     <tr>
- *         <td>RO_TV</td>
- *         <td>TV content rating system for Romania</td>
- *     </tr>
- *     <tr>
- *         <td>RU_TV</td>
- *         <td>TV content rating system for Russia</td>
- *     </tr>
- *     <tr>
- *         <td>RS_TV</td>
- *         <td>TV content rating system for Serbia</td>
- *     </tr>
- *     <tr>
  *         <td>SG_TV</td>
  *         <td>TV content rating system for Singapore</td>
  *     </tr>
  *     <tr>
- *         <td>SI_TV</td>
- *         <td>TV content rating system for Slovenia</td>
- *     </tr>
- *     <tr>
- *         <td>TH_TV</td>
- *         <td>TV content rating system for Thailand</td>
- *     </tr>
- *     <tr>
- *         <td>TR_TV</td>
- *         <td>TV content rating system for Turkey</td>
- *     </tr>
- *     <tr>
- *         <td>TW_TV</td>
- *         <td>TV content rating system for Taiwan</td>
- *     </tr>
- *     <tr>
- *         <td>UA_TV</td>
- *         <td>TV content rating system for Ukraine</td>
- *     </tr>
- *     <tr>
  *         <td>US_TV</td>
  *         <td>TV content rating system for the United States</td>
  *     </tr>
- *     <tr>
- *         <td>VE_TV</td>
- *         <td>TV content rating system for Venezuela</td>
- *     </tr>
- *     <tr>
- *         <td>ZA_TV</td>
- *         <td>TV content rating system for South Africa</td>
- *     </tr>
  * </table>
  *
  * <h4>System defined strings for ratings</h4>
@@ -357,137 +204,61 @@
  *         <th>Description</th>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="6">AM_TV_RS</td>
- *         <td>AM_TV_RS_Y</td>
- *         <td>Suitable for ages 2-11</td>
- *     </tr>
- *     <tr>
- *         <td>AM_TV_RS_Y7</td>
- *         <td>Suitable for ages 7-16</td>
- *     </tr>
- *     <tr>
- *         <td>AM_TV_RS_GA</td>
- *         <td>Suitable for general audiences</td>
- *     </tr>
- *     <tr>
- *         <td>AM_TV_RS_TW</td>
- *         <td>Suitable for teens ages 9 and up</td>
- *     </tr>
- *     <tr>
- *         <td>AM_TV_RS_T</td>
- *         <td>Suitable for teens ages 12 and up</td>
- *     </tr>
- *     <tr>
- *         <td>AM_TV_RS_A</td>
- *         <td>Suitable only for adults ages 18 and up</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="6">AM_TV_AS</td>
- *         <td>AM_TV_AS_EC</td>
- *         <td>Suitable for ages 2 and up</td>
- *     </tr>
- *     <tr>
- *         <td>AM_TV_AS_E</td>
- *         <td>Suitable for ages 5 and up</td>
- *     </tr>
- *     <tr>
- *         <td>AM_TV_AS_E9</td>
- *         <td>Suitable for ages 9 and up</td>
- *     </tr>
- *     <tr>
- *         <td>AM_TV_AS_T</td>
- *         <td>Suitable for ages 12 and up</td>
- *     </tr>
- *     <tr>
- *         <td>AM_TV_AS_M</td>
- *         <td>Suitable for ages 16 and up</td>
- *     </tr>
- *     <tr>
- *         <td>AM_TV_AS_AO</td>
- *         <td>Suitable for ages 17 and up</td>
- *     </tr>
- *     <tr>
  *         <td valign="top" rowspan="4">AR_TV</td>
- *         <td>AR_TV_ALL</td>
+ *         <td>AR_TV_ATP</td>
  *         <td>Suitable for all audiences. Programs may contain mild violence, language and mature
  *         situations</td>
  *     </tr>
  *     <tr>
- *         <td>AR_TV_13</td>
+ *         <td>AR_TV_SAM_13</td>
  *         <td>Suitable for ages 13 and up. Programs may contain mild to moderate language and mild
  *         violence and sexual references</td>
  *     </tr>
  *     <tr>
- *         <td>AR_TV_16</td>
+ *         <td>AR_TV_SAM_16</td>
  *         <td>Suitable for ages 16 and up. Programs may contain more intensive violence and coarse
  *         language, partial nudity and moderate sexual references</td>
  *     </tr>
  *     <tr>
- *         <td>AR_TV_18</td>
+ *         <td>AR_TV_SAM_18</td>
  *         <td>Suitable for mature audiences only. Programs contain strong violence, coarse language
  *         and explicit sexual references</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="7">AU_TV</td>
- *         <td>AU_TV_CTC</td>
- *         <td>This has advertising approval, but is not yet classified</td>
+ *         <td valign="top" rowspan="8">AU_TV</td>
+ *         <td>AU_TV_P</td>
+ *         <td>Recommended for younger children aged between 2 and 11 years</td>
+ *     </tr>
+ *     <tr>
+ *         <td>AU_TV_C</td>
+ *         <td>Recommended for older children aged between 5 and 14 years</td>
  *     </tr>
  *     <tr>
  *         <td>AU_TV_G</td>
- *         <td>The content is very mild in impact, and suitable for everyone</td>
+ *         <td>Recommended for all ages</td>
  *     </tr>
  *     <tr>
  *         <td>AU_TV_PG</td>
- *         <td>The content is mild in impact, but it may contain content that children find
- *         confusing or upsetting and may require the guidance or parents and guardians</td>
+ *         <td>Parental guidance is recommended for young viewers under 15</td>
  *     </tr>
  *     <tr>
  *         <td>AU_TV_M</td>
- *         <td>The content is moderate in impact, and it is recommended for teenagers aged 15 years
- *         and over</td>
+ *         <td>Recommended for mature audiences aged 15 years and over</td>
  *     </tr>
  *     <tr>
- *         <td>AU_TV_MA15</td>
- *         <td>The content is strong in impact, and it is legally restricted to persons 15 years and
- *         over</td>
+ *         <td>AU_TV_MA</td>
+ *         <td>Not suitable for children and teens under 15, due to sexual descriptions, course
+ *         language, adult themes or drug use</td>
  *     </tr>
  *     <tr>
- *         <td>AU_TV_R18</td>
- *         <td>The content is high in impact, and it is restricted to adults</td>
+ *         <td>AU_TV_AV</td>
+ *         <td>Not suitable for children and teens under 15. This category is used specifically for
+ *         violent programs</td>
  *     </tr>
  *     <tr>
- *         <td>AU_TV_X18</td>
- *         <td>The content is restricted to adults. This classification is a special and legally
- *         restricted category which contains only sexually explicit content</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="5">BG_TV</td>
- *         <td>BG_TV_A</td>
- *         <td>Recommended to children. When the film confirms the ideals of humanism or popularizes
- *         the national and world cultures or contributes to upbringing children</td>
- *     </tr>
- *     <tr>
- *         <td>BG_TV_B</td>
- *         <td>No restrictive recommendations from the Committee. When the film is in no way
- *         contrary to the universal rules of morality in this country, has no restrictive
- *         recommendations from the Committee and does not fall in rating A</td>
- *     </tr>
- *     <tr>
- *         <td>BG_TV_C</td>
- *         <td>No persons under the age of 12 are admitted unless accompanied by an adult. When the
- *         film contains certain erotic scenes or scenes with drinking, taking drugs or stimulants
- *         or a few scenes of violence</td>
- *     </tr>
- *     <tr>
- *         <td>BG_TV_D</td>
- *         <td>No persons under the age of 16 are admitted. When the film contains quite a number of
- *         erotic scenes or scenes with drinking, taking drugs or stimulants or a considerable
- *         number of scenes showing violence</td>
- *     </tr>
- *     <tr>
- *         <td>BG_TV_X</td>
- *         <td>No persons under the age of 18 are admitted. When the film is naturalistically erotic
- *         or shows violence in an ostentatious manner</td>
+ *         <td>AU_TV_R</td>
+ *         <td>Not for children under 18. Content may include graphic violence, sexual situations,
+ *         coarse language and explicit drug use</td>
  *     </tr>
  *     <tr>
  *         <td valign="top" rowspan="6">BR_TV</td>
@@ -515,422 +286,272 @@
  *         <td>Content suitable for viewers over the age of 18</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="7">CA_TV_CA</td>
- *         <td>CA_TV_CA_EXEMPT</td>
- *         <td>Exempt from ratings and won't display an on-screen rating</td>
+ *         <td valign="top" rowspan="15">DVB</td>
+ *         <td>DVB_4</td>
+ *         <td>Recommended for ages 4 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_CA_C</td>
- *         <td>Suitable for children ages 2-7. May contain mild violence</td>
+ *         <td>DVB_5</td>
+ *         <td>Recommended for ages 5 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_CA_C8</td>
- *         <td>Suitable for children ages 8 and older. May contain mild violence, fantasy horror,
- *         and socially offensive language</td>
+ *         <td>DVB_6</td>
+ *         <td>Recommended for ages 6 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_CA_G</td>
- *         <td>Suitable for the entire family and may contain mild violence, profanity, and censored
- *         language</td>
+ *         <td>DVB_7</td>
+ *         <td>Recommended for ages 7 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_CA_PG</td>
- *         <td>May contain moderate violence, profanity, nudity, and sexual references</td>
+ *         <td>DVB_8</td>
+ *         <td>Recommended for ages 8 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_CA_14</td>
- *         <td>Intended for viewers ages 14 and older. May contain strong violence and profanity,
- *         and depictions of sexual activity</td>
+ *         <td>DVB_9</td>
+ *         <td>Recommended for ages 9 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_CA_18</td>
- *         <td>Intended for viewers ages 18 and older. May contain explicit violence and sexual
- *         activity</td>
+ *         <td>DVB_10</td>
+ *         <td>Recommended for ages 10 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="6">CA_TV_QC</td>
- *         <td>CA_TV_QC_E</td>
- *         <td>Exempt from ratings and won't display an on-screen rating</td>
+ *         <td>DVB_11</td>
+ *         <td>Recommended for ages 11 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_QC_G</td>
- *         <td>Appropriate for all ages and must contain little or no violence and little to no
- *         sexual content</td>
+ *         <td>DVB_12</td>
+ *         <td>Recommended for ages 12 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_QC_8</td>
- *         <td>Appropriate for children 8 and may contain with little violence, language, and little
- *         to no sexual situations</td>
+ *         <td>DVB_13</td>
+ *         <td>Recommended for ages 13 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_QC_13</td>
- *         <td>Suitable for children 13 and may contain with moderate violence, language, and some
- *         sexual situations</td>
+ *         <td>DVB_14</td>
+ *         <td>Recommended for ages 14 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_QC_16</td>
- *         <td>Recommended for children over the age of 16 and may contain with strong violence,
- *         strong language, and strong sexual content</td>
+ *         <td>DVB_15</td>
+ *         <td>Recommended for ages 15 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CA_TV_QC_18</td>
- *         <td>Only to be viewed by adults and may contain extreme violence and graphic sexual
- *         content. It is mostly used for 18+ movies and pornography</td>
+ *         <td>DVB_16</td>
+ *         <td>Recommended for ages 16 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="2">CH_TV</td>
- *         <td>CH_TV_ALL</td>
- *         <td>This program is suitable for all ages</td>
+ *         <td>DVB_17</td>
+ *         <td>Recommended for ages 17 and over</td>
  *     </tr>
  *     <tr>
- *         <td>CH_TV_RED</td>
- *         <td>This program contains scenes that may hurt sensitive people, therefore the red symbol
- *         will be displayed</td>
+ *         <td>DVB_18</td>
+ *         <td>Recommended for ages 18 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="7">CL_TV</td>
- *         <td>CL_TV_I</td>
- *         <td>Programs suitable for all children</td>
- *     </tr>
- *     <tr>
- *         <td>CL_TV_I7</td>
- *         <td>Programs recommended for children ages 7 or older</td>
- *     </tr>
- *     <tr>
- *         <td>CL_TV_I10</td>
- *         <td>Programs recommended for children ages 10 or older</td>
- *     </tr>
- *     <tr>
- *         <td>CL_TV_I12</td>
- *         <td>Programs recommended for children and teens ages 12 or older</td>
- *     </tr>
- *     <tr>
- *         <td>CL_TV_F</td>
- *         <td>Programs suitable for a general audience, with content appropriate for all ages</td>
- *     </tr>
- *     <tr>
- *         <td>CL_TV_R</td>
- *         <td>Programs may content not suitable for children not accompanied by an adult</td>
- *     </tr>
- *     <tr>
- *         <td>CL_TV_A</td>
- *         <td>Programs suitable for adult audiences only (ages 18 or older), may contain coarse
- *         language, and sexual or explicit situations</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="4">DE_TV</td>
- *         <td>DE_TV_ALL</td>
- *         <td>The program is suitable for all ages</td>
- *     </tr>
- *     <tr>
- *         <td>DE_TV_12</td>
- *         <td>The program is not suitable for viewers under the age of 12</td>
- *     </tr>
- *     <tr>
- *         <td>DE_TV_16</td>
- *         <td>The program is not suitable for viewers under the age of 16</td>
- *     </tr>
- *     <tr>
- *         <td>DE_TV_18</td>
- *         <td>The program is not suitable for viewers under the age of 18</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="4">DK_TV</td>
- *         <td>DK_TV_G</td>
- *         <td>programs suitable for all ages</td>
- *     </tr>
- *     <tr>
- *         <td>DK_TV_Y</td>
- *         <td>programs suitable children accompanied by an adult</td>
- *     </tr>
- *     <tr>
- *         <td>DK_TV_R</td>
- *         <td>programs containing material with more intensive content</td>
- *     </tr>
- *     <tr>
- *         <td>DK_TV_B</td>
- *         <td>programs containing explicit content and strictly for adults only</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="7">ES_TV</td>
- *         <td>ES_TV_TP</td>
+ *         <td valign="top" rowspan="18">ES_DVB</td>
+ *         <td>ES_DVB_ALL</td>
  *         <td>Recommended for all ages</td>
  *     </tr>
  *     <tr>
- *         <td>ES_TV_I</td>
- *         <td>Specially recommended for preschoolers and kids</td>
+ *         <td>ES_DVB_C</td>
+ *         <td>Recommended for children</td>
  *     </tr>
  *     <tr>
- *         <td>ES_TV_7</td>
- *         <td>Recommended for people older than 7 years old</td>
+ *         <td>ES_DVB_X</td>
+ *         <td>Recommended for adults</td>
  *     </tr>
  *     <tr>
- *         <td>ES_TV_7I</td>
- *         <td>Recommended for kids older than 7 years old</td>
+ *         <td>ES_DVB_4</td>
+ *         <td>Recommended for ages 4 and over</td>
  *     </tr>
  *     <tr>
- *         <td>ES_TV_12</td>
- *         <td>Recommended for people older than 12 years old</td>
+ *         <td>ES_DVB_5</td>
+ *         <td>Recommended for ages 5 and over</td>
  *     </tr>
  *     <tr>
- *         <td>ES_TV_16</td>
- *         <td>Recommended for people older than 16 years old</td>
+ *         <td>ES_DVB_6</td>
+ *         <td>Recommended for ages 6 and over</td>
  *     </tr>
  *     <tr>
- *         <td>ES_TV_18</td>
- *         <td>Recommended for people older than 18 years old</td>
+ *         <td>ES_DVB_7</td>
+ *         <td>Recommended for ages 7 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="5">FI_TV</td>
- *         <td>FI_TV_S</td>
- *         <td>Allowed at all times</td>
+ *         <td>ES_DVB_8</td>
+ *         <td>Recommended for ages 8 and over</td>
  *     </tr>
  *     <tr>
- *         <td>FI_TV_K7</td>
- *         <td>Not recommended for children under 7</td>
+ *         <td>ES_DVB_9</td>
+ *         <td>Recommended for ages 9 and over</td>
  *     </tr>
  *     <tr>
- *         <td>FI_TV_K12</td>
- *         <td>Not recommended for children under 12</td>
+ *         <td>ES_DVB_10</td>
+ *         <td>Recommended for ages 10 and over</td>
  *     </tr>
  *     <tr>
- *         <td>FI_TV_K16</td>
- *         <td>Not recommended for children under 16</td>
+ *         <td>ES_DVB_11</td>
+ *         <td>Recommended for ages 11 and over</td>
  *     </tr>
  *     <tr>
- *         <td>FI_TV_K18</td>
- *         <td>Not recommended for children under 18</td>
+ *         <td>ES_DVB_12</td>
+ *         <td>Recommended for ages 12 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="5">FR_TV</td>
- *         <td>FR_TV_ALL</td>
- *         <td>Appropriate for all ages</td>
+ *         <td>ES_DVB_13</td>
+ *         <td>Recommended for ages 13 and over</td>
  *     </tr>
  *     <tr>
- *         <td>FR_TV_10</td>
- *         <td>Not recommended for children under 10</td>
+ *         <td>ES_DVB_14</td>
+ *         <td>Recommended for ages 14 and over</td>
  *     </tr>
  *     <tr>
- *         <td>FR_TV_12</td>
- *         <td>Not recommended for children under 12</td>
+ *         <td>ES_DVB_15</td>
+ *         <td>Recommended for ages 15 and over</td>
  *     </tr>
  *     <tr>
- *         <td>FR_TV_16</td>
- *         <td>Not recommended for children under 16</td>
+ *         <td>ES_DVB_16</td>
+ *         <td>Recommended for ages 16 and over</td>
  *     </tr>
  *     <tr>
- *         <td>FR_TV_18</td>
- *         <td>Not recommended for persons under 18</td>
+ *         <td>ES_DVB_17</td>
+ *         <td>Recommended for ages 17 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="5">GR_TV</td>
- *         <td>GR_TV_ALL</td>
- *         <td>Suitable for all ages</td>
+ *         <td>ES_DVB_18</td>
+ *         <td>Recommended for ages 18 and over</td>
  *     </tr>
  *     <tr>
- *         <td>GR_TV_10</td>
- *         <td>Parental consent suggested</td>
+ *         <td valign="top" rowspan="16">FR_DVB</td>
+ *         <td>FR_DVB_U</td>
+ *         <td>Recommended for all ages</td>
  *     </tr>
  *     <tr>
- *         <td>GR_TV_12</td>
- *         <td>Required parental consent</td>
+ *         <td>FR_DVB_4</td>
+ *         <td>Recommended for ages 4 and over</td>
  *     </tr>
  *     <tr>
- *         <td>GR_TV_15</td>
- *         <td>Suitable for minors over the age of 15</td>
+ *         <td>FR_DVB_5</td>
+ *         <td>Recommended for ages 5 and over</td>
  *     </tr>
  *     <tr>
- *         <td>GR_TV_18</td>
- *         <td>Suitable only for adults profanity before midnight is punishable by fine, except when
- *         used in the context of the program</td>
+ *         <td>FR_DVB_6</td>
+ *         <td>Recommended for ages 6 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="3">HK_TV</td>
- *         <td>HK_TV_G</td>
- *         <td>For general audiences</td>
+ *         <td>FR_DVB_7</td>
+ *         <td>Recommended for ages 7 and over</td>
  *     </tr>
  *     <tr>
- *         <td>HK_TV_PG</td>
- *         <td>Programs are unsuitable for children, parental guidance is recommended</td>
+ *         <td>FR_DVB_8</td>
+ *         <td>Recommended for ages 8 and over</td>
  *     </tr>
  *     <tr>
- *         <td>HK_TV_M</td>
- *         <td>Programs are recommended only for adult viewers above the age of 18</td>
+ *         <td>FR_DVB_9</td>
+ *         <td>Recommended for ages 9 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="6">HU_TV</td>
- *         <td>HU_TV_U</td>
- *         <td>Programs can be viewed by any age</td>
+ *         <td>FR_DVB_10</td>
+ *         <td>Recommended for ages 10 and over</td>
  *     </tr>
  *     <tr>
- *         <td>HU_TV_CF</td>
- *         <td>Programs recommended for children. It is an optional rating, there is no obligation
- *         for broadcasters to indicate it</td>
+ *         <td>FR_DVB_11</td>
+ *         <td>Recommended for ages 11 and over</td>
  *     </tr>
  *     <tr>
- *         <td>HU_TV_6</td>
- *         <td>Programs not recommended for children below the age of 6, may not contain any
- *         violence or sexual content</td>
+ *         <td>FR_DVB_12</td>
+ *         <td>Recommended for ages 12 and over</td>
  *     </tr>
  *     <tr>
- *         <td>HU_TV_12</td>
- *         <td>Programs not recommended for children below the age of 12, may contain light sexual
- *         content or explicit language</td>
+ *         <td>FR_DVB_13</td>
+ *         <td>Recommended for ages 13 and over</td>
  *     </tr>
  *     <tr>
- *         <td>HU_TV_16</td>
- *         <td>Programs not recommended for teens and children below the age of 16, may contain more
- *         intensive violence and sexual content</td>
+ *         <td>FR_DVB_14</td>
+ *         <td>Recommended for ages 14 and over</td>
  *     </tr>
  *     <tr>
- *         <td>HU_TV_18</td>
- *         <td>The program is recommended only for adult viewers (for ages 18 and up), may contain
- *         explicit violence and explicit sexual content</td>
+ *         <td>FR_DVB_15</td>
+ *         <td>Recommended for ages 15 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="8">ID_TV</td>
- *         <td>ID_TV_P</td>
- *         <td>Suitable for children from ages 2 through 11</td>
+ *         <td>FR_DVB_16</td>
+ *         <td>Recommended for ages 16 and over</td>
  *     </tr>
  *     <tr>
- *         <td>ID_TV_A</td>
- *         <td>Suitable for teens and children from ages 7 through 16</td>
+ *         <td>FR_DVB_17</td>
+ *         <td>Recommended for ages 17 and over</td>
  *     </tr>
  *     <tr>
- *         <td>ID_TV_A_BO</td>
- *         <td>Suitable for children ages 5 through 10, with parental guidance or permission</td>
+ *         <td>FR_DVB_18</td>
+ *         <td>Recommended for ages 18 and over</td>
  *     </tr>
  *     <tr>
- *         <td>ID_TV_SU</td>
- *         <td>Suitable for general audiences</td>
+ *         <td valign="top" rowspan="17">ISDB</td>
+ *         <td>ISDB_4</td>
+ *         <td>Recommended for ages 4 and over</td>
  *     </tr>
  *     <tr>
- *         <td>ID_TV_BO</td>
- *         <td>Parental guidance suggested for ages 5 and under</td>
+ *         <td>ISDB_5</td>
+ *         <td>Recommended for ages 5 and over</td>
  *     </tr>
  *     <tr>
- *         <td>ID_TV_R</td>
- *         <td>Suitable for teens from ages 13 through 17</td>
+ *         <td>ISDB_6</td>
+ *         <td>Recommended for ages 6 and over</td>
  *     </tr>
  *     <tr>
- *         <td>ID_TV_R_BO</td>
- *         <td>Suitable for teens with parental guidance or permission</td>
+ *         <td>ISDB_7</td>
+ *         <td>Recommended for ages 7 and over</td>
  *     </tr>
  *     <tr>
- *         <td>ID_TV_D</td>
- *         <td>Suitable for viewers over 18 and older only</td>
+ *         <td>ISDB_8</td>
+ *         <td>Recommended for ages 8 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="5">IE_TV</td>
- *         <td>IE_TV_GA</td>
- *         <td>Suitable for all ages</td>
+ *         <td>ISDB_9</td>
+ *         <td>Recommended for ages 9 and over</td>
  *     </tr>
  *     <tr>
- *         <td>IE_TV_CH</td>
- *         <td>Suitable for children ages 5 to 10, may contain comedic violence or action fantasy
- *         violence</td>
+ *         <td>ISDB_10</td>
+ *         <td>Recommended for ages 10 and over</td>
  *     </tr>
  *     <tr>
- *         <td>IE_TV_YA</td>
- *         <td>Suitable for adolescent audiences, may contain thematic elements that would appeal to
- *         teenagers</td>
+ *         <td>ISDB_11</td>
+ *         <td>Recommended for ages 11 and over</td>
  *     </tr>
  *     <tr>
- *         <td>IE_TV_PS</td>
- *         <td>Suitable for more mature viewers, more mature themes may be present</td>
+ *         <td>ISDB_12</td>
+ *         <td>Recommended for ages 12 and over</td>
  *     </tr>
  *     <tr>
- *         <td>IE_TV_MA</td>
- *         <td>Most restrictive classification, allowing for heavy subject matter and coarse
- *         language</td>
+ *         <td>ISDB_13</td>
+ *         <td>Recommended for ages 13 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="5">IL_TV</td>
- *         <td>IL_TV_G</td>
- *         <td>General audience; anyone, regardless of age, can view the program, usually news and
- *         children's programming</td>
+ *         <td>ISDB_14</td>
+ *         <td>Recommended for ages 14 and over</td>
  *     </tr>
  *     <tr>
- *         <td>IL_TV_12</td>
- *         <td>Suitable for teens and children ages 12 and over, no child under 12 are permitted to
- *         view the program</td>
+ *         <td>ISDB_15</td>
+ *         <td>Recommended for ages 15 and over</td>
  *     </tr>
  *     <tr>
- *         <td>IL_TV_15</td>
- *         <td>Suitable for teens ages 15 and over, no child under 15 may view the programme</td>
+ *         <td>ISDB_16</td>
+ *         <td>Recommended for ages 16 and over</td>
  *     </tr>
  *     <tr>
- *         <td>IL_TV_18</td>
- *         <td>Suitable for adults only, no minors may view the programme</td>
+ *         <td>ISDB_17</td>
+ *         <td>Recommended for ages 17 and over</td>
  *     </tr>
  *     <tr>
- *         <td>IL_TV_E</td>
- *         <td>Exempt from classification</td>
+ *         <td>ISDB_18</td>
+ *         <td>Recommended for ages 18 and over</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="4">IN_TV</td>
- *         <td>IN_TV_U</td>
- *         <td>Unrestricted public exhibition</td>
+ *         <td>ISDB_19</td>
+ *         <td>Recommended for ages 19 and over</td>
  *     </tr>
  *     <tr>
- *         <td>IN_TV_U_A</td>
- *         <td>Unrestricted public exhibition, but with a caution regarding parental guidance to
- *         those under 12 years of age</td>
- *     </tr>
- *     <tr>
- *         <td>IN_TV_A</td>
- *         <td>Public exhibition restricted to adults 18 years of age and older only</td>
- *     </tr>
- *     <tr>
- *         <td>IN_TV_S</td>
- *         <td>Public exhibition restricted to members of any profession or any class of persons
- *         </td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="7">IS_TV</td>
- *         <td>IS_TV_L</td>
- *         <td>Programs suitable for all ages</td>
- *     </tr>
- *     <tr>
- *         <td>IS_TV_7</td>
- *         <td>Programs suitable for ages 7 and older</td>
- *     </tr>
- *     <tr>
- *         <td>IS_TV_10</td>
- *         <td>Programs suitable for ages 10 and older</td>
- *     </tr>
- *     <tr>
- *         <td>IS_TV_12</td>
- *         <td>Programs suitable for ages 12 and older</td>
- *     </tr>
- *     <tr>
- *         <td>IS_TV_14</td>
- *         <td>Programs suitable for ages 14 and older</td>
- *     </tr>
- *     <tr>
- *         <td>IS_TV_16</td>
- *         <td>Programs suitable for ages 16 and older</td>
- *     </tr>
- *     <tr>
- *         <td>IS_TV_18</td>
- *         <td>Programs suitable for ages 18 and older</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="4">JP_TV</td>
- *         <td>JP_TV_G</td>
- *         <td>General, suitable for all ages</td>
- *     </tr>
- *     <tr>
- *         <td>JP_TV_PG12</td>
- *         <td>Parental guidance requested for young people under 12 years</td>
- *     </tr>
- *     <tr>
- *         <td>JP_TV_R15</td>
- *         <td>For persons aged 15 and above only</td>
- *     </tr>
- *     <tr>
- *         <td>JP_TV_R18</td>
- *         <td>For persons aged 18 and above only</td>
+ *         <td>ISDB_20</td>
+ *         <td>Recommended for ages 20 and over</td>
  *     </tr>
  *     <tr>
  *         <td valign="top" rowspan="5">KR_TV</td>
@@ -957,314 +578,6 @@
  *         <td>For adults only</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="9">MV_TV</td>
- *         <td>MV_TV_Y</td>
- *         <td>Young children</td>
- *     </tr>
- *     <tr>
- *         <td>MV_TV_G</td>
- *         <td>General viewing for all ages</td>
- *     </tr>
- *     <tr>
- *         <td>MV_TV_PG</td>
- *         <td>Parental guidance is required unaccompanied children</td>
- *     </tr>
- *     <tr>
- *         <td>MV_TV_PG_12</td>
- *         <td>Parental guidance is required for children under the age of 12</td>
- *     </tr>
- *     <tr>
- *         <td>MV_TV_12</td>
- *         <td>Teens and children aged 12 and older may watch, otherwise restricted</td>
- *     </tr>
- *     <tr>
- *         <td>MV_TV_15</td>
- *         <td>Restricted to viewers aged 15 and above</td>
- *     </tr>
- *     <tr>
- *         <td>MV_TV_18</td>
- *         <td>Restricted to viewers aged 18 and above</td>
- *     </tr>
- *     <tr>
- *         <td>MV_TV_21</td>
- *         <td>Restricted to viewers aged 21 and above</td>
- *     </tr>
- *     <tr>
- *         <td>MV_TV_X</td>
- *         <td>Most restrictive classification, only adults ages 25 and above may view</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="6">MX_TV</td>
- *         <td>MX_TV_A</td>
- *         <td>Appropriate for all ages, parental guidance is recommended for children under 7 years
- *         </td>
- *     </tr>
- *     <tr>
- *         <td>MX_TV_B</td>
- *         <td>Designed for ages 12 and older, may contain some sexual situations, mild violence,
- *         and mild language</td>
- *     </tr>
- *     <tr>
- *         <td>MX_TV_B_15</td>
- *         <td>Designed for ages 15 and up, slightly more intensive than the 'A' and 'B' ratings
- *         </td>
- *     </tr>
- *     <tr>
- *         <td>MX_TV_C</td>
- *         <td>Designed to be viewed by adults aged 18 or older only, generally more intensive
- *         content</td>
- *     </tr>
- *     <tr>
- *         <td>MX_TV_D</td>
- *         <td>Designed to be viewed only by mature adults (at least 21 years of age and over),
- *         contains extreme content matter</td>
- *     </tr>
- *     <tr>
- *         <td>MX_TV_RC</td>
- *         <td>Banned from public television in Mexico</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="3">MY_TV</td>
- *         <td>MY_TV_U</td>
- *         <td>General viewing for all ages, can be broadcast anytime</td>
- *     </tr>
- *     <tr>
- *         <td>MY_TV_P13</td>
- *         <td>For viewers ages 13 and above, children under 13 needs parental guidance, can be
- *         broadcast anytime, but some elements may only be broadcast at night</td>
- *     </tr>
- *     <tr>
- *         <td>MY_TV_18</td>
- *         <td>For viewers ages 18 and above only</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="5">NL_TV</td>
- *         <td>NL_TV_AL</td>
- *         <td>All Ages</td>
- *     </tr>
- *     <tr>
- *         <td>NL_TV_6</td>
- *         <td>Parental advisory for children under 6</td>
- *     </tr>
- *     <tr>
- *         <td>NL_TV_9</td>
- *         <td>Parental advisory for children under 9</td>
- *     </tr>
- *     <tr>
- *         <td>NL_TV_12</td>
- *         <td>Parental advisory for children under 12</td>
- *     </tr>
- *     <tr>
- *         <td>NL_TV_16</td>
- *         <td>Parental advisory for children under 16</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="3">NZ_FTV</td>
- *         <td>NZ_FTV_G</td>
- *         <td>These exclude material likely to harm children under 14 and can screen at any time.
- *         Programmes may not necessarily be designed for younger viewers, but must not contain
- *         material likely to cause them undue distress or discomfort</td>
- *     </tr>
- *     <tr>
- *         <td>NZ_FTV_PGR</td>
- *         <td>Programmes more suited to more mature viewers. These are not necessarily unsuitable
- *         for children, but viewer discretion is advised, and parents and guardians are encouraged
- *         to supervise younger viewers</td>
- *     </tr>
- *     <tr>
- *         <td>NZ_FTV_AO</td>
- *         <td>Contain material of an adult nature handled in such a way that it is unsuitable for
- *         children</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="5">NZ_PTV</td>
- *         <td>NZ_PTV_G</td>
- *         <td>suitable for general audiences</td>
- *     </tr>
- *     <tr>
- *         <td>NZ_PTV_PG</td>
- *         <td>Parental guidance recommended for under 10</td>
- *     </tr>
- *     <tr>
- *         <td>NZ_PTV_M</td>
- *         <td>Suitable for mature audiences 13 and up</td>
- *     </tr>
- *     <tr>
- *         <td>NZ_PTV_16</td>
- *         <td>Suitable for viewers 16 and up</td>
- *     </tr>
- *     <tr>
- *         <td>NZ_PTV_18</td>
- *         <td>Suitable for viewers 18 and up</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="3">PE_TV</td>
- *         <td>PE_TV_A</td>
- *         <td>Suitable for all audiences</td>
- *     </tr>
- *     <tr>
- *         <td>PE_TV_14</td>
- *         <td>Suitable for people aged 14 and above only</td>
- *     </tr>
- *     <tr>
- *         <td>PE_TV_18</td>
- *         <td>Suitable for people aged 18 and above only</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="4">PE_ATV</td>
- *         <td>PE_ATV_GP</td>
- *         <td>General audience</td>
- *     </tr>
- *     <tr>
- *         <td>PE_ATV_PG</td>
- *         <td>Parental guidance required for under 6</td>
- *     </tr>
- *     <tr>
- *         <td>PE_ATV_14</td>
- *         <td>Suitable for people aged 14 and above only</td>
- *     </tr>
- *     <tr>
- *         <td>PE_ATV_18</td>
- *         <td>Suitable for people aged 18 and above only</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="3">PH_TV</td>
- *         <td>PH_TV_G</td>
- *         <td>Suitable for all public viewers</td>
- *     </tr>
- *     <tr>
- *         <td>PH_TV_PG</td>
- *         <td>Programmes rated PG may contain scenes or other content that are unsuitable for
- *         children without the guidance of a parent</td>
- *     </tr>
- *     <tr>
- *         <td>PH_TV_SPG</td>
- *         <td>Contains mature themes or moderate to intense violence, which may be deemed unfit for
- *         children to watch without strict parental supervision</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="5">PL_TV</td>
- *         <td>PL_TV_G</td>
- *         <td>Positive or neutral view of the world, little to no violence, non-sexual love, and no
- *         sexual content</td>
- *     </tr>
- *     <tr>
- *         <td>PL_TV_7</td>
- *         <td>Age 7 and above. May additionally contain some mild language, bloodless violence, and
- *         a more negative view of the world</td>
- *     </tr>
- *     <tr>
- *         <td>PL_TV_12</td>
- *         <td>Age 12 and above. May contain some foul language, some violence, and some sexual
- *         content</td>
- *     </tr>
- *     <tr>
- *         <td>PL_TV_16</td>
- *         <td>Age 16 and above. Deviant social behaviour, world filled with violence and sexuality,
- *         simplified picture of adulthood, display of physical force, especially in controversial
- *         social context, immoral behaviour without ethic dilemma, putting the blame on the victim,
- *         excessive concentration on material possessions</td>
- *     </tr>
- *     <tr>
- *         <td>PL_TV_18</td>
- *         <td>Age 18 and above. One-sided display of the joys of adult life without showing
- *         responsibilities, social justification of violent behaviour, excessive vulgarity, use of
- *         racial slurs and social stereotypes, explicit sexual content, praise of aggression or
- *         vulgarity</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="4">PT_TV</td>
- *         <td>PT_TV_T</td>
- *         <td>Suitable for all</td>
- *     </tr>
- *     <tr>
- *         <td>PT_TV_10</td>
- *         <td>May not be suitable for children under 10, parental guidance advised</td>
- *     </tr>
- *     <tr>
- *         <td>PT_TV_12</td>
- *         <td>May not be suitable for children under 12, parental guidance advised</td>
- *     </tr>
- *     <tr>
- *         <td>PT_TV_16</td>
- *         <td>Not suitable for children under 16</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="6">RO_TV</td>
- *         <td>RO_TV_Y</td>
- *         <td>Young Ages</td>
- *     </tr>
- *     <tr>
- *         <td>RO_TV_G</td>
- *         <td>General Exhibition</td>
- *     </tr>
- *     <tr>
- *         <td>RO_TV_AP</td>
- *         <td>Parental guidance is recommended for children below the age of 12</td>
- *     </tr>
- *     <tr>
- *         <td>RO_TV_12</td>
- *         <td>Forbidden for children under 12 years of age</td>
- *     </tr>
- *     <tr>
- *         <td>RO_TV_15</td>
- *         <td>Forbidden for children under 15 years of age</td>
- *     </tr>
- *     <tr>
- *         <td>RO_TV_18</td>
- *         <td>Forbidden for children under 18 years of age</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="5">RU_TV</td>
- *         <td>RU_TV_0</td>
- *         <td>Can be watched by Any Age</td>
- *     </tr>
- *     <tr>
- *         <td>RU_TV_6</td>
- *         <td>Only kids the age of 6 or older can watch</td>
- *     </tr>
- *     <tr>
- *         <td>RU_TV_12</td>
- *         <td>Only kids the age of 12 or older can watch</td>
- *     </tr>
- *     <tr>
- *         <td>RU_TV_16</td>
- *         <td>Only teens the age of 16 or older can watch</td>
- *     </tr>
- *     <tr>
- *         <td>RU_TV_18</td>
- *         <td>Restricted to children ONLY people 18 or older</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="7">RS_TV</td>
- *         <td>RS_TV_G</td>
- *         <td>Program suitable for all ages</td>
- *     </tr>
- *     <tr>
- *         <td>RS_TV_12</td>
- *         <td>Program not suitable for children under the age of 12</td>
- *     </tr>
- *     <tr>
- *         <td>RS_TV_14</td>
- *         <td>Program not suitable for children/teens under the age of 14</td>
- *     </tr>
- *     <tr>
- *         <td>RS_TV_15</td>
- *         <td>Program not suitable for children/teens under the age of 15</td>
- *     </tr>
- *     <tr>
- *         <td>RS_TV_16</td>
- *         <td>Program not suitable for children/teens under the age of 16</td>
- *     </tr>
- *     <tr>
- *         <td>RS_TV_17</td>
- *         <td>Program not suitable for children/teens under the age of 17</td>
- *     </tr>
- *     <tr>
- *         <td>RS_TV_18</td>
- *         <td>Program not suitable for minors under the age of 18</td>
- *     </tr>
- *     <tr>
  *         <td valign="top" rowspan="6">SG_TV</td>
  *         <td>SG_TV_G</td>
  *         <td>Suitable for all ages</td>
@@ -1291,101 +604,6 @@
  *         <td>Suitable for adults aged 21 and above</td>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="4">SI_TV</td>
- *         <td>SI_TV_VS</td>
- *         <td>Parental guidance suggested (for children under 6)</td>
- *     </tr>
- *     <tr>
- *         <td>SI_TV_12</td>
- *         <td>Content suitable for teens over 12 years</td>
- *     </tr>
- *     <tr>
- *         <td>SI_TV_15</td>
- *         <td>Content suitable for teens over 15 years</td>
- *     </tr>
- *     <tr>
- *         <td>SI_TV_AD</td>
- *         <td>Content exclusively for adults</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="6">TH_TV</td>
- *         <td>TH_TV_P</td>
- *         <td>Content suitable for primary school aged children</td>
- *     </tr>
- *     <tr>
- *         <td>TH_TV_C</td>
- *         <td>Content suitable for children between 6-12 years old</td>
- *     </tr>
- *     <tr>
- *         <td>TH_TV_G</td>
- *         <td>Content suitable for general audiences</td>
- *     </tr>
- *     <tr>
- *         <td>TH_TV_PG13</td>
- *         <td>Content suitable for people aged 13 and above, but can be watched by those who are
- *         under the recommended age if parental guidance is provided</td>
- *     </tr>
- *     <tr>
- *         <td>TH_TV_PG18</td>
- *         <td>Content suitable for people aged above 18 years old; those who are younger that 18
- *         must be provided with parental guidance</td>
- *     </tr>
- *     <tr>
- *         <td>TH_TV_A</td>
- *         <td>Content unsuitable for children and youngsters</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="4">TR_TV</td>
- *         <td>TR_TV_G</td>
- *         <td>General audience. Suitable for all ages</td>
- *     </tr>
- *     <tr>
- *         <td>TR_TV_7</td>
- *         <td>Suitable for ages 7 and over</td>
- *     </tr>
- *     <tr>
- *         <td>TR_TV_13</td>
- *         <td>Suitable for ages 13 and over</td>
- *     </tr>
- *     <tr>
- *         <td>TR_TV_18</td>
- *         <td>Suitable for ages 13 and over</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="4">TW_TV</td>
- *         <td>TW_TV_G</td>
- *         <td>For all ages</td>
- *     </tr>
- *     <tr>
- *         <td>TW_TV_P</td>
- *         <td>Not suitable for children under 6 years old. People aged 6 but under 12 require
- *         guidance from accompanying adults to watch</td>
- *     </tr>
- *     <tr>
- *         <td>TW_TV_PG</td>
- *         <td>Not suitable for people under 12 years of age. Parental guidance is required for
- *         people aged 12 but under 18</td>
- *     </tr>
- *     <tr>
- *         <td>TW_TV_R</td>
- *         <td>For adults only and people under 18 years of age must not watch</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="3">UA_TV</td>
- *         <td>UA_TV_G</td>
- *         <td>This program does not have age restrictions</td>
- *     </tr>
- *     <tr>
- *         <td>UA_TV_Y</td>
- *         <td>Children must view this program with parents. In it program there are fragments,
- *         which unsuitable for children</td>
- *     </tr>
- *     <tr>
- *         <td>UA_TV_R</td>
- *         <td>This program is only for adult viewers. In it there are scenes with nudity, drug use,
- *         or violence</td>
- *     </tr>
- *     <tr>
  *         <td valign="top" rowspan="6">US_TV</td>
  *         <td>US_TV_Y</td>
  *         <td>This program is designed to be appropriate for all children</td>
@@ -1413,63 +631,6 @@
  *         <td>This program is specifically designed to be viewed by adults and therefore may be
  *         unsuitable for children under 17</td>
  *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="3">VE_TV</td>
- *         <td>VE_TV_TU</td>
- *         <td>For all ages</td>
- *     </tr>
- *     <tr>
- *         <td>VE_TV_SU</td>
- *         <td>Parental guidance for young viewers</td>
- *     </tr>
- *     <tr>
- *         <td>VE_TV_A</td>
- *         <td>Mature viewers</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="6">ZA_TV</td>
- *         <td>ZA_TV_F</td>
- *         <td>This is a program/film that does not contain any obscenity, and is suitable for
- *         family viewing. A logo must be displayed in the corner of the screen for 30 seconds after
- *         each commercial break</td>
- *     </tr>
- *     <tr>
- *         <td>ZA_TV_PG</td>
- *         <td>Children under 6 may watch this program/film, but must be accompanied by an adult.
- *         This program contains an adult related theme, which might include very mild language,
- *         violence and sexual innuendo. A logo must be displayed in the corner of the screen for
- *         one minute after each commercial break</td>
- *     </tr>
- *     <tr>
- *         <td>ZA_TV_13</td>
- *         <td>Children under 13 are prohibited from watching this program/film. This program
- *         contains mild language, violence and sexual innuendo. A logo must be displayed in the
- *         corner of the screen for two minutes after each commercial break</td>
- *     </tr>
- *     <tr>
- *         <td>ZA_TV_16</td>
- *         <td>Children under 16 are prohibited from watching this program/film. It contains
- *         moderate violence, language, and some sexual situations. In the case of television, this
- *         program may only be broadcast after 9pm-4:30am. A logo must be displayed in the corner of
- *         the screen for five minutes after each commercial break. A full-screen warning must be
- *         issued before the start of the program. If the program is longer than an hour, a warning
- *         must be displayed every half an hour</td>
- *     </tr>
- *     <tr>
- *         <td>ZA_TV_18</td>
- *         <td>Children under 18 are prohibited from watching this program/film. It contains extreme
- *         violence, language and/or graphic sexual content. In the case of television, this program
- *         may only be broadcast from 10pm-4:30am. A logo must be displayed in the corner of the
- *         screen for the duration of the program. A full-screen warning must be issued before the
- *         start of the program and after each commercial break</td>
- *     </tr>
- *     <tr>
- *         <td>ZA_TV_R18</td>
- *         <td>This is reserved for films of an extreme sexual nature (pornography). R18 films may
- *         only be distributed in the form of video and DVD in a controlled environment (e.g. Adult
- *         Shops). No public viewing of this film may take place. R18 films may not be broadcast on
- *         television and in cinemas</td>
- *     </tr>
  * </table>
  *
  * <h4>System defined strings for sub-ratings</h4>
@@ -1480,101 +641,43 @@
  *         <th>Description</th>
  *     </tr>
  *     <tr>
- *         <td valign="top" rowspan="6">NL_TV</td>
- *         <td>NL_TV_V</td>
- *         <td>Violence<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9, NL_TV_12, NL_TV_16</td>
+ *         <td valign="top" rowspan="3">BR_TV</td>
+ *         <td>BR_TV_D</td>
+ *         <td>Drugs<br/>Applicable to BR_TV_L, BR_TV_10, BR_TV_12, BR_TV_14, BR_TV_16, and BR_TV_18
+ *         </td>
  *     </tr>
  *     <tr>
- *         <td>NL_TV_F</td>
- *         <td>Scary or Disturbing ContentViolence<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9,
- *         NL_TV_12, NL_TV_16</td>
+ *         <td>BR_TV_S</td>
+ *         <td>Sex<br/>Applicable to BR_TV_L, BR_TV_10, BR_TV_12, BR_TV_14, BR_TV_16, and BR_TV_18
+ *         </td>
  *     </tr>
  *     <tr>
- *         <td>NL_TV_S</td>
- *         <td>Sexual Content<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9, NL_TV_12, NL_TV_16</td>
- *     </tr>
- *     <tr>
- *         <td>NL_TV_D</td>
- *         <td>Discrimination<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9, NL_TV_12, NL_TV_16</td>
- *     </tr>
- *     <tr>
- *         <td>NL_TV_DA</td>
- *         <td>Drug and/or Alcohol abuse<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9, NL_TV_12,
- *         NL_TV_16</td>
- *     </tr>
- *     <tr>
- *         <td>NL_TV_L</td>
- *         <td>Bad Language<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9, NL_TV_12, NL_TV_16</td>
- *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="4">NZ_PTV</td>
- *         <td>NZ_PTV_C</td>
- *         <td>Content may offend<br/>Applicable to NZ_PTV_PG, NZ_PTV_M, NZ_PTV_16, NZ_PTV_18</td>
- *     </tr>
- *     <tr>
- *         <td>NZ_PTV_V</td>
- *         <td>Violence<br/>Applicable to NZ_PTV_PG, NZ_PTV_M, NZ_PTV_16, NZ_PTV_18</td>
- *     </tr>
- *     <tr>
- *         <td>NZ_PTV_L</td>
- *         <td>Language<br/>Applicable to NZ_PTV_PG, NZ_PTV_M, NZ_PTV_16, NZ_PTV_18</td>
- *     </tr>
- *     <tr>
- *         <td>NZ_PTV_S</td>
- *         <td>Sexual content<br/>Applicable to NZ_PTV_PG, NZ_PTV_M, NZ_PTV_16, NZ_PTV_18</td>
+ *         <td>BR_TV_V</td>
+ *         <td>Violence<br/>Applicable to BR_TV_L, BR_TV_10, BR_TV_12, BR_TV_14, BR_TV_16, and
+ *         BR_TV_18</td>
  *     </tr>
  *     <tr>
  *         <td valign="top" rowspan="5">US_TV</td>
  *         <td>US_TV_D</td>
- *         <td>Suggestive dialogue (Usually means talks about sex)<br/>Applicable to US_TV_PG,
- *         US_TV_14, US_TV</td>
+ *         <td>Suggestive dialogue (Usually means talks about sex)<br/>Applicable to US_TV_PG, and
+ *         US_TV_14</td>
  *     </tr>
  *     <tr>
  *         <td>US_TV_L</td>
- *         <td>Coarse language<br/>Applicable to US_TV_PG, US_TV_14</td>
+ *         <td>Coarse language<br/>Applicable to US_TV_PG, US_TV_14, and US_TV_MA</td>
  *     </tr>
  *     <tr>
  *         <td>US_TV_S</td>
- *         <td>Sexual content<br/>Applicable to US_TV_PG, US_TV_14, US_TV_MA</td>
+ *         <td>Sexual content<br/>Applicable to US_TV_PG, US_TV_14, and US_TV_MA</td>
  *     </tr>
  *     <tr>
  *         <td>US_TV_V</td>
- *         <td>Violence<br/>Applicable to US_TV_PG, US_TV_14, US_TV_MA</td>
+ *         <td>Violence<br/>Applicable to US_TV_PG, US_TV_14, and US_TV_MA</td>
  *     </tr>
  *     <tr>
  *         <td>US_TV_FV</td>
  *         <td>Fantasy violence (Children's programming only)<br/>Applicable to US_TV_Y7</td>
  *     </tr>
- *     <tr>
- *         <td valign="top" rowspan="6">ZA_TV</td>
- *         <td>ZA_TV_D</td>
- *         <td>Drug<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18, ZA_TV_R18
- *         </td>
- *     </tr>
- *     <tr>
- *         <td>ZA_TV_V</td>
- *         <td>Violence<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18, ZA_TV_R18
- *         </td>
- *     </tr>
- *     <tr>
- *         <td>ZA_TV_N</td>
- *         <td>Nudity<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18, ZA_TV_R18
- *         </td>
- *     </tr>
- *     <tr>
- *         <td>ZA_TV_P</td>
- *         <td>Prejudice<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18,
- *         ZA_TV_R18</td>
- *     </tr>
- *     <tr>
- *         <td>ZA_TV_S</td>
- *         <td>Sex<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18, ZA_TV_R18</td>
- *     </tr>
- *     <tr>
- *         <td>ZA_TV_L</td>
- *         <td>Language<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18, ZA_TV_R18
- *         </td>
- *     </tr>
  * </table>
  */
 public final class TvContentRating {
diff --git a/media/jni/android_media_ImageReader.cpp b/media/jni/android_media_ImageReader.cpp
index f4eb459..aaff9a2 100644
--- a/media/jni/android_media_ImageReader.cpp
+++ b/media/jni/android_media_ImageReader.cpp
@@ -294,7 +294,7 @@
     uint8_t* jpegBuffer = buffer->data;
 
     if (usingRGBAOverride) {
-        width *= 4;
+        width = (buffer->width + buffer->stride * (buffer->height - 1)) * 4;
     }
 
     // First check for JPEG transport header at the end of the buffer
diff --git a/packages/CaptivePortalLogin/AndroidManifest.xml b/packages/CaptivePortalLogin/AndroidManifest.xml
index c5fb167..2ec15be 100644
--- a/packages/CaptivePortalLogin/AndroidManifest.xml
+++ b/packages/CaptivePortalLogin/AndroidManifest.xml
@@ -20,6 +20,7 @@
     package="com.android.captiveportallogin" >
 
     <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 
     <application android:label="@string/app_name" >
         <activity
diff --git a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
index ae52a1e..b3a6e88 100644
--- a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
+++ b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
@@ -20,7 +20,10 @@
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.net.ConnectivityManager;
+import android.net.ConnectivityManager.NetworkCallback;
 import android.net.Network;
+import android.net.NetworkCapabilities;
+import android.net.NetworkRequest;
 import android.os.Bundle;
 import android.provider.Settings;
 import android.provider.Settings.Global;
@@ -55,6 +58,7 @@
 
     private URL mURL;
     private int mNetId;
+    private NetworkCallback mNetworkCallback;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -73,7 +77,27 @@
         getActionBar().setDisplayShowHomeEnabled(false);
 
         mNetId = Integer.parseInt(getIntent().getStringExtra(Intent.EXTRA_TEXT));
-        ConnectivityManager.setProcessDefaultNetwork(new Network(mNetId));
+        final Network network = new Network(mNetId);
+        ConnectivityManager.setProcessDefaultNetwork(network);
+
+        // Exit app if Network disappears.
+        final NetworkCapabilities networkCapabilities =
+                ConnectivityManager.from(this).getNetworkCapabilities(network);
+        if (networkCapabilities == null) {
+            finish();
+            return;
+        }
+        mNetworkCallback = new NetworkCallback() {
+            @Override
+            public void onLost(Network lostNetwork) {
+                if (network.equals(lostNetwork)) done(false);
+            }
+        };
+        final NetworkRequest.Builder builder = new NetworkRequest.Builder();
+        for (int transportType : networkCapabilities.getTransportTypes()) {
+            builder.addTransportType(transportType);
+        }
+        ConnectivityManager.from(this).registerNetworkCallback(builder.build(), mNetworkCallback);
 
         WebView myWebView = (WebView) findViewById(R.id.webview);
         WebSettings webSettings = myWebView.getSettings();
@@ -84,6 +108,7 @@
     }
 
     private void done(boolean use_network) {
+        ConnectivityManager.from(this).unregisterNetworkCallback(mNetworkCallback);
         Intent intent = new Intent(ACTION_CAPTIVE_PORTAL_LOGGED_IN);
         intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(mNetId));
         intent.putExtra(LOGGED_IN_RESULT, use_network ? "1" : "0");
diff --git a/packages/Keyguard/src/com/android/keyguard/CarrierText.java b/packages/Keyguard/src/com/android/keyguard/CarrierText.java
index 05f2962..ad07a7a 100644
--- a/packages/Keyguard/src/com/android/keyguard/CarrierText.java
+++ b/packages/Keyguard/src/com/android/keyguard/CarrierText.java
@@ -233,7 +233,11 @@
         final boolean plmnValid = !TextUtils.isEmpty(plmn);
         final boolean spnValid = !TextUtils.isEmpty(spn);
         if (plmnValid && spnValid) {
-            return new StringBuilder().append(plmn).append(mSeparator).append(spn).toString();
+            if (plmn.equals(spn)) {
+                return plmn;
+            } else {
+                return new StringBuilder().append(plmn).append(mSeparator).append(spn).toString();
+            }
         } else if (plmnValid) {
             return plmn;
         } else if (spnValid) {
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java b/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
index 34bbc2e..954046c 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeLog.java
@@ -95,10 +95,11 @@
         log("dozing " + dozing);
     }
 
-    public static void traceFling(boolean expand, boolean aboveThreshold, boolean thresholdNeeded) {
+    public static void traceFling(boolean expand, boolean aboveThreshold, boolean thresholdNeeded,
+            boolean screenOnFromTouch) {
         if (!ENABLED) return;
         log("fling expand=" + expand + " aboveThreshold=" + aboveThreshold + " thresholdNeeded="
-                + thresholdNeeded);
+                + thresholdNeeded + " screenOnFromTouch=" + screenOnFromTouch);
     }
 
     public static void traceEmergencyCall() {
diff --git a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
index 5caf1ac..8416ad7 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java
@@ -112,15 +112,11 @@
         mTaskStackBounds = new Rect();
     }
 
-    public void onStart() {}
-
-    public void onBootCompleted() {
+    public void onStart() {
         // Initialize some static datastructures
         TaskStackViewLayoutAlgorithm.initializeCurve();
         // Load the header bar layout
         reloadHeaderBarLayout();
-        mBootCompleted = true;
-
         // Try and pre-emptively bind the search widget on startup to ensure that we
         // have the right thumbnail bounds to animate to.
         if (Constants.DebugFlags.App.EnableSearchLayout) {
@@ -138,6 +134,10 @@
         }
     }
 
+    public void onBootCompleted() {
+        mBootCompleted = true;
+    }
+
     /** Shows the recents */
     public void onShowRecents(boolean triggeredFromAltTab, View statusBarView) {
         mStatusBarView = statusBarView;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
index b9efb22..26420e1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -1551,7 +1551,8 @@
     @Override
     protected void onEdgeClicked(boolean right) {
         if ((right && getRightIcon().getVisibility() != View.VISIBLE)
-                || (!right && getLeftIcon().getVisibility() != View.VISIBLE)) {
+                || (!right && getLeftIcon().getVisibility() != View.VISIBLE)
+                || isDozing()) {
             return;
         }
         mHintAnimationRunning = true;
@@ -1747,6 +1748,7 @@
         updateKeyguardStatusBarVisibility();
     }
 
+    @Override
     public boolean isDozing() {
         return mDozing;
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java
index cacc2df7..c612e4c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java
@@ -337,7 +337,8 @@
                     boolean expand = flingExpands(vel, vectorVel);
                     onTrackingStopped(expand);
                     DozeLog.traceFling(expand, mTouchAboveFalsingThreshold,
-                            mStatusBar.isFalsingThresholdNeeded());
+                            mStatusBar.isFalsingThresholdNeeded(),
+                            mStatusBar.isScreenOnComingFromTouch());
                     fling(vel, expand);
                     mUpdateFlingOnLayout = expand && mPanelClosedOnDown && !mHasLayoutedSinceDown;
                     if (mUpdateFlingOnLayout) {
@@ -914,7 +915,9 @@
     private boolean onMiddleClicked() {
         switch (mStatusBar.getBarState()) {
             case StatusBarState.KEYGUARD:
-                startUnlockHintAnimation();
+                if (!isDozing()) {
+                    startUnlockHintAnimation();
+                }
                 return true;
             case StatusBarState.SHADE_LOCKED:
                 mStatusBar.goToKeyguard();
@@ -932,6 +935,8 @@
 
     protected abstract void onEdgeClicked(boolean right);
 
+    protected abstract boolean isDozing();
+
     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
         pw.println(String.format("[PanelView(%s): expandedHeight=%f maxPanelHeight=%d closing=%s"
                 + " tracking=%s justPeeked=%s peekAnim=%s%s timeAnim=%s%s touchDisabled=%s"
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
index 79d769a..3625997 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
@@ -646,19 +646,10 @@
                     mLastSignalLevel = iconLevel = mSignalStrength.getLevel();
                 }
 
-                if (isCdma()) {
-                    if (isCdmaEri()) {
-                        iconList = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_ROAMING[mInetCondition];
-                    } else {
-                        iconList = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH[mInetCondition];
-                    }
+                if (isRoaming()) {
+                    iconList = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_ROAMING[mInetCondition];
                 } else {
-                    // Though mPhone is a Manager, this call is not an IPC
-                    if (mPhone.isNetworkRoaming()) {
-                        iconList = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_ROAMING[mInetCondition];
-                    } else {
-                        iconList = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH[mInetCondition];
-                    }
+                    iconList = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH[mInetCondition];
                 }
                 mPhoneSignalIconId = iconList[iconLevel];
                 mQSPhoneSignalIconId =
@@ -811,14 +802,9 @@
             }
         }
 
-        if (isCdma()) {
-            if (isCdmaEri()) {
-                mDataTypeIconId = TelephonyIcons.ROAMING_ICON;
-                mQSDataTypeIconId = TelephonyIcons.QS_DATA_R[mInetCondition];
-            }
-        } else if (mPhone.isNetworkRoaming()) {
-                mDataTypeIconId = TelephonyIcons.ROAMING_ICON;
-                mQSDataTypeIconId = TelephonyIcons.QS_DATA_R[mInetCondition];
+        if (isRoaming()) {
+            mDataTypeIconId = TelephonyIcons.ROAMING_ICON;
+            mQSDataTypeIconId = TelephonyIcons.QS_DATA_R[mInetCondition];
         }
     }
 
@@ -836,6 +822,14 @@
         return false;
     }
 
+    private boolean isRoaming() {
+        if (isCdma()) {
+            return isCdmaEri();
+        } else {
+            return mServiceState != null && mServiceState.getRoaming();
+        }
+    }
+
     private final void updateDataIcon() {
         int iconId;
         boolean visible = true;
@@ -1233,12 +1227,7 @@
 
             mDataTypeIconId = 0;
             mQSDataTypeIconId = 0;
-            if (isCdma()) {
-                if (isCdmaEri()) {
-                    mDataTypeIconId = TelephonyIcons.ROAMING_ICON;
-                    mQSDataTypeIconId = TelephonyIcons.QS_DATA_R[mInetCondition];
-                }
-            } else if (mPhone.isNetworkRoaming()) {
+            if (isRoaming()) {
                 mDataTypeIconId = TelephonyIcons.ROAMING_ICON;
                 mQSDataTypeIconId = TelephonyIcons.QS_DATA_R[mInetCondition];
             }
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index 42ee666..5f3b877 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -2929,6 +2929,10 @@
                             }
                         }
 
+                        // The action mode's theme may differ from the app, so
+                        // always show the status guard above it if we have one.
+                        showStatusGuard = mStatusGuard != null;
+
                         // We only need to consume the insets if the action
                         // mode is overlaid on the app content (e.g. it's
                         // sitting in a FrameLayout, see
@@ -2936,11 +2940,7 @@
                         final boolean nonOverlay = (getLocalFeatures()
                                 & (1 << FEATURE_ACTION_MODE_OVERLAY)) == 0;
                         insets = insets.consumeSystemWindowInsets(
-                                false, nonOverlay /* top */, false, false);
-
-                        // The action mode's theme may differ from the app, so
-                        // always show the status guard above it.
-                        showStatusGuard = true;
+                                false, nonOverlay && showStatusGuard /* top */, false, false);
                     } else {
                         // reset top margin
                         if (mlp.topMargin != 0) {
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index be3fc47..cc17422 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -67,6 +67,7 @@
 import android.util.Pools.SimplePool;
 import android.util.Slog;
 import android.util.SparseArray;
+import android.view.AccessibilityManagerInternal;
 import android.view.Display;
 import android.view.IWindow;
 import android.view.InputDevice;
@@ -91,6 +92,7 @@
 import com.android.internal.R;
 import com.android.internal.content.PackageMonitor;
 import com.android.internal.statusbar.IStatusBarService;
+import com.android.internal.widget.LockPatternUtils;
 import com.android.server.LocalServices;
 
 import org.xmlpull.v1.XmlPullParserException;
@@ -202,6 +204,8 @@
 
     private final UserManager mUserManager;
 
+    private final LockPatternUtils mLockPatternUtils;
+
     private int mCurrentUserId = UserHandle.USER_OWNER;
 
     //TODO: Remove this hack
@@ -225,9 +229,11 @@
         mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
         mSecurityPolicy = new SecurityPolicy();
         mMainHandler = new MainHandler(mContext.getMainLooper());
+        mLockPatternUtils = new LockPatternUtils(context);
         registerBroadcastReceivers();
         new AccessibilityContentObserver(mMainHandler).register(
                 context.getContentResolver());
+        LocalServices.addService(AccessibilityManagerInternal.class, new LocalService());
     }
 
     private UserState getUserStateLocked(int userId) {
@@ -1294,6 +1300,7 @@
         updateTouchExplorationLocked(userState);
         updateEnhancedWebAccessibilityLocked(userState);
         updateDisplayColorAdjustmentSettingsLocked(userState);
+        updateEncryptionState(userState);
         scheduleUpdateInputFilter(userState);
         scheduleUpdateClientsIfNeededLocked(userState);
     }
@@ -1570,6 +1577,21 @@
         DisplayAdjustmentUtils.applyAdjustments(mContext, userState.mUserId);
     }
 
+    private void updateEncryptionState(UserState userState) {
+        if (userState.mUserId != UserHandle.USER_OWNER) {
+            return;
+        }
+        if (hasRunningServicesLocked(userState) && LockPatternUtils.isDeviceEncrypted()) {
+            // If there are running accessibility services we do not have encryption as
+            // the user needs the accessibility layer to be running to authenticate.
+            mLockPatternUtils.clearEncryptionPassword();
+        }
+    }
+
+    private boolean hasRunningServicesLocked(UserState userState) {
+        return !userState.mBoundServices.isEmpty() || !userState.mBindingServices.isEmpty();
+    }
+
     private MagnificationSpec getCompatibleMagnificationSpecLocked(int windowId) {
         IBinder windowToken = mGlobalWindowTokens.get(windowId);
         if (windowToken == null) {
@@ -1982,7 +2004,15 @@
             } else {
                 userState.mBindingServices.add(mComponentName);
                 mService = userState.mUiAutomationServiceClient.asBinder();
-                onServiceConnected(mComponentName, mService);
+                mMainHandler.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        // Simulate asynchronous connection since in onServiceConnected
+                        // we may modify the state data in case of an error but bind is
+                        // called while iterating over the data and bad things can happen.
+                        onServiceConnected(mComponentName, mService);
+                    }
+                });
                 userState.mUiAutomationService = this;
             }
             return false;
@@ -3883,4 +3913,14 @@
             }
         }
     }
+
+    private final class LocalService extends AccessibilityManagerInternal {
+        @Override
+        public boolean isNonDefaultEncryptionPasswordAllowed() {
+            synchronized (mLock) {
+                UserState userState = getCurrentUserStateLocked();
+                return !hasRunningServicesLocked(userState);
+            }
+        }
+    }
 }
diff --git a/services/core/java/com/android/server/MountService.java b/services/core/java/com/android/server/MountService.java
index 7f24d07..b0535b3 100644
--- a/services/core/java/com/android/server/MountService.java
+++ b/services/core/java/com/android/server/MountService.java
@@ -63,6 +63,7 @@
 import android.util.Slog;
 import android.util.Xml;
 
+import android.view.AccessibilityManagerInternal;
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.app.IMediaContainerService;
@@ -557,6 +558,8 @@
 
     private final Handler mHandler;
 
+    private final AccessibilityManagerInternal mAccessibilityManagerInternal;
+
     void waitForAsecScan() {
         waitForLatch(mAsecsScanned);
     }
@@ -1454,6 +1457,9 @@
         hthread.start();
         mHandler = new MountServiceHandler(hthread.getLooper());
 
+        mAccessibilityManagerInternal = LocalServices.getService(
+                AccessibilityManagerInternal.class);
+
         // Watch for user changes
         final IntentFilter userFilter = new IntentFilter();
         userFilter.addAction(Intent.ACTION_USER_ADDED);
@@ -2254,8 +2260,15 @@
 
         final NativeDaemonEvent event;
         try {
+            // The accessibility layer may veto having a non-default encryption
+            // password because if there are enabled accessibility services the
+            // user cannot authenticate as the latter need access to the data.
+            if (!TextUtils.isEmpty(password)
+                    && !mAccessibilityManagerInternal.isNonDefaultEncryptionPasswordAllowed()) {
+                return getEncryptionState();
+            }
             event = mConnector.execute("cryptfs", "changepw", CRYPTO_TYPES[type],
-                                       new SensitiveArg(toHex(password)));
+                        new SensitiveArg(toHex(password)));
             return Integer.parseInt(event.getMessage());
         } catch (NativeDaemonConnectorException e) {
             // Encryption failed
@@ -2302,7 +2315,7 @@
      * @return The type, one of the CRYPT_TYPE_XXX consts from StorageManager.
      */
     @Override
-    public int getPasswordType() throws RemoteException {
+    public int getPasswordType() {
 
         waitForReady();
 
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 01e80b7..f430c56 100755
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -1468,6 +1468,7 @@
                 app.services.remove(r);
                 r.app = null;
                 scheduleServiceRestartLocked(r, false);
+                return;
             }
         }
 
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 12c98c1..e482273 100755
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -27,6 +27,7 @@
 import static com.android.internal.util.XmlUtils.writeIntAttribute;
 import static com.android.internal.util.XmlUtils.writeLongAttribute;
 import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST;
+import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
 import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
 import static org.xmlpull.v1.XmlPullParser.START_TAG;
 import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
@@ -1192,7 +1193,7 @@
     static final int SYSTEM_USER_START_MSG = 42;
     static final int SYSTEM_USER_CURRENT_MSG = 43;
     static final int ENTER_ANIMATION_COMPLETE_MSG = 44;
-    static final int ENABLE_SCREEN_AFTER_BOOT_MSG = 45;
+    static final int FINISH_BOOTING_MSG = 45;
     static final int START_USER_SWITCH_MSG = 46;
     static final int SEND_LOCALE_TO_MOUNT_DAEMON_MSG = 47;
 
@@ -1877,8 +1878,13 @@
                 }
                 break;
             }
-            case ENABLE_SCREEN_AFTER_BOOT_MSG: {
-                enableScreenAfterBoot();
+            case FINISH_BOOTING_MSG: {
+                if (msg.arg1 != 0) {
+                    finishBooting();
+                }
+                if (msg.arg2 != 0) {
+                    enableScreenAfterBoot();
+                }
                 break;
             }
             case SEND_LOCALE_TO_MOUNT_DAEMON_MSG: {
@@ -6258,8 +6264,9 @@
         Binder.restoreCallingIdentity(origId);
     }
 
-    void postEnableScreenAfterBootLocked() {
-        mHandler.sendEmptyMessage(ENABLE_SCREEN_AFTER_BOOT_MSG);
+    void postFinishBooting(boolean finishBooting, boolean enableScreen) {
+        mHandler.sendMessage(mHandler.obtainMessage(FINISH_BOOTING_MSG,
+                finishBooting? 1 : 0, enableScreen ? 1 : 0));
     }
 
     void enableScreenAfterBoot() {
@@ -9349,6 +9356,7 @@
                 checkTime(startTime, "getContentProviderImpl: after getProviderByClass");
                 final boolean firstClass = cpr == null;
                 if (firstClass) {
+                    final long ident = Binder.clearCallingIdentity();
                     try {
                         checkTime(startTime, "getContentProviderImpl: before getApplicationInfo");
                         ApplicationInfo ai =
@@ -9366,6 +9374,8 @@
                         cpr = new ContentProviderRecord(this, cpi, ai, comp, singleton);
                     } catch (RemoteException ex) {
                         // pm is in same process, this will never happen.
+                    } finally {
+                        Binder.restoreCallingIdentity(ident);
                     }
                 }
 
@@ -11272,6 +11282,7 @@
 
             // Start up initial activity.
             mBooting = true;
+            startHomeActivityLocked(mCurrentUserId);
 
             try {
                 if (AppGlobals.getPackageManager().hasSystemUidErrors()) {
@@ -12505,7 +12516,7 @@
 
         boolean printedAnything = false;
 
-        if (mRecentTasks.size() > 0) {
+        if (mRecentTasks != null && mRecentTasks.size() > 0) {
             boolean printedHeader = false;
 
             final int N = mRecentTasks.size();
@@ -12904,10 +12915,12 @@
             if (dumpAll) {
                 pw.println("  Total persistent processes: " + numPers);
                 pw.println("  mProcessesReady=" + mProcessesReady
-                        + " mSystemReady=" + mSystemReady);
-                pw.println("  mBooting=" + mBooting
+                        + " mSystemReady=" + mSystemReady
                         + " mBooted=" + mBooted
                         + " mFactoryTest=" + mFactoryTest);
+                pw.println("  mBooting=" + mBooting
+                        + " mCallFinishBooting=" + mCallFinishBooting
+                        + " mBootAnimationComplete=" + mBootAnimationComplete);
                 pw.print("  mLastPowerCheckRealtime=");
                         TimeUtils.formatDuration(mLastPowerCheckRealtime, pw);
                         pw.println("");
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 0646cce..c7b9d96 100755
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -1482,6 +1482,11 @@
     final boolean resumeTopActivityInnerLocked(ActivityRecord prev, Bundle options) {
         if (ActivityManagerService.DEBUG_LOCKSCREEN) mService.logLockScreen("");
 
+        if (!mService.mBooting && !mService.mBooted) {
+            // Not ready yet!
+            return false;
+        }
+
         ActivityRecord parent = mActivityContainer.mParentActivity;
         if ((parent != null && parent.state != ActivityState.RESUMED) ||
                 !mActivityContainer.isAttachedLocked()) {
@@ -3606,6 +3611,10 @@
 
         final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null;
         if (task == tr && tr.isOverHomeStack() || numTasks <= 1 && isOnHomeDisplay()) {
+            if (!mService.mBooting && !mService.mBooted) {
+                // Not ready yet!
+                return false;
+            }
             final int taskToReturnTo = tr.getTaskToReturnTo();
             tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE);
             return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null);
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 83a8d45..e9f0558 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -421,6 +421,11 @@
     }
 
     boolean resumeHomeStackTask(int homeStackTaskType, ActivityRecord prev) {
+        if (!mService.mBooting && !mService.mBooted) {
+            // Not ready yet!
+            return false;
+        }
+
         if (homeStackTaskType == RECENTS_ACTIVITY_TYPE) {
             mWindowManager.showRecentApps();
             return false;
@@ -2295,9 +2300,7 @@
             activityRemoved |= r.task.stack.destroyActivityLocked(r, true, "finish-idle");
         }
 
-        if (booting) {
-            mService.finishBooting();
-        } else {
+        if (!booting) {
             // Complete user switch
             if (startingUsers != null) {
                 for (int i = 0; i < startingUsers.size(); i++) {
@@ -2318,8 +2321,8 @@
         //dump();
         //mWindowManager.dump();
 
-        if (enableScreen) {
-            mService.postEnableScreenAfterBootLocked();
+        if (booting || enableScreen) {
+            mService.postFinishBooting(booting, enableScreen);
         }
 
         if (activityRemoved) {
@@ -2584,7 +2587,6 @@
                         r.mLaunchTaskBehind);
             }
         }
-        resumeHomeStackTask(HOME_ACTIVITY_TYPE, null);
     }
 
     void moveTaskToStack(int taskId, int stackId, boolean toTop) {
diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java
index e2a548a..e3a25c0 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController.java
@@ -227,6 +227,9 @@
     // turning off the screen.
     private boolean mPendingScreenOff;
 
+    // True if we have unfinished business and are holding a suspend blocker.
+    private boolean mUnfinishedBusiness;
+
     // The elapsed real time when the screen on was blocked.
     private long mScreenOnBlockStartRealTime;
 
@@ -633,22 +636,42 @@
             mAppliedLowPower = true;
         }
 
-        // Animate the screen brightness when the screen is on.
-        if (state != Display.STATE_OFF) {
-            animateScreenBrightness(brightness, slowChange
-                    ? BRIGHTNESS_RAMP_RATE_SLOW : BRIGHTNESS_RAMP_RATE_FAST);
-        }
-
         // Animate the screen state change unless already animating.
         animateScreenStateChange(state, performScreenOffTransition);
 
-        // Report whether the display is ready for use and all changes have been applied.
-        if (mustNotify
-                && mPendingScreenOnUnblocker == null
+        // Animate the screen brightness when the screen is on or dozing.
+        // Skip the animation when the screen is off or suspended.
+        final int actualState = mPowerState.getScreenState();
+        if (actualState == Display.STATE_ON || actualState == Display.STATE_DOZE) {
+            animateScreenBrightness(brightness,
+                    slowChange ? BRIGHTNESS_RAMP_RATE_SLOW : BRIGHTNESS_RAMP_RATE_FAST);
+        } else {
+            animateScreenBrightness(brightness, 0);
+        }
+
+        // Determine whether the display is ready for use in the newly requested state.
+        // Note that we do not wait for the brightness ramp animation to complete before
+        // reporting the display is ready because we only need to ensure the screen is in the
+        // right power state even as it continues to converge on the desired brightness.
+        final boolean ready = mPendingScreenOnUnblocker == null
                 && !mColorFadeOnAnimator.isStarted()
                 && !mColorFadeOffAnimator.isStarted()
-                && !mScreenBrightnessRampAnimator.isAnimating()
-                && mPowerState.waitUntilClean(mCleanListener)) {
+                && mPowerState.waitUntilClean(mCleanListener);
+        final boolean finished = ready
+                && !mScreenBrightnessRampAnimator.isAnimating();
+
+        // Grab a wake lock if we have unfinished business.
+        if (!finished && !mUnfinishedBusiness) {
+            if (DEBUG) {
+                Slog.d(TAG, "Unfinished business...");
+            }
+            mCallbacks.acquireSuspendBlocker();
+            mUnfinishedBusiness = true;
+        }
+
+        // Notify the power manager when ready.
+        if (ready && mustNotify) {
+            // Send state change.
             synchronized (mLock) {
                 if (!mPendingRequestChangedLocked) {
                     mDisplayReadyLocked = true;
@@ -660,6 +683,15 @@
             }
             sendOnStateChangedWithWakelock();
         }
+
+        // Release the wake lock when we have no unfinished business.
+        if (finished && mUnfinishedBusiness) {
+            if (DEBUG) {
+                Slog.d(TAG, "Finished business...");
+            }
+            mUnfinishedBusiness = false;
+            mCallbacks.releaseSuspendBlocker();
+        }
     }
 
     @Override
@@ -723,6 +755,9 @@
     }
 
     private void animateScreenBrightness(int target, int rate) {
+        if (DEBUG) {
+            Slog.d(TAG, "Animating brightness: target=" + target +", rate=" + rate);
+        }
         if (mScreenBrightnessRampAnimator.animateTo(target, rate)) {
             try {
                 mBatteryStats.noteScreenBrightness(target);
diff --git a/services/core/java/com/android/server/display/DisplayPowerState.java b/services/core/java/com/android/server/display/DisplayPowerState.java
index a7651e4..fc068af 100644
--- a/services/core/java/com/android/server/display/DisplayPowerState.java
+++ b/services/core/java/com/android/server/display/DisplayPowerState.java
@@ -80,6 +80,7 @@
         mBacklight = backlight;
         mColorFade = electronBeam;
         mPhotonicModulator = new PhotonicModulator();
+        mPhotonicModulator.start();
 
         // At boot time, we know that the screen is on and the electron beam
         // animation is not playing.  We don't know the screen's brightness though,
@@ -336,7 +337,7 @@
     /**
      * Updates the state of the screen and backlight asynchronously on a separate thread.
      */
-    private final class PhotonicModulator {
+    private final class PhotonicModulator extends Thread {
         private static final int INITIAL_SCREEN_STATE = Display.STATE_OFF; // unknown, assume off
         private static final int INITIAL_BACKLIGHT = -1; // unknown
 
@@ -361,7 +362,7 @@
 
                     if (!mChangeInProgress) {
                         mChangeInProgress = true;
-                        AsyncTask.THREAD_POOL_EXECUTOR.execute(mTask);
+                        mLock.notifyAll();
                     }
                 }
                 return !mChangeInProgress;
@@ -369,75 +370,78 @@
         }
 
         public void dump(PrintWriter pw) {
-            pw.println();
-            pw.println("Photonic Modulator State:");
-            pw.println("  mPendingState=" + Display.stateToString(mPendingState));
-            pw.println("  mPendingBacklight=" + mPendingBacklight);
-            pw.println("  mActualState=" + Display.stateToString(mActualState));
-            pw.println("  mActualBacklight=" + mActualBacklight);
-            pw.println("  mChangeInProgress=" + mChangeInProgress);
+            synchronized (mLock) {
+                pw.println();
+                pw.println("Photonic Modulator State:");
+                pw.println("  mPendingState=" + Display.stateToString(mPendingState));
+                pw.println("  mPendingBacklight=" + mPendingBacklight);
+                pw.println("  mActualState=" + Display.stateToString(mActualState));
+                pw.println("  mActualBacklight=" + mActualBacklight);
+                pw.println("  mChangeInProgress=" + mChangeInProgress);
+            }
         }
 
-        private final Runnable mTask = new Runnable() {
-            @Override
-            public void run() {
-                // Apply pending changes until done.
-                for (;;) {
-                    final int state;
-                    final boolean stateChanged;
-                    final int backlight;
-                    final boolean backlightChanged;
-                    synchronized (mLock) {
-                        state = mPendingState;
-                        stateChanged = (state != mActualState);
-                        backlight = mPendingBacklight;
-                        backlightChanged = (backlight != mActualBacklight);
-                        if (!stateChanged && !backlightChanged) {
-                            mChangeInProgress = false;
-                            break;
-                        }
-                        mActualState = state;
-                        mActualBacklight = backlight;
+        @Override
+        public void run() {
+            for (;;) {
+                // Get pending change.
+                final int state;
+                final boolean stateChanged;
+                final int backlight;
+                final boolean backlightChanged;
+                synchronized (mLock) {
+                    state = mPendingState;
+                    stateChanged = (state != mActualState);
+                    backlight = mPendingBacklight;
+                    backlightChanged = (backlight != mActualBacklight);
+                    if (!stateChanged && !backlightChanged) {
+                        // All changed applied, notify outer class and wait for more.
+                        mChangeInProgress = false;
+                        postScreenUpdateThreadSafe();
+                        try {
+                            mLock.wait();
+                        } catch (InterruptedException ex) { }
+                        continue;
                     }
-
-                    if (DEBUG) {
-                        Slog.d(TAG, "Updating screen state: state="
-                                + Display.stateToString(state) + ", backlight=" + backlight);
-                    }
-                    boolean suspending = Display.isSuspendedState(state);
-                    if (stateChanged && !suspending) {
-                        requestDisplayState(state);
-                    }
-                    if (backlightChanged) {
-                        setBrightness(backlight);
-                    }
-                    if (stateChanged && suspending) {
-                        requestDisplayState(state);
-                    }
+                    mActualState = state;
+                    mActualBacklight = backlight;
                 }
 
-                // Let the outer class know that all changes have been applied.
-                postScreenUpdateThreadSafe();
-            }
-
-            private void requestDisplayState(int state) {
-                Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestDisplayState("
-                        + Display.stateToString(state) + ")");
-                try {
-                    mBlanker.requestDisplayState(state);
-                } finally {
-                    Trace.traceEnd(Trace.TRACE_TAG_POWER);
+                // Apply pending change.
+                if (DEBUG) {
+                    Slog.d(TAG, "Updating screen state: state="
+                            + Display.stateToString(state) + ", backlight=" + backlight);
+                }
+                boolean suspending = Display.isSuspendedState(state);
+                if (stateChanged && !suspending) {
+                    requestDisplayState(state);
+                }
+                if (backlightChanged) {
+                    setBrightness(backlight);
+                }
+                if (stateChanged && suspending) {
+                    requestDisplayState(state);
                 }
             }
+        }
 
-            private void setBrightness(int backlight) {
-                Trace.traceBegin(Trace.TRACE_TAG_POWER, "setBrightness(" + backlight + ")");
-                try {
-                    mBacklight.setBrightness(backlight);
-                } finally {
-                    Trace.traceEnd(Trace.TRACE_TAG_POWER);
-                }
+        private void requestDisplayState(int state) {
+            Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestDisplayState("
+                    + Display.stateToString(state) + ")");
+            try {
+                mBlanker.requestDisplayState(state);
+            } finally {
+                Trace.traceEnd(Trace.TRACE_TAG_POWER);
             }
-        };
+        }
+
+        private void setBrightness(int backlight) {
+            Trace.traceBegin(Trace.TRACE_TAG_POWER, "setBrightness(" + backlight + ")");
+            try {
+                mBacklight.setBrightness(backlight);
+            } finally {
+                Trace.traceEnd(Trace.TRACE_TAG_POWER);
+            }
+        }
     }
 }
diff --git a/services/core/java/com/android/server/display/RampAnimator.java b/services/core/java/com/android/server/display/RampAnimator.java
index ad1e857..d71269f 100644
--- a/services/core/java/com/android/server/display/RampAnimator.java
+++ b/services/core/java/com/android/server/display/RampAnimator.java
@@ -50,20 +50,32 @@
     /**
      * Starts animating towards the specified value.
      *
-     * If this is the first time the property is being set, the value jumps
-     * directly to the target.
+     * If this is the first time the property is being set or if the rate is 0,
+     * the value jumps directly to the target.
      *
      * @param target The target value.
-     * @param rate The convergence rate, in units per second.
+     * @param rate The convergence rate in units per second, or 0 to set the value immediately.
      * @return True if the target differs from the previous target.
      */
     public boolean animateTo(int target, int rate) {
         // Immediately jump to the target the first time.
-        if (mFirstTime) {
-            mFirstTime = false;
-            mProperty.setValue(mObject, target);
-            mCurrentValue = target;
-            return true;
+        if (mFirstTime || rate <= 0) {
+            if (mFirstTime || target != mCurrentValue) {
+                mFirstTime = false;
+                mRate = 0;
+                mTargetValue = target;
+                mCurrentValue = target;
+                mProperty.setValue(mObject, target);
+                if (mAnimating) {
+                    mAnimating = false;
+                    cancelAnimationCallback();
+                }
+                if (mListener != null) {
+                    mListener.onAnimationEnd();
+                }
+                return true;
+            }
+            return false;
         }
 
         // Adjust the rate based on the closest target.
@@ -88,7 +100,7 @@
             mAnimating = true;
             mAnimatedValue = mCurrentValue;
             mLastFrameTimeNanos = System.nanoTime();
-            postCallback();
+            postAnimationCallback();
         }
 
         return changed;
@@ -108,11 +120,15 @@
         mListener = listener;
     }
 
-    private void postCallback() {
-        mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, mCallback, null);
+    private void postAnimationCallback() {
+        mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, mAnimationCallback, null);
     }
 
-    private final Runnable mCallback = new Runnable() {
+    private void cancelAnimationCallback() {
+        mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, mAnimationCallback, null);
+    }
+
+    private final Runnable mAnimationCallback = new Runnable() {
         @Override // Choreographer callback
         public void run() {
             final long frameTimeNanos = mChoreographer.getFrameTimeNanos();
@@ -144,7 +160,7 @@
             }
 
             if (mTargetValue != mCurrentValue) {
-                postCallback();
+                postAnimationCallback();
             } else {
                 mAnimating = false;
                 if (mListener != null) {
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 27184390..851cf17 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -4729,6 +4729,18 @@
         return dexCodeInstructionSets.toArray(new String[dexCodeInstructionSets.size()]);
     }
 
+    /**
+     * Returns deduplicated list of supported instructions for dex code.
+     */
+    public static String[] getAllDexCodeInstructionSets() {
+        String[] supportedInstructionSets = new String[Build.SUPPORTED_ABIS.length];
+        for (int i = 0; i < supportedInstructionSets.length; i++) {
+            String abi = Build.SUPPORTED_ABIS[i];
+            supportedInstructionSets[i] = VMRuntime.getInstructionSet(abi);
+        }
+        return getDexCodeInstructionSets(supportedInstructionSets);
+    }
+
     @Override
     public void forceDexOpt(String packageName) {
         enforceSystemOrRoot("forceDexOpt");
diff --git a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
index 468a344..111c09b 100644
--- a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
+++ b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
@@ -18,6 +18,7 @@
 
 import com.android.server.EventLogTags;
 import com.android.server.SystemService;
+import com.android.server.pm.PackageManagerService;
 
 import android.app.Notification;
 import android.app.NotificationManager;
@@ -51,6 +52,8 @@
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
 
+import dalvik.system.VMRuntime;
+
 /**
  * This class implements a service to monitor the amount of disk
  * storage space on the device.  If the free storage on device is less
@@ -89,6 +92,7 @@
     private long mLastReportedFreeMemTime;
     boolean mLowMemFlag=false;
     private boolean mMemFullFlag=false;
+    private final boolean mIsBootImageOnDisk;
     private final ContentResolver mResolver;
     private final long mTotalMemory;  // on /data
     private final StatFs mDataFileStats;
@@ -285,6 +289,10 @@
                     mLowMemFlag = false;
                 }
             }
+            if (!mLowMemFlag && !mIsBootImageOnDisk) {
+                Slog.i(TAG, "No boot image on disk due to lack of space. Sending notification");
+                sendNotification();
+            }
             if (mFreeMem < mMemFullThreshold) {
                 if (!mMemFullFlag) {
                     sendFullNotification();
@@ -314,6 +322,7 @@
         super(context);
         mLastReportedFreeMemTime = 0;
         mResolver = context.getContentResolver();
+        mIsBootImageOnDisk = isBootImageOnDisk();
         //create StatFs object
         mDataFileStats = new StatFs(DATA_PATH.getAbsolutePath());
         mSystemFileStats = new StatFs(SYSTEM_PATH.getAbsolutePath());
@@ -331,6 +340,15 @@
         mStorageNotFullIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
     }
 
+    private static boolean isBootImageOnDisk() {
+        for (String instructionSet : PackageManagerService.getAllDexCodeInstructionSets()) {
+            if (!VMRuntime.isBootClassPathOnDisk(instructionSet)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     /**
     * Initializes the disk space threshold value and posts an empty message to
     * kickstart the process.
@@ -364,7 +382,7 @@
 
         @Override
         public boolean isMemoryLow() {
-            return mLowMemFlag;
+            return mLowMemFlag || !mIsBootImageOnDisk;
         }
 
         @Override
@@ -409,6 +427,7 @@
 
         pw.print("  mLowMemFlag="); pw.print(mLowMemFlag);
         pw.print(" mMemFullFlag="); pw.println(mMemFullFlag);
+        pw.print(" mIsBootImageOnDisk="); pw.print(mIsBootImageOnDisk);
 
         pw.print("  mClearSucceeded="); pw.print(mClearSucceeded);
         pw.print(" mClearingCache="); pw.println(mClearingCache);
@@ -445,19 +464,25 @@
                         Context.NOTIFICATION_SERVICE);
         CharSequence title = context.getText(
                 com.android.internal.R.string.low_internal_storage_view_title);
-        CharSequence details = context.getText(
-                com.android.internal.R.string.low_internal_storage_view_text);
+        CharSequence details = context.getText(mIsBootImageOnDisk
+                ? com.android.internal.R.string.low_internal_storage_view_text
+                : com.android.internal.R.string.low_internal_storage_view_text_no_boot);
         PendingIntent intent = PendingIntent.getActivityAsUser(context, 0,  lowMemIntent, 0,
                 null, UserHandle.CURRENT);
-        Notification notification = new Notification();
-        notification.icon = com.android.internal.R.drawable.stat_notify_disk_full;
-        notification.tickerText = title;
+        Notification notification = new Notification.Builder(context)
+                .setSmallIcon(com.android.internal.R.drawable.stat_notify_disk_full)
+                .setTicker(title)
+                .setColor(context.getResources().getColor(
+                    com.android.internal.R.color.system_notification_accent_color))
+                .setContentTitle(title)
+                .setContentText(details)
+                .setContentIntent(intent)
+                .setStyle(new Notification.BigTextStyle()
+                      .bigText(details))
+                .setVisibility(Notification.VISIBILITY_PUBLIC)
+                .setCategory(Notification.CATEGORY_SYSTEM)
+                .build();
         notification.flags |= Notification.FLAG_NO_CLEAR;
-        notification.color = context.getResources().getColor(
-                com.android.internal.R.color.system_notification_accent_color);
-        notification.setLatestEventInfo(context, title, details, intent);
-        notification.visibility = Notification.VISIBILITY_PUBLIC;
-        notification.category = Notification.CATEGORY_SYSTEM;
         mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification,
                 UserHandle.ALL);
         context.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 999649b..41574ca 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -2712,9 +2712,10 @@
 
         if (atoken != null) {
             if (atoken.startingWindow == win) {
-                if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Nulling startingWindow " + win);
-                atoken.startingWindow = null;
-            } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
+                if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Notify removed startingWindow " + win);
+                scheduleRemoveStartingWindowLocked(atoken);
+            } else
+            if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
                 // If this is the last window and we had requested a starting
                 // transition window, well there is no point now.
                 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Nulling last startingWindow");
@@ -2722,7 +2723,7 @@
             } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
                 // If this is the last window except for a starting transition
                 // window, we need to get rid of the starting transition.
-                scheduleRemoveStartingWindow(atoken);
+                scheduleRemoveStartingWindowLocked(atoken);
             }
         }
 
@@ -4329,7 +4330,7 @@
         synchronized (mWindowMap) {
             AppWindowToken wtoken = mTokenMap.get(token).appWindowToken;
             if (wtoken.startingWindow != null) {
-                scheduleRemoveStartingWindow(wtoken);
+                scheduleRemoveStartingWindowLocked(wtoken);
             }
         }
     }
@@ -4791,14 +4792,19 @@
             if (!delayed && wtoken != null) {
                 wtoken.updateReportedVisibilityLocked();
             }
+
+            // Will only remove if startingToken non null.
+            scheduleRemoveStartingWindowLocked(startingToken);
         }
         Binder.restoreCallingIdentity(origId);
 
-        // Will only remove if startingToken non null.
-        scheduleRemoveStartingWindow(startingToken);
     }
 
-    void scheduleRemoveStartingWindow(AppWindowToken wtoken) {
+    void scheduleRemoveStartingWindowLocked(AppWindowToken wtoken) {
+        if (mH.hasMessages(H.REMOVE_STARTING, wtoken)) {
+            // Already scheduled.
+            return;
+        }
         if (wtoken != null && wtoken.startingWindow != null) {
             if (DEBUG_STARTING_WINDOW) Slog.v(TAG, Debug.getCallers(1) +
                     ": Schedule remove starting " + wtoken + (wtoken != null ?
@@ -9093,6 +9099,11 @@
                 // gotten drawn.
                 wtoken.allDrawn = true;
                 wtoken.deferClearAllDrawn = false;
+                // Ensure that apps that are mid-starting are also scheduled to have their
+                // starting windows removed after the animation is complete
+                if (wtoken.startingWindow != null && !wtoken.startingWindow.mExiting) {
+                    scheduleRemoveStartingWindowLocked(wtoken);
+                }
 
                 if (animLp != null) {
                     int layer = -1;
@@ -10236,7 +10247,7 @@
                     winAnimator.mSurfaceShown = false;
                     winAnimator.mSurfaceControl = null;
                     winAnimator.mWin.mHasSurface = false;
-                    scheduleRemoveStartingWindow(winAnimator.mWin.mAppToken);
+                    scheduleRemoveStartingWindowLocked(winAnimator.mWin.mAppToken);
                 }
 
                 try {
diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java
index 5b007d4..0c727f3 100644
--- a/services/core/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java
@@ -515,6 +515,7 @@
 
     static class SurfaceTrace extends SurfaceControl {
         private final static String SURFACE_TAG = "SurfaceTrace";
+        private final static boolean logSurfaceTrace = DEBUG_SURFACE_TRACE;
         final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>();
 
         private float mSurfaceTraceAlpha = 0;
@@ -534,7 +535,7 @@
             super(s, name, w, h, format, flags);
             mName = name != null ? name : "Not named";
             mSize.set(w, h);
-            Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
+            if (logSurfaceTrace) Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
                     + Debug.getCallers(3));
             synchronized (sSurfaces) {
                 sSurfaces.add(0, this);
@@ -544,8 +545,8 @@
         @Override
         public void setAlpha(float alpha) {
             if (mSurfaceTraceAlpha != alpha) {
-                Slog.v(SURFACE_TAG, "setAlpha(" + alpha + "): OLD:" + this + ". Called by "
-                        + Debug.getCallers(3));
+                if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setAlpha(" + alpha + "): OLD:" + this +
+                        ". Called by " + Debug.getCallers(3));
                 mSurfaceTraceAlpha = alpha;
             }
             super.setAlpha(alpha);
@@ -554,8 +555,8 @@
         @Override
         public void setLayer(int zorder) {
             if (zorder != mLayer) {
-                Slog.v(SURFACE_TAG, "setLayer(" + zorder + "): OLD:" + this + ". Called by "
-                        + Debug.getCallers(3));
+                if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setLayer(" + zorder + "): OLD:" + this
+                        + ". Called by " + Debug.getCallers(3));
                 mLayer = zorder;
             }
             super.setLayer(zorder);
@@ -576,8 +577,8 @@
         @Override
         public void setPosition(float x, float y) {
             if (x != mPosition.x || y != mPosition.y) {
-                Slog.v(SURFACE_TAG, "setPosition(" + x + "," + y + "): OLD:" + this
-                        + ". Called by " + Debug.getCallers(3));
+                if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setPosition(" + x + "," + y + "): OLD:"
+                        + this + ". Called by " + Debug.getCallers(3));
                 mPosition.set(x, y);
             }
             super.setPosition(x, y);
@@ -586,8 +587,8 @@
         @Override
         public void setSize(int w, int h) {
             if (w != mSize.x || h != mSize.y) {
-                Slog.v(SURFACE_TAG, "setSize(" + w + "," + h + "): OLD:" + this + ". Called by "
-                        + Debug.getCallers(3));
+                if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setSize(" + w + "," + h + "): OLD:"
+                        + this + ". Called by " + Debug.getCallers(3));
                 mSize.set(w, h);
             }
             super.setSize(w, h);
@@ -597,8 +598,9 @@
         public void setWindowCrop(Rect crop) {
             if (crop != null) {
                 if (!crop.equals(mWindowCrop)) {
-                    Slog.v(SURFACE_TAG, "setWindowCrop(" + crop.toShortString() + "): OLD:" + this
-                            + ". Called by " + Debug.getCallers(3));
+                    if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setWindowCrop("
+                            + crop.toShortString() + "): OLD:" + this + ". Called by "
+                            + Debug.getCallers(3));
                     mWindowCrop.set(crop);
                 }
             }
@@ -608,8 +610,8 @@
         @Override
         public void setLayerStack(int layerStack) {
             if (layerStack != mLayerStack) {
-                Slog.v(SURFACE_TAG, "setLayerStack(" + layerStack + "): OLD:" + this
-                        + ". Called by " + Debug.getCallers(3));
+                if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setLayerStack(" + layerStack + "): OLD:"
+                        + this + ". Called by " + Debug.getCallers(3));
                 mLayerStack = layerStack;
             }
             super.setLayerStack(layerStack);
@@ -618,8 +620,8 @@
         @Override
         public void setOpaque(boolean isOpaque) {
             if (isOpaque != mIsOpaque) {
-                Slog.v(SURFACE_TAG, "setOpaque(" + isOpaque + "): OLD:" + this
-                        + ". Called by " + Debug.getCallers(3));
+                if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setOpaque(" + isOpaque + "): OLD:"
+                        + this + ". Called by " + Debug.getCallers(3));
                 mIsOpaque = isOpaque;
             }
             super.setOpaque(isOpaque);
@@ -628,8 +630,9 @@
         @Override
         public void setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
             if (dsdx != mDsdx || dtdx != mDtdx || dsdy != mDsdy || dtdy != mDtdy) {
-                Slog.v(SURFACE_TAG, "setMatrix(" + dsdx + "," + dtdx + "," + dsdy + "," + dtdy +
-                        "): OLD:" + this + ". Called by " + Debug.getCallers(3));
+                if (logSurfaceTrace) Slog.v(SURFACE_TAG, "setMatrix(" + dsdx + "," + dtdx + ","
+                        + dsdy + "," + dtdy + "): OLD:" + this + ". Called by "
+                        + Debug.getCallers(3));
                 mDsdx = dsdx;
                 mDtdx = dtdx;
                 mDsdy = dsdy;
@@ -641,7 +644,8 @@
         @Override
         public void hide() {
             if (mShown) {
-                Slog.v(SURFACE_TAG, "hide: OLD:" + this + ". Called by " + Debug.getCallers(3));
+                if (logSurfaceTrace) Slog.v(SURFACE_TAG, "hide: OLD:" + this + ". Called by "
+                        + Debug.getCallers(3));
                 mShown = false;
             }
             super.hide();
@@ -650,7 +654,8 @@
         @Override
         public void show() {
             if (!mShown) {
-                Slog.v(SURFACE_TAG, "show: OLD:" + this + ". Called by " + Debug.getCallers(3));
+                if (logSurfaceTrace) Slog.v(SURFACE_TAG, "show: OLD:" + this + ". Called by "
+                        + Debug.getCallers(3));
                 mShown = true;
             }
             super.show();
@@ -659,7 +664,8 @@
         @Override
         public void destroy() {
             super.destroy();
-            Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by " + Debug.getCallers(3));
+            if (logSurfaceTrace) Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by "
+                    + Debug.getCallers(3));
             synchronized (sSurfaces) {
                 sSurfaces.remove(this);
             }
@@ -668,7 +674,7 @@
         @Override
         public void release() {
             super.release();
-            Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
+            if (logSurfaceTrace) Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
                     + Debug.getCallers(3));
             synchronized (sSurfaces) {
                 sSurfaces.remove(this);
diff --git a/services/usage/java/com/android/server/usage/UsageStatsDatabase.java b/services/usage/java/com/android/server/usage/UsageStatsDatabase.java
index 972c929..cfa4436 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsDatabase.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsDatabase.java
@@ -382,6 +382,10 @@
         File[] files = dir.listFiles();
         if (files != null) {
             for (File f : files) {
+                String path = f.getPath();
+                if (path.endsWith(".bak")) {
+                    f = new File(path.substring(0, path.length() - 4));
+                }
                 long beginTime = Long.parseLong(f.getName());
                 if (beginTime < expiryTime) {
                     new AtomicFile(f).delete();
diff --git a/tests/SharedLibrary/lib/res/layout/main.xml b/tests/SharedLibrary/lib/res/layout/main.xml
new file mode 100644
index 0000000..df0204d9
--- /dev/null
+++ b/tests/SharedLibrary/lib/res/layout/main.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="@string/sample_layout"/>
+
+    <com.google.android.test.shared_library.AddressView xmlns:address="http://schemas.android.com/apk/res-auto"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:background="#03a9f4"
+        address:name="Librarian L"
+        address:streetNumber="21"
+        address:streetName="Android Lane"
+        address:city="AndroidVille"
+        address:state="OS"
+        address:zip="12345"
+        address:country="Mobile"/>
+
+</LinearLayout>
diff --git a/tests/SharedLibrary/lib/res/values/strings.xml b/tests/SharedLibrary/lib/res/values/strings.xml
index 6827f93..9beccd9 100644
--- a/tests/SharedLibrary/lib/res/values/strings.xml
+++ b/tests/SharedLibrary/lib/res/values/strings.xml
@@ -28,4 +28,5 @@
     </string-array>
 
     <string name="racoon">Racoon</string>
+    <string name="sample_layout">This is an example of a layout this library provides.</string>
 </resources>
diff --git a/tests/SharedLibrary/lib/src/com/google/android/test/shared_library/ActivityMain.java b/tests/SharedLibrary/lib/src/com/google/android/test/shared_library/ActivityMain.java
index 895aced..4b4893c 100644
--- a/tests/SharedLibrary/lib/src/com/google/android/test/shared_library/ActivityMain.java
+++ b/tests/SharedLibrary/lib/src/com/google/android/test/shared_library/ActivityMain.java
@@ -18,15 +18,11 @@
 
 import android.app.Activity;
 import android.os.Bundle;
-import android.widget.TextView;
 
 public class ActivityMain extends Activity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-
-        TextView content = new TextView(this);
-        content.setText("Dummy main entry for this apk; not really needed...");
-        setContentView(content);
+        setContentView(R.layout.main);
     }
 }